Graphics Reference
In-Depth Information
// Calculate diffuse color with consideration of all 16
// control points (using alpha from only the first)
float3 color, c1;
DeCasteljauBicubic(uv, c, color, c1);
float4 diffuse = float4(color, patch[0].Diffuse.a);
// Prepare pixel shader input:
// Transform world position to view-projection
result.Position = mul(float4(position, 1),
ViewProjection);
result.Diffuse = diffuse;
result.WorldNormal = normal;
result.WorldPosition = position;
return result;
}
7.
Add a new C# renderer class named BezierPatchRenderer with the appropriate
SharpDX using directives. This renderer will be used to render a 16 control point
Bezier surface.
8.
Within the BezierPatchRenderer.CreateDeviceDependentResources
override, we will add the following code to define the 16 control points:
// Create the cubic Bezier surface
// Note: the normals are calculated from the Bezier surface
vertexBuffer = ToDispose(Buffer.Create(device, BindFlags.
VertexBuffer, new[] {
// x, y, z u, v texture coord
new Vertex(-1, 0, 1, 0, 0),
new Vertex(-0.34f, 0, 1, 1, 0),
new Vertex(0.34f, 0, 1, 2, 0),
new Vertex(1, 0, 1, 3, 0),
new Vertex(-1, 0, 0.34f, 0, 1),
new Vertex(-0.34f, 2, 0.34f,1, 1),
new Vertex(0.34f, 2, 0.34f, 2, 1),
new Vertex(1, 0, 0.34f, 3, 1),
new Vertex(-1, 0, -0.34f, 0, 2),
new Vertex(-0.34f, 2, -0.34f, 1, 2),
new Vertex(0.34f, 2, -0.34f, 2, 2),
new Vertex(1, 0, -0.34f, 3, 2),
new Vertex(-1, 0, -1, 0, 3),
new Vertex(-0.34f, 0, -1, 1, 3),
new Vertex(0.34f, 0, -1, 2, 3),
new Vertex(1, 0, -1, 3, 3),}));
vertexBinding = new VertexBufferBinding(vertexBuffer,
Utilities.SizeOf<Vertex>(), 0);
 
Search WWH ::




Custom Search