Class ShadowUtils
Various utility functions used for shadows.
Inherited Members
Namespace: UnityEngine.Rendering.Universal
Assembly: Unity.RenderPipelines.Universal.Runtime.dll
Syntax
public static class ShadowUtils
Methods
AllocShadowRT(int, int, int, int, float, string)
Allocate a Shadow Map
Declaration
public static RTHandle AllocShadowRT(int width, int height, int bits, int anisoLevel, float mipMapBias, string name)
Parameters
Type | Name | Description |
---|---|---|
int | width | Width of the Shadow Map. |
int | height | Height of the Shadow Map. |
int | bits | Minimum depth bits of the Shadow Map. |
int | anisoLevel | Anisotropic filtering level of the Shadow Map. |
float | mipMapBias | Bias applied to mipmaps during filtering of the Shadow Map. |
string | name | Name of the Shadow Map. |
Returns
Type | Description |
---|---|
RTHandle | If an RTHandle for the Shadow Map |
ApplySliceTransform(ref ShadowSliceData, int, int)
Used for baking bake cascade transforms in each shadow matrix.
Declaration
public static void ApplySliceTransform(ref ShadowSliceData shadowSliceData, int atlasWidth, int atlasHeight)
Parameters
Type | Name | Description |
---|---|---|
ShadowSliceData | shadowSliceData | |
int | atlasWidth | |
int | atlasHeight |
ExtractDirectionalLightMatrix(ref CullingResults, ref ShadowData, int, int, int, int, int, float, out Vector4, out ShadowSliceData)
Extracts the directional light matrix.
Declaration
public static bool ExtractDirectionalLightMatrix(ref CullingResults cullResults, ref ShadowData shadowData, int shadowLightIndex, int cascadeIndex, int shadowmapWidth, int shadowmapHeight, int shadowResolution, float shadowNearPlane, out Vector4 cascadeSplitDistance, out ShadowSliceData shadowSliceData)
Parameters
Type | Name | Description |
---|---|---|
CullingResults | cullResults | |
ShadowData | shadowData | |
int | shadowLightIndex | |
int | cascadeIndex | |
int | shadowmapWidth | |
int | shadowmapHeight | |
int | shadowResolution | |
float | shadowNearPlane | |
Vector4 | cascadeSplitDistance | |
ShadowSliceData | shadowSliceData |
Returns
Type | Description |
---|---|
bool |
ExtractDirectionalLightMatrix(ref CullingResults, ref ShadowData, int, int, int, int, int, float, out Vector4, out ShadowSliceData, out Matrix4x4, out Matrix4x4)
Extracts the directional light matrix.
Declaration
public static bool ExtractDirectionalLightMatrix(ref CullingResults cullResults, ref ShadowData shadowData, int shadowLightIndex, int cascadeIndex, int shadowmapWidth, int shadowmapHeight, int shadowResolution, float shadowNearPlane, out Vector4 cascadeSplitDistance, out ShadowSliceData shadowSliceData, out Matrix4x4 viewMatrix, out Matrix4x4 projMatrix)
Parameters
Type | Name | Description |
---|---|---|
CullingResults | cullResults | |
ShadowData | shadowData | |
int | shadowLightIndex | |
int | cascadeIndex | |
int | shadowmapWidth | |
int | shadowmapHeight | |
int | shadowResolution | |
float | shadowNearPlane | |
Vector4 | cascadeSplitDistance | |
ShadowSliceData | shadowSliceData | |
Matrix4x4 | viewMatrix | |
Matrix4x4 | projMatrix |
Returns
Type | Description |
---|---|
bool |
ExtractPointLightMatrix(ref CullingResults, ref ShadowData, int, CubemapFace, float, out Matrix4x4, out Matrix4x4, out Matrix4x4, out ShadowSplitData)
Extracts the spot light matrix.
Declaration
public static bool ExtractPointLightMatrix(ref CullingResults cullResults, ref ShadowData shadowData, int shadowLightIndex, CubemapFace cubemapFace, float fovBias, out Matrix4x4 shadowMatrix, out Matrix4x4 viewMatrix, out Matrix4x4 projMatrix, out ShadowSplitData splitData)
Parameters
Type | Name | Description |
---|---|---|
CullingResults | cullResults | |
ShadowData | shadowData | |
int | shadowLightIndex | |
CubemapFace | cubemapFace | |
float | fovBias | |
Matrix4x4 | shadowMatrix | |
Matrix4x4 | viewMatrix | |
Matrix4x4 | projMatrix | |
ShadowSplitData | splitData |
Returns
Type | Description |
---|---|
bool |
ExtractSpotLightMatrix(ref CullingResults, ref ShadowData, int, out Matrix4x4, out Matrix4x4, out Matrix4x4, out ShadowSplitData)
Extracts the spot light matrix.
Declaration
public static bool ExtractSpotLightMatrix(ref CullingResults cullResults, ref ShadowData shadowData, int shadowLightIndex, out Matrix4x4 shadowMatrix, out Matrix4x4 viewMatrix, out Matrix4x4 projMatrix, out ShadowSplitData splitData)
Parameters
Type | Name | Description |
---|---|---|
CullingResults | cullResults | |
ShadowData | shadowData | |
int | shadowLightIndex | |
Matrix4x4 | shadowMatrix | |
Matrix4x4 | viewMatrix | |
Matrix4x4 | projMatrix | |
ShadowSplitData | splitData |
Returns
Type | Description |
---|---|
bool |
GetMaxTileResolutionInAtlas(int, int, int)
Calculates the maximum tile resolution in an Atlas.
Declaration
public static int GetMaxTileResolutionInAtlas(int atlasWidth, int atlasHeight, int tileCount)
Parameters
Type | Name | Description |
---|---|---|
int | atlasWidth | |
int | atlasHeight | |
int | tileCount |
Returns
Type | Description |
---|---|
int | The maximum tile resolution in an Atlas. |
GetShadowBias(ref VisibleLight, int, ref ShadowData, Matrix4x4, float)
Calculates the depth and normal bias from a light.
Declaration
public static Vector4 GetShadowBias(ref VisibleLight shadowLight, int shadowLightIndex, ref ShadowData shadowData, Matrix4x4 lightProjectionMatrix, float shadowResolution)
Parameters
Type | Name | Description |
---|---|---|
VisibleLight | shadowLight | |
int | shadowLightIndex | |
ShadowData | shadowData | |
Matrix4x4 | lightProjectionMatrix | |
float | shadowResolution |
Returns
Type | Description |
---|---|
Vector4 | The depth and normal bias from a visible light. |
RenderShadowSlice(CommandBuffer, ref ScriptableRenderContext, ref ShadowSliceData, ref ShadowDrawingSettings)
Renders shadows to a shadow slice.
Declaration
public static void RenderShadowSlice(CommandBuffer cmd, ref ScriptableRenderContext context, ref ShadowSliceData shadowSliceData, ref ShadowDrawingSettings settings)
Parameters
Type | Name | Description |
---|---|---|
CommandBuffer | cmd | |
ScriptableRenderContext | context | |
ShadowSliceData | shadowSliceData | |
ShadowDrawingSettings | settings |
RenderShadowSlice(CommandBuffer, ref ScriptableRenderContext, ref ShadowSliceData, ref ShadowDrawingSettings, Matrix4x4, Matrix4x4)
Renders shadows to a shadow slice.
Declaration
public static void RenderShadowSlice(CommandBuffer cmd, ref ScriptableRenderContext context, ref ShadowSliceData shadowSliceData, ref ShadowDrawingSettings settings, Matrix4x4 proj, Matrix4x4 view)
Parameters
Type | Name | Description |
---|---|---|
CommandBuffer | cmd | |
ScriptableRenderContext | context | |
ShadowSliceData | shadowSliceData | |
ShadowDrawingSettings | settings | |
Matrix4x4 | proj | |
Matrix4x4 | view |
SetupShadowCasterConstantBuffer(CommandBuffer, ref VisibleLight, Vector4)
Sets up the shadow bias, light direction and position for rendering.
Declaration
public static void SetupShadowCasterConstantBuffer(CommandBuffer cmd, ref VisibleLight shadowLight, Vector4 shadowBias)
Parameters
Type | Name | Description |
---|---|---|
CommandBuffer | cmd | |
VisibleLight | shadowLight | |
Vector4 | shadowBias |
ShadowRTNeedsReAlloc(RTHandle, int, int, int, int, float, string)
Return true if handle does not match the requirements
Declaration
public static bool ShadowRTNeedsReAlloc(RTHandle handle, int width, int height, int bits, int anisoLevel, float mipMapBias, string name)
Parameters
Type | Name | Description |
---|---|---|
RTHandle | handle | RTHandle to check (can be null). |
int | width | Width of the RTHandle to match. |
int | height | Height of the RTHandle to match. |
int | bits | Depth bits of the RTHandle to match. |
int | anisoLevel | Anisotropic filtering level of the RTHandle to match. |
float | mipMapBias | Bias applied to mipmaps during filtering of the RTHandle to match. |
string | name | Name of the RTHandle of the RTHandle to match. |
Returns
Type | Description |
---|---|
bool | If the RTHandle needs to be re-allocated |
ShadowRTReAllocateIfNeeded(ref RTHandle, int, int, int, int, float, string)
Allocate a Shadow Map or re-allocate if it doesn't match requirements. For use only if the map requirements changes at runtime.
Declaration
public static bool ShadowRTReAllocateIfNeeded(ref RTHandle handle, int width, int height, int bits, int anisoLevel = 1, float mipMapBias = 0, string name = "")
Parameters
Type | Name | Description |
---|---|---|
RTHandle | handle | RTHandle to check (can be null). |
int | width | Width of the Shadow Map. |
int | height | Height of the Shadow Map. |
int | bits | Minimum depth bits of the Shadow Map. |
int | anisoLevel | Anisotropic filtering level of the Shadow Map. |
float | mipMapBias | Bias applied to mipmaps during filtering of the Shadow Map. |
string | name | Name of the Shadow Map. |
Returns
Type | Description |
---|---|
bool | If the RTHandle was re-allocated |