Graphics Reference
In-Depth Information
over how many lights can affect each pixel and the number of light sources is still
decoupled from the rendering complexity.
Another advantage of light indexed rendering is that it allows the user to turn
on hardware antialiasing. This is not possible with the previous two techniques
because the APIs do not expose multisampled multiple render targets.
OpenGL ES 2.0 and 3.0. Light indexed rendering can be applied in both OpenGL
ES 2.0 and 3.0. In this technique the application first renders the light volumes in
the scene to a fullscreen texture. Each of these volumes has a unique index. This
index is written to the texture in a specific channel using glColorMask() allowing
up to four lights (one for each channel of the texture) and up to 256 different
lights in the scene (the maximum index that can be stored in one channel of an
RGBA8 texture). If the application determines that some pixels will be affected
by more than four lights, it can render the extra light volumes to a different
texture. This allows the application in reality to have any number of lights per
pixel.
In the second pass the application renders the scene geometry passing in
diffuse textures and information to shade the scene. It then looks up the index
from the light index texture in screen space and uses that index to look up the
light properties. An example of this lighting calculation is shown in Listing 2.5.
uniform sampler2D lightIndexTex , lightPositions ,
lightScales , lightColors , diffuseTex ;
varying vec3 worldPosition ;
varying vec2 diffuseTexCoord ;
varying vec3 vertexWorldNormals ;
vec3 doLightCalc ( float lightId , vec3 worldNormal )
{ // very simple lighting
float lightScale = texture2D ( lightScales , vec2 (0.0 , lightId )). x ;
vec3 lightPosition = texture2D ( lightPositions , vec2 (0.0 ,
lightId )). rgb ;
vec3 lightColor = texture2D ( lightColors , vec2 (0.0,
lightId )). rgb ;
vec3 lightDirection = normalize ( lightPosition worldPosition );
float lightDist = distance ( lightPosition , worldPosition );
float invLightDist = max ( lightScale
0.5, 0.0);
lightDist
float attenuation =1.0/ lightDist ;
float ndl = clamp ( dot ( worldNormal , lightDirection ) , 0.0, 1.0);
float attenuation2 = ndl ￿ invLightDist ￿ attenuation ;
return attenuation2 ￿ lightColor ;
}
Listing 2.5. Lighting calculations in light indexed deferred rendering.
Search WWH ::




Custom Search