I've been having trouble with my lighting.
Everything on the screen appears dark unless I go in and manually set the color, in which case I can see that the cube does draw to the screen. I played around with different variables to figure out where the problem is, and it seems like it has something to do with my normal vector.
Is there anything that immediately stands out as wrong about this code?:
Code: Select all
//GLSL
vec3 normalVector=normalize(modelviewInverseTranspose*vertexNormal);
vec3 lightVector= normalize(vec3(mainLight.position));
vec3 lighting=vec3(mainLight.color) * vec3(objectColor) * max(0.0, dot(normalVector, lightVector) );
fragmentColor=vec4(lighting, 1.0); //Move final lighting to fragment shader.
the modelviewInverseTranspose matrix is defined this way;
Code: Select all
model=glm::translate(glm::mat4(1.0f) , glm::vec3(0.0, 0.0, -4.0) );
view= glm::lookAt(glm::vec3(0.0, 2.0, 0.0), glm::vec3(0.0, 0.0, -4.0), glm::vec3(0.0, 1.0, 0.0));
modelviewMatrix=model*view;
glm::mat3 modelviewInverseTranspose=glm::transpose(glm::inverse(glm::mat3(modelviewMatrix)));