jeudi 4 mai 2017

Tessellation Shader Reflection Issue

after inserting the tessellation stage into our OpenGL pipeline all the reflections of the tessellated objects fail and are not correctly displayed anymore. Reflections are drawn with an inverted (y-axis) camera to an intermediate framebuffer before rendering them to the scene. All the other tessellated non-inverted objects are drawn correctly. This is especially puzzling since the tessellation basically took over the logic from the former vertex shader.

Vertex Shader:

# version 410 core

in vec3 position;

void main() {
    gl_Position = vec4(position, 1.f);
}

Tessellation Control Shader:

# version 410 core

layout (vertices = 3) out;

void main(void)
{
    if (gl_InvocationID == 0) {
        gl_TessLevelInner[0] = 2.0;
        gl_TessLevelOuter[0] = 2.0;
        gl_TessLevelOuter[1] = 2.0;
        gl_TessLevelOuter[2] = 2.0;
    }

    gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
}

Tessellation Evaluation Shader:

# version 410 core

uniform mat4 MVP;
uniform sampler2D tex;

out vec2 uv;

layout (triangles) in;

void main(void) {

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

    uv = ((position + vec3(4.0)) * 0.125).xy;

    float height = texture(tex, uv).r;
    vec4 worldPosition = vec4(position.x, height, position.y, 1.f);
    gl_Position = MVP * worldPosition;
}

What am I missing when it comes to drawing reflections in the tessellation shaders?

Thanks in advance.





Aucun commentaire:

Enregistrer un commentaire