Wed . 20 Aug 2020
TR | RU | UK | KK | BE |


what is z-buffering, z buffering
In computer graphics, z-buffering, also known as depth buffering, is the management of image depth coordinates in 3D graphics, usually done in hardware, sometimes in software It is one solution to the visibility problem, which is the problem of deciding which elements of a rendered scene are visible, and which are hidden The painter's algorithm is another common solution which, though less efficient, can also handle non-opaque scene elements

When an object is rendered, the depth of a generated pixel z coordinate is stored in a buffer the z-buffer or depth buffer This buffer is usually arranged as a two-dimensional array x-y with one element for each screen pixel If another object of the scene must be rendered in the same pixel, the method compares the two depths and overrides the current pixel if the object is closer to the observer The chosen depth is then saved to the z-buffer, replacing the old one In the end, the z-buffer will allow the method to correctly reproduce the usual depth perception: a close object hides a farther one This is called z-culling

The granularity of a z-buffer has a great influence on the scene quality: a 16-bit z-buffer can result in artifacts called "z-fighting" or stitching when two objects are very close to each other A 24-bit or 32-bit z-buffer behaves much better, although the problem cannot be entirely eliminated without additional algorithms An 8-bit z-buffer is almost never used since it has too little precision


  • 1 Uses
  • 2 Developments
  • 3 Z-culling
  • 4 Mathematics
    • 41 Fixed-point representation
    • 42 W-buffer
  • 5 See also
  • 6 References
  • 7 External links
  • 8 Notes


The Z-buffer is a technology used in almost all contemporary computers, laptops and mobile phones for performing 3D graphics, for example for computer games The Z-buffer is implemented as hardware in the silicon ICs integrated circuits within these computers The Z-buffer is also used implemented as software as opposed to hardware for producing computer-generated special effects for films

Furthermore, Z-buffer data obtained from rendering a surface from a light's point-of-view permits the creation of shadows by the shadow mapping technique


Even with small enough granularity, quality problems may arise when precision in the z-buffer's distance values is not spread evenly over distance Nearer values are much more precise and hence can display closer objects better than values which are farther away Generally, this is desirable, but sometimes it will cause artifacts to appear as objects become more distant A variation on z-buffering which results in more evenly distributed precision is called w-buffering see below

At the start of a new scene, the z-buffer must be cleared to a defined value, usually 10, because this value is the upper limit on a scale of 0 to 1 of depth, meaning that no object is present at this point through the viewing frustum

The invention of the z-buffer concept is most often attributed to Edwin Catmull, although Wolfgang Straßer described this idea in his 1974 PhD thesis months before Catmull's invention 1

On recent PC graphics cards 1999–2005, z-buffer management uses a significant chunk of the available memory bandwidth Various methods have been employed to reduce the performance cost of z-buffering, such as lossless compression computer resources to compress/decompress are cheaper than bandwidth and ultra fast hardware z-clear that makes obsolete the "one frame positive, one frame negative" trick skipping inter-frame clear altogether using signed numbers to cleverly check depths


In rendering, z-culling is early pixel elimination based on depth, a method that provides an increase in performance when rendering of hidden surfaces is costly It is a direct consequence of z-buffering, where the depth of each pixel candidate is compared to the depth of existing geometry behind which it might be hidden

When using a z-buffer, a pixel can be culled discarded as soon as its depth is known, which makes it possible to skip the entire process of lighting and texturing a pixel that would not be visible anyway Also, time-consuming pixel shaders will generally not be executed for the culled pixels This makes z-culling a good optimization candidate in situations where fillrate, lighting, texturing or pixel shaders are the main bottlenecks

While z-buffering allows the geometry to be unsorted, sorting polygons by increasing depth thus using a reverse painter's algorithm allows each screen pixel to be rendered fewer times This can increase performance in fillrate-limited scenes with large amounts of overdraw, but if not combined with z-buffering it suffers from severe problems such as:

  • polygons might occlude one another in a cycle eg : triangle A occludes B, B occludes C, C occludes A, and
  • there is no canonical "closest" point on a triangle eg: no matter whether one sorts triangles by their centroid or closest point or furthest point, one can always find two triangles A and B such that A is "closer" but in reality B should be drawn first

As such, a reverse painter's algorithm cannot be used as an alternative to Z-culling without strenuous re-engineering, except as an optimization to Z-culling For example, an optimization might be to keep polygons sorted according to x/y-location and z-depth to provide bounds, in an effort to quickly determine if two polygons might possibly have an occlusion interaction


The range of depth values in camera space to be rendered is often defined between a n e a r and f a r value of z After a perspective transformation, the new value of z , or z ′ , is defined by:

z ′ = f a r + n e a r f a r − n e a r + 1 z − 2 ⋅ f a r ⋅ n e a r f a r − n e a r +-+\left\cdot -\right

After an orthographic projection, the new value of z , or z ′ , is defined by:

z ′ = 2 ⋅ z − n e a r f a r − n e a r − 1 ---1

where z is the old value of z in camera space, and is sometimes called w or w ′

