3
\$\begingroup\$

I originally asked this question on StackOverflow & was directed here by a commenter.

Im currently working on a OpenGL planet rendering. I'm using the Tessellation pipeline. So far things are going very well bar one issue. It's at the stage where I've been banging my head off it for ages and feel like progress isnt happening.

First of all here is a gif of what I'm dealing with. Essentially my problem is that whenever the mouse is moved the planet rotates as if its "looking" at where the camera is pointing.

There are some graphical issues but they are due to me simply repeating the same heightmap across the whole cubemap. Since it doesnt match up on the sides there are clear seams.

Below is my evaluation shader:

void main(void) {
    vec4 p0 = gl_in[0].gl_Position;
    vec4 p1 = gl_in[1].gl_Position;
    vec4 p2 = gl_in[2].gl_Position;
    vec3 p = gl_TessCoord.xyz;

    Normal_FS_in = mat3(transpose(inverse((MV)))) * (p0*p.x + (p1*p.y) + p2*p.z).xyz;

    float displacment = texture(tex1, Normal_FS_in).r * 800;
    gl_Position = MVP*(p0*p.x + (p1*p.y) + p2*p.z) + (vec4(vec3(displacment,displacment,0) * normalize(Normal_FS_in),1));
}

Its pretty simple. The shader calculates a normal for the output vertex. This is then used to grab a displacement value from the heightmap which is a cube map. Then GL_Position is calculated. What I've been trying to work out is if my problem lies in the shaders or in the rest of the package.

My attempts have largely been tinkering. I've moved all normal related stuff into the evaluation shader rather then calculating it in the vertex shader and passing them through to the control and evaluation shaders.

The issue only occurs when the mouse is moved.

Any suggestions would be fantastic - hopefully all I'll need is a pointed in the right direction.

Edit - Doing the inverse transpose of the modelview matrix OR view matrix yields the result in the gif. Using the model matrix leads to distortion of the normals when the camera is moved, such that the terrain bends about the place.

\$\endgroup\$
  • \$\begingroup\$ Have you tried moving the camera with arrow keys and not the mouse to see if it does the same thing? \$\endgroup\$ – Ashigaru Sep 8 '15 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.