Graphics Reference
In-Depth Information
3.4.2 Step 2: Light Accumulation
This step makes use of both the Shader Pixel Local Storage extension and the
depth/stencil fetch extension to compute the light contribution of each light.
The lights are rendered with depth test enabled and depth writes off. (See
Listing 3.9.)
#version 300 es
#extension GL EXT shader pixel local storage : enable
#extension GL ARM shader framebuffer fetch depth stencil : enable
precision mediump float ;
__pixel_localEXT FragData
{ layout ( r11f_g11f_b10f ) mediump vec3 Color ;
layout ( rgb10_a2 ) mediump vec4 Normal ;
layout ( r11f_g11f_b10f ) mediump vec3 Lighting ;
}
gbuf ;
uniform mat4 uInvViewProj ;
uniform vec2 uInvViewport ;
uniform vec3 uLightPos ;
uniform vec3 uLightColor ;
uniform float uInvLightRadius ;
void main ( void )
{ vec4 ClipCoord ;
ClipCoord . xy = gl FragCoord . xy ￿ uInvViewport ;
ClipCoord . z = gl_LastFragDepthARM ;
ClipCoord . w =1.0;
ClipCoord = ClipCoord ￿ 2.0
1.0;
// Transform to world space
vec4 WorldPos = ClipCoord ￿ uInvViewProj ;
WorldPos /= WorldPos . w ;
vec3 LightVec = WorldPos . xyz
uLightPos ;
float fDist = length ( LightVec );
LightVec /= fDist ;
// unpack normal from pixel local storage
vec3 normal = gbuf . Normal . xyz ￿ 2.0
1.0;
// Compute light attenuation factor
float fAtt = clamp (1.0
uInvLightRadius ,0.0,1.0);
float NdotL = clamp ( dot ( LightVec , normal ) , 0.0, 1.0);
fDist
// compute and add light value back to pixel local gbuf storage
gbuf . Lighting += uLightColor ￿ NdotL ￿ fAtt ;
}
Listing 3.9. Accumulate light contribution by rendering light geometry.
Search WWH ::




Custom Search