I took a quick read and I didnt get it all. At the moment I was reading through this document http://www.nps.navy.mil/cs/sullivan/MV4470/resources/projective_texture_mapping.doc

which also comes from nvidia, though Im not sure where it is on their site (I found it through google).

I’ve never been very good at texgen. Ive tried it before, and after a lot of experimenting, the few times I tried it I was able to hack my way to get it to work eventually (you know, like when you matrix transform doesnt work, first you try flipping a sign bit, then you flip 2, that doesnt work so you invert a matrix…etc until it eventually works). When I was done, I never quite understood why it eventually worked. I’ve been meaning to learn texgen inside and out eventually, so this discussion is helping.

Here is what I think is going on (at least what I can pull together from what I read). Keep in mind that EVERYTHING I say below might be wrong.

In 3D, you usually:

start with object space coords

transform by model matrix M to get world space coords

transform by view matrix V to get eye space coords

transform by projection and so on (the rest isnt important for this discussion)

When you use object linear texgen, the texgen takes place before the M or V transformation. When you use “eye” linear texgen, the texgen takes place after the M but before the V transformation.

The tricky thing here is that openGL only has a combined modelview matrix MV. So what happens is that when you specify the texgen plane, that plane gets transformed by V. This means at that very moment, you must have a valid V transformation matrix (ie: camera matrix) as your modelview matrix.

Then when you draw a vertex, it gets transformed by MV. Hence both the plane and the vertex are in eye space when the texture coordinates are generated.

Thats where the tricky part of the name comes from. Eye linear doesnt mean that you specify the plane in eye space. It means that when the texgen takes place, both the plane and the vertex are already transformed into eye space. The clip plane is actually specified in world space (and the vertex was specified in object space).

This brings me to the point I hate to come to, but (sorry about this, especially if Im completely wrong) but I think Cass had a misunderstanding when he wrote that document. He says:

OpenGL will automatically multiply the planes specified with (modelviewpo)-1, i.e. the inverse of the modelview matrix in effect when the planes are specified. From Equation 1 we see that the net effect is to map the vertex position in eye coordinates [xe,ye,ze,we]T back to the ‘object space’

defined by (modelviewpo)-1.

If I am right (and he is wrong) I think his confusion might come from the fact that you are multiplying by the inverse of the modelview matrix. As I mentioned earlier, I seen to recall that transforming a plane requires that you multiply by the inverst transpose of a matrix, not the matrix itself. When you see that you multiply by the inverse modelview matrix, the natrual conclusion is that you are reverse transforming back into world or object space. However, if Im right about this then transforming by the inverse modelview actually allows you to transform from world space into eye space.

I’ll have to sit down later and calculate some of this out and experiment to see if I’m right, but it suddenly makes a heck of a lot more sense to me. Most everything seems to pop into place.

Another note on this. As I said, when you specify the plane for the eye linear transform you are actually specifying it in world space and it gets transformed to eye space by the (inverse of) the current modelview matrix. If you actually want to specify your plane in true eye space, you can just make the modelview matrix the identity before calling glTexGenfv and that will do it for you.

And one again, EVERYTHING above may be incorrect. However, since everything now really fits into place in my head I have this gut fealing that I am correct (or at least mostly correct)

I think pretty soon I am going to try putting together a comprehensive texgen tutorial to go along with my per-pixel lighting tutorials. I learned so much writing those tutorials that I thing the same thing would happen if I wrote some on texgen

P.S.

I see now that document was written by Cass Everitt, Ashu Rege, and Cem Cebenoyan, (I thought it was just cass) so I extend my potential appologies to them too.

[This message has been edited by LordKronos (edited 05-30-2002).]