docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class ShadowUtils

    Various utility functions used for shadows.

    Inheritance
    object
    ShadowUtils
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    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

    The results of a culling operation.

    ShadowData shadowData

    Data containing shadow settings.

    int shadowLightIndex

    The visible light index.

    int cascadeIndex

    The cascade index.

    int shadowmapWidth

    The shadow map width.

    int shadowmapHeight

    The shadow map height.

    int shadowResolution

    The shadow map resolution.

    float shadowNearPlane

    Near plane value to use for shadow frustums.

    Vector4 cascadeSplitDistance

    The culling sphere for the cascade.

    ShadowSliceData shadowSliceData

    The struct container for shadow slice data.

    Returns
    Type Description
    bool

    True if the matrix was successfully extracted.

    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

    The results of a culling operation.

    ShadowData shadowData

    Data containing shadow settings.

    int shadowLightIndex

    The visible light index.

    int cascadeIndex

    The cascade index.

    int shadowmapWidth

    The shadow map width.

    int shadowmapHeight

    The shadow map height.

    int shadowResolution

    The shadow map resolution.

    float shadowNearPlane

    Near plane value to use for shadow frustums.

    Vector4 cascadeSplitDistance

    The culling sphere for the cascade.

    ShadowSliceData shadowSliceData

    The struct container for shadow slice data.

    Matrix4x4 viewMatrix

    The view matrix to be set.

    Matrix4x4 projMatrix

    The projection matrix to be set.

    Returns
    Type Description
    bool

    True if the matrix was successfully extracted.

    ExtractDirectionalLightMatrix(ref CullingResults, UniversalShadowData, int, int, int, int, int, float, out Vector4, out ShadowSliceData)

    Extracts the directional light matrix.

    Declaration
    public static bool ExtractDirectionalLightMatrix(ref CullingResults cullResults, UniversalShadowData 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

    The results of a culling operation.

    UniversalShadowData shadowData

    Data containing shadow settings.

    int shadowLightIndex

    The visible light index.

    int cascadeIndex

    The cascade index.

    int shadowmapWidth

    The shadow map width.

    int shadowmapHeight

    The shadow map height.

    int shadowResolution

    The shadow map resolution.

    float shadowNearPlane

    Near plane value to use for shadow frustums.

    Vector4 cascadeSplitDistance

    The culling sphere for the cascade.

    ShadowSliceData shadowSliceData

    The struct container for shadow slice data.

    Returns
    Type Description
    bool

    True if the matrix was successfully extracted.

    ExtractPointLightMatrix(ref CullingResults, ref ShadowData, int, CubemapFace, float, out Matrix4x4, out Matrix4x4, out Matrix4x4, out ShadowSplitData)

    Extracts the point 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

    The results of a culling operation.

    ShadowData shadowData

    Data containing shadow settings.

    int shadowLightIndex

    The visible light index.

    CubemapFace cubemapFace

    The face of the cubemap to use.

    float fovBias

    The guard angle that must be added to a point light shadow face frustum angle in order to avoid shadows missing at the boundaries between cube faces.

    Matrix4x4 shadowMatrix

    The shadow matrix to be set.

    Matrix4x4 viewMatrix

    The view matrix to be set.

    Matrix4x4 projMatrix

    The projection matrix to be set.

    ShadowSplitData splitData

    The shadow split data containing culling information.

    Returns
    Type Description
    bool

    True if the matrix was successfully extracted.

    ExtractPointLightMatrix(ref CullingResults, UniversalShadowData, int, CubemapFace, float, out Matrix4x4, out Matrix4x4, out Matrix4x4, out ShadowSplitData)

    Extracts the point light matrix.

    Declaration
    public static bool ExtractPointLightMatrix(ref CullingResults cullResults, UniversalShadowData 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

    The results of a culling operation.

    UniversalShadowData shadowData

    Data containing shadow settings.

    int shadowLightIndex

    The visible light index.

    CubemapFace cubemapFace

    The face of the cubemap to use.

    float fovBias

    The guard angle that must be added to a point light shadow face frustum angle in order to avoid shadows missing at the boundaries between cube faces.

    Matrix4x4 shadowMatrix

    The shadow matrix to be set.

    Matrix4x4 viewMatrix

    The view matrix to be set.

    Matrix4x4 projMatrix

    The projection matrix to be set.

    ShadowSplitData splitData

    The shadow split data containing culling information.

    Returns
    Type Description
    bool

    True if the matrix was successfully extracted.

    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

    The results of a culling operation.

    ShadowData shadowData

    Data containing shadow settings.

    int shadowLightIndex

    The visible light index.

    Matrix4x4 shadowMatrix

    The shadow matrix to be set.

    Matrix4x4 viewMatrix

    The view matrix to be set.

    Matrix4x4 projMatrix

    The projection matrix to be set.

    ShadowSplitData splitData

    The shadow split data containing culling information.

    Returns
    Type Description
    bool

    True if the matrix was successfully extracted.

    ExtractSpotLightMatrix(ref CullingResults, UniversalShadowData, int, out Matrix4x4, out Matrix4x4, out Matrix4x4, out ShadowSplitData)

    Extracts the spot light matrix.

    Declaration
    public static bool ExtractSpotLightMatrix(ref CullingResults cullResults, UniversalShadowData shadowData, int shadowLightIndex, out Matrix4x4 shadowMatrix, out Matrix4x4 viewMatrix, out Matrix4x4 projMatrix, out ShadowSplitData splitData)
    Parameters
    Type Name Description
    CullingResults cullResults

    The results of a culling operation.

    UniversalShadowData shadowData

    Data containing shadow settings.

    int shadowLightIndex

    The visible light index.

    Matrix4x4 shadowMatrix

    The shadow matrix to be set.

    Matrix4x4 viewMatrix

    The view matrix to be set.

    Matrix4x4 projMatrix

    The projection matrix to be set.

    ShadowSplitData splitData

    The shadow split data containing culling information.

    Returns
    Type Description
    bool

    True if the matrix was successfully extracted.

    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.

    GetShadowBias(ref VisibleLight, int, UniversalShadowData, Matrix4x4, float)

    Calculates the depth and normal bias from a light.

    Declaration
    public static Vector4 GetShadowBias(ref VisibleLight shadowLight, int shadowLightIndex, UniversalShadowData shadowData, Matrix4x4 lightProjectionMatrix, float shadowResolution)
    Parameters
    Type Name Description
    VisibleLight shadowLight
    int shadowLightIndex
    UniversalShadowData 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

    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)