HOME

TheInfoList



OR:

Demonstration of z-fighting with multiple colors and textures over a grey background Z-fighting, also called stitching, or planefighting, is a phenomenon in
3D rendering 3D rendering is the 3D computer graphics process of converting 3D modeling, 3D models into 2D computer graphics, 2D images on a computer. 3D renders may include photorealistic rendering, photorealistic effects or non-photorealistic rendering, no ...
that occurs when two or more primitives have very similar distances to the camera. This would cause them to have near-similar or identical values in the
z-buffer A depth buffer, also known as a z-buffer, is a type of data buffer used in computer graphics to represent depth information of objects in 3D space from a particular perspective. Depth buffers are an aid to rendering a scene to ensure that the ...
, which keeps track of depth. This then means that when a specific pixel is being rendered, it is ambiguous which one of the two primitives are drawn in that pixel because the z-buffer cannot distinguish precisely which one is farther from the other. If one pixel was unambiguously closer, the less close one could be discarded. It is particularly prevalent with
coplanar In geometry, a set of points in space are coplanar if there exists a geometric plane that contains them all. For example, three points are always coplanar, and if the points are distinct and non-collinear, the plane they determine is unique. Howe ...
polygons, where two faces occupy essentially the same space, with neither in front. Affected pixels are rendered with
fragment Fragment may refer to: Entertainment Television and film * "Fragments" (''Torchwood''), an episode from the BBC TV series * "Fragments", an episode from the Canadian TV series ''Sanctuary'' * "Fragments" (Steven Universe Future), an episode f ...
s from one polygon or the other arbitrarily, in a manner determined by the precision of the z-buffer. It can also vary as the scene or camera is changed, causing one polygon to "win" the z test, then another, and so on. The overall effect is flickering, noisy rasterization of two polygons which "fight" to color the screen pixels. This problem is usually caused by limited sub-pixel precision and
floating point In computing, floating-point arithmetic (FP) is arithmetic that represents real numbers approximately, using an integer with a fixed precision, called the significand, scaled by an integer exponent of a fixed base. For example, 12.345 can be ...
and fixed point
round-off error A roundoff error, also called rounding error, is the difference between the result produced by a given algorithm using exact arithmetic and the result produced by the same algorithm using finite-precision, rounded arithmetic. Rounding errors are d ...
s. The more z-buffer precision one uses, the less likely it is that z-fighting will be encountered. But for coplanar polygons, the problem is inevitable unless corrective action is taken. As the distance between
near and far clip plane In 3D computer graphics, the view frustum (also called viewing frustum) is the region of space in the modeled world that may appear on the screen; it is the field of view in video games, field of view of a Perspective (graphical), perspective ...
s increases, and in particular the near plane is selected near the eye, the greater the likelihood exists that z-fighting between primitives will occur. With large virtual environments inevitably there is an inherent conflict between the need to resolve visibility in the distance and in the foreground, so for example in a space flight simulator, if a distant galaxy is drawn to scale, the viewer will not have the precision to resolve visibility on any cockpit geometry in the foreground (although even a numerical representation would present problems prior to z-buffered rendering). To mitigate these problems, z-buffer precision is weighted towards the near clip plane, but this is not the case with all visibility schemes and it is insufficient to eliminate all z-fighting issues.


Mitigation

The effect seen on two co-planar polygons. Z-fighting can be reduced through the use of a higher resolution
depth buffer A depth buffer, also known as a z-buffer, is a type of data buffer used in computer graphics to represent depth information of objects in 3D space from a particular perspective. Depth buffers are an aid to rendering a scene to ensure that the ...
, by
z-buffering A depth buffer, also known as a z-buffer, is a type of data buffer used in computer graphics to represent depth information of objects in 3D space from a particular perspective. Depth buffers are an aid to rendering a scene to ensure that the ...
in some scenarios, or by simply moving the polygons further apart. Z-fighting which cannot be entirely eliminated in this manner is often resolved by the use of a
stencil buffer A stencil buffer is an extra data buffer, in addition to the ''color buffer'' and ''Z-buffer'', found on modern graphics hardware. The buffer is per pixel and works on integer values, usually with a depth of one byte per pixel. The Z-buffer and ...
, or by applying a post-transformation screen space z-buffer offset to one polygon which does not affect the projected shape on screen but does affect the z-buffer value to eliminate the overlap during pixel interpolation and comparison. Where z-fighting is caused by different transformation paths in hardware for the same geometry (for example in a multi-pass rendering scheme) it can sometimes be resolved by requesting that the hardware use invariant vertex transformation. Z-fighting that is caused by insufficient precision in the depth buffer can be resolved by simply reducing the visible distance in the world. This reduces the distance between the near and far planes and solves the precision issue. However, in certain virtual environments, such as a space simulator, or a flight simulator, this is not possible. Alternative techniques exist in these cases. One of these techniques is to "simulate" the distance of objects far from the user without actually changing their position. For example, if the maximum safe view distance (beyond which z-fighting occurs) is 10,000 units, and an object to be rendered is 15,000 units away, that object could instead be rendered at 10,000 units but it could be scaled down in proportion to the distance that it was moved. So, an object that has been scaled down by half will look like it is twice as far as it actually is. If this is done only for objects that are already close to, or at, the maximum view distance, and objects close to the user are rendered normally, this technique should not be noticeable. Another technique that is utilized to reduce or completely eliminate Z-fighting is switching to a logarithmic Z-buffer, reversing Z. This technique is seen in the game ''
Grand Theft Auto V ''Grand Theft Auto V'' is a 2013 action-adventure game developed by Rockstar North and published by Rockstar Games. It is the seventh main entry in the Grand Theft Auto, ''Grand Theft Auto'' series, following 2008's ''Grand Theft Auto IV'', and ...
''. Due to the way they are encoded, floating-point numbers have much more precision when closer to 0. Here, reversing Z leads to more precision when storing the depth of very distant objects, hence greatly reducing Z-fighting.


References

{{Reflist 3D graphic artifacts 3D rendering