Why is gl_FragDepthEXT undefined in my WebGL fragment shader? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why is gl_FragDepthEXT undefined in my WebGL fragment shader?

I'm trying to follow documentation at: https://developer.mozilla.org/en-US/docs/Web/API/EXT_frag_depth. I want to have a fragment shader calculate depth in a step toward creating something more interesting. Here is the broken code: https://code.sololearn.com/W8a159A1485a Shader compilation errors show in the JavaScript console as: shaders.js:9 Shader compiler log: ERROR: 0:4: 'GL_EXT_frag_depth' : extension is disabled If the gl_FragDepthEXT is commented out along with the #version, a red triangle is drawn. Is setting depth so weird now that a browser flag needs to be turned on that is defaulted to disabled? Is the error related to my call to gl.getExtension('EXT_frag_depth')? Please identify the code changes so this code actually calculates the depth for each pixel in the triangle. I've looked at many articles on setting depth in a WebGL shader and OpenGL shader so please don't just point me at an article that I've already seen.

22nd Jan 2021, 3:40 AM
Josh Greig
Josh Greig - avatar
1 Answer
+ 5
trying console.log(this.gl.getExtension('EXT_frag_depth')) gives null which means that frag_depth extension is unavailable on your device ..so we cant use it... for getting fragment coordinate you can use gl_FragCoord which is a vec3 and use like this gl_FragColor=vec4(1.0,1.0,gl_FragCoord.z,1.0); for maybe depth testing !? hope that helps out!
7th Jun 2021, 7:42 PM
Prashanth Kumar
Prashanth Kumar - avatar