Skip to content

Commit c4dbfb9

Browse files
committed
** Increasing HDRP fined prunned light tile count to 64. **
* Missing offset * Adding the light counter as a centralized parameter in ShaderConfig.cs * Extra in comment * Making bit allocation of clustered size / counter be automatically packed from new config * Fixing some bugs with min / max * Extra comment on configuration for 8k rendering * Fixing flags for contact shadows and other review items from feedback * Changelog * Updated features and new doc for ShaderConfig light limit setting * Adding upgrade guide and what's new * Merging changes from fast PrepareLightsForGPU * Fixing MD files / whats new etc * Formatting
1 parent d0828e0 commit c4dbfb9

File tree

15 files changed

+90
-28
lines changed

15 files changed

+90
-28
lines changed

com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44

55
namespace UnityEngine.Rendering.HighDefinition
66
{
7+
//Do not change these numbers!!
8+
//Its not a full power of 2 because the last light slot is reserved.
9+
internal enum FPTLMaxLightSizes
10+
{
11+
Low = 31,
12+
High = 63
13+
}
14+
715
/// <summary>
816
/// Project-wide shader configuration options.
917
/// </summary>
@@ -36,6 +44,13 @@ public enum ShaderOptions
3644

3745
/// <summary>Support to apply a global mip bias on all texture samplers of HDRP.</summary>
3846
GlobalMipBias = 1,
47+
48+
/// <summary>
49+
/// Maximum number of lights for a fine pruned light tile. This number can only be the prespecified possibilities in FPTLMaxLightSizes
50+
/// Lower count will mean some memory savings.
51+
/// Note: For any rendering bigger than 4k (in native) it is recommended to use Low count per tile, to avoid possible artifacts.
52+
/// </summary>
53+
FPTLMaxLightCount = FPTLMaxLightSizes.High
3954
};
4055

4156
// Note: #define can't be use in include file in C# so we chose this way to configure both C# and hlsl
@@ -73,5 +88,8 @@ public class ShaderConfig
7388
/// <summary>Indicates whether to support application of global mip bias on all texture samplers of hdrp.</summary>
7489
///<seealso cref="ShaderOptions.GlobalMipBias"/>
7590
public static bool s_GlobalMipBias = (int)ShaderOptions.GlobalMipBias != 0;
91+
/// <summary>Indicates the maximum number of lights available for Fine Prunning Tile Lighting.</summary>
92+
/// <seealso cref="ShaderOptions.FPTLMaxLightCount"/>
93+
public static int FPTLMaxLightCount = (int)ShaderOptions.FPTLMaxLightCount;
7694
}
7795
}

com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs.hlsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#define SHADEROPTIONS_AREA_LIGHTS (1)
1616
#define SHADEROPTIONS_BARN_DOOR (0)
1717
#define SHADEROPTIONS_GLOBAL_MIP_BIAS (1)
18+
#define SHADEROPTIONS_FPTLMAX_LIGHT_COUNT (63)
1819

1920

2021
#endif

com.unity.render-pipelines.high-definition/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
4545

4646
### Added
4747
- Added a SG node to get the main directional light direction.
48+
- Added public API to edit materials from script at runtime.
49+
- Added new configuration ShderOptions.FPTLMaxLightCount in ShaderConfig.cs for maximum light count per fine pruned tile.
4850

4951
### Changed
5052
- MaterialReimporter.ReimportAllMaterials and MaterialReimporter.ReimportAllHDShaderGraphs now batch the asset database changes to improve performance.
@@ -58,6 +60,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
5860
- Fixed misleading text and improving the eye scene material samples. (case 1368665)
5961
- Fixed missing DisallowMultipleComponent annotations in HDAdditionalReflectionData and HDAdditionalLightData (case 1365879).
6062
- Fixed ambient occlusion strenght incorrectly using GTAOMultiBounce
63+
- Maximum light count per fine prunned tile (opaque deferred) is now 63 instead of 23.
6164

6265
## [13.0.0] - 2021-09-01
6366

com.unity.render-pipelines.high-definition/Documentation~/HDRP-Features.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,11 @@ Real time raytracing effect are currently in Preview and behavior could change i
318318

319319
<a name="Camera"></a>
320320

