0

I have created a tessellated plane through triangle tessellation. I would like to make each internal new triangle move up and down on the y axis, independently from the others. I would like to modify their gl_Position to do so, in either TES or TCS, but all I obtained till now is to make all the primitives to move simultaneously. How can I achieve my goal?

Here is the tessellated plane [plane]: https://ibb.co/jWRjvH ""

Here is my TCS

#version 450 core

layout (vertices = 3) out;

// Input Block
in VS_OUT{
    vec2 UV;
} tcs_in[];

// Output Block
out TCS_OUT{
    vec2 UV;
} tcs_out[];


void main()
{


    if(gl_InvocationID == 0)
    {
        gl_TessLevelInner[0] = 10.0;
        gl_TessLevelOuter[0] = 10.0;
        gl_TessLevelOuter[1] = 10.0;
        gl_TessLevelOuter[2] = 10.0;
    }
    gl_out[gl_InvocationID].gl_Position=gl_in[gl_InvocationID].gl_Position;

    tcs_out[gl_InvocationID].UV = tcs_in[gl_InvocationID].UV;   
}

Here is my TES

#version 450 core

layout (triangles, equal_spacing, cw) in;    

// Input Block
in TCS_OUT{
    vec2 UV;
} tes_in[];

// Output Block
out TES_OUT{
    vec2 UV;
} tes_out;


void main()
{

    gl_Position = (gl_TessCoord.x * gl_in[0].gl_Position +
                   gl_TessCoord.y * gl_in[1].gl_Position + 
                   gl_TessCoord.z * gl_in[2].gl_Position);


     tes_out.UV = gl_TessCoord.x * tes_in[0].UV + 
                  gl_TessCoord.y * tes_in[1].UV + 
                  gl_TessCoord.z * tes_in[2].UV;

     }
 }
jovchaos
  • 31
  • 4
  • You cant do it add geometry shader and Before and after geometry shader there is fixed functionality pipeline stage called Input Assembler runs. So basically Gemoetry shader has ability to move , add ,delete vertices or change topology. But be aware Geometry shader is very bad for performance so I would suggest adding compute shader and do what you want in that. – Paritosh Kulkarni Mar 20 '18 at 16:13

1 Answers1

1

I would like to make each internal new triangle move up and down on the y axis, independently from the others.

You can't do that. The TES generates the vertices for the tessellated primitives, but it has no control over the primitives themselves. Tessellation generates a field of triangles, all of which are interconnected to cover the area of the abstract patch. If you tessellate a triangle, you will get a large number of interconnected triangles, and there's no way to make them independent.

At least, there's no way with just tessellation. You can do it with a post-tessellation geometry shader, which is able to act on independent primitives.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982