• Create Account

Implementing my own z-Buffer

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

6 replies to this topic

#1ZBufferOP  Members   -  Reputation: 102

Like
0Likes
Like

Posted 31 December 2013 - 05:42 PM

Hi guys,

I have some problems understanding the z-Buffer and how to interpolate the values between vertices correctly in respect to perspective.

What I have done so far is take a vertex in World Space (x, y,z) and transform it using my ViewProjection Matrix to get coordinates in clip-space of the form (x, y, z, w). These coordinates still need to be divided by w.

What do I have to use here z or w? And how do I interpolate it?

What I would do is:

- normalize (x,y,z,w) => (x/w, y/w, z/w, 1)

- linearly interpolate z/w

Would that be correct?

Do I have to divide by 1/w at the end? IF no, why not?

#2Álvaro  Crossbones+   -  Reputation: 9886

Like
0Likes
Like

Posted 01 January 2014 - 06:55 AM

#3ZBufferOP  Members   -  Reputation: 102

Like
0Likes
Like

Posted 01 January 2014 - 07:18 AM

OpenGL is interpolating linearly aswell once you are in clip space and normalized your coordinates afaik. Your coordinates look like this:

(x,y,z,1) where x,y,z are in the range [-1, 1].

Any more opinions on this? My impresison is that I dont have to do perspective correct interpolation on the z here but a linear interpolation is correct since z is already divided by w.

#4Álvaro  Crossbones+   -  Reputation: 9886

Like
0Likes
Like

Posted 01 January 2014 - 12:49 PM

Really, just do a web search for something like `software rasterizer z interpolation'. There is no point in repeating everything here.

#5ZBufferOP  Members   -  Reputation: 102

Like
-2Likes
Like

Posted 01 January 2014 - 06:58 PM

Yep thanks, i am right. You were wrong.

After transforming to the NDC,

So the depth value can be directly interpolated using z-NDC  for depth test.

Conclusion
In this post, the steps to linear interpolate the vertex in screen space is described. And for rasterizing the depth buffer only (e.g. for occlusion), the depth value can be linearly interpolated directly with the z coordinate in NDC space which is even simpler.

Edited by ZBufferOP, 01 January 2014 - 06:59 PM.

#6Álvaro  Crossbones+   -  Reputation: 9886

Like
0Likes
Like

Posted 01 January 2014 - 07:37 PM

However we cannot directly interpolate those attributes in screen space because projection transform after perspective division is not an affine transformation (i.e. after transformation, the mid-point of the line segment is no longer the mid-point), this will result in some distortion and this artifact is even more noticeable when the triangle is large[.]

But you seem to think you know what you are doing, so go ahead and do linear interpolation and hope something good will happen.

#7Paradigm Shifter  Crossbones+   -  Reputation: 4747

Like
0Likes
Like

Posted 02 January 2014 - 05:29 PM

Alvaro is a bit grumpy recently it's like he wanted Optimus Prime for Christmas and got Soundwave ;)

Al knows his stuff though I'd listen to what he has to say.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS