Hello,
I am a beginner in GLSL and a lot of the tutorials are now outdated which are making my life hell. I am attempting to add a simple Lambert light to my textured cube I have in a VBO. Inside this VBO I store the texture coords, vertices, indices, and normals. Everything shows up well enough on the screen, but now I want to put these normals to use with lighting. The old way seemed to use these methods in GLSL (normal = gl_NormalMatrix * gl_Normal;) however, these functions are now deprecated as I understand. Currently the cube I am rendering is too dark in some areas while rotating the cube. Does anyone think they understand the problem going on here is? I can post more code from my OpenGL app if required, here are the pics and the GLSL code.
If I remember correctly the normal matrix is the same as the model matrix, except if you do non-uniform scaling, then it has to do some correction or the normal will be incorrect. But you can review the link to be sure.
I think for vfNormal it should be "mat3(modelMatrix) * in_Normal", not the reverse like you have it.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
just like your other calls. The vector is always on the right side.
gl_NormalMatrix and gl_Normal anyway? ------gl_Normal is just the input. So it is the raw data untransformed that you sent with your VBO. gl_NormalMatrix is basically the same as the modelview matrix.
gl_NormalMatrix is technically the transposed inverse of the 3x3 part of the modelview matrix. So using the CML maths library to calculate it on the cpu before sending it to the shader:
[source lang="cpp"]
// (mv_matrix is the modelview matrix)
IMHO, it's better to do this properly to begin with instead of hacking it with the modelview matrix, so it won't suddenly break when you change something apparently unrelated later.