Hi! I wrote vertex and fragment shader to texture a planet in the way that bright side is of another texture than dark one. The light is at the same position all the time.
The planet rotates around its axis. Everything is fine except that bright side rotates with the planet!!! I am not sure where is the problem.
OK it seems I forgot about rotating the normals in vertex shader. But still I cannot fix the prob. When I rotate the normals the light side of the planet dissapears at all
The “obvious” solution would be to apply the inverse rotation of the planet around it’s axis to the modelview matrix before you draw the “glow”. Either apply the same rotation (with the angle negated) or pop the rotation off the matrix (if you do the axis rotation on it’s own when drawing the planet).
The other solution is to transform the Normal vector. IIRC (no doubt someone will correct me if I’m wrong) you have to multiply the Normal Vector by the inverse of the modelView matrix.
The reason you are getting the problem you are getting is you are rotating the vertex - but still using the original Normal. So point A - which in it’s home location has a normal that points directly at the Sun is then rotated around the “dark side” - but it’s normal still points directly at the sun - so it will be bright.
I have tried multiplying normal vector by inverse of modelview matrix but it didnt work. I also tried to multiply the vector by rotation matrix (which holds only the rotation along main axis). I use this matrix to rotate the globe too. Unfortunately it didnt work either :-/ grrrrr…