Texture Q Coordinate / NVIDIA

Please someone explain me the difference between:

glBegin(GL_QUADS);
glTexCoord4f(0.0f, 0.0f, 0, 1.0f);
glVertex2i(-1, -1);
glTexCoord4f(.25f, 0.0f, 0, .25f);
glVertex2i(+1, -1);
glTexCoord4f(.25f, .25f, 0, .25f);
glVertex2i(+1, +1);
glTexCoord4f(0.0f, 1.0f, 0, 1.0f);
glVertex2i(-1, +1);
glEnd();

and :

glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex2i(-1, -1);
glTexCoord2f(1.0f, 0.0f);
glVertex2i(+1, -1);
glTexCoord2f(1.0f, 1.0f);
glVertex2i(+1, +1);
glTexCoord2f(0.0f, 1.0f);
glVertex2i(-1, +1);
glEnd();

On my GeForce4MX I get different results. Is it me that is missing something, or is it the driver ?
TIA,

You’ve changed W in some of the texture coordinates. This is implicitly 1.0. With your changes the perspective correction will be significantly different. There is not the homogeneous divide of texture coordinates that you think there is. The w is used to weight the perspective warp, the coordinates you supply at the vertices are the ones that will produce the texel at the vertices.

[This message has been edited by dorbie (edited 02-08-2003).]

Thanks for the reply,

>> With your changes the perspective correction
>> will be significantly different.

If you mean GL_PERSPECTIVE_CORRECTION_HINT, I’ve already set to GL_NICEST and nothing change. Though, I know it’s just a “hint” and implementations are free to ignore it.

>> There is not the homogeneous divide of
>> texture coordinates that you think there is

You mean that Q does not divide STR ? Well, in fact, the division happens. All “borders” are rendered correctly. That’s the interior of the quad that is interpolated strangely, just like perspective issues.

The thing is, I don’t know when homogeneous division is performed. I can’t find it in the spec, and don’t even know if the spec explicitly details it. If division was performed per-vertex, both code samples would give the same result, isn’t it ?

What Dorbie is saying is that q division occurs per-pixel, and doing it per vertex is not supposed to produce the same results. In other words:

(0.5a + 0.5b)/(0.5c + 0.5d) != 0.5a/c + 0.5b/d

-Evan

EDIT: Bad code tag.

[This message has been edited by ehart (edited 02-08-2003).]

[This message has been edited by ehart (edited 02-08-2003).]

Ah, thanks. It makes sense. Though, it does not help ! I mean, I can not correct the kind of “perspective error” issue. That’s due to quad-to-triangle split and OpenGL’s linear math (not really helpful when dealing with homogenous coordinates).

I have to look for another solution, but thanks anyway.

Solution for what? If you explicitly fiddle with q, you should know what you’re doing

Btw, your quad is not even planar. You should submit two triangles for well behaved results.

LOL my quad is not planar ? if this one is not planar, then no one is !
glBegin(GL_QUADS);
glVertex2i(-1, -1);
glVertex2i(+1, -1);
glVertex2i(+1, +1);
glVertex2i(-1, +1);
glEnd();

Solution for what ? Solution for “perspective correction”-like distortions. If you try the two code samples (in the beginning of the thread) you’ll quickly see what I mean IMHO.

Depth-based perspective distortions have already been corrected in OpenGL implementations. Why not with homogenous texture coordinates ? Maybe it is a different issue even though the problem “looks” similar.

Post-divide it is indeed planar, but that doesn’t count.
GL’s definition of ‘planar’ is not limited to screen space x/y/z. It applies to clip space and it includes colors, textures and all other vertex attributes.

Besides, texture ‘distortion’ is exactly what can be expected with your quad. Interpolated w/q controls texture mapping, not q alone. For your quad to look ‘right’, you’d have to fiddle with the vertex coords too to compensate.

And last but not least ‘depth-based perspective distortions’ are solved by virtue of transforming everything to homogenous coords. Look at how a perspective projection matrix is composed and you’ll see that for every unit in z, you get some amount in w. A projection that doesn’t touch w is ortographic and this obviously won’t correct perspective distortions on textures. So it’s not really depth-based, it’s w based.

Ie

//orthographic projection
glTexCoord2f(0.0f,1.0f);
glVertex3f(-1.0f, 1.0f,-1.0f);
glTexCoord2f(0.0f,0.0f);
glVertex3f(-1.0f,-1.0f,-1.0f);
glTexCoord2f(1.0f,0.5f);
glVertex3f( 0.2f, 0.0f,-5.0f);

!=

//perspective projection
glTexCoord2f(0.0f,1.0f);
glVertex3f(-1.0f, 1.0f,-1.0f);
glTexCoord2f(0.0f,0.0f);
glVertex3f(-1.0f,-1.0f,-1.0f);
glTexCoord2f(1.0f,0.5f);
glVertex3f( 1.0f, 0.0f,-5.0f);

To get the same result in ortho mode, you need this

//ortho projection
glTexCoord2f(0.0f,1.0f);
glVertex4f(-1.0f, 1.0f,-1.0f,1.0f);
glTexCoord2f(0.0f,0.0f);
glVertex4f(-1.0f,-1.0f,-1.0f,1.0f);
glTexCoord2f(1.0f,0.5f);
glVertex4f( 1.0f, 0.0f,-5.0f,5.0f);

[This message has been edited by zeckensack (edited 02-10-2003).]

Ok I think I’ve got it.
I’ll try it tonight.
Thanks !

Yay it’s working.
It’s still a bit hard for me to realize how that homogeneous coordinate works with all its secrets, but at least today I’ve learned one more thing : how it is interpolated, and why the linear interpolation can give the feeling of “perspective distortion”.

Thanks a ton !

Np. You might also be interested in a little trick cass told me

Wow, cass is really an incredible guy. Such short explanation, yet so clear !
Thanks for the link, it really helps me once again.