http://www.cs.cmu.edu/~djames/15-462/Fall03/notes/CassEveritt-MathematicsOfPerPixelLighting.pdf
However, in OpenGL, there's only 2 spaces:
1. ModelView: Object
2. Projection: Eye (or camera)
OpenGL has no explicit world space.
From OpenGL.org:
Think of the projection matrix as describing the attributes of your camera, such as field of view, focal length, fish eye lens, etc. Think of the ModelView matrix as where you stand with the camera and the direction you point it.
For the specular lights, we will need the inverse matrix to compute the camera view. However OpenGL matrix is column major. So beware!
Here is one good read on Matrix, OpenGL style.
MacTech: Macintosh Technology has a simple reading for texture gen and texture mapping.
My lighting algorithm was right as far as mathematics is concerned but I did not care about the Eye and View Space that I got them all topsy turvy. From OpenGL Forum:
+--------------+ +--------------+
| Object Space | -> Modeling Transform -> | World Space |
+--------------+ +--------------+
+--------------+ +--------------+
| World Space | -> Viewing Transform -> | Eye Space |
+--------------+ +--------------+
+--------------+ +--------------+
| Object Space | -> Modelview Transform -> | Eye Space |
+--------------+ +--------------+
The modelview matrix gets you from object space to eye space (use the inverse to get back). It doesn't know about world
space.
The only way you can use modelview to get back to world space is if your object space and world space are the same (i.e. your modeling transform is the identity matrix -- i.e. a no-op). in other words, if the position vertex data for all objects in your scene are specified in a common coordinate system.
You're probably goin to find it simpler to pre-transform your light to eye space in your app and pass that into your shader, so you don't have to think about world space in your shader.
No comments:
Post a Comment