Graphics Reference
In-Depth Information
Figure 8.19. The results of using displacement mapping for mesh rendering.
With the interpolated world-space position, vertex normal vector, and texture coordi-
nate, we can move ahead with the displacement mapping process. We first sample the dis-
placement map (HeightTexture) to determine the desired magnitude of the displacement.
This sampling process must use the SampleLevel function, since the domain shader stage
can't automatically determine what mip-map level to use. Here we perform a simple calcu-
lation based on the distance from the viewer, then clamp the result between levels 0 and 3.
The sampled height value is scaled by a constant after being read to allow for adjustments
of the overall range of displacement values, if desired. The displacement magnitude is then
used to scale the normal vector, and the result is added to the interpolated world-space posi-
tion. The result of this calculation is the final output world-space position of the tessellated
point, which represents a piece of our injected higher-resolution geometry.
Finally, the domain shader transforms the new vertex to clip space with the
ViewProjMatrix transform and passes the texture coordinate to the pixel shader. As stated
earlier, the pixel shader remains the same as in our earlier examples. From the point of view
of the pixel shader, the geometry could have come from either the input vertex buffer or
from the tessellation system—both would appear identical to the pixel shader. The result-
ing rendering contains higher-detail geometry where the user can see it, and can reduce the
level of detail of the geometry where the user can't see it. Several sample renderings using
the new algorithm are shown in Figure 8.19.
8.33 Conclusion
To review the algorithm we have implemented, we can now perform detailed animation
of complex objects, while also reducing the amount of geometry that must be processed
to obtain an equal amount of surface detail. Displacement mapping allows the expensive
Search WWH ::




Custom Search