Sign in to follow this  
maxest

Interpolating 1/z in screen-space

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this