# Tessellation and Dynamic UV Mapping (Resolve)

Alright, I have a huge issue with my tessellation and i need help understanding the problem.

I m generating 4 Quads which i do manual Mapping on them for now, The mapping is done like that

``````    Quad box;
box = new Quad(10 * (xEnd - xStart), 20 * (yEnd - yStart));

box.clearBuffer(VertexBuffer.Type.Index);
box.setBuffer(VertexBuffer.Type.Index, 4, BufferUtils.createIntBuffer(0, 1, 2, 3));
box.setMode(Mesh.Mode.Patch);
box.setPatchVertexCount(4);

Vector2f[] texCoord0 = new Vector2f[4];
texCoord0[0] = new Vector2f(0.0f, 0);
texCoord0[1] = new Vector2f(0.2f, 0f);
texCoord0[2] = new Vector2f(0.2f, 1f);
texCoord0[3] = new Vector2f(0.0f, 1f);

Vector2f[] texCoord1 = new Vector2f[4];
texCoord1[0] = new Vector2f(0.20f, 0f);
texCoord1[1] = new Vector2f(0.40f, 0f);
texCoord1[2] = new Vector2f(0.40f, 1f);
texCoord1[3] = new Vector2f(0.20f, 1f);

Vector2f[] texCoord2 = new Vector2f[4];
texCoord2[0] = new Vector2f(0.40f, 0f);
texCoord2[1] = new Vector2f(0.60f, 0f);
texCoord2[2] = new Vector2f(0.60f, 1f);
texCoord2[3] = new Vector2f(0.4f, 1f);

Vector2f[] texCoord3 = new Vector2f[4];
texCoord3[0] = new Vector2f(0.60f, 0f);
texCoord3[1] = new Vector2f(0.80f, 0f);
texCoord3[2] = new Vector2f(0.80f, 1f);
texCoord3[3] = new Vector2f(0.60f, 1f);

//Later Clone and Map are set For Each Of Them
box.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord0));
``````

From there i did test with a Unshaded Material and the Visual was perfectly fine(Btw i didnâ€™t do the remapping of VerticeBuffer only the texture UV position), But once i use this on My own MatDefinition for Tessellation, The mapping get all messed up. There seem to be a side Pulling toward a specific Direction.

I know it wonâ€™t be easy to trouble shoot the problem but there is 2 place it goes wrong, The first is the code up there, the second is Tessellation Evaluation Shader which doesnâ€™t have the write formula for UV mapping.

``````vec2 interpolate2D(vec2 v0, vec2 v1, vec2 v2, vec2 v3)
{
return v0 + vec2(gl_TessCoord.x) *  v1 + vec2(gl_TessCoord.xy) * v2 +  vec2(gl_TessCoord.y) *v3;
}
void main(){

return v0 + vec2(gl_TessCoord.y) *  v1.y + vec2(gl_TessCoord.yx) * v2 +  vec2(gl_TessCoord.x) *v3.x;

}
``````

Does anyone know how i could fix this issue

picture for visual people

i used alway a method like this for quad tessellation:

``````// interpolate in horizontal direction between vert. 0 and 3
vec3 p0 = mix(tcPosition[0], tcPosition[3], gl_TessCoord.x);
// interpolate in horizontal direction between vert. 1 and 2
vec3 p1 = mix(tcPosition[1], tcPosition[2], gl_TessCoord.x);
// interpolate in vert direction
vec3 p = mix(p0, p1, gl_TessCoord.y);``````
1 Like

Yea but it doesnâ€™t move the texture? I use exactly your code in but how do i get the Texture Position per vertice?

omg I just toke the code and INstead of applying it as a gl_Position i use it as a TessCoord and as you said everything is working just find, you are a life saver !

For anyone wondering what was the anwser

``````vec2 interpolate2D(vec2 v0, vec2 v1, vec2 v2, vec2 v3)
{
//return v0 + vec2(gl_TessCoord.y) *  v1.y + vec2(gl_TessCoord.yx) * v2 +  vec2(gl_TessCoord.x) *v3.x;