I recently bought the third edition of the orange OpenGL Shader Language and found that a lot had changed since the OpenGL Superbible was last updated. One of the biggest changes was that global uniforms such as gl_Vertex and gl_Normal were deprecated, and instead we were to use the 'in' keyword to show we are expecting input.
One problem: the Vertices seem fine, but the normals given to me seem incorrect. If i use gl_Normal my shader works fine, but if i use the following line: "in vec3 MCnormal;", the normal never seems to change. I'm rendering a glutSolidTorus, so the normals should be correct, and as I said before, if i just reference "gl_Normal" i get results.
Any idea why this is? I'm still learning the changes surrounding OpenGL 3.2, so perhaps I'm missing something in my code? Besides passing in the ModelViewMatrix, ModelViewProjectionMatrix and NormalMatrix, everything else seems to be basically the same.
Vertex Shader:
#version 130
in vec4 MCvertex;
in vec3 MCnormal;
uniform mat4 MVMatrix;
uniform mat4 MVPMatrix;
uniform mat4 NormalMatrix;
out float LightIntensity;
void main()
{
float diffuse = 0.7;
vec3 lightPos = vec3(0,10,0);
mat3 NMat = mat3(NormalMatrix);
vec3 position = vec3(MCvertex * MVMatrix);
vec3 L = normalize(lightPos - position);
vec3 N = normalize(NMat * normalize(MCnormal));
LightIntensity = diffuse * max(dot(N, L), 0.0);
gl_Position = MCvertex * MVMatrix * MVPMatrix;
}
Fragment Shader:
#version 130
in float LightIntensity;
out vec4 FragColor;
void main()
{
FragColor = vec4(LightIntensity, LightIntensity, LightIntensity, 1.0);
}
Bow before me... for i am l33t!