| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- #include "$ENGINE$\PerCameraData.bslinc"
- Technique : inherits("PerCameraData") =
- {
- Language = "HLSL11";
-
- Pass =
- {
- Compute =
- {
- cbuffer Params : register(b0)
- {
- // Offsets at which specific light types begin in gLights buffer
- // Assumed directional lights start at 0
- // x - offset to point lights, y - offset to spot lights, z - total number of lights
- uint3 gLightOffsets;
- uint gNumCells;
- uint3 gGridSize;
- uint gMaxNumLightsPerCell;
- }
-
- Buffer<uint> gLinkedListHeads : register(t0);
- Buffer<uint2> gLinkedList : register(t1);
-
- RWBuffer<uint> gGridDataCounter : register(u0);
- RWBuffer<uint2> gGridLightOffsetAndSize : register(u1);
- RWBuffer<uint> gGridLightIndices : register(u2);
-
- [numthreads(THREADGROUP_SIZE, THREADGROUP_SIZE, THREADGROUP_SIZE)]
- void main(
- uint3 groupId : SV_GroupID,
- uint3 groupThreadId : SV_GroupThreadID,
- uint3 dispatchThreadId : SV_DispatchThreadID)
- {
- uint2 viewportMax = gViewportRectangle.xy + gViewportRectangle.zw;
- // Ignore pixels out of valid range
- if (all(dispatchThreadId.xy >= viewportMax))
- return;
-
- uint maxNumLinks = gNumCells * gMaxNumLightsPerCell;
- uint cellIdx = (dispatchThreadId.z * gGridSize.y + dispatchThreadId.y) * gGridSize.x + dispatchThreadId.x;
-
- // First count total number of lights affecting the tile
- uint currentIdx = gLinkedListHeads[cellIdx];
- uint numLights = 0;
- while(currentIdx != 0xFFFFFFFF)
- {
- numLights++;
- currentIdx = gLinkedList[currentIdx].y;
- }
-
- // Allocate enough room and remember the offset to indices
- uint indicesStart;
- InterlockedAdd(gGridDataCounter[0], numLights, indicesStart);
- gGridLightOffsetAndSize[cellIdx] = uint2(indicesStart, numLights);
-
- // Actually write light indices
- // Note: Values are written in the reverse order than they were found in
- currentIdx = gLinkedListHeads[cellIdx];
- uint lightIdx = 0;
- while(currentIdx != 0xFFFFFFFF)
- {
- uint2 entry = gLinkedList[currentIdx];
-
- gGridLightIndices[indicesStart + lightIdx] = entry.x;
-
- currentIdx = entry.y;
- lightIdx++;
- }
- }
- };
- };
- };
- Technique : inherits("PerCameraData") =
- {
- Language = "GLSL";
-
- Pass =
- {
- Compute =
- {
- layout (local_size_x = THREADGROUP_SIZE, local_size_y = THREADGROUP_SIZE, local_size_z = THREADGROUP_SIZE) in;
-
- layout(binding = 0, std140) uniform Params
- {
- // Offsets at which specific light types begin in gLights buffer
- // Assumed directional lights start at 0
- // x - offset to point lights, y - offset to spot lights, z - total number of lights
- uvec3 gLightOffsets;
- uint gNumCells;
- uvec3 gGridSize;
- uint gMaxNumLightsPerCell;
- };
-
- layout(binding = 1) uniform usamplerBuffer gLinkedListHeads;
- layout(binding = 2) uniform usamplerBuffer gLinkedList;
-
- layout(binding = 3, r32ui) uniform uimageBuffer gGridDataCounter;
- layout(binding = 4, rg32ui) uniform uimageBuffer gGridLightOffsetAndSize;
- layout(binding = 5, r32ui) uniform uimageBuffer gGridLightIndices;
-
- void main()
- {
- uvec2 viewportMax = gViewportRectangle.xy + gViewportRectangle.zw;
- // Ignore pixels out of valid range
- if (all(greaterThanEqual(gl_GlobalInvocationID.xy, viewportMax)))
- return;
-
- uint maxNumLinks = gNumCells * gMaxNumLightsPerCell;
- int cellIdx = int((gl_GlobalInvocationID.z * gGridSize.y + gl_GlobalInvocationID.y) * gGridSize.x + gl_GlobalInvocationID.x);
-
- // First count total number of lights affecting the tile
- int currentIdx = int(texelFetch(gLinkedListHeads, cellIdx).x);
- uint numLights = 0;
- while(currentIdx != 0xFFFFFFFF)
- {
- numLights++;
- currentIdx = int(texelFetch(gLinkedList, currentIdx).y);
- }
-
- // Allocate enough room and remember the offset to indices
- uint indicesStart = imageAtomicAdd(gGridDataCounter, 0, numLights);
- imageStore(gGridLightOffsetAndSize, cellIdx, uvec4(indicesStart, numLights, 0, 0));
- // Actually write light indices
- // Note: Values are written in the reverse order than they were found in
- currentIdx = int(texelFetch(gLinkedListHeads, cellIdx).x);
- uint lightIdx = 0;
- while(currentIdx != 0xFFFFFFFF)
- {
- uvec2 entry = texelFetch(gLinkedList, currentIdx).xy;
-
- imageStore(gGridLightIndices, int(indicesStart + lightIdx), uvec4(entry.x, 0, 0, 0));
-
- currentIdx = int(entry.y);
- lightIdx++;
- }
- }
- };
- };
- };
|