GL_CULLDISTANCE(3G)

๐Ÿ’… GL_CULLDISTANCE (3G) โ€” the gl_CullDistance manual, bestie edition

okay so this is the page for gl_CullDistance, and it's chillin' in manual section 3G. It's basically the little shader variable that lets you decide what gets culled. Culling era. ๐Ÿฆ‹


โœจ NAME

gl_CullDistance โ€” it literally provides a mechanism for controlling user culling. that's the whole gig. no cap.


๐ŸŽ€ DECLARATION

so gl_CullDistance is a member of the gl_PerVertex named block. iconic family, love them:

out gl_PerVertex {
    vec4 gl_Position;
    float gl_PointSize;
    float gl_ClipDistance[];
    float gl_CullDistance[];
};

and over in fragment shaders, it's intrinsically declared as this:

in float gl_CullDistance[] ;

(yeah, that spacing before the semicolon is in the original, we don't touch it, we respect it ๐Ÿ’…)


๐Ÿ”ฅ DESCRIPTION

The gl_CullDistance variable provides a mechanism for controlling user culling. (say it with me: user culling)

The element gl_CullDistance[i] specifies a cull distance for each plane i. And here's the vibe check on the numbers ๐Ÿงš:

  • a distance of 0.0 means that the vertex is on the plane
  • a positive distance means that the vertex is inside the cull volume
  • a negative distance means that the point is outside the cull volume

Primitives whose vertices all have a negative clip distance for plane i will be discarded. bye bestie ๐Ÿ‘‹๐Ÿ’€

The gl_CullDistance array is predeclared as unsized and must be sized by the shader either by redeclaring it with a size or by indexing it only with integral constant expressions. The size determines the number and set of enabled cull distances, and it can be at most gl_MaxCullDistances. The number of varying components consumed by gl_CullDistance will match the size of the array.

๐Ÿšจ okay this part matters: shaders writing gl_CullDistance must write all enabled distances, or culling results are undefined. that's not me being dramatic, that's the spec. write them all or the vibes are undefined. ๐Ÿ˜ญ

As an output variable, gl_CullDistance provides the place for the shader to write these distances. As an input in all but the fragment language, it reads the values written in the previous shader stage. In the fragment language, the gl_CullDistance array contains linearly interpolated values for the vertex values written by a shader to the gl_CullDistance vertex output variable. interpolated slay โœจ

And it's a compile-time or link-time error for the set of shaders forming a program to have the sum of the sizes of the gl_ClipDistance and gl_CullDistance arrays to be larger than gl_MaxCombinedClipAndCullDistances. so like... do the math before you commit, queen. ๐Ÿงฎ


๐Ÿ‘‘ VERSION SUPPORT

the chart, translated into main-character energy โ€” the column header up top was OpenGL Shading Language Version, the row header was Variable Name, and the star of the show is gl_CullDistance:

  • 1.10 โ€” - (nope, not here)
  • 1.20 โ€” -
  • 1.30 โ€” -
  • 1.40 โ€” -
  • 1.50 โ€” -
  • 3.30 โ€” -
  • 4.00 โ€” -
  • 4.10 โ€” -
  • 4.20 โ€” -
  • 4.30 โ€” -
  • 4.40 โ€” -
  • 4.50 โ€” โœ” (there she is!! the only one. arrived late and ate. ๐ŸŒˆ)

so yeah: gl_CullDistance shows up in exactly one place on that whole grid, and it's 4.50. iykyk.


๐ŸŒธ SEE ALSO

go give these two a lil visit, they're literally in the same friend group:

  • gl_ClipDistance()
  • gl_PointSize()

Copyright ยฉ 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 ยฉ 2014 Khronos Group


and that's the whole page bestie ๐Ÿซถ sign-off time: the source line says [FIXME: source], the date is 08/09/2021, and yes we're still on GL_CULLDISTANCE(3G). go cull responsibly. ๐Ÿ’–๐Ÿฆ‹๐ŸŽ€

๐Ÿ“ฆ where this page comes from