In some applications, we may be interested in changing the default behavior of depth testing, which discards fragments with a higher depth value than those fragments in the depth buffer. For that purpose, WebGL provides the gl.depthFunc(function) method.
This method has only one parameter, the function to use:
Parameter | Description |
gl.NEVER | The depth test always fails. |
gl.LESS | Only fragments with a depth lower than current fragments on the depth buffer will pass the test. |
gl.LEQUAL | Fragments with a depth less than or equal to corresponding current fragments in the depth buffer will pass the test. |
gl.EQUAL | Only fragments with the same depth as current fragments on the depth buffer will pass the test. |
gl.NOTEQUAL | Only fragments that do not have the same depth value as fragments on the depth buffer will pass the test. |
gl.GEQUAL | Fragments with greater or equal depth value will pass the test. |
gl.GREATER | Only fragments with a greater depth value will pass the test. |
gl.ALWAYS | The depth test always passes. |
The depth test is disabled by default in WebGL. When enabled, if no depth function is set, the gl.LESS function is selected by default.