Depth Test: Difference between revisions

From OpenGL Wiki
Jump to navigation Jump to search
m Steps: Punctuation.
Outline to match Stencil Test
Line 1: Line 1:
{{pipeline float}}
{{pipeline float}}
The '''Depth Test''' is a per-sample operation performed [[Early Depth Test|conceptually]] after the [[Fragment Shader]]. The output depth may be tested against the [[Depth Buffer|depth of the sample being written to]]. If the test fails, the fragment is discarded. If the test passes, the depth buffer may be written to.
The '''Depth Test''' is a [[Per-Sample_Processing|per-sample processing operation]] performed after the [[Fragment Shader]] (and [[#Early test|sometimes before). The [[Fragment]]'s output depth value may be tested against the [[Depth Buffer|depth of the sample being written to]]. If the test fails, the fragment is discarded. If the test passes, the depth buffer will be updated with the fragment's output depth, unless a subsequent per-sample operation prevents it (such as [[Write Mask|turning off depth writes]]).
 
== Depth buffer ==
 
== Fragment depth value ==
 
== Depth test ==
 
== Early test ==
{{main|Early Depth Test}}
 
 
== See also ==
 
* [[Stencil Test]]
* [[Fragment Shader]]


== Steps ==
== Steps ==

Revision as of 06:10, 25 June 2015

The Depth Test is a per-sample processing operation performed after the Fragment Shader (and [[#Early test|sometimes before). The Fragment's output depth value may be tested against the depth of the sample being written to. If the test fails, the fragment is discarded. If the test passes, the depth buffer will be updated with the fragment's output depth, unless a subsequent per-sample operation prevents it (such as turning off depth writes).

Depth buffer

Fragment depth value

Depth test

Early test


See also

Steps

If the depth buffer exists, the value it is cleared to can be assigned with glClearDepth or retrieved with glGet...(GL_DEPTH_CLEAR_VALUE), and then the buffer itself is cleared using glClear(GL_DEPTH_BUFFER_BIT).

After clipping and division by w, depth coordinates range from -1 to 1, corresponding to the near and far clipping planes. Each viewport has an independent depth range specified as a linear mapping of the normalized depth coordinates in this range to window depth coordinates. Regardless of the actual depth buffer implementation, window coordinate depth values are treated as though they range from 0 through 1 (like color components). The depth values are mapped from window coordinates to normalized device coordinates using glDepthRange(GLdouble nearVal​, GLdouble farVal​), which can be retrieved as a pair using glGet...(GL_DEPTH_RANGE); the initial values are 0 and 1 respectively. When there are multiple viewports, glDepthRangeIndexed(GLuint index​, GLdouble nearVal​, GLdouble farVal​) and glDepthRangeArray(GLuint first​, GLsizei count​, const GLdouble *v​) are used.

The depth test does not occur unless if GL_DEPTH_TEST is enabled; the initial value is false. The depth of the sample being written to (s) is compared to the value in the depth buffer (d) using the function specified by glDepthFunc(GLenum func​), which is retrieved with glGet...(GL_DEPTH_FUNC). This can be GL_NEVER (false), GL_LESS (s < d), GL_EQUAL (s = d), GL_LEQUAL (sd), GL_GREATER (s > d), GL_NOTEQUAL (sd), GL_GEQUAL (sd), or GL_ALWAYS (true). The initial value is GL_LESS.

If the test passes or is disabled, the depth value may then be written to the depth buffer. To control whether to write to the depth buffer, call glDepthMask(GLboolean flag​) or retrieve the current setting with glGet...(GL_DEPTH_WRITEMASK​). The default is true.

Associated Gets

glGet with argument GL_DEPTH_CLEAR_VALUE, GL_DEPTH_FUNC, GL_DEPTH_RANGE, GL_DEPTH_WRITEMASK​

glIsEnabled with argument GL_DEPTH_TEST

See Also

glClear, glClearDepth, glDepthFunc, glDepthMask, glDepthRange, glDepthRangeArray, glDepthRangeIndexed