Hi again, I am trying to somehow control my tessellation factors using keyboard control keys. Here’s my code:
The GPU side of things…
Vertex Shader
#version 430 core
layout (location = 0) in vec3 vertex_position;
layout (location = 1) in vec3 vertex_color;
out vec3 Color;
out vec3 controlpoint;
uniform mat4 Model;
uniform mat4 View;
uniform mat4 Projection;
uniform float tessLevelInner;
uniform float tessLevelOutter;
void main()
{
gl_Position = Projection * View * Model * vec4(vertex_position, 1.0f);
}
Tessellation Control Shader
#version 430 core
layout (vertices = 3) out;
in vec3 Color[];
uniform float tessLevelInner = 4.0f; // Default value of 4
uniform float tessLevelOutter = 4.0f; // Default value of 4
void main()
{
gl_TessLevelInner[0] = tessLevelInner;
gl_TessLevelOuter[0] = tessLevelOutter;
gl_TessLevelOuter[1] = tessLevelOutter;
gl_TessLevelOuter[2] = tessLevelOutter;
gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
}
Tessellation Evaluation Shader
#version 430 core
layout (triangles, equal_spacing, cw) in;
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);
}
CPU side of things…
I create the shader program and do all the lovely things…
Now I have this function that is supposed to send floats to the TCS:
void Shader::UpdateLevelOfDetails(float inner, float outter)
{
GLuint innerLoc = glGetUniformLocation(m_program, "tessLevelInner");
GLuint outterLoc = glGetUniformLocation(m_program, "tessLevelOutter");
glUniform1fv(innerLoc, 1, &inner);
glUniform1fv(outterLoc, 1, &outter);
}
Then somewhere within my update function in my demo, I do this:
ShaderWithTessellation.UpdateLevelOfDetails(inner, outter); // Variables inner and outter are of type float and assigned the numbers 6 and 3 respectively
Then somewhere else in my code (I still didn’t write that part yet), I control the levels via input.
So, what’s happening, my inner and outter values are not affecting the shape whatsoever, it’s like they don’t exist as far as the TCS is concerned. If I remove the default values for the uniforms in my TCS, the whole shape (which is just a triangle) disappears.
Why is this not working?
All the best.