Graphics Reference
In-Depth Information
Incorporating multisample anti-aliasing
One of the problems with classic deferred rendering is that to support the built-in hardware
anti-aliasing, we must implement some extra shader code to correctly sample from the MSAA
G-Buffer. More recent improvements in Direct3D have made this problem easy to solve by using
the SV_SampleIndex and SV_Coverage pixel shader system-value semantics to run the
shader for each sample and to determine which samples are covered by the current fragment.
Getting ready
It is necessary that all render targets are created with multisampling enabled. This includes
the render targets of the G-Buffer, the depth buffer, and also the light accumulation buffer
of the light renderer. Our implementations of the GBuffer and LightRenderer classes
already support multisampling provided we pass in the correct sample description to the
GBuffer constructor, for example, new SampleDescription(4, 0) .
Our existing ScreenAlignedQuadRenderer must be modified to use the
multisampling pixel shader found in the There's more… section of Implementing a
screen-aligned quad renderer . A good way to organize this would be to check if the first
ScreenAlignedQuadRenderer.ShaderResources SRV has a ShaderResourceView.
Description.Dimension of SharpDX.Direct3D.ShaderResourceViewDimension.
Texture2DMultisampled or not and choose the default pixel shader accordingly. This will
allow us to continue to use the same class when MSAA is on or off.
Be sure to have the Direct3D debug layer active during development. This provides useful
information to help address any incorrect configuration of resources.
How to do it…
We'll begin by updating our existing HLSL code to read the G-Buffer. We'll then update each
of the LightRenderer pixel shaders.
1.
First we need to use the multisampled textures of the G-Buffer by changing
Texture2D to Texture2DMS , as shown in the following HLSL snippet.
Texture2DMS<float4> Texture0 : register(t0);
Texture2DMS<uint> Texture1 : register(t1);
Texture2DMS<float4> Texture2 : register(t2);
Texture2DMS<float> TextureDepth : register(t3);
Unlike the Texture2D resource, the Texture2DMS resource requires a
<data_type> to be specified, for example, Texture2DMS<float4>
 
Search WWH ::




Custom Search