Graphics Reference
In-Depth Information
performs the comparison, and then uses the clip() or discard intrinsics to prevent that
pixel from being output. However this can still suffer the same problems inherent with us-
ing an equality comparison on the g-buffer contents. Once the stencil mask is generated,
the lighting must be rendered with two passes: one where the subsamples are lit individu-
ally and one where only one sample is used (Persson, Deferred shading 2, 2008).
Ideally, we would want to mark "edge" pixels (pixels where subsamples aren't all
identical), based on the actual subpixel triangle coverage, rather than performing a compar-
ison after the fact. In Direct3D 11 the pixel shader can get this information directly through
the SV_Coverage semantic, making it trivial to determine if a pixel is fully covered, and
then output an appropriate value to the g-buffer. The code in Listing 11.17 demonstrates
how this can be implemented.
// G-Buffer Pixel shader that generates an MSAA mask using SV_Coverage
float4 PSMain( in PSInput input, in uint coverageMask : SV_Coverage ) : SV_Target0
{
// Compare the input mask with a "full" mask to determine if all
// samples passed the coverage test
const uint FullMask = ( 1 << NUMSUBSAMPLES ) - 1 ;
float edgePixel = coverageMask != FullMask ? 1.0f : 0.0f;
}
Listing 11.17. Shader code for edge mask generation using SV_Coverage.
MSAA with Light Pre-Pass Deferred Rendering
With light pre-pass deferred rendering, our rendering pipeline is split into three steps, in-
stead of two. Thus, if the MSAA subsamples are resolved during the lighting pass and
the final pass is rendered without MSAA, the albedo from one surface can incorrectly be
applied to a lighting value that is the combined result of two different surfaces. Or alterna-
tively, if MSAA is used for the final pass, the two separate albedo values will be used, but
the lighting values will already have been combined. This will produce artifacts, since the
lighting equation is nonlinear.
Ideally, the lighting pass should calculate lighting for each individual subsample in
the g-buffer and then store the results to the corresponding subsample of an MSAA render
target. While Direct3D 11 allows loading the subsamples of a texture, it doesn't have a
mechanism for specifying separate values for the individual subsamples of a render target
when a pixel shader runs at a per-pixel frequency. To work around this, we can have the
lighting pixel shader run at the per-sample frequency, so that the light values for each sub-
sample are preserved. The shader code in Listing 11.18 demonstrates this approach.
Search WWH ::




Custom Search