The resulting values of z ′ are normalized between the values of -1 and 1, where the n e a r plane is at -1 and the f a r plane is at 1 Values outside of this range correspond to points which are not in the viewing frustum, and shouldn't be rendered

Fixed-point representationedit

Typically, these values are stored in the z-buffer of the hardware graphics accelerator in fixed point format First they are normalized to a more common range which is 0,1 by substituting the appropriate conversion z 2 ′ = z 1 ′ + 1 2 =+1\right into the previous formula:

z ′ = f a r + n e a r 2 ⋅ f a r − n e a r + 1 z − f a r ⋅ n e a r f a r − n e a r + 1 2 +-\right+\left\cdot -\right+

Second, the above formula is multiplied by S = 2 d − 1 -1 where d is the depth of the z-buffer usually 16, 24 or 32 bits and rounding the result to an integer:1

z ′ = f z = ⌊ 2 d − 1 ⋅ f a r + n e a r 2 ⋅ f a r − n e a r + 1 z − f a r ⋅ n e a r f a r − n e a r + 1 2 ⌋ -1\right\cdot \left+-\right+\left\cdot -\right+\right\right\rfloor

This formula can be inverted and derived in order to calculate the z-buffer resolution the 'granularity' mentioned earlier The inverse of the above f z :

z = − f a r ⋅ n e a r z ′ S f a r − n e a r − f a r = − S ⋅ f a r ⋅ n e a r z ′ f a r − n e a r − f a r ⋅ S \cdot \left-\right-=\cdot \cdot -\right-\cdot S

where S = 2 d − 1 -1

The z-buffer resolution in terms of camera space would be the incremental value resulted from the smallest change in the integer stored in the z-buffer, which is +1 or -1 Therefore this resolution can be calculated from the derivative of z as a function of z ′ :

d z d z ′ = − 1 ⋅ − 1 ⋅ S ⋅ f a r ⋅ n e a r z ′ f a r − n e a r − f a r ⋅ S 2 ⋅ f a r − n e a r =\cdot \cdot -\right-\cdot S\right^\cdot \left-\right

Expressing it back in camera space terms, by substituting z ′ by the above f z :

d z d z ′ = − 1 ⋅ − 1 ⋅ S ⋅ f a r ⋅ n e a r ⋅ f a r − n e a r S ⋅ − f a r ⋅ n e a r z + f a r − f a r ⋅ S 2 = =\cdot \cdot \cdot \left-\right\cdot \left\cdot +\right-\cdot S\right^=

f a r − n e a r ⋅ z 2 S ⋅ f a r ⋅ n e a r = -\right\cdot z^\cdot =

z 2 S ⋅ n e a r − z 2 S ⋅ f a r = -=

~ z 2 S ⋅ n e a r

This shows that the values of z ′ are grouped much more densely near the n e a r plane, and much more sparsely farther away, resulting in better precision closer to the camera The smaller the n e a r / f a r / ratio is, the less precision there is far away—having the n e a r plane set too closely is a common cause of undesirable rendering artifacts in more distant objects2

To implement a z-buffer, the values of z ′ are linearly interpolated across screen space between the vertices of the current polygon, and these intermediate values are generally stored in the z-buffer in fixed point format


To implement a w-buffer,clarification needed the old values of z in camera space, or w , are stored in the buffer, generally in floating point format However, these values cannot be linearly interpolated across screen space from the vertices—they usually have to be inverted, interpolated, and then inverted again The resulting values of w , as opposed to z ′ , are spaced evenly between n e a r and f a r There are implementations of the w-buffer that avoid the inversions altogether

Whether a z-buffer or w-buffer results in a better image depends on the application

See alsoedit

  • Z-fighting
  • Irregular Z-buffer
  • Z-order
  • z-index
  • A-buffer
  • Depth map
  • HyperZ
  • Stencil buffer


  1. ^ The OpenGL Organization "Open GL / FAQ 12 - The Depth buffer" Retrieved 2010-11-01 
  2. ^ Grégory Massal "Depth buffer - the gritty details" Retrieved 2008-08-03 

External linksedit

  • Learning to Love your Z-buffer
  • Alpha-blending and the Z-buffer


Note 1: see WK Giloi, JL Encarnação, W Straßer "The Giloi’s School of Computer Graphics" Computer Graphics 35 4:12–16

what is z-buffering, z buffering

Z-buffering Information about


  • user icon

    Z-buffering beatiful post thanks!


Z-buffering viewing the topic.
Z-buffering what, Z-buffering who, Z-buffering explanation

There are excerpts from wikipedia on this article and video

Random Posts

Amorphous metal

Amorphous metal

An amorphous metal also known as metallic glass or glassy metal is a solid metallic material, usuall...
Arthur Lake (bishop)

Arthur Lake (bishop)

Arthur Lake September 1569 – 4 May 1626 was Bishop of Bath and Wells and a translator of the King Ja...
John Hawkins (author)

John Hawkins (author)

Sir John Hawkins 29 March 1719 – 21 May 1789 was an English author and friend of Dr Samuel Johnson a...
McDonnell Douglas MD-12

McDonnell Douglas MD-12

The McDonnell Douglas MD-12 was an aircraft design study undertaken by the McDonnell Douglas company...