Graphics Reference
In-Depth Information
Tessellating bicubic Bezier surfaces
In this recipe, we will perform tessellation upon a bicubic Bezier control patch using the
tessellation stages of the graphics pipeline. This tessellation will use the quad domain of the
tessellator. We will update the CommonTess.hlsl shader code to include the methods to
perform bicubic interpolation of the Bezier control points using De Casteljau's algorithm to
subdivide a Bezier curve at an arbitrary point along the curve.
Getting ready
We will continue on from the earlier recipe, Preparing the vertex shader and buffers
for tessellation .
How to do it…
We will first implement the shader code for tessellating our Bezier control points. We will
then implement a renderer for a bicubic Bezier surface. Consider the following steps:
1.
First within CommonTess.hlsl , we add the hull shader constant data structure
to be generated for a Bezier patch:
// Max 32 outputs
struct HS_BezierPatchConstant {
float EdgeTessFactor[4] : SV_TessFactor;
float InsideTessFactor[2] : SV_InsideTessFactor;
float2 TextureUV[16]: TEXCOORD0;
};
2.
Then, we add a new function for bicubic interpolation to CommonTess.hlsl .
As with the previous recipe, we will implement the interpolation for float2 and
float3 variables. The following code shows the implementation for float3 :
// Calculate point upon Bezier curve and return
void DeCasteljau(float u, float3 p0, float3 p1, float3 p2, float3
p3, out float3 p, out float3 t)
{
float3 q0 = lerp(p0, p1, u);
float3 q1 = lerp(p1, p2, u);
float3 q2 = lerp(p2, p3, u);
 
Search WWH ::




Custom Search