views:

56

answers:

2

I am just trying to better understand the directX pipeline. Just curious if depth buffers are mandatory in order to get things work. Or is it just a buffer you need if you want objects to appear behind one another.

+2  A: 

The depth buffer is not mandatory. In a 2D game, for example, there is usually no need for it.

You need a depth buffer if you want objects to appear behind each other, but still want to be able to draw them in arbitrary order.

If you draw all triangles from the back to the front, and none of them intersect, then you could do without the depth buffer. However, it's generally easier to do away with depth sorting and just to use the depth buffer anyway.

Thomas
well, that, and it's _faster_ to draw front-to-back. You don't have to run shaders on pixels that are occluded.
Bahbar
+1  A: 

Depth buffers are not mandatory. They simply solve the following problem: suppose you have an object near to the camera which is drawn first. Then, after that is already drawn, you want to draw an object which is far away, but at the same position as the nearby object on-screen. Without depth buffers, it gets drawn on top, which looks wrong. With depth buffers, it is obscured, because the GPU figures out its behind something else that has already been drawn.

You can turn them off and deal with that, eg. by drawing back-to-front (but this has other problems solved by depth buffering), which is easy in 2D games. Alternatively for some reason you might want that over-draw as some kind of effect. But it is by no means necessary for basic rendering.

AshleysBrain