Graphics Reference
In-Depth Information
float3 r0 = lerp(q0, q1, u);
float3 r1 = lerp(q1, q2, u);
t = r0 - r1; // tangent
p = lerp(r0, r1, u);
}
// Bicubic interpolation of cubic Bezier surface
void DeCasteljauBicubic(float2 uv, float3 p[16], out float3
result, out float3 normal)
{
// Interpolated values (e.g. points)
float3 p0, p1, p2, p3;
// Tangents (derivatives)
float3 t0, t1, t2, t3;
// Calculate tangent and positions along each curve
DeCasteljau(uv.x, p[ 0], p[ 1], p[ 2], p[ 3], p0, t0);
DeCasteljau(uv.x, p[ 4], p[ 5], p[ 6], p[ 7], p1, t1);
DeCasteljau(uv.x, p[ 8], p[ 9], p[10], p[11], p2, t2);
DeCasteljau(uv.x, p[12], p[13], p[14], p[15], p3, t3);
// Calculate final position and tangents across surface
float3 du, dv, tmp;
DeCasteljau(uv.y, p0, p1, p2, p3, result, dv);
DeCasteljau(uv.y, t0, t1, t2, t3, du, tmp);
// du represents tangent
// dv represents bitangent
normal = normalize(cross(du, dv));
}
A difference in the implementation of float2 support is that we
will not calculate the normal vector.
3.
Create a new shader file named Shaders\TessellateBezier.hlsl , as per the
quad example provided in the previous recipe.
4.
The hull shaders are identical to the quad hull shaders, except that the number of
input and output control points is now 16 instead of 4 , and the names should begin
with HS_Bezier (for example, HS_BezierInteger ). The patchconstantfunc
attribute should also be changed to HS_BezierConstant .
5.
The Bezier patch constant function, as shown in the following code snippet, is very
similar to the quad example:
HS_BezierPatchConstant HS_BezierConstant(InputPatch<HullShaderInp
ut, 16> patch)
{
 
Search WWH ::




Custom Search