Graphics Reference
In-Depth Information
Figure 3.57. The mapping of the unit cube in normalized device coordinates to a render target's screen
space coordinate system.
Viewport Transformation
The final step before the actual rasterization takes place is the viewport transformation.
The vertices of the primitive currently reside in normalized device coordinates, where the
X- and Y -coordinates range between [-1,1] and the Z coordinate ranges between [0,1 ]. The
viewport provides the information needed to map the primitive from normalized device
coordinates to pixel coordinates. The viewport data structure provides an offset (with the
TopLeftX and TopLeftY parameters) and a scale (with the Width and Height parameters)
for positioning the primitives within the desired region of a render target. This mapping
process is depicted in Figure 3.57.
After the mapping has been performed, the new coordinates will have a range of
[TopLeftX,TopLeftX+Width] for the X component, and [TopLeftY,TopLeftY+Height] for
the Y component, where width and height are the dimensions of the render target area to be
rendered to. It is also possible to scale the Z-component of the position as well, to manipu-
late the depth values used later in the pipeline. As we have mentioned previously, multiple
viewports can be used to achieve effects such as split screen rendering, where the scene is
rasterized into two different regions of a render target to indicate what is visible from each
player's current view point. However, this could also be used to only render a scene to a re-
gion that isn't covered by a user interface element. For example, it is common in real-time
strategy (RTS) games to have a large user interface element at the bottom of the screen. If
this user interface is not transparent, then it can significantly reduce the size of the region
being rasterized into, and subsequently reduce the number of fragments/pixels that need to
be generated. In general, if there is a reason to restrict the region that is being rendered with
a viewport, it is a good practice to do so!
Search WWH ::




Custom Search