0

I wrote shader for diffuse lighting.
Normals rotate with rotation of 3D model, and its looks like when I rotate the model, light rotate to.

Vertex Shader

position = gl_ModelViewMatrix * gl_Vertex;
gl_Position = gl_ModelViewProjectionMatrix *  gl_Vertex;
normal = vec4(gl_Normal, 1.0); <---
gl_TexCoord[0] = gl_MultiTexCoord0;

Fragment Shader

lightVector = normalize(vec4(lightPosition + cameraPosition, 1.0) - position);
resultNormal = normalize(normal.xyz); <---

How to fix it? enter image description here

NoName
  • 57
  • 7
  • In which space are the normals in the image? Worldspace, Viewspace? How do you calculate them? – BDL Jun 29 '16 at 10:39
  • relevant: http://stackoverflow.com/questions/13654401/what-is-the-logic-behind-transforming-normals-with-the-transpose-of-the-inverse – PeterT Jun 29 '16 at 10:50

1 Answers1

2

You don't seem to be transforming your normals with gl_NormalMatrix. Also, this line is suspicious:

normal = vec4(gl_Normal, 1.0);

Normals are directions, not positions, so their .w component should be 0.

SurvivalMachine
  • 7,946
  • 15
  • 57
  • 87