Graphics Reference
In-Depth Information
float3 ProjectOntoPlane(float3 planeNormal, float3 planePoint,
float3 pointToProject)
{
return pointToProject - dot(pointToProject-planePoint,
planeNormal) * planeNormal;
}
7.
Finally, we create the new domain shader. Begin by copying the existing triangle
domain shader from the recipe, Tessellating a triangle and quad , and rename to
DS_PhongTessellation .
8.
Within the new domain shader, after the code that performs the barycentric
interpolation, we insert the following Phong tessellation logic:
// Interpolate using barycentric coordinates
...SNIP - existing triangle domain shader code
// BEGIN Phong Tessellation
// Orthogonal projection in the tangent planes
float3 posProjectedU =
ProjectOntoPlane(constantData.WorldNormal[0],
patch[0].Position, position);
float3 posProjectedV =
ProjectOntoPlane(constantData.WorldNormal[1],
patch[1].Position, position);
float3 posProjectedW =
ProjectOntoPlane(constantData.WorldNormal[2],
patch[2].Position, position);
// Interpolate the projected points
position = BarycentricInterpolate(posProjectedU,
posProjectedV, posProjectedW, barycentricCoords);
// END Phong Tessellation
// Transform world position to view-projection
...SNIP - existing triangle domain shader code
9. Within D3DApp.CreateDeviceDependentResources , compile the new domain
shader. Remember to use the ds_5_0 shader profile.
10. Within the render loop, ensure that the Character.cmo mesh is being loaded
correctly into a TessellatedMeshRenderer instance, and update the mesh
rendering section of the render loop with the following code:
context.VertexShader.Set(tessellateVertexShader);
context.HullShader.Set(activeTriTessellator);
if (usePhongTessellation)
context.DomainShader.Set(tessellatePhongDomainShader);
else
 
Search WWH ::




Custom Search