-
Notifications
You must be signed in to change notification settings - Fork 860
Increasing HDRP fined pruned light tile count to 63. #5771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,8 +4,6 @@ | |
| #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs.hlsl" | ||
| #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/CookieSampling.hlsl" | ||
|
|
||
| #define DWORD_PER_TILE 16 // See dwordsPerTile in LightLoop.cs, we have roomm for 31 lights and a number of light value all store on 16 bit (ushort) | ||
|
|
||
| // Some file may not required HD shadow context at all. In this case provide an empty one | ||
| // Note: if a double defintion error occur it is likely have include HDShadow.hlsl (and so HDShadowContext.hlsl) after lightloopdef.hlsl | ||
| #ifndef HAVE_HD_SHADOW_CONTEXT | ||
|
|
@@ -192,7 +190,7 @@ void GetCountAndStartTile(PositionInputs posInput, uint lightCategory, out uint | |
| #endif | ||
|
|
||
| // The first entry inside a tile is the number of light for lightCategory (thus the +0) | ||
| lightCount = g_vLightListTile[DWORD_PER_TILE * tileOffset + 0] & 0xffff; | ||
| lightCount = g_vLightListTile[LIGHT_DWORD_PER_FPTL_TILE * tileOffset + 0] & 0xffff; | ||
| start = tileOffset; | ||
| } | ||
|
|
||
|
|
@@ -212,7 +210,7 @@ uint FetchIndex(uint tileOffset, uint lightOffset) | |
| { | ||
| const uint lightOffsetPlusOne = lightOffset + 1; // Add +1 as first slot is reserved to store number of light | ||
| // Light index are store on 16bit | ||
| return (g_vLightListTile[DWORD_PER_TILE * tileOffset + (lightOffsetPlusOne >> 1)] >> ((lightOffsetPlusOne & 1) * DWORD_PER_TILE)) & 0xffff; | ||
| return (g_vLightListTile[LIGHT_DWORD_PER_FPTL_TILE * tileOffset + (lightOffsetPlusOne >> 1)] >> ((lightOffsetPlusOne & 1) * 16)) & 0xffff; | ||
| } | ||
|
|
||
| #elif defined(USE_CLUSTERED_LIGHTLIST) | ||
|
|
@@ -236,15 +234,20 @@ uint GetLightClusterIndex(uint2 tileIndex, float linearDepth) | |
| return SnapToClusterIdxFlex(linearDepth, logBase, g_isLogBaseBufferEnabled != 0); | ||
| } | ||
|
|
||
| void UnpackClusterLayeredOffset(uint packedValue, out uint offset, out uint count) | ||
| { | ||
| offset = packedValue & LIGHT_CLUSTER_PACKING_OFFSET_MASK; | ||
| count = packedValue >> LIGHT_CLUSTER_PACKING_OFFSET_BITS; | ||
| } | ||
|
|
||
| void GetCountAndStartCluster(uint2 tileIndex, uint clusterIndex, uint lightCategory, out uint start, out uint lightCount) | ||
| { | ||
| int nrClusters = (1 << g_iLog2NumClusters); | ||
|
|
||
| const int idx = GenerateLayeredOffsetBufferIndex(lightCategory, tileIndex, clusterIndex, _NumTileClusteredX, _NumTileClusteredY, nrClusters, unity_StereoEyeIndex); | ||
|
|
||
| uint dataPair = g_vLayeredOffsetsBuffer[idx]; | ||
| start = dataPair & 0x7ffffff; | ||
| lightCount = (dataPair >> 27) & 31; | ||
| UnpackClusterLayeredOffset(dataPair, start, lightCount); | ||
| } | ||
|
|
||
| void GetCountAndStartCluster(PositionInputs posInput, uint lightCategory, out uint start, out uint lightCount) | ||
|
|
@@ -346,16 +349,17 @@ EnvLightData FetchEnvLight(uint index) | |
| return _EnvLightDatas[index]; | ||
| } | ||
|
|
||
| // In the first 8 bits of the target we store the max fade of the contact shadows as a byte | ||
| // In the first bits of the target we store the max fade of the contact shadows as a byte. | ||
| //By default its 8 bits for the fade and 24 for the mask, please check the LightLoop.cs definitions. | ||
| void UnpackContactShadowData(uint contactShadowData, out float fade, out uint mask) | ||
| { | ||
| fade = float(contactShadowData >> 24) / 255.0; | ||
| mask = contactShadowData & 0xFFFFFF; // store only the first 24 bits which represent | ||
| fade = float(contactShadowData >> CONTACT_SHADOW_MASK_BITS) / ((float)CONTACT_SHADOW_FADE_MASK); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So yeah contact shadow are gonna be awkward :D I wonder if we should change a bit how we do it later on. Now if we have only one light that has contact shadow, but that happens to have an index bigger than 24 in the list it will not show up. Even worse if that light changes depending on culling from say 20 and 25 as index, it will "flicker" contact shadows :/
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't remind exactly but aren't we sorting light by shadow casting? i.e the first set of light in the list currently cast shadow? increasing the likelihood that we have shadow on the first 24 light index. Guess something to test
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So there is no sorting by shadow casting as far as I can tell. We sort by light type on the entire frame, then we sort per light index per tile. The very first 24 lights that Have shadows enabled get it, and the allocation is on the CPU. Note that we can have 1 light with contact shadows followed by 32 that dont, and then 24 more that have contact shadows. In this case it will be perfectly fine. The only way shadow allocation can vary is if a new light enters the view (passes culling). For example, we have in the frame 512 lights in view. The first one and last 23 ones have contact shadows enabled.
Now lets assume we have 1 more light with contact shadow, now we have a total of 25. Hope this makes sense.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah stuff changed and forgot, used to be that each bit of the 24 bit mapped to the index of the light in the tile (and there 24 was convenient for that :P ) |
||
| mask = contactShadowData & CONTACT_SHADOW_MASK_MASK; // store only the first 24 bits which represent | ||
| } | ||
|
|
||
| uint PackContactShadowData(float fade, uint mask) | ||
| { | ||
| uint fadeAsByte = (uint(saturate(fade) * 255) << 24); | ||
| uint fadeAsByte = (uint(saturate(fade) * CONTACT_SHADOW_FADE_MASK) << CONTACT_SHADOW_MASK_BITS); | ||
|
|
||
| return fadeAsByte | mask; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be here?