GL_FRAGDEPTH(3G)

πŸ’… GL_FRAGDEPTH (3G) πŸ’…

ok so bestie, welcome to the 3G manual page for gl_FragDepth β€” yes it's a lowercase-gl_ situation, yes that's normal, no we don't ask questions ✨


πŸŽ€ NAME πŸŽ€

gl_FragDepth β€” the variable that literally sets the depth value for the current fragment. main character energy fr fr πŸ‘‘


🌸 DECLARATION 🌸

out float gl_FragDepth ;

that's it. that's the whole declaration. she's simple, she's a float, she's an out variable. obsessed 🫢


✨ DESCRIPTION ✨

okay so here's the tea, and this part is only available in the fragment language β€” no vertex shader, no geometry shader, don't even try it πŸ’€

gl_FragDepth is an output variable that you use to establish the depth value for the current fragment. simple as that.

now for the ✨ nuance ✨ (iykyk):

  • if depth buffering is enabled and no shader writes to gl_FragDepth, then the fixed function value for depth will be used β€” that value is contained in the z component of gl_FragCoord()
  • otherwise, the value written to gl_FragDepth is used

and now the part where you gotta pay attention bestie, because this is the πŸ’€ gotcha πŸ’€:

If a shader statically assigns to gl_FragDepth, then the value of the fragment's depth may be undefined for executions of the shader that take that path. that is, if the set of linked fragment shaders statically contain a write to gl_FragDepth, then it is responsible for always writing it.

translation: you touched it, it's yours now. you commit to writing that depth on every path, or you get undefined behavior. no halfsies, no take-backs. periodt πŸ’…


🌈 VERSION SUPPORT 🌈

vibe check on which OpenGL Shading Language versions have gl_FragDepth β€” she's been an icon in every single one of these, no cap:

  • 1.10 β€” βœ” yup
  • 1.20 β€” βœ” yup
  • 1.30 β€” βœ” yup
  • 1.40 β€” βœ” yup
  • 1.50 β€” βœ” yup
  • 3.30 β€” βœ” yup
  • 4.00 β€” βœ” yup
  • 4.10 β€” βœ” yup
  • 4.20 β€” βœ” yup
  • 4.30 β€” βœ” yup
  • 4.40 β€” βœ” yup
  • 4.50 β€” βœ” yup

so yeah, the variable gl_FragDepth is checked off across the entire board 🧚 it ate and left no crumbs


πŸ¦‹ SEE ALSO πŸ¦‹

  • gl_FragCoord() β€” go read that one too, bestie, they're literally siblings 🫢

Copyright Β© 2011-2014 Khronos Group. This material may be distributed subject to the terms and conditions set forth in the Open Publication License, v 1.0, 8 June 1999. http://opencontent.org/openpub/.

Copyright Β© 2011-2014 Khronos Group


πŸ’– and that's the whole page!! source: [FIXME: source], dated 08/09/2021, page GL_FRAGDEPTH(3G) β€” mwah, slay, go write your depth values responsibly πŸŽ€βœ¨πŸŒΈ
πŸ“¦ where this page comes from