PDA

View Full Version : Lighting questions, feeling stupid....



Keith Z. Leonard
09-06-2007, 10:48 PM
I've been writing shaders in Cg for quite a while, but when doing so in GLSL (which I'd like to switch to), I'm having some issues with lighting.

Basically, what space should I be feeding light positions in, what gets transformed by the GL, that sort of thing? I have grabbed up some simple lighting examples from places (lighthouse 3D, for instance, also the orange book), and I can't seem to get it correct. It's vexing me, as I have written FAR more complex shaders in Cg, and it's difficult to get started when basic lighting isn't working correctly.

I am using GL 2.1 and sending lights in through the GL lighting API, accessing them in the shader via the pre-defined variable names. I know these will go away in GL 3, but still.....

Thanks all,

Keith

Zengar
09-07-2007, 12:03 AM
When you specify a light position/direction, it will be transformed by the current modelview matrix, I guess that is the source of your problems :) To get this values in world space, set the matrix to identity before you load them. Or just use uniforms (preferable).

Keith Z. Leonard
09-07-2007, 11:50 AM
Ah, so if I have a world space position for the light, I could transform it by the inverse of the modelview to get it into object space, then make the lighting calls once per render call, yes?

Obviously I'll need to use uniforms at some point anyway, for gl 3.