ZBUFFER question 2

Started by
1 comment, last by oreste 9 years, 7 months ago
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?
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].

Thanx. That makes a lot clearer for me!! Oreste

This topic is closed to new replies.

Advertisement