Graphics Reference
In-Depth Information
Figure 9.15. A "best fit" plane.
normalizing these 4 raw normal vectors results in a single unit-length normal vector for the
patch, one that is generally representative of the underlying surface. 5 By taking any of the four
corner positions, it is possible to derive a standard plane equation, as shown in Equation (9.1):
Ax + By + Cz + D = 0,
A =N ,
B=N y ,
(9.1)
C = N z ,
D=-(N*P).
With this plane equation known, the compute shader can evaluate each height map
sample for the distance between it and the plane.
Implementing with a Compute Shader
Notation and indexes in the compute shader are not immediately obvious; Figure 9.16 in-
troduces two of the key variables in the context of a terrain rendering pre-pass. 6 The core
HLSL shader has an entry point, shown in Listing 9.10, with the [numthreads(x, y,z)] at-
tribute attached to it.
5 The process of calculating a normal vector is demonstrated in the vertex shader and rasterizer sections
of Chapter 3.
6 Compute shaders are discussed in detail in Chapter 5.
Search WWH ::




Custom Search