# Tessellation cracks

i'm trying to a mesh tessellate with dx11 with the tessellation factor calculated by the size of the triangle and the distance to the screen.

I do the same operation on the 3 edges of the triangle, so i would expect i get the same level of tesselation on the other triangle that shares the edge, but it seems like it doesn't. Does anyone have an idea why this doesn't work like expected?

I need the same amount of tessellation on the other side of the edge to do displacement mapping without any cracks.

There are 5 triangles in this image, the red "circle" is around 2 edges shared by 4 of the triangles in pairs. float calcLod(float3 a, float3 b)
{
float dist = distance(a,b) ;

float3 center = (b+a)/2;

float camDist = distance(CameraPosition, center);

return dist * tesselationStrength / camDist;
}

{
// get worldspace positions
float3 v0 = ip.position;
float3 v1 = ip.position;
float3 v2 = ip.position;

output.edges = calcLod(v0, v1);
output.edges = calcLod(v1, v2);
output.edges = calcLod(v2, v0);

output.inside = (output.edges + output.edges + output.edges)/3;

return output;
}

[domain("tri")]
[partitioning("integer")]
[outputtopology("triangle_cw")]
[outputcontrolpoints(3)]
{
output.position = input[pointId].position;
output.uv = input[pointId].uv;
output.tangentToWorld = input[pointId].tangentToWorld;
return output;
}


I also tried to create my own algorithm for tessellation, but it produced micro-cracking, then found this (on AMD's site if I recall correctly), which works like a charm:

cbuffer tessBuf:register(b0)
{
float4 g_f4Eye; //camera position in world space
float4 g_f4TessFactors; //constant tessfactors (from a material for example)
};

struct ConstantOutputType
{
float fTessFactor : SV_TessFactor;
float fInsideTessFactor : SV_InsideTessFactor;
//other outputs beside tessfactors
}

ConstantOutputType PatchConstantFunction(InputPatch<HullInputType, 3> I)
{
ConstantOutputType O = (ConstantOutputType)0;

static const float MODIFIER = 0.6f;

float fDistance;
float3 f3MidPoint;
// Edge 0
f3MidPoint = ( I.f3Position + I.f3Position ) / 2.0f;
fDistance = distance( f3MidPoint, g_f4Eye.xyz )*MODIFIER - g_f4TessFactors.z;
O.fTessFactor = g_f4TessFactors.x * ( 1.0f - clamp( ( fDistance / g_f4TessFactors.w ), 0.0f, 1.0f - ( 1.0f / g_f4TessFactors.x ) ) );
// Edge 1
f3MidPoint = ( I.f3Position + I.f3Position ) / 2.0f;
fDistance = distance( f3MidPoint, g_f4Eye.xyz )*MODIFIER - g_f4TessFactors.z;
O.fTessFactor = g_f4TessFactors.x * ( 1.0f - clamp( ( fDistance / g_f4TessFactors.w ), 0.0f, 1.0f - ( 1.0f / g_f4TessFactors.x ) ) );
// Edge 2
f3MidPoint = ( I.f3Position + I.f3Position ) / 2.0f;
fDistance = distance( f3MidPoint, g_f4Eye.xyz )*MODIFIER - g_f4TessFactors.z;
O.fTessFactor = g_f4TessFactors.x * ( 1.0f - clamp( ( fDistance / g_f4TessFactors.w ), 0.0f, 1.0f - ( 1.0f / g_f4TessFactors.x ) ) );
// Inside
O.fInsideTessFactor = ( O.fTessFactor + O.fTessFactor + O.fTessFactor ) / 3.0f;

//Then pass the other members of the outputtype
}


Hope it helps!

• wah, serious, Edge 0 is vertex 2 and 0? so my edges are just shifted, lets try. Thanks, it's really hard to find the correct order for the edge factors. – Stijn Tallon Jan 18 '14 at 17:42