Sign in to follow this  
ZBufferOP

Implementing my own z-Buffer

Recommended Posts

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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Yep thanks, i am right. You were wrong.

 

After transforming to the NDC,

zNDC.png

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

 

http://www.altdevblogaday.com/2012/04/29/software-rasterizer-part-2/

 

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

Share this post


Link to post
Share on other sites

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.

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