GLSL and object vs. world space

Started by
-1 comments, last by mk27 14 years, 4 months ago
I just started trying to learn GLSL and I have a problem when rotating an object with lighting enabled. This is the vertex shader, which passes on a "diffuse" light value for the fragement shader:

void rotateY (inout vec4 vert, float rads);

uniform float YRot;
varying float Diffuse;

void main() {
	vec3 vnormal = normalize(gl_NormalMatrix * gl_Normal);
	Diffuse = max(dot(vnormal, gl_LightSource[0].position.xyz), 0.0);
	rotateY (gl_Vertex, YRot);
	gl_Position = ftransform();
}


void rotateY (inout vec4 vert, float rads) {
	vec4 old = vert;
	mat2 rotY = mat2(cos(rads), -sin(rads), sin(rads), cos(rads));
	vert.xz = old.xz * rotY;
}
So the problem is that the light on the object rotated with this appears to move with the object rather than remaining fixed in world space. What can I do?

This topic is closed to new replies.

Advertisement