I’ve been trying to implement PPL (in eye space) using OpenGL and Cg, but I can’t get it work correctly. When I change my camera position (I use gluLookAt), lighting gets wrong - it looks like I would be moving/rotating the object, not the camera.
Download this to see what I mean. Use N/M, U/I and J/K to move the camera.
Obviously, my light and eye (camera) position aren’t in eye space, but in world space - I tried transforming them, but it didn’t change anything.
I’ve been trying to solve this for over a month now, so I would highly appreciate if someone could help me.
Just a guess after a quick look: Don’t you need to transform the light vector L into tangent space?
So if I get this right, I should actually do some sort of bump mapping to get correct lighting? Well, I guess I should just read on (Cg Tutorial book), becasue I don’t know bump mapping yet. I hope it will help, thanks again.
To do per-pixel lighting, you need to bring the normal and the light vector into the fragment program. Both of these need to be transformed into the same space, whether it is tangent space, world space, model space, or whatever. More than likely, you aren’t transforming one of them into the same space as the other.
If you look at the vertex program, you can see that I do transform object space vertex position and normal into eye space. You’re saying I should transform normal and light vector only, that’s all? And how can I transform world space to eye space within a shader, then?
But like I said, I already tried to transform everything into the same space, but it didn’t work - lighting looked the same. So I assume problem’s somewhere else as well, but don’t have any idea where.
It just sounds like you need to make sure that you know which coordinate space you specify your different vectors in, and how the vector specification works (for example, the coordinates for glLight are transformed by the MODELVIEW at the time of specification (only)). Then just work out what lighting equation you actually want, and implement it appropriately. There’s no silver bullet; just keeping things straight.