Game Development Reference
In-Depth Information
// 1D texture holding per-tile light lists
uniform isampleBuffer tex_tileLightLists;
// uniform buffer holding each tile's light count and
// start offset of the tile's light list (in
// tex_tileLightIndices)
uniform TileLightListRanges
ivec2 u_lightListRange[MAX_NUM_TILES];
void shading_function( inout FragmentData aFragData )
// ...
// find fragment's tile using gl_FragCoord
ivec2 tileCoord = ivec2(gl_FragCoord.xy)
int tileIdx = tileCoord.x
+ tileCoord.y * LIGHT_GRID_SIZE_X;
// fetch tile's light data start offset (.y) and
// number of lights (.x)
ivec2 lightListRange = u_lightListRange[tileIdx].xy;
// iterate over lights affecting this tile
for ( int i = 0; i < lightListRange.x; ++i )
int lightIndex = lightListRange.y + i;
// fetch global light ID
int globalLightId = texelFetch(
tex_tileLightLists, lightIndex ).x;
// get the light's data (position, colors, ...)
LightData lightData;
light_get_data( lightData, globalLightId );
// compute shading from the light
shade( aFragData, lightData );
// ...
Listing 4.1. GLSL pseudocode that demonstrates how lights affecting a given sample are
fetched. First, we find the fragment's associated tile ( tileIdx ) based on its position in the
framebuffer. For each tile we store two integers ( u_lightListRange array), one indicating
the number of lights affecting the tile, and the other describes the offset into the global
per-tile light list buffer ( tex_tileLightLists ). The light list buffer stores a number of
integers per tile, each integer identifying a globally unique light that is affecting the
transparent geometries. The Z-bounds for tiles used with opaque geometry are
computed as described in Section 4.4, which gives a good light assignment for the
opaque geometry ( Figure 4.3(a) ) .
Search Nedrilad ::

Custom Search