Depth Buffer Method / Z-Buffer Method
Algorithm for Depth Buffer Method
1) Initialize the depth buffer and refresh buffer so that for all buffer positions(x, y),
- 𝑑𝑒𝑝𝑡ℎ(𝑥, 𝑦) = 0, 𝑟𝑒𝑓𝑟𝑒𝑠ℎ(𝑥, 𝑦) = 𝐼𝑏𝑎𝑐𝑘𝑔𝑛𝑑
2) For each position on each polygon surface, compare depth values to previously stored values in the depth buffer to determine visibility.
3) Calculate the depth z for each (x, y) position on the polygon.
4) If z > depth(x, y), then set
- 𝑑𝑒𝑝𝑡ℎ(𝑥, 𝑦) = 𝑧, 𝑟𝑒𝑓𝑟𝑒𝑠ℎ(𝑥, 𝑦) = 𝐼𝑠𝑢𝑟𝑓 (𝑥, 𝑦)
5) Where 𝐼𝑏𝑎𝑐𝑘𝑔𝑛𝑑 is the value for the background intensity, and 𝐼𝑠𝑢𝑟𝑓 (𝑥, 𝑦) is the projected intensity value for the surface at pixel position (x,y). After all, surfaces have been processed, the depth buffer contains depth values for the visible surfaces and the refresh buffer contains the corresponding intensity values for those surfaces.
End of Algorithm
It is image space approach.
Moreover, It compares surface depth at each pixel position on the projection plane.
It also referred to as z-buffer method since generally depth is measured in the z-direction.
Each surface of the scene processed separately one point at a time across the surface.
- Fig for Depth Buffer Method, A view plane position (x, y), surface s1 has the smallest depth from the view plane and so is visible at that position.
- We are starting with the pixel position of view plane and for a particular surface of an object.
- If we take the orthographic projection of any point (x,y,z) of the surface on the view plane we get two-dimension coordinate (x,y) for that point to display.
- Here we are taking (x.y) position on plan and find particular surface is how much depth.
- We can implement depth buffer algorithm in normalized coordinates so that z values range from 0 at the back clipping plane to zmax at the front clipping plane.
Zmax value can be 1 for unit cube or the largest value. [ Depth Buffer Method ]
- Here two buffers required. A depth buffer to store depth value of each (x,y) position and refresh buffer to store corresponding intensity values.
- Initially, depth buffer value 0 and refresh buffer value is an intensity of the background.
- Each surface of the polygon then processed one by one scanline at a time.
- Calculate the z values at each (x,y) pixel position.
- If calculated depth value is greater than the value stored in depth buffer it replaced with newly calculated values and store intensity of that point into refresh buffer at (x,y) position.
- Also, Depth values calculated from plane equation 𝐴𝑥 + 𝐵𝑦 + 𝐶𝑧 + 𝐷 = 0 as: Z = (-Ax-By-D)/C