Graphics Reference
In-Depth Information
Per-sample execution. The first such modification is that pixel shaders can be run for each
subsample, rather than once per pixel. This behavior is triggered when the pixel shader
takes an input with the SV_SampleIndex system value semantic attached, which provides
the index of the subsample currently being processed. It is also triggered if an input at-
tribute is marked with the sample interpolation mode. We will discuss the usage of the
SV_SampleIndex later in this section in more detail.
Subsample coverage. The second possible interaction with the MSAA system involves
the use of the SV_Coverage system value semantic. When an input attribute is declared
with this semantic, it provides an unsigned integer value, where each bit corresponds to one
of the subsamples of the current pixel. This essentially indicates to the pixel shader which
subsamples were detected as being covered by the rasterizer stage during rasterization.
We will see later how this system value semantic can also be used as an output attribute
as well to perform custom modifications to the selected subsamples that will be written to
with the pixel shader's results. This lets custom coverage masks be implemented, which is
commonly used for alpha-to-coverage algorithms.
Fragment Location
Two more system value semantics are accessible as inputs to the pixel shader to identify
the location of a fragment, which is where it will ultimately be written to. These attributes
can be used to aid the pixel shader program in processing a fragment.
Source position. When a pixel shader declares an input attribute with the SV_Position
system value semantic, the pixel shader receives the four coordinate fragment positions
produced by the rasterizer stage. In general, the most important parts of this position are
the X- and Y- coordinates, which indicate the location of the fragment within the current
render target. In most cases, these coordinates will indicate the pixel center location with
the 0.5 pixel offset. This can be used to identify the location in other textures that need to
be sampled when multiple textures are used to generate a pixel shader result. A common
example of this is the use of multiple textures as a G-buffer for deferred rendering (see
Chapter 11 for more details on deferred rendering).
In addition to the pixel center location, it is also possible to use this system value
semantic to obtain the centroid position of the current fragment. As described above, the
centroid location is guaranteed to be within the primitive boundary, and is normally used
to ensure that the coordinates used for interpolation do not extend beyond the primitive's
edge. The centroid value used in interpolation can be received if this semantic value is
declared with the centroid interpolation modifier.
The depth value generated by the rasterizer stage is also available from within the
SV_Position system value semantic. This is the normalized device coordinate depth, so
its value will be in the range of [0,1]. This can be used to perform calculations within the
Search WWH ::




Custom Search