Lighting questions, feeling stupid

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

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 :slight_smile: To get this values in world space, set the matrix to identity before you load them. Or just use uniforms (preferable).

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.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.