Jump to content
  • Advertisement
Sign in to follow this  

GLSL and object vs. world space

This topic is 3268 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!