//----------------------------------------------------------------------------- // Configuration //----------------------------------------------------------------------------- using System; namespace UnityEngine.Rendering.HighDefinition { //Do not change these numbers!! //Its not a full power of 2 because the last light slot is reserved. internal enum FPTLMaxLightSizes { Low = 31, High = 63, Higher = 127, Ultra = 255 } internal enum PathTracingLightListSizes { Low = 8, Medium = 16, High = 32, Ultra = 64 } /// /// Project-wide shader configuration options. /// /// This enum will generate the proper shader defines. /// [GenerateHLSL(PackingRules.Exact)] public enum ShaderOptions { /// Supports colored shadows in shaders. ColoredShadow = 1, /// Uses [camera-relative rendering](../manual/Camera-Relative-Rendering.md) to enhance precision. CameraRelativeRendering = 1, /// Uses pre-exposition to enhance color precision. PreExposition = 1, /// Precomputes atmospheric attenuation for the directional light on the CPU. This makes it independent from the fragment's position, which increases performance but reduces accuracy. PrecomputedAtmosphericAttenuation = 1, /// Maximum number of views for XR. #if ENABLE_VR XrMaxViews = 2, #else XrMaxViews = 1, #endif /// Support for area lights. AreaLights = 1, /// Support for barn doors. BarnDoor = 0, /// Support to apply a global mip bias on all texture samplers of HDRP. GlobalMipBias = 1, /// /// Maximum number of lights for a fine pruned light tile. This number can only be the prespecified possibilities in FPTLMaxLightSizes /// Lower count will mean some memory savings. /// Note: For any rendering bigger than 4k (in native) it is recommended to use Low count per tile, to avoid possible artifacts. /// FPTLMaxLightCount = FPTLMaxLightSizes.High, /// /// The upper limit for the maximum amount of elements per cell in the light cluster. The maximum can be set in the project settings. This value caps the maximum. /// LightClusterMaxCellElementCount = 24, /// /// Maximum number of lights used in the path tracer light list. This number can be one of the prespecified possibilities in PathTracingLightListSizes, or can be chosen manually. /// Lower count will mean some memory savings. /// PathTracingMaxLightCount = PathTracingLightListSizes.Medium }; // Note: #define can't be use in include file in C# so we chose this way to configure both C# and hlsl // Changing a value in this enum Config here require to regenerate the hlsl include and recompile C# and shaders /// /// Project-wide shader configuration options. /// This class reflects the enum. Use it in C# code to check the current configuration. /// public class ShaderConfig { // REALLY IMPORTANT! This needs to be the maximum possible XrMaxViews for any supported platform! // this needs to be constant and not vary like XrMaxViews does as it is used to generate the cbuffer declarations /// Maximum number of XR views for constant buffer allocation. public const int k_XRMaxViewsForCBuffer = 2; /// Indicates whether to use [camera-relative rendering](../manual/Camera-Relative-Rendering.md) to enhance precision. /// public static int s_CameraRelativeRendering = (int)ShaderOptions.CameraRelativeRendering; /// Indicates whether to use pre-exposition to enhance color prevision. /// public static int s_PreExposition = (int)ShaderOptions.PreExposition; /// Specifies the maximum number of views to use for XR rendering. /// public static int s_XrMaxViews = (int)ShaderOptions.XrMaxViews; /// Indicates whether to precompute atmosphere attenuation for the directional light on the CPU. /// public static int s_PrecomputedAtmosphericAttenuation = (int)ShaderOptions.PrecomputedAtmosphericAttenuation; /// Indicates whether to support area lights. /// public static int s_AreaLights = (int)ShaderOptions.AreaLights; /// Indicates whether to support barn doors. /// public static int s_BarnDoor = (int)ShaderOptions.BarnDoor; /// Indicates whether to support application of global mip bias on all texture samplers of hdrp. /// public static bool s_GlobalMipBias = (int)ShaderOptions.GlobalMipBias != 0; /// Indicates the maximum number of lights available for Fine Prunning Tile Lighting. /// public static int FPTLMaxLightCount = (int)ShaderOptions.FPTLMaxLightCount; /// Indicates the cap on the maximum number of elements per cell in the light cluster. /// public const int LightClusterMaxCellElementCount = (int)ShaderOptions.LightClusterMaxCellElementCount; /// Indicates the maximum number of lights in the path tracing light list. /// public static int PathTracingMaxLightCount = (int)ShaderOptions.PathTracingMaxLightCount; } /// /// Internal definitions for FPTL and light culling algorithms. Do not modify, these variables are /// generated from the FPTLMaxLightCount setting automatically. /// [GenerateHLSL] public class InternalLightCullingDefs { /// Maximum number of lights for a big tile. Do not modify value, since its generated from ShaderConfig.FPTLMaxLightCount. public static int s_MaxNrBigTileLightsPlusOne = Math.Clamp((ShaderConfig.FPTLMaxLightCount + 1) * 8, 512, 1024); // if light count is 64, may be overkill but the footprint is 2 bits per pixel using uint16. // light list limits /// Maximum number of lights for coarse entries (before fine prunning). Do not modify value, since its generated from ShaderConfig.FPTLMaxLightCount. public static int s_LightListMaxCoarseEntries = Math.Clamp(ShaderConfig.FPTLMaxLightCount + 1, 64, 256); /// Maximum number of lights for cluster coarse entries. Do not modify value, since its generated from ShaderConfig.FPTLMaxLightCount. public static int s_LightClusterMaxCoarseEntries = Math.Clamp((ShaderConfig.FPTLMaxLightCount + 1) * 2, 128, 256); // we expect coarse cluster max count to grow with FPTL light count // We have room for ShaderConfig.FPTLMaxLightCount lights, plus 1 implicit value for length. // We allocate only 16 bits per light index & length, thus we divide by 2, and store in a word buffer. /// Maximum number of dwords per tile. Each light occupies 16 bits. Do not modify value, since its generated from ShaderConfig.FPTLMaxLightCount. public static int s_LightDwordPerFptlTile = ((ShaderConfig.FPTLMaxLightCount + 1)) / 2; /// Number of bits required to pack cluster count. Do not modify value, since its generated from ShaderConfig.FPTLMaxLightCount. public static int s_LightClusterPackingCountBits = (int)Mathf.Ceil(Mathf.Log(Mathf.NextPowerOfTwo(ShaderConfig.FPTLMaxLightCount), 2)); /// Bit mask for packing cluster count. Do not modify value, since its generated from ShaderConfig.FPTLMaxLightCount. public static int s_LightClusterPackingCountMask = (1 << s_LightClusterPackingCountBits) - 1; /// Number of bits required to pack a cluster offset. Do not modify value, since its generated from ShaderConfig.FPTLMaxLightCount. public static int s_LightClusterPackingOffsetBits = 32 - s_LightClusterPackingCountBits; /// Bit mask for packing cluster light offset. Do not modify value, since its generated from ShaderConfig.FPTLMaxLightCount. public static int s_LightClusterPackingOffsetMask = (1 << s_LightClusterPackingOffsetBits) - 1; } }