bostrov

07-24-2003, 07:42 PM

I wasn't sure if this would be a basic question or not, but which I checked the basic board there were questions about how to compute the normal of a set of vectors, so I'm going to wing it and presume this is an advanced question.

I've long since gotten tired of the built in lighting model in opengl ( specular of ( n dot h ) ^ shine * color - n the normal and h the half angle...) and thought for a warm up I would implement phong lighting without the Blinn half-angles used - in other words actually compute the reflection vector of the lighting vector l through normal n by 2*(n dot l)(n - l) - use that vector r for computing specular values with (r dot v) ^ shine -

Now it's obvious in the vertex program I'll need to compute r, and I'll have to do other housework such as transforming the incoming vertex to the clipping volume which is no problem either. So I presume all the data coming into a vertex program is untransformed, is that correct? This would include lights?

If I want to get the lighting vector and I have a vertex still in model space, do I need to transform that vertex into world space (by multiplying by the modelview matrix) before doing the subtraction and subsequent normalization, or has opengl already transformed the light for me by multiplying the light position (if it's a positional light) by the inverse of the modelview matrix?

It would seem like on a per-model basis OpenGL should save me the work of having to transform lights on a per-vertex basis but I can't really find any clear documentation on what the state of a positional light is at the start of a vertex transformation in a vertex program.

Thanks for the help guys..

I've long since gotten tired of the built in lighting model in opengl ( specular of ( n dot h ) ^ shine * color - n the normal and h the half angle...) and thought for a warm up I would implement phong lighting without the Blinn half-angles used - in other words actually compute the reflection vector of the lighting vector l through normal n by 2*(n dot l)(n - l) - use that vector r for computing specular values with (r dot v) ^ shine -

Now it's obvious in the vertex program I'll need to compute r, and I'll have to do other housework such as transforming the incoming vertex to the clipping volume which is no problem either. So I presume all the data coming into a vertex program is untransformed, is that correct? This would include lights?

If I want to get the lighting vector and I have a vertex still in model space, do I need to transform that vertex into world space (by multiplying by the modelview matrix) before doing the subtraction and subsequent normalization, or has opengl already transformed the light for me by multiplying the light position (if it's a positional light) by the inverse of the modelview matrix?

It would seem like on a per-model basis OpenGL should save me the work of having to transform lights on a per-vertex basis but I can't really find any clear documentation on what the state of a positional light is at the start of a vertex transformation in a vertex program.

Thanks for the help guys..