understanding z buffer formats direct x
A z buffer is just a 3d array that shows what object should be written in front of another object. each element in the array represents a pixel that holds a value from 0.0 to 1.0. My question is if that is all a z buffer does, then why are some buffers 24bit, 32bit, and 16 bit ?
A Z-Buffer is not a 3D array. It's a 2D array that has a value at each pixel. That value represents the depth of the last pixel written to that position.
If the pending pixel has a depth that's behind the current value on the Z-Buffer, the pixel is not visible and so it is skipped. This is what allows objects to be rendered in any order: pixel behind won't overwrite pixel in front; they will be discarded.
The thing is, that value has differing precision. That's where the bits come in. A 16-bit Z-Buffer takes half as much memory as a 32-bit Z-Buffer, but cannot represent the same range.
Memory is not exactly cheap (well, that's changing, but still), so if you don't need lots of precision use 16-bit and save memory. (This was more important in the past, where memory truly was scarce.)
Trying to store too many values in a buffer that can't hold them will cause them to combine (16.5 and 15.5 both becoming 16, for example), and you get artifacts.
精彩评论