View Full Version : Passing light pos/dir to GLSL in eye space

08-06-2009, 07:16 PM
Im making some changes to a few of my shaders, I do my lighting in eye space, and Ive been setting the light position with world matrix from scene and glLight calls like this.

- Set view by loading a view matrix in (LookAt like)
- Push matrix, multiply light matrix in
- set glLight position as default (0, 0, 0, 1), (0, 0, 0, 1) is transformed my modelview and stored in eye space (from docs)
- Pop matrix
- Push object matrix
- render object
- Pop object matrix

I would then get gl_LightSource[0].position in eye space in the pixel shader. Now I would like to pass the light position which I have in world coordiantes from a scene graph, directly to the shader as a uniform.
How do I accomplish the automatic conversion to eye space that I use to get from the use of glLight?

08-06-2009, 08:02 PM
See the source of chapter 17 here


Looking forward you probably want to send your own light data as user defined uniforms and do your own transformations.

Many more examples here