PDA

View Full Version : Texture Q Coordinate / NVIDIA



vincoof
02-08-2003, 04:11 AM
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,

dorbie
02-08-2003, 06:34 AM
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).]

vincoof
02-08-2003, 07:30 AM
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 ?

ehart
02-08-2003, 09:09 AM
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.5*a + 0.5*b)/(0.5*c + 0.5*d) != 0.5*a/c + 0.5*b/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).]

vincoof
02-10-2003, 12:51 AM
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.

zeckensack
02-10-2003, 01:06 AM
Solution for what? If you explicitly fiddle with q, you should know what you're doing http://www.opengl.org/discussion_boards/ubb/wink.gif

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

vincoof
02-10-2003, 04:51 AM
LOL my quad is not planar ? if this one is not planar, then no one is ! http://www.opengl.org/discussion_boards/ubb/smile.gif
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.

zeckensack
02-10-2003, 09:15 PM
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).]

vincoof
02-11-2003, 06:48 AM
Ok I think I've got it.
I'll try it tonight.
Thanks !

vincoof
02-11-2003, 03:21 PM
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 !

zeckensack
02-11-2003, 03:39 PM
Np. You might also be interested in a little trick cass told me (http://www.opengl.org/discussion_boards/ubb/Forum3/HTML/008135.html) http://www.opengl.org/discussion_boards/ubb/smile.gif

vincoof
02-12-2003, 11:16 AM
Wow, cass is really an incredible guy. Such short explanation, yet so clear !
Thanks for the link, it really helps me once again.