Graphics Reference
In-Depth Information
Parametric surfaces
By implementing a domain shader for parametric shapes, it is possible to generate
complex shapes with minimal memory bandwidth, for example, a single control point can
be used to create a sphere. By passing a single control point using the primitive topology,
PrimitiveTopology.PatchListWith1ControlPoints , and duplicating the Quad
renderer HLSL while changing the hull and domain shaders in order to accept a single input
and output control point, we can implement a range of parametric surfaces. The domain shader
provides two parameters for our equations via the SV_DomainLocation ( UV ) parameter.
The completed project includes the parametric renderer along with shader source code:
PixelShaderInput DS_Parametric( HS_QuadPatchConstant constantData,
const OutputPatch<DS_ControlPointInput, 1> patch, float2 uv : SV_
DomainLocation )
{
PixelShaderInput result = (PixelShaderInput)0;
float PI2 = 6.28318530;
float PI = 3.14159265;
float S = PI2 * uv.x;
float T = PI2 * uv.y;
float sinS, cosS, sinT, cosT;
sincos(S, sinS, cosS);
sincos(T, sinT, cosT);
// Torus
float R1 = 0.5; // radius of ring
float R2 = 0.25;// radius of tube
float R3 = (R1 + R2 * cosT);
float3 torusPos = float3(R3 * cosS, R3 * sinS, R2 * sinT);
float3 position = torusPos;
float4 diffuse = float4(normalize(position)+0.4, 1);
float3 normal = normalize(position);
// Prepare pixel shader input:
// Transform to World-view-projection
result.Position = mul(float4(position,1),WorldViewProjection);
result.Diffuse = diffuse;
result.WorldNormal = normal;
result.WorldPosition = position;
return result;
}
 
Search WWH ::




Custom Search