Calculating texture mapping scale for displacement

This code in the tessellation evaluation shader determines the area over which a texture is applied to a surface:

float p = length(tess_vertexWorldPosition[0].xyz - tess_vertexWorldPosition[1].xyz);
float t = length(tess_texCoords[0].xy - tess_texCoords[1].xy);
if (p > 0.0001f && t > 0.0001f) uvscale = p / t; else uvscale = 0.0f;

The code results in a different value for two adjacent triangles with two shared vertices:


Here are the edges highlighted in RGB for edges 0, 1, and 2:

The texture mapping scale across the two triangles is constant and equal on the U/V axes. Even if a different length edge is being tested, the length of the position and texcoord difference should be scaled exactly the same, so it should return the same value.

I applied a grid texture to the material and it shows there is nothing unexpected going on with the UV coords:

I tried replacing it with this more convoluted code that finds the longest edge and uses that for the calculation:

float GetUVScale(in vec3 a, in vec3 b, in vec3 c, in vec2 ta, in vec2 tb, in vec2 tc)
{
	float ab = length(a - b);
	float bc = length(c - b);
	float ac = length(a - c);
	float tab = length(ta - tb);
	float tbc = length(tc - tb);
	float tac = length(ta - tc);
	if (length(ab) > length(bc))
	{
		if (ab > ac)
		{
			return ab / tab;
		}
		else
		{
			return ac / tac;
		}
	}
	else
	{
		if (bc > ac)
		{
			return bc / tac;
		}
		else
		{
			return ac / tac;
		}
	}
}

This code returns the same result for both triangles, eliminating the crack, but I do not understand why testing any of the edges would not return the same value.

Any ideas what the problem might be? Am I overlooking something really obvious?

It’s a 1024x512 texture, so the U and V scales were in fact different. :stuck_out_tongue_closed_eyes: