DirectX Tessellation Function for Triangles

Started by
1 comment, last by PhillipHamlyn 7 years, 4 months ago

Hi - I have the following simple patch function in DX11, but I keep getting rips, and when I look at the wireframe its clear that adjacent edges are not getting the same tessellation factor. The CalcTessFactor() function just does a distance from the camera to the point passed, so should always give the same value for the same edge center that I pass in.

PatchTess patchFunction_Far(InputPatch<VertexToPixel_Far, 3> patch, uint patchID : SV_PrimitiveID)
{
PatchTess pt;
// Compute midpoint on edges, and patch center
float3 e0 = 0.5f*(patch[0].WorldPosition + patch[1].WorldPosition);
float3 e1 = 0.5f*(patch[1].WorldPosition + patch[2].WorldPosition);
float3 e2 = 0.5f*(patch[2].WorldPosition + patch[0].WorldPosition);
float3 c = (patch[0].WorldPosition + patch[1].WorldPosition + patch[2].WorldPosition) / 3.0f;
pt.EdgeTess[0] = CalcTessFactor(e0);
pt.EdgeTess[1] = CalcTessFactor(e1);
pt.EdgeTess[2] = CalcTessFactor(e2);
pt.InsideTess = CalcTessFactor(c);
return pt;
}

My patches are triangles.

Is there something I'm doing trivially wrong here (like assuming that EdgeTess[0] is correctly assumed to be edge 0-1, rather than edge 2->0 for instance ? - its a wild guess..

Advertisement

Should be opposite:

struct PatchOutputType
{
float edges[3] : SV_TessFactor;
float inside : SV_InsideTessFactor;
};
PatchOutputType ExamplePatchFunction(InputPatch<HullInputVertice, 3> input)
{
PatchOutputType output;
output.edges[2] = FactorFromPoints(input[0].pos.xy, input[1].pos.xy);
output.edges[0] = FactorFromPoints(input[1].pos.xy, input[2].pos.xy);
output.edges[1] = FactorFromPoints(input[0].pos.xy, input[2].pos.xy);
output.inside = FactorFromPoints((input[0].pos.xy + input[1].pos.xy + input[2].pos.xy) / 3.0f);
return output;
}

Thanks TeaTreaTim - that works fine now.

Out of interest, how did you know which of the edge indexes were correct ? I couldn't find any docs on this.

This topic is closed to new replies.

Advertisement