I am rendering some LineLoops on a sphere (borders on a planet) and want to tessallate them into shorter lines to prevent long lines clipping into the sphere.
Example:
Here is my current source code: C++ draw call:
void Border::Draw() const
{
glBindVertexArray(_vao);
glPatchParameteri(GL_PATCH_VERTICES, 2);
glDrawArrays(GL_PATCHES, 0, _size);
glBindVertexArray(0);
}
Vertex Shader:
#version 400
in layout(location = 0) vec3 position;
void main()
{
gl_Position = vec4(position, 1.0);
}
Tessallation Control Shader:
#version 400
layout (vertices = 2) out;
void main()
{
if(gl_InvocationID == 0)
{
//get the distance between two points
float dist = length(gl_in[0].gl_Position - gl_in[1].gl_Position);
gl_TessLevelOuter[0] = 1;
//divide line in segments of size 1.0
gl_TessLevelOuter[1] = abs(dist);
}
gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
}
Tessallation Evaluation Shader
#version 400
layout (isolines, equal_spacing) in;
uniform float planetRadius;
uniform mat4 view;
uniform mat4 projection;
void main()
{
vec4 p = mix(gl_in[0].gl_Position, gl_in[1].gl_Position, gl_TessCoord.x);
//offset point so it is on the spheres surface
p = normalize(p);
p *= planetRadius;
gl_Position = projection * view * p;
}
Fragment Shader:
#version 400
out vec4 outColor;
void main()
{
outColor = vec4(1.0, 1.0, 1.0, 1.0);
}
The tessallation doesn't seem to work like I expect it to work (documentation on isolines is also bad).
This is how it looked when I draw it with LineLoops and only Vertex/Fragment Shader:
and this is how it looks like after I implemented my tessallation:
The lines also do not look tessallated and have the same length as before.
Greetings Jhonny
Edit: Found the solution myself. Look in answer section below to see it.