Looking at your solution, from the link you posted in the comments, the first thing that strikes my eye is: in the lighting pass vertex shader, you do
viewSpace = gl_ModelViewMatrix * gl_Vertex;
Then in the fragment shader you do
vec3 lightPos = pointLightPostion * viewSpace;
vec3 WorldPos = texture2D(positionMap, TexCoord) * viewSpace;
vec3 normal = texture2D(normalMap, TexCoord) * viewSpace;
This has no sense at all.
Now, you are doing deferred shading, which is a technique typical of modern openGL (3.2+), that doesn't perform good an ancient hardware, and I think you used stuff form this tutorial, which is also modern openGL, so why do you use glPushMatrix
and that kind of old stuff? Too bad, I've never learned old openGL, so I'm not always sure that I understand correctly your code.
By the way, back to the geometry pass. In the vertex shader, you do
position = gl_ModelViewMatrix * gl_Vertex;
normal = (modelMatrix * vec4(gl_Normal,0.0)).xyz;
but then you have position in view space and normal in model space. (if the modelMatrix you pass to the shader is really the model matrix, because from your screenshot the normals seem to be in view space).
Also, be careful, if the normals are not in view space, but in model space, you'll have to bias and scale them, normal = 0.5f*(modelMatrix * vec4(gl_Normal,0.0)).xyz +1.0f;
. I'd just go for
position = gl_ModelViewMatrix * gl_Vertex;
normal = (gl_ModelViewMatrix * vec4(gl_Normal,0.0)).xyz;
Remember, the important thing is that you have both position and normal in the same space. You can use either world space or view space, but then stick to your choice. In the lighting pass, just do
vec3 WorldPos = texture2D(positionMap, TexCoord).rgb;
vec3 normal = texture2D(normalMap, TexCoord).rgb;
vec3 lightVector = WorldPos - pointLightPostion;
and be sure that pointLightPostion
is in the same space you decided, by transforming it in your application, on the CPU side, and then passing it to openGL, already transformed.
Also, I don't understand why you do
lightColor += diffuse + specular;
isntead of
lightColor *= diffuse + specular;
That way you'll have an emissive component in your lighting with the color of your light and the diffuse and specular without it. It doesn't seem a nice choice, especially in deferred shading, where you can easily perform an ambient pass on the whole frame.
Hope I helped. Too bad I don't use glut and I can't build your code.
EDIT
To transform pointLightPostion
(which I assume is in the world space already) to the view space, just do
pointLightPostion = (ViewMatrix * glm::vec4(pointLightPostion,1.0f)).xyz;