Graphics Reference
In-Depth Information
{
// Sample the light target for the current sub-sample
float4 lighting = LightTexture.Load( sampleCoord, i );
// Seperate into diffuse and specular components
diffuse += lighting.xyz;
specular += lighting.www;
++numSamplesApplied;
}
}
// Apply the diffuse normalization factor
const float DiffuseNormalizationFactor = 1.0f / 3.14159265f;
diffuse *= DiffuseNormalizationFactor;
// Apply the albedos
float3 diffuseAlbedo = DiffuseMap.Sample( AnisoSampler, input . TexCoord ).rgb;
float3 specularAlbedo = float3( 0.7f, 0.7f, 0.7f );
diffuse *= diffuseAlbedo;
specular *= specularAlbedo;
// Final output is the sum of diffuse + specular divided by number of
// samples covered
float3 output = ( diffuse + specular ) / numSamplesApplied;
return float4(output , 1.0f );
}
Listing 11.19. Final pass pixel shader code for light prepass deferred rendering with MSAA.
As with the lighting pass, it's possible to use a stencil mask or dynamic branching
to prevent sampling and applying multiple subsamples from the light buffer. However we
should keep in mind that the work done per-subsample is very little in the final pass, and
thus the savings in terms of pixel shading performance are much smaller than in the light-
ing pass. Also, if a stencil mask is used, this means rendering all of the scene geometry
twice, which makes it very likely that performance could actually be worse than if we sim-
ply looped through all of the subsamples. Either way, profiling should be done on the target
hardware to determine which approach produces the best performance.
11.5.3 Screen-Space Anti-Aliasing
In this section, we'll describe techniques that apply an anti-aliasing effect in screen space
after the scene has been rendered and shaded. The main advantage of such techniques
is that they are mostly orthogonal to the techniques used to render the geometry, which
Search WWH ::




Custom Search