Graphics Reference
In-Depth Information
23. Setting the depth pixel shader as the active pixel shader will result in the output
as shown in the following screenshot. The completed example in the downloadable
code bundle, provided with this topic on Packt's website, binds Z-key to toggle the
depth shader.
The output of depth
How it works…
As the normal vector is a vector and not a point, when we are transforming it into world space
using our matrix, we must be careful that we are performing either of the following:
F Either using 0 in the W component of a four-component vector when multiplying with
the 4 x 4 matrix or multiplying a three-component vector with a 3 x 3 matrix (in our
vertex shader here, we are casting our matrix to a float3x3 variable)
F Multiply with the inverse transpose of the World matrix, especially when non-uniform
scaling is involved (or always use uniform scaling)
This ensures that the normal vector is still pointing in the correct direction despite the
affine transformations; for example, if the normal vector that points one unit up the y axis is
translated by x1, y2, and z3, it is still pointing up the y axis. So, no matter where in the space
the normal vector is, it is still pointing in the same direction.
It is also important to keep track of whether a normal vector is normalized
or not. Normalizing in a shader comes at a cost, and the normal vector
that the pixel shader receives is not guaranteed to be normalized.
 
Search WWH ::




Custom Search