Jump to content
  • Advertisement
Sign in to follow this  
Mr Furious

Unexpected Texture Sampling

This topic is 3568 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In trying to mimic a 3 monitor setup I have tested rendering to texture and then applying that texture to 3 screen space quads. The scene consists of a skybox with a checkerboard texture on every face. For now, all 3 screen quads are rendering the exact same texture. It seems like my texture coordinates are not properly interpolated on the sides. Can someone explain this behavior? [Edited by - Mr Furious on October 8, 2008 6:23:44 PM]

Share this post


Link to post
Share on other sites
Advertisement
That's perspective-incorrect interpolation of texture coordinates. In GL you can fix this with glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)

Also perspective correct interpolation will only work if you are setting the z values of your vertices correctly.

Share this post


Link to post
Share on other sites
Ok, I've tried that and ended up with the same result. I'm rendering those 3 quads with an orthographic camera. Maybe it's not possible to be perspective correct when rendering in ortho.

I don't really understand why texturing behaves this way when rendering quads in ortho as opposed to rendering 3 world space quads with perspective projection. Does the projection matrix get used somehow in the process of sampling a texture?

Share this post


Link to post
Share on other sites
The W component (the reciprocal of depth) is used in the perspective correct interpolation to reconstruct the sample position in homogenous texture space, so yes, the projection matrix plays a part in the calculation of the sampling position.

Whereas affine (non-corrected) sampling is effectively a linear interpolation in screen space, not in texture space - which is the original problem) - the w-divided coordinate is calculated as follows:



//let frac = 0 to 1, interpolation parameter between tc0 and tc1
tc' =
((1-frac)*tc0.xy/tc0.z + frac*tc1.xy/tc1.z) //z divide
/
((1-frac)*1.0/tc0.z + frac*1.0/tc1.z) // reciprocal of z divide (1/z), AKA w divide
;


As you can see from the formula, you need to generate the per-vertex w value in order to achieve correct texture mapping. The projection matrix is usually set up to calculate it for you.

[Edited by - Nik02 on October 9, 2008 2:49:55 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!