OpenGL Planet Generation - Simple Matrix Problem (Spins Planet with Mouse)

Im currently working on rendering OpenGL. I am using the Tessellation pipeline. So far, everything is going well, one problem. This is on the stage where I knocked my head for many years, feeling that progress was not happening.

First of all, here is the gif about what I mean. In fact, my problem is that whenever the mouse moves, the planet rotates as if it was β€œlooking” at where the camera is pointing.

There are some graphical problems, but because of me they simply repeat the same height map throughout the cuquet. Since it does not match, 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*px + (p1*py) + p2*pz).xyz; float displacment = texture(tex1, Normal_FS_in).r * 800; gl_Position = MVP*(p0*px + (p1*py) + p2*pz) + (vec4(vec3(displacment,displacment,0) * normalize(Normal_FS_in),1)); } 

It is pretty simple. The shader calculates the normal for the output vertex. It is then used to capture the offset value from the height map, which is a cube map. Then computes GL_Position. What I was trying to solve is that my problem is with the shaders or the rest of the package.

My attempts were mostly messing around. I moved all the normal related things to the evaluation shader, and then calculated it in the vertex shader and passed them to the control and evaluation shaders.

The problem only occurs when moving the mouse.

Any suggestions would be fantastic - I hope all I need is pointed in the right direction.

Change Performing the inverse transposition of the matrix of the viewing matrix or viewing matrix gives the result in gif. Using the matrix model leads to distortion of the normals when moving the camera, so that the relief bends around the place.

+5
source share
1 answer

This may be a few things. Here are some examples: 1) You messed up something in the shader (forgot the reverse or converted) 2) You incorrectly connected the controls (the mouse on the left does something strange). 3) The control model is confused (you move the target, not the camera). 4) Something else. 5) Some / All of the above.

Try debugging a bit. Does this look normal if you completely disable the shader? Just draw a simple cube (it might be easier to track the sphere).

If this is normal, add a shader, but do nothing in it, see if the shader transformations are reasonable (this is still a cube).

This should help narrow down the possible causes.

0
source

Source: https://habr.com/ru/post/1215495/


All Articles