Graphics Reference
In-Depth Information
Getting ready
We will continue on from the point where we left off with the Refining meshes with Phong
tessellation recipe.
All the code for implementing the back-face culling methods
and dynamic LoD is included as comments within the HS_
TrianglesConstant function in TessellateTri.hlsl
for the Ch05_02TessellatedMesh project.
How to do it…
We will implement two methods of back-face culling, and then incorporate a reduction
of the tessellation factor for non-silhouette faces.
Back-face culling using face normal vectors
Consider the following steps:
1.
After loading the project from our previous recipe, open Shaders\TessellateTri.
hlsl .
2.
Locate the HS_TrianglesConstant function, and modify it to include the
following code:
...SNIP
HS_TrianglePatchConstant result = (HS_TrianglePatchConstant)0;
// Backface culling - using face normal
// Calculate face normal
float3 edge0 = patch[1].WorldPosition -
patch[0].WorldPosition;
float3 edge2 = patch[2].WorldPosition -
patch[0].WorldPosition;
float3 faceNormal = normalize(cross(edge2, edge0));
// Create view vector
float3 view = normalize(CameraPosition -
patch[0].WorldPosition);
// If cosine(angle) < -0.25
if (dot(view, faceNormal) < -0.25) {
result.EdgeTessFactor[0] = 0;
result.EdgeTessFactor[1] = 0;
 
Search WWH ::




Custom Search