Skip to content

Commit 335eb77

Browse files
HDRenderLoop: Fix issue with tile list index + Rename SFiniteLightData to LightShapeData
1 parent 9a7a1b6 commit 335eb77

File tree

5 files changed

+86
-82
lines changed

5 files changed

+86
-82
lines changed

Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/Resources/lightlistbuild-bigtile.compute

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ uniform float g_fNearPlane;
2121
uniform float g_fFarPlane;
2222

2323
StructuredBuffer<float3> g_vBoundsBuffer : register( t1 );
24-
StructuredBuffer<SFiniteLightData> g_vLightData : register( t2 );
24+
StructuredBuffer<LightShapeData> _LightShapeData : register(t2);
2525
StructuredBuffer<SFiniteLightBound> g_data : register( t3 );
2626

2727

@@ -212,7 +212,7 @@ void CullByExactEdgeTests(uint threadID, int iNrCoarseLights, uint2 viTilLL, uin
212212
for(int l=0; l<iNrCoarseLights; l++)
213213
{
214214
const uint idxCoarse = lightsListLDS[l];
215-
[branch]if(idxCoarse<(uint) g_iNrVisibLights && g_vLightData[idxCoarse].lightType!=SPHERE_LIGHT) // don't bother doing edge tests for sphere lights since these have camera aligned bboxes.
215+
[branch]if (idxCoarse<(uint)g_iNrVisibLights && _LightShapeData[idxCoarse].lightType != SPHERE_LIGHT) // don't bother doing edge tests for sphere lights since these have camera aligned bboxes.
216216
{
217217
SFiniteLightBound lgtDat = g_data[idxCoarse];
218218

Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/Resources/lightlistbuild-clustered.compute

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Texture2DMS<float> g_depth_tex : register( t0 );
3838
Texture2D g_depth_tex : register( t0 );
3939
#endif
4040
StructuredBuffer<float3> g_vBoundsBuffer : register( t1 );
41-
StructuredBuffer<SFiniteLightData> g_vLightData : register( t2 );
41+
StructuredBuffer<LightShapeData> _LightShapeData : register(t2);
4242
StructuredBuffer<SFiniteLightBound> g_data : register( t3 );
4343

4444
#ifdef USE_TWO_PASS_TILED_LIGHTING
@@ -346,8 +346,8 @@ void LIGHTLISTGEN(uint threadID : SV_GroupIndex, uint3 u3GroupID : SV_GroupID)
346346
{
347347
if(offs<(start+iSpaceAvail) && i<nrClusters && CheckIntersection(l, i, viTilLL.xy, viTilUR.xy, suggestedBase) )
348348
{
349-
uint lightModel = g_vLightData[ coarseList[l] ].lightModel;
350-
++modelListCount[ lightModel==REFLECTION_LIGHT ? 1 : 0];
349+
uint lightCategory = _LightShapeData[coarseList[l]].lightCategory;
350+
++modelListCount[lightCategory == REFLECTION_LIGHT ? 1 : 0];
351351
g_vLayeredLightList[offs++] = coarseList[l]; // reflection lights will be last since we sorted
352352
}
353353
}
@@ -480,7 +480,7 @@ int CullByExactEdgeTests(uint threadID, int iNrCoarseLights, uint2 viTilLL, uint
480480
GroupMemoryBarrierWithGroupSync();
481481
#endif
482482
const int idxCoarse = coarseList[l];
483-
[branch]if(g_vLightData[idxCoarse].lightType!=SPHERE_LIGHT) // don't bother doing edge tests for sphere lights since these have camera aligned bboxes.
483+
[branch]if (_LightShapeData[idxCoarse].lightType != SPHERE_LIGHT) // don't bother doing edge tests for sphere lights since these have camera aligned bboxes.
484484
{
485485
SFiniteLightBound lgtDat = g_data[idxCoarse];
486486

Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/Resources/lightlistbuild.compute

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@
1818

1919

2020
uniform int g_iNrVisibLights;
21-
uniform int _PunctualLightCount;
2221
uniform uint2 g_viDimensions;
2322
uniform float4x4 g_mInvScrProjection;
2423
uniform float4x4 g_mScrProjection;
2524

2625

2726
Texture2D g_depth_tex : register( t0 );
2827
StructuredBuffer<float3> g_vBoundsBuffer : register( t1 );
29-
StructuredBuffer<SFiniteLightData> g_vLightData : register( t2 );
28+
StructuredBuffer<LightShapeData> _LightShapeData : register(t2);
3029
StructuredBuffer<SFiniteLightBound> g_data : register( t3 );
3130

3231
#ifdef USE_TWO_PASS_TILED_LIGHTING
@@ -233,7 +232,7 @@ void LIGHTLISTGEN(uint threadID : SV_GroupIndex, uint3 u3GroupID : SV_GroupID)
233232
int nrLightsCombinedList = min(ldsNrLightsFinal,MAX_NR_COARSE_ENTRIES);
234233
for(int i=t; i<nrLightsCombinedList; i+=NR_THREADS)
235234
{
236-
InterlockedAdd(ldsModelListCount[ g_vLightData[ prunedList[i] ].lightModel ], 1);
235+
InterlockedAdd(ldsModelListCount[_LightShapeData[prunedList[i]].lightCategory], 1);
237236
}
238237

239238

@@ -247,9 +246,6 @@ void LIGHTLISTGEN(uint threadID : SV_GroupIndex, uint3 u3GroupID : SV_GroupID)
247246
int localOffs=0;
248247
int offs = tileIDX.y*nrTilesX + tileIDX.x;
249248

250-
// This should thow a warning if NR_LIGHT_MODELS change
251-
int indicesShift[NR_LIGHT_MODELS] = {0, _PunctualLightCount};
252-
253249
for(int m=0; m<NR_LIGHT_MODELS; m++)
254250
{
255251
int nrLightsFinal = ldsModelListCount[ m ];
@@ -259,8 +255,9 @@ void LIGHTLISTGEN(uint threadID : SV_GroupIndex, uint3 u3GroupID : SV_GroupID)
259255
const int nrDWords = ((nrLightsFinalClamped+1)+1)>>1;
260256
for(int l=(int) t; l<(int) nrDWords; l += NR_THREADS)
261257
{
262-
uint uLow = l==0 ? nrLightsFinalClamped : prunedList[2*l-1+localOffs] - indicesShift[m];
263-
uint uHigh = prunedList[2*l+0+localOffs] - indicesShift[m];
258+
// We remap the prunedList index to the original LightData / EnvLightData indices
259+
uint uLow = l==0 ? nrLightsFinalClamped : _LightShapeData[prunedList[2*l-1+localOffs]].lightIndex;
260+
uint uHigh = _LightShapeData[prunedList[2 * l + 0 + localOffs]].lightIndex;
264261

265262
g_vLightList[16*offs + l] = (uLow&0xffff) | (uHigh<<16);
266263
}
@@ -333,12 +330,12 @@ void FinePruneLights(uint threadID, int iNrCoarseLights, uint2 viTilLL, float4 v
333330
{
334331
// fetch light
335332
int idxCoarse = l<iNrCoarseLights ? coarseList[l] : 0;
336-
uint uLgtType = l<iNrCoarseLights ? g_vLightData[idxCoarse].lightType : 0;
333+
uint uLgtType = l<iNrCoarseLights ? _LightShapeData[idxCoarse].lightType : 0;
337334

338335
// spot
339336
while(l<iNrCoarseLights && uLgtType==SPOT_LIGHT)
340337
{
341-
SFiniteLightData lightData = g_vLightData[idxCoarse];
338+
LightShapeData lightData = _LightShapeData[idxCoarse];
342339
// TODO: Change by SebL
343340
const bool bIsSpotDisc = true; // (lightData.flags&IS_CIRCULAR_SPOT_SHAPE) != 0;
344341

@@ -364,13 +361,13 @@ void FinePruneLights(uint threadID, int iNrCoarseLights, uint2 viTilLL, float4 v
364361

365362
uLightsFlags[l<32 ? 0 : 1] |= (uVal<<(l&31));
366363
++l; idxCoarse = l<iNrCoarseLights ? coarseList[l] : 0;
367-
uLgtType = l<iNrCoarseLights ? g_vLightData[idxCoarse].lightType : 0;
364+
uLgtType = l<iNrCoarseLights ? _LightShapeData[idxCoarse].lightType : 0;
368365
}
369366

370367
// sphere
371368
while(l<iNrCoarseLights && uLgtType==SPHERE_LIGHT)
372369
{
373-
SFiniteLightData lightData = g_vLightData[idxCoarse];
370+
LightShapeData lightData = _LightShapeData[idxCoarse];
374371

375372
// serially check 4 pixels
376373
uint uVal = 0;
@@ -391,13 +388,13 @@ void FinePruneLights(uint threadID, int iNrCoarseLights, uint2 viTilLL, float4 v
391388

392389
uLightsFlags[l<32 ? 0 : 1] |= (uVal<<(l&31));
393390
++l; idxCoarse = l<iNrCoarseLights ? coarseList[l] : 0;
394-
uLgtType = l<iNrCoarseLights ? g_vLightData[idxCoarse].lightType : 0;
391+
uLgtType = l<iNrCoarseLights ? _LightShapeData[idxCoarse].lightType : 0;
395392
}
396393

397394
// Box
398395
while(l<iNrCoarseLights && uLgtType==BOX_LIGHT)
399396
{
400-
SFiniteLightData lightData = g_vLightData[idxCoarse];
397+
LightShapeData lightData = _LightShapeData[idxCoarse];
401398

402399
// serially check 4 pixels
403400
uint uVal = 0;
@@ -418,7 +415,7 @@ void FinePruneLights(uint threadID, int iNrCoarseLights, uint2 viTilLL, float4 v
418415

419416
uLightsFlags[l<32 ? 0 : 1] |= (uVal<<(l&31));
420417
++l; idxCoarse = l<iNrCoarseLights ? coarseList[l] : 0;
421-
uLgtType = l<iNrCoarseLights ? g_vLightData[idxCoarse].lightType : 0;
418+
uLgtType = l<iNrCoarseLights ? _LightShapeData[idxCoarse].lightType : 0;
422419
}
423420

424421
// in case we have some corrupt data make sure we terminate

0 commit comments

Comments
 (0)