All Topics  
Z-buffering

 
Z Buffering

   Email Print
   Bookmark   Link






 

Z-buffering



 
 
In computer graphics
Computer graphics

Computer graphics are graphics created by computers and, more generally, the representation and manipulation of pictorial data by a computer....
, z-buffering is the management of image depth coordinates in three-dimensional (3-D) graphics, usually done in hardware
Hardware

Hardware is a general term that refers to the physical cultural artifacts of a technology. It may also mean the physical components of a computer system, in the form of computer 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.






Discussion
Ask a question about 'Z-buffering'
Start a new discussion about 'Z-buffering'
Answer questions from other users
Full Discussion Forum



Encyclopedia


Z Buffer
In computer graphics
Computer graphics

Computer graphics are graphics created by computers and, more generally, the representation and manipulation of pictorial data by a computer....
, z-buffering is the management of image depth coordinates in three-dimensional (3-D) graphics, usually done in hardware
Hardware

Hardware is a general term that refers to the physical cultural artifacts of a technology. It may also mean the physical components of a computer system, in the form of computer 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
Painter's algorithm

The painter's algorithm, also known as a priority fill, is one of the simplest solutions to the visibility problem in 3D computer graphics....
 is another common solution which, though less efficient, can also handle non-opaque scene elements. Z-buffering is also known as depth buffering.

When an object is rendered by a 3D graphics card, the depth of a generated pixel
Pixel

In digital imaging, a pixel is the smallest item of information in an image. Pixels are normally arranged in a 2-dimensional grid, and are often represented using dots, squares, or rectangles....
 (z coordinate) is stored in a buffer
Buffer (computer science)

