Graphics Reference
In-Depth Information
How it works…
By using normalized device coordinates as the position of the input vertices, we can generate
the UV coordinates within the vertex shader. Because the positions are already normalized
device coordinates, there is also no need to apply any transformations. The following diagram
shows the screen-aligned quad triangle-strip layout, and coordinates. In this recipe, we have
used a Z value of -1.0f to represent the far clip plane. In a left-handed coordinate system,
this would need to be 1.0f .
Screen-aligned Quad triangle-strip, positions in device coordinates, and generated UV texture coordinates
The DoRender method first backs up the current context state properties that are to
be modified, then binds the provided SRVs to the pixel shader, sets the active pixel and
vertex shader, and draws the four vertices of the quad's triangle strip. Finally, we restore
the previous device context state so as to not interfere with any other renderers.
There's more…
The SV_Position input semantic of the PixelIn.Position property gives us the screen
coordinates in pixels, for example, with a viewport of 640 x 480, this gives an X value in the
range of 0-639 and a Y value in the range of 0-479. Assuming the texture is the same size
as the viewport, this allows us to use the Texture2D.Load function to retrieve the SRV
contents, as shown in the following snippet.
Texture2D<float4> Texture0 : register(t0);
float4 PSMain(PixelIn input) : SV_Target
{
int3 screenPos = int3(pixel.Position.xy, 0);
return Texture0.Load(screenPos);
}
The above pixel shader effectively copies the contents of Texture0 into the current
RTV. Although we haven't used the UV coordinates above, for flexibility we will keep
these properties in the PixelIn structure.
 
Search WWH ::




Custom Search