builtin
Creates a node that directly references/writes a shader built-in by name (e.g., gl_FragDepth, gl_PointSize, gl_ClipDistance[i]). Useful for hardware-accelerated clipping, custom depth, etc.
Core Advantages
Zero boilerplate, straight to the backend: no uniforms/varyings needed. Enables features like hardware clip distances.
Common Uses
Hardware clipping via gl_ClipDistance[i] (or the backend equivalent)
Custom fragment depth via gl_FragDepth
Controlling point size via gl_PointSize
Any other writable built-in exposed by the target backend
How to adjust
Takes a single string (the built-in symbol). This node assumes float; prefer scalar built-ins (gl_FragDepth, gl_PointSize) or index components (e.g., gl_ClipDistance[0]). Names are backend-specific (GLSL uses gl_*; others may differ). Some built-ins are read-only in certain stages; writes only take effect if supported.
Code Examples
1// 1) Plane clipping (write gl_ClipDistance[0])
2const clip0 = builtin('gl_ClipDistance[0]');
3clip0.assign( dot( vec4( positionWorld, 1.0 ), planeWorld ) );
4
5// 2) Custom fragment depth (write gl_FragDepth)
6const fragDepth = builtin('gl_FragDepth');
7fragDepth.assign( viewZToPerspectiveDepth( positionView.z, cameraNear, cameraFar ) );
8
9// 3) Point size control (write gl_PointSize)
10const pointSize = builtin('gl_PointSize');
11pointSize.assign( materialPointSize.mul( 1.5 ) );