In computing, a buffer is a region of Memory used to temporarily hold data while it is being moved from one place to another. Typically, the data is stored in a buffer as it is retrieved from an input device or just before it is sent to an output device ....
 (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 graphics card compares the two depths and chooses the one 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 graphics card 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
16-bit

16-bit architectureThe HP 2100#Descendants and variants , introduced in 1975, was the world's first 16-bit microprocessor.Prominent 16-bit processors include the PDP-11, Intel 8086, Intel 80286 and the WDC 65C816....
 z-buffer can result in artifact
Artifact (observational)

In natural science and signal processing, an artifact is any perceived distortion or other data error caused by the instrument of observation....
s (called "z-fighting
Z-fighting

Z-fighting is a phenomenon in rendering that occurs when two or more primitive s have similar values in the z-buffer, and is particularly prevalent with coplanar polygons....
") when two objects are very close to each other. A 24-bit
24-bit

The IBM System/360, announced in 1964, was an extremely popular computer system with 24-bit addressing and 32-bit general registers and arithmetic. The early 1980s saw the first popular personal computers, including the IBM PC/AT with an Intel 80286 processor using 24-bit addressing and 16-bit general registers and arithmetic, and the Apple Inc....
 or 32-bit
32-bit

The range of integer values that can be stored in 32 bits is 0 through 4,294,967,295 or -2,147,483,648 through 2,147,483,647 using two's complement encoding....
 z-buffer behaves much better, although the problem cannot be entirely eliminated without additional algorithms. An 8-bit
8-bit

Eight-bit CPUs normally use an 8-bit data bus and a 16-bit address bus which means that their address space is limited to 64 KBs. This is not a "natural law", however, so there are exceptions....
 z-buffer is almost never used since it has too little precision.

Uses


Z-buffer data in the area of video editing permits one to combine 2D video elements in 3D space, permitting virtual sets, "ghostly passing through wall" effects, and complex effects like mapping of video on surfaces. An application for Maya, called IPR, permits one to perform post-rendering texturing on objects, utilizing multiple buffers like z-buffers, alpha, object id, UV coordinates and any data deemed as useful to the post-production process, saving time otherwise wasted in re-rendering of the video.

Z-buffer data obtained from rendering a surface from a light's POV permits the creation of shadows in a scanline renderer, by projecting the z-buffer data onto the ground and affected surfaces below the object. This is the same process used in non-raytracing modes by the free and open sourced 3D application Blender.

Developments


Even with enough granularity, quality problems may arise when precision
Accuracy and precision

In the fields of science, engineering, industry and statistics, accuracy is the degree of closeness of a Measure d or calculated quantity to its actual Value ....
 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 1.0, 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
Viewing frustum

In 3D computer graphics, the viewing frustum or view frustum is the region of space in the modeled world that may appear on the screen; it is the field of view of the notional camera....
.

The invention of the z-buffer concept is most often attributed to Edwin Catmull
Edwin Catmull

Edwin Catmull, Ph.D. is an Academy Award winning computer scientist and current president of Walt Disney Animation Studios and Pixar Animation Studios....
, although Wolfgang Straßer also described this idea in his 1974 Ph.D. thesis1.

On recent PC graphics cards (1999-2005), z-buffer management uses a significant chunk of the available memory
Computer storage

Computer data storage, often called storage or memory, refers to computer components, devices, and recording medium that retain digital data used for computing for some interval of time....
 bandwidth
Bandwidth (computing)

In computer networking and computer science, digital bandwidth, network bandwidth or just bandwidth is a measure of available or consumed data communication resources expressed in bit/s or multiples of it ....
. 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).

Z-culling


In rendering
Rendering (computer graphics)

Rendering is the process of generating an image from a 3D model, by means of computer programs. The model is a description of three-dimensional objects in a strictly defined language or data structure....
, 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
Texture mapping

Texture mapping is a method for adding detail, surface texture, or colour to a computer-generated imagery or 3D model. Its application to 3D graphics was pioneered by Dr Edwin Catmull in his Ph.D....
 a pixel that would not be visible
Visibility (geometry)

Visibility is a mathematical abstraction of the real-life notion of visibility.Given a set of obstacles in the Euclidean space, two points in the space are said to be visible to each other, if the line segment that joins them does not intersect any obstacles....
 anyway. Also, time-consuming pixel shader
Pixel shader

A pixel shader is a shader program, often executed on a graphics processing unit. It adds 3D shading and lighting effects to pixels in an image, for example those in video games....
s will generally not be executed for the culled pixels. This makes z-culling a good optimization candidate in situations where fillrate
Fillrate

The fillrate usually refers to the number of pixels a video card can render and write to video memory in a second. In this case, fillrates are given in megapixels per second or in gigapixels per second , and they are obtained by multiplying the number of raster operations by the clock frequency of the graphics processor unit of a video card...
, lighting, texturing or pixel shaders are the main bottlenecks.

While z-buffering allows the geometry to be unsorted, sorting polygon
Polygon

In geometry a polygon is traditionally a plane Shape that is bounded by a closed curve path or circuit, composed of a finite sequence of straight line segments ....
s by increasing depth (thus using a reverse painter's algorithm
Painter's algorithm

The painter's algorithm, also known as a priority fill, is one of the simplest solutions to the visibility problem in 3D computer graphics....
) 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 (e.g. : triangle A occludes B occludes C occludes A), and
  • there is no canonical to pick a point on a triangle (e.g.: no matter whether one sorts triangles by their centroid
    Centroid

    In geometry, the centroid, geometric center, or barycenter of a plane figure is the intersection of all straight lines that divide into two parts of equal moment about the line....
     or closest point or furthest point, one can always find two triangles A and B such that A is "closer" but in reality A 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.

Mathematics


The range of depth values in camera space
Space

Space is the boundless, three-dimensional extent in which Physical body and events occur and have relative position and direction. Physical space is often conceived in three linear dimensions, although modern physics usually consider it, with time, to be part of the boundless four-dimensional continuum known as spacetime....
 (see 3D projection
3D projection

3D projection is any method of mapping three-dimensional points to a two-dimensional plane. As most current methods for displaying graphical data are based on planar two-dimensional media, the use of this type of projection is widespread, especially in computer graphics, engineering and drafting....
) to be rendered is often defined between a and value of . After a perspective transformation, the new value of , or , is defined by:

where is the old value of in camera space, and is sometimes called or .

The resulting values of are normalized between the values of -1 and 1, where the plane
Plane (mathematics)

In mathematics, a plane is a curvature surface. Planes can arise as subspaces of some higher dimensional space, as with the walls of a room, or they may enjoy an independent existence in their own right, as in the setting of Euclidean geometry....
 is at -1 and the plane is at 1. Values outside of this range correspond to points which are not in the viewing frustum
Frustum

A frustum is the portion of a solid?normally a Cone or pyramid ?which lies between two parallel planes cutting the solid. The term is commonly used in computer graphics to describe the 3d area which is visible on the screen ....
, and shouldn't be rendered.

In order to convert the normalised values of back into camera space, the inverse of the above formula can be used:

This allows measurement of distances (between objects and the camera) in the camera/object space, after a depth buffer calculation has been performed. This formula assumes that the value of has been normalised to the range [-1,1] as described above (this may not be the case, however, when reading a depth buffer from a hardware graphics accelerator). The resolution of values of calculated from will depend on the selected and planes, as described below.

To implement a z-buffer, the values of are linearly interpolated
Linear interpolation

Linear interpolation is a method of curve fitting using linear polynomials. It is heavily employed in mathematics , and numerous applications including computer graphics....
 across screen space between the vertices
Vertex (geometry)

In geometry, a vertex is a special kind of point which describes the corners or intersections of geometric shapes. Vertices are commonly used in computer graphics to define the corners of surfaces in 3d models, where each such point is given as a vector....
 of the current polygon
Polygon

In geometry a polygon is traditionally a plane Shape that is bounded by a closed curve path or circuit, composed of a finite sequence of straight line segments ....
, and these intermediate values are generally stored in the z-buffer in fixed point
Fixed-point arithmetic

In computing, a fixed-point number representation is a real data type for a number that has a fixed number of digits after the radix point . Fixed-point number representation can be compared to the more complicated floating point number representation....
 format. The values of are grouped much more densely near the plane, and much more sparsely farther away, resulting in better precision closer to the camera. The smaller the ratio is, the less precision there is far away—having the plane set too closely is a common cause of undesirable rendering artifacts in more distant objects.

W-buffer


To implement a w-buffer, the old values of in camera space, or , are stored in the buffer, generally in floating point
Floating point

In computing, floating point describes a system for numerical representation in which a String of digits represents a rational number.The term floating point refers to the fact that the radix point can "float": that is, it can be placed anywhere relative to the Significant figures of the number....
 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 , as opposed to , are spaced evenly between and . 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 also

  • Edwin Catmull
    Edwin Catmull

    Edwin Catmull, Ph.D. is an Academy Award winning computer scientist and current president of Walt Disney Animation Studios and Pixar Animation Studios....
     – inventor of the z-buffer concept.
  • 3D computer graphics
    3D computer graphics

    3D computer graphics are graphics that use a Cartesian coordinate system#Three-dimensional coordinate system representation of geometric data that is stored in the computer for the purposes of performing calculations and rendering 2D images....
  • z-fighting
    Z-fighting

    Z-fighting is a phenomenon in rendering that occurs when two or more primitive s have similar values in the z-buffer, and is particularly prevalent with coplanar polygons....
  • Irregular Z-buffer
    Irregular Z-buffer

    The irregular Z-buffer is an algorithm designed to solve the visibility problemin real-time 3-d computer graphics. It is related to the classical ...
  • Z-order
    Z-order

    Z-order is an ordering of overlapping two-dimensional objects, such as Window in a graphical user interface or shapes in a vector graphics editor....
  • Hierarchical Z-buffer


External links