

The gl_FragCoord variable also contains a z-component which contains the depth value of the fragment. The x and y components of gl_FragCoord represent the fragment's screen-space coordinates (with (0,0) being the bottom-left corner). The screen space coordinates relate directly to the viewport defined by OpenGL's glViewport function and can be accessed via GLSL's built-in gl_FragCoord variable in the fragment shader. If the depth test fails, the fragment is discarded.ĭepth testing is done in screen space after the fragment shader has run (and after the stencil test which we'll get to in the next chapter). OpenGL performs a depth test and if this test passes, the fragment is rendered and the depth buffer is updated with the new depth value. When depth testing is enabled, OpenGL tests the depth value of a fragment against the content of the depth buffer. In most systems you'll see a depth buffer with a precision of 24 bits.
Revolt game no z buffer 32 bit#
The depth buffer is automatically created by the windowing system and stores its depth values as 16, 24 or 32 bit floats. The depth-buffer is a buffer that, just like the color buffer (that stores all the fragment colors: the visual output), stores information per fragment and has the same width and height as the color buffer. In this chapter we're going to elaborate a bit more on those depth values the depth buffer (or z-buffer) stores and how it actually determines if a fragment is in front. In the coordinate systems chapter we've rendered a 3D container and made use of a depth buffer to prevent triangles rendering in the front while they're supposed to be behind other triangles.
