Jump to content
  • Advertisement
Sign in to follow this  
oreste

ZBUFFER question 2

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

This a more fundamental aspect and i have been trying to get to a question clearly submitted. The fact is this: where does the ZBUFFER get the depth coordinates from? The code i am studying is an initiation to the ZBUUFER. Here the triangle is rendered twice, in the geometry pipeline Triangle A is translated 0.0f, 0.0f, 2.0f and Triangle B is translated 0.0f, 0.0f, -2.0f. I suppose the ZBUFFER uses the Z coordinates 2.0f and -2.0f........................................Now suppose i have 2 different objects like a triangle and a square, one's vertices have the same z-coordinate (for ex. 2.0f) and the other's vertices have a different z-coordinate (for ex. -2.0f)then what? where does the ZBUFFER gets the depth?

Share this post


Link to post
Share on other sites
Advertisement

After the projection matrix is applied, the coordinates are converted into normalized device coordinates by dividing by the w component. This puts the x,y coordinates into the range [-1, 1] and the z coordinate into the range [0, 1] (for DirectX). For z, 0 is closest and 1 is farthest.

 

When each pixel is rendered, it's z value is compared to the same location in the zbuffer using a configurable comparison function.  By default, the comparison function is less than. This means that if the z value of the new pixel being rendered is less than the z value already in that location of the zbuffer, the new pixel is rendered and the zbuffer is updated with the new value.  If the z value greater than or equal to the existing value, the new pixel is skipped and not rendered because it is farther away than the pixel already there.  Clearing the zbuffer typically resets everything to 1 since that is the farthest value, and you usually want the closest objects to be visible.

 

If you are using a left handed coordinate system where +z goes into the screen, and you are using the default < compare, then in your example the zbuffer will contain the lower z value since it is closer (providing it isn't behind the camera).  However, that value will have been normalized to the range [0, 1], so it won't actually be -2.

 

Edit: I only mentioned DirectX because your other post referred to DirectX, but for completeness OpenGL normalizes z values to [-1, 1].

Edited by megadan

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!