Graphics Reference
In-Depth Information
large amounts of data to be kept per-pixel, with zero external memory bandwidth
impact.
The Shader Pixel Local Storage extension can be used to implement deferred
shading in a way very similar to the classic multiple render target based approach.
In this section we look at what such an implementation might look like.
The implementation can be split up into three rendering steps:
1. render geometry,
2. light accumulation,
3. resolve.
3.4.1 Step 1: Render Geometry
This step is implemented almost the same way as the classic approach using
multiple render targets. The only difference is that we write everything to the
pixel local storage. This means that existing code can often be easily ported to
make use of this extension. (See Listing 3.8.)
#version 300 es
#extension GL EXT shader pixel local storage : enable
precision mediump float ;
__pixel_local_outEXT FragData
{ layout ( r11f_g11f_b10f ) mediump vec3 Color ;
layout ( rgb10_a2 ) mediump vec4 Normal ;
layout ( r11f_g11f_b10f ) mediump vec3 Lighting ;
}
gbuf ;
in mediump vec2 vTexCoord ;
in mediump vec3 vNormal ;
uniform mediump sampler2D uDiffuse ;
void main ( void )
{ // store diffuse color
gbuf . Color = texture ( uDiffuse , vTexCoord ). xyz ;
// store normal vector
gbuf . Normal = vec4 ( normalize ( vNormal ) ￿ 0.5 + 0.5 , 0.0) ;
// reserve and set lighting to 0
gbuf . Lighting = vec3 (0.0) ;
}
Listing 3.8. Example code that initializes the pixel local storage with G-buffer data.
Search WWH ::




Custom Search