NoName
NoName

Reputation: 57

Normals move with model

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

Upvotes: 0

Views: 329

Answers (1)

SurvivalMachine
SurvivalMachine

Reputation: 8356

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.

Upvotes: 3

Related Questions