Class ShadowUtils
Various utility functions used for shadows.
Inherited Members
Namespace: UnityEngine.Rendering.Universal
Syntax
public static class ShadowUtils
Methods
AllocShadowRT(Int32, Int32, Int32, Int32, Single, 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 |
---|---|---|
Int32 | width | Width of the Shadow Map. |
Int32 | height | Height of the Shadow Map. |
Int32 | bits | Minimum depth bits of the Shadow Map. |
Int32 | anisoLevel | Anisotropic filtering level of the Shadow Map. |
Single | 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, Int32, Int32)
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 | |
Int32 | atlasWidth | |
Int32 | atlasHeight |
ExtractDirectionalLightMatrix(ref CullingResults, ref ShadowData, Int32, Int32, Int32, Int32, Int32, Single, 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 | |
Int32 | shadowLightIndex | |
Int32 | cascadeIndex | |
Int32 | shadowmapWidth | |
Int32 | shadowmapHeight | |
Int32 | shadowResolution | |
Single | shadowNearPlane | |
Vector4 | cascadeSplitDistance | |
ShadowSliceData | shadowSliceData |
Returns
Type | Description |
---|---|
Boolean |
ExtractDirectionalLightMatrix(ref CullingResults, ref ShadowData, Int32, Int32, Int32, Int32, Int32, Single, 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 | |
Int32 | shadowLightIndex | |
Int32 | cascadeIndex | |
Int32 | shadowmapWidth | |
Int32 | shadowmapHeight | |
Int32 | shadowResolution | |
Single | shadowNearPlane | |
Vector4 | cascadeSplitDistance | |
ShadowSliceData | shadowSliceData | |
Matrix4x4 | viewMatrix | |
Matrix4x4 | projMatrix |
Returns
Type | Description |
---|---|
Boolean |
ExtractPointLightMatrix(ref CullingResults, ref ShadowData, Int32, CubemapFace, Single, 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 | |
Int32 | shadowLightIndex | |
CubemapFace | cubemapFace | |
Single | fovBias | |
Matrix4x4 | shadowMatrix | |
Matrix4x4 | viewMatrix | |
Matrix4x4 | projMatrix | |
ShadowSplitData | splitData |
Returns
Type | Description |
---|---|
Boolean |
ExtractSpotLightMatrix(ref CullingResults, ref ShadowData, Int32, 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 | |
Int32 | shadowLightIndex | |
Matrix4x4 | shadowMatrix | |
Matrix4x4 | viewMatrix | |
Matrix4x4 | projMatrix | |
ShadowSplitData | splitData |
Returns
Type | Description |
---|---|
Boolean |
GetMaxTileResolutionInAtlas(Int32, Int32, Int32)
Calculates the maximum tile resolution in an Atlas.
Declaration
public static int GetMaxTileResolutionInAtlas(int atlasWidth, int atlasHeight, int tileCount)
Parameters
Type | Name | Description |
---|---|---|
Int32 | atlasWidth | |
Int32 | atlasHeight | |
Int32 | tileCount |
Returns
Type | Description |
---|---|
Int32 | The maximum tile resolution in an Atlas. |
GetShadowBias(ref VisibleLight, Int32, ref ShadowData, Matrix4x4, Single)
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 | |
Int32 | shadowLightIndex | |
ShadowData | shadowData | |
Matrix4x4 | lightProjectionMatrix | |
Single | 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, Int32, Int32, Int32, Int32, Single, 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). |
Int32 | width | Width of the RTHandle to match. |
Int32 | height | Height of the RTHandle to match. |
Int32 | bits | Depth bits of the RTHandle to match. |
Int32 | anisoLevel | Anisotropic filtering level of the RTHandle to match. |
Single | 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 |
---|---|
Boolean | If the RTHandle needs to be re-allocated |
ShadowRTReAllocateIfNeeded(ref RTHandle, Int32, Int32, Int32, Int32, Single, 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 = 0F, string name = "")
Parameters
Type | Name | Description |
---|---|---|
RTHandle | handle | RTHandle to check (can be null). |
Int32 | width | Width of the Shadow Map. |
Int32 | height | Height of the Shadow Map. |
Int32 | bits | Minimum depth bits of the Shadow Map. |
Int32 | anisoLevel | Anisotropic filtering level of the Shadow Map. |
Single | mipMapBias | Bias applied to mipmaps during filtering of the Shadow Map. |
String | name | Name of the Shadow Map. |
Returns
Type | Description |
---|---|
Boolean | If the RTHandle was re-allocated |