Game Development Reference
In-Depth Information
is a memory counter for the memory pool. Memory sections for light indices
for a tile are not allocated in advance. Thus, we first need to reserve memory
in gLightIdx . This is done by an atomic operation to gLightIdxCounter using a
thread in the thread group.
Once a memory offset is obtained, we just fill the light indices to the assigned
contiguous memory of gLightIdx using all the threads in a thread group.
The
code for doing this memory write is as follows:
{ // write back
u32 startOffset = 0;
if ( lIdx == 0 )
{ // reserve memory
if ( ldsLightIdxCounter != 0 )
InterlockedAdd( gLightIdxCounter , ldsLightIdxCounter,
startOffset );
ptLowerBound[tileIdx] = startOffset;
ldsLightIdxStart = startOffset;
}
GroupMemoryBarrierWithGroupSync();
startOffset = ldsLightIdxStart;
for ( int i=lIdx; i<ldsLightIdxCounter; i+=64)
{
gLightIdx[startOffset+i] = ldsLightIdx[i];
}
}
This light-culling kernel reads light geometry (for spherical lights, that includes
the location of the light and its radius). There are several options for the structure
of the light buffer. Of course, we can pack light geometry and lighting properties,
such as intensity and falloff, to a single structure. However, this is not a good idea
for our light-culling approach because all the necessary data for the light culling
is padded with light properties, which are not used in the light culling. A GPU
usually reads data by page. Therefore, it is likely to transfer lighting properties
as well as light geometry although they are not read by the kernel when this data
structure is employed for the lights.
A better choice for the data structure is to separate the light geometry and
lighting properties into two separate buffers. The light-culling kernel only touches
the light geometry buffer, increasing the performance because we do not have to
read unnecessary data.
5.3.2
Final Shading
For final shading, all objects in the camera frustum are rendered with their au-
thored materials. This is different than forward rendering because we need to
iterate through the lights overlapping each tile.
 
Search Nedrilad ::




Custom Search