Unit 4
Unit 4
are visible and which are hidden behind other objects. It works by utilizing a buffer, called the Z-
buffer or depth buffer, which stores the depth (Z-coordinate) of each pixel in the scene. When
rendering polygons, the Z-buffer algorithm compares the depth of each pixel being rendered to the
corresponding depth value stored in the Z-buffer. If the depth of the pixel being rendered is closer to
the viewer than the depth stored in the Z-buffer, the pixel is considered visible and its depth value is
updated in the buffer. Otherwise, the pixel is occluded by another object and is discarded.
When two polygons have the same Z-value, which often occurs when they lie on the same plane in
the scene, the Z-buffer algorithm typically prioritizes one over the other based on the order in which
the polygons are rendered. The pixel with the corresponding depth value is updated in the Z-buffer
based on whichever polygon is rendered last. This means that the polygon rendered last will appear
on top, effectively resolving the visibility between polygons with the same Z-value.
However, if two polygons overlap and have the same Z-value but are rendered in such a way that
they partially cover each other (for example, if one polygon partially occludes the other), artifacts
like flickering or "Z-fighting" may occur. Z-fighting happens when the depth values of the polygons
are very close, causing the Z-buffer to alternate between which polygon is rendered on top, resulting
in a flickering effect. To mitigate this issue, techniques such as using higher precision depth buffers,
depth biasing, or adjusting the near and far clipping planes can be employed.
Ray casting : pg 35