Graphics Reference
In-Depth Information
Figure 3.16. The difference between per-vertex and per-pixel calculations in a pair of triangles.
Generic Per-Vertex Calculations
Many other types of calculations can follow a model similar to the one described above
for lighting. If a calculation can be performed in the vertex shader stage and an interpo-
lated version of the data can be used at the per-pixel level, then it makes sense to perform
the calculations in the vertex shader where they will only be performed once per vertex.
If the calculations were instead performed after rasterization, they would be performed
many more times. Figure 3.16 shows the difference in calculation frequency between a
per-vertex calculation and a per-pixel calculation.
Mathematically speaking, if the calculation is a linear combination of its inputs, then
the results of the per-vertex calculation will be identical to those of the per-pixel calcula-
tions, because of the interpolation between vertex attributes. Even if a calculation is not
linear, per-vertex calculations can still provide a fairly good approximation of the full per-
pixel calculations. The effectiveness of this approximation depends on the type of calcula-
tion, as well as on how large the final rasterized primitive will appear in the final render
target. If the number of pixels generated between vertices is very small, any inaccuracy of
the interpolated values is less likely to be noticed. This also means that if an input set of
geometry is created to have a larger number of vertices, the interpolation effects will be less
noticeable, at the expense of an increased number of vertices to process. There is no simple
rule to determine the required level of detail for a particular model. This is a function of the
available processing power and the desired image quality. As a small indication of what is
coming later in this chapter, the new tessellation stages are aimed at striking a balance in
this regard, by dynamically generating an appropriate number of vertices, only where they
are needed (where they are visible). This reduces the overall vertex processing costs, while
still producing small screen-space-sized primitives, which effectively raises the available
image quality for the same amount of required processing.
Control Point Processing
One other way to use the vertex shader stage is to process data that is actually not vertices,
but rather control points of a higher-order primitive or control patch. These control points
Search WWH ::




Custom Search