9
votes

Can fragment shader in OpenGL ES 2.0 change the Z value (depth) of a pixel?

How is this achieved in OpenGL ES 2.0?

2

2 Answers

10
votes

No -- gl_FragDepth (which is part of the desktop version of GLSL) is not present in OpenGL ES.

You can, however, check for the existence of GL_EXT_frag_depth. If it's available, then you can write the depth to gl_FragDepthEXT.

The extension paper gives more details about how to enable the extension and such.

0
votes

While gl_fragDepth is not available in OpenGL ES 2.0, is is available from version 3.0 onwards, so upgrading would be the way to go unless you need to use the older version for compatibility.