Sign in to follow this  

GLSL and object vs. world space

Recommended Posts

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], 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?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this