321+
### Light count limit
322+
323+
HDRP has a maximum limit on the number of lights a single pixel can get influence from. This setting can be configured through the ShaderConfig.cs file as the FPTLMaxLightCount. By default, HDRP's maximum light count per pixel is 63.
324+
The only two possible values HDRP supports are Low (31 lights) and High (63 lights). For more information on how to configure this setting, please see [HDRP Config package](HDRP-Config-Package.md).
325+
321326
## Camera
322327

323328
### Post-processing

com.unity.render-pipelines.high-definition/Documentation~/Upgrading-from-2021.1-to-2021.2.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ The algorithm to calculate the contribution of ambient occlusion and specular oc
3535

3636
The previous `g_vLightListGlobal` uniform have been rename to explicit `g_vLightListTile` and `g_vLightListCluster` light list name. This work required to fix a wrong behavior on console.
3737

38+
Added a new setting in ShaderConfig.cs, FPTLMaxLightCount. This setting can now set the maximum number of lights per tile on the GPU. A new Shader config project must be generated to upgrade. See the [HDRP-Config-Package](HDRP-Config-Package.md) guide for information on how to upgrade.
39+
3840
## Density Volumes
3941

4042
Density Volumes are now known as **Local Volumetric Fog**.

com.unity.render-pipelines.high-definition/Documentation~/whats-new-12.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ From HDRP 12.0, HDRP includes a new [Light Anchor](light-anchor.md) component. Y
6060
![](Images/LightAnchor0.png)
6161

6262

63+
### Maximum light count for gpu
64+
65+
The new default maximum light count per pixel for Fine Prunning Tile List is now 63.
66+
Added a new setting in ShaderConfig.cs, FPTLMaxLightCount. This setting can now set the maximum number of lights per tile on the GPU. A new Shader config project must be generated to upgrade. See the [HDRP-Config-Package](HDRP-Config-Package.md) guide for information on how to upgrade.
6367

6468
## New upsampling methods
6569

com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1534,7 +1534,7 @@ void RegisterLightingDebug()
15341534
data.fullScreenContactShadowLightIndex = value;
15351535
},
15361536
min = () => - 1, // -1 will display all contact shadow
1537-
max = () => LightDefinitions.s_LightListMaxPrunedEntries - 1
1537+
max = () => ShaderConfig.FPTLMaxLightCount - 1
15381538
},
15391539
}
15401540
});

com.unity.render-pipelines.high-definition/Runtime/Debug/DebugViewTiles.shader

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ Shader "Hidden/HDRP/DebugViewTiles"
190190

191191
#ifdef DISABLE_TILE_MODE
192192
// Tile debug mode is not supported in MSAA (only cluster)
193-
int maxLights = 32;
193+
int maxLights = (LIGHT_CLUSTER_PACKING_COUNT_MASK + 1);
194194
const int textSize = 23;
195195
const int text[textSize] = {'N', 'o', 't', ' ', 's', 'u', 'p', 'p', 'o', 'r', 't', 'e', 'd', ' ', 'w', 'i', 't', 'h', ' ', 'M', 'S', 'A', 'A'};
196196
if (input.positionCS.y < DEBUG_FONT_TEXT_HEIGHT)
@@ -209,7 +209,7 @@ Shader "Hidden/HDRP/DebugViewTiles"
209209
// Tile overlap counter
210210
if (n >= 0)
211211
{
212-
const uint maxLightsPerTile = 31;
212+
const uint maxLightsPerTile = SHADEROPTIONS_FPTLMAX_LIGHT_COUNT;
213213
const float opacity = 0.3f;
214214
result = OverlayHeatMap(int2(posInput.positionSS.xy), GetTileSize(), n, maxLightsPerTile, opacity);
215215
}
@@ -224,8 +224,8 @@ Shader "Hidden/HDRP/DebugViewTiles"
224224
}
225225

226226
// Print light lists for selected tile at the bottom of the screen
227-
int maxLights = 32;
228-
if (tileCoord.y < LIGHTCATEGORY_COUNT && tileCoord.x < maxLights + 3)
227+
int maxAreaWidth = SHADEROPTIONS_FPTLMAX_LIGHT_COUNT + 4;
228+
if (tileCoord.y < LIGHTCATEGORY_COUNT && tileCoord.x < maxAreaWidth)
229229
{
230230
float depthMouse = GetTileDepth(_MousePixelCoord.xy);
231231

com.unity.render-pipelines.high-definition/Runtime/Lighting/Light/HDGpuLightsBuilder.LightLoop.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ private void GetContactShadowMask(HDAdditionalLightData hdAdditionalLightData, B
221221
// If contact shadows are not enabled or we already reached the manimal number of contact shadows
222222
// or this is not rasterization
223223
if ((!hdAdditionalLightData.useContactShadow.Value(contactShadowEnabled))
224-
|| m_ContactShadowIndex >= LightDefinitions.s_LightListMaxPrunedEntries)
224+
|| m_ContactShadowIndex >= LightDefinitions.s_ContactShadowMaskMask)
225225
return;
226226

227227
// Evaluate the contact shadow index of this light

com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,16 @@ class LightDefinitions
107107

108108
// light list limits
109109
public static int s_LightListMaxCoarseEntries = 64;
110-
public static int s_LightListMaxPrunedEntries = 24;
111110
public static int s_LightClusterMaxCoarseEntries = 128;
112111

112+
// We have room for ShaderConfig.FPTLMaxLightCount lights, plus 1 implicit value for length.
113+
// We allocate only 16 bits per light index & length, thus we divide by 2, and store in a word buffer.
114+
public static int s_LightDwordPerFptlTile = ((ShaderConfig.FPTLMaxLightCount + 1)) / 2;
115+
public static int s_LightClusterPackingCountBits = (int)Mathf.Ceil(Mathf.Log(Mathf.NextPowerOfTwo(ShaderConfig.FPTLMaxLightCount), 2));
116+
public static int s_LightClusterPackingCountMask = (1 << s_LightClusterPackingCountBits) - 1;
117+
public static int s_LightClusterPackingOffsetBits = 32 - s_LightClusterPackingCountBits;
118+
public static int s_LightClusterPackingOffsetMask = (1 << s_LightClusterPackingOffsetBits) - 1;
119+
113120
// Following define the maximum number of bits use in each feature category.
114121
public static uint s_LightFeatureMaskFlags = 0xFFF000;
115122
public static uint s_LightFeatureMaskFlagsOpaque = 0xFFF000 & ~((uint)LightFeatureFlags.SSRefraction); // Opaque don't support screen space refraction
@@ -121,6 +128,13 @@ class LightDefinitions
121128
public static uint s_ScreenSpaceColorShadowFlag = 0x100;
122129
public static uint s_InvalidScreenSpaceShadow = 0xff;
123130
public static uint s_ScreenSpaceShadowIndexMask = 0xff;
131+
132+
//Contact shadow bit definitions
133+
public static int s_ContactShadowFadeBits = 8;
134+
public static int s_ContactShadowMaskBits = 32 - s_ContactShadowFadeBits;
135+
public static int s_ContactShadowFadeMask = (1 << s_ContactShadowFadeBits) - 1;
136+
public static int s_ContactShadowMaskMask = (1 << s_ContactShadowMaskBits) - 1;
137+
124138
}
125139

126140
[GenerateHLSL]
@@ -2131,14 +2145,15 @@ bool WillRenderContactShadow()
21312145

21322146
// The first rendered 24 lights that have contact shadow enabled have a mask used to select the bit that contains
21332147
// the contact shadow shadowed information (occluded or not). Otherwise -1 is written
2148+
// 8 bits are reserved for the fading.
21342149
void GetContactShadowMask(HDAdditionalLightData hdAdditionalLightData, BoolScalableSetting contactShadowEnabled, HDCamera hdCamera, bool isRasterization, ref int contactShadowMask, ref float rayTracingShadowFlag)
21352150
{
21362151
contactShadowMask = 0;
21372152
rayTracingShadowFlag = 0.0f;
21382153
// If contact shadows are not enabled or we already reached the manimal number of contact shadows
21392154
// or this is not rasterization
21402155
if ((!hdAdditionalLightData.useContactShadow.Value(contactShadowEnabled))
2141-
|| m_ContactShadowIndex >= LightDefinitions.s_LightListMaxPrunedEntries
2156+
|| m_ContactShadowIndex >= LightDefinitions.s_ContactShadowMaskMask
21422157
|| !isRasterization)
21432158
return;
21442159

0 commit comments

Comments
 (0)