Jump to content
  • Advertisement
Sign in to follow this  
maxest

Interpolating 1/z in screen-space

This topic is 2776 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

I want to do perspective-correct interpolation. I took the formula (12) from here http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.3.211&rep=rep1&type=pdf and it seems something is a bit wrongly "inversed". The code:

mtx mat = world * cameraTranslate * cameraRotate * persp * ortho;
float s = 0.0f;

for (int i = 0; i <= 10; i++)
{
vec4 q(-5,0,0), Q(5,0,0);
q *= mat;
Q *= mat;
float wt = 1.0f/q.w + s*(1.0f/Q.w - 1.0f/q.w);
wt = 1.0f/wt;
...
s += 0.1f;

(during wt computation, q.w and Q/w contain view-space Z-values [both are < 0 since I have right-handed coordinate system])

And the perspective and ortho matrices:

mtx persp(-near, 0.0f, 0.0f, 0.0f,
0.0f, -near, 0.0f, 0.0f,
0.0f, 0.0f, -near-far, 1.0f,
0.0f, 0.0f, -near*far, 0.0f);

mtx ortho(2.0f/(right-left), 0.0f, 0.0f, 0.0f,
0.0f, 2.0f/(top-bottom), 0.0f, 0.0f,
0.0f, 0.0f, -2.0f/(far-near), 0.0f,
-(right+left)/(right-left), -(top+bottom)/(top-bottom), -(near+far)/(far-near), 1.0f);


Thoeretically, for such a positioning of points in screen-space:

q... . . .Q

I should get values like:

-10 -9.5 -9 -7 -3 -1

But I get:

-10 -6 -4 -2 -1.5 -1

So it looks a bit "inversed" and I can't figure out why

[Edited by - maxest on November 14, 2010 7:46:22 AM]

Share this post


Link to post
Share on other sites
Advertisement
Hmm... I'm starting to think that I misinterpreted the results and in fact the ones I get are valid. Can somebody confirm that?

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!