Capítulo 799 de 859

Chapter 799: TSL Utility & Post-processing Functions

Core Idea

On top of the core language (ch797) and built-in inputs (ch798), TSL ships a large library of ready-made helper functions — math/color utilities, texture-sampling helpers, and post-processing effect nodes (bloom, AO, FXAA, afterimage...) callable directly instead of hand-writing the shader graph. This chapter curates the ones you'll reach for most; the full function library is in the hundreds and the rest is best discovered via editor autocomplete on three/tsl.

Key Concepts

  • Tone mapping functions: acesFilmicToneMapping, agxToneMapping — pure node functions equivalent to the renderer's built-in tone mapping, usable inline in a custom post-processing graph.
  • Effect node factories: functions like ao(...), afterImage(...), anaglyphPass(...) build a configured *Node/*PassNode instance in one call, instead of new GTAONode(...) + manual wiring.
  • UV/screen helpers: barrelUV, barrelMask and similar distortion/mask helpers for screen-space effects.
  • Array/attribute helpers: array(...), attribute(...), attributeArray(...) — construct typed TSL arrays/attributes for custom vertex data or compute buffers.
  • Compute/atomic helpers: atomicAdd, atomicMax, barrier(scope) — synchronization primitives for compute-shader passes.

Reference Tables

Math (mirrors ch797's operators but as free functions, e.g. abs(x) instead of x.abs())

FunctionSignature
abs, sign, negate(x : Node|number) : Node
acos, asin, atan(y, x?), acosh, asinh, atanh(x) : Node
all, any(x : Node) : Node<bool> — vector-wide boolean reduction
and, or, not(...nodes) : OperatorNode
bitAnd/bitOr/bitXor/shiftLeft/shiftRightbitwise ops for int/uint nodes

Tone mapping & color

FunctionSignatureNotes
acesFilmicToneMapping(color : Node<vec3>, exposure : Node<float>) : Node<vec3>Matches THREE.ACESFilmicToneMapping.
agxToneMapping(color, exposure) : Node<vec3>Matches THREE.AgXToneMapping.

Post-processing effect factories (each returns a configured pass/effect node — pipe into PostProcessing)

FunctionPurpose
ao(depthNode, normalNode, camera)Ground-truth ambient occlusion (GTAO).
afterImage(node, damp)Motion-trail / afterimage effect.
anaglyphPass(scene, camera)Red/cyan stereo anaglyph.
bilateralBlur(node, direction, sigma, sigmaColor)Edge-preserving blur, common in denoising/SSAO pipelines.
billboarding(config)Camera-facing quad orientation node.

Data / compute construction

FunctionSignature
array(valuesOrType, count?)→ ArrayNode — fixed-size TSL array.
attribute(name, nodeType)→ AttributeNode — read a custom vertex attribute by name.
attributeArray(count, type)→ StorageBufferNode — GPU storage buffer for compute passes.
barrier(scope)→ BarrierNode — compute-shader memory/execution barrier.
atomicAdd/atomicMax/atomicMin/atomicOr/atomicAnd/atomicXor/atomicLoad/atomicStore/atomicSub(pointerNode, valueNode?) : AtomicFunctionNode

Anti-patterns

  • Re-deriving a post-processing effect from scratch when an equivalent factory (ao, afterImage, anaglyphPass, ...) already exists — check the function library before hand-rolling.
  • Mixing atomic operations without a barrier() in compute passes — cross-invocation reads/writes need explicit synchronization or results are undefined.

Key Takeaways

  1. Free-function form (add(a, b)) and method-chained form (a.add(b)) are equivalent — pick whichever composes better for a given expression.
  2. Post-processing effects in the Node system are just node factories you compose into a PostProcessing graph, not a fixed EffectComposer pass list — this is more flexible than the classic EffectComposer/*Pass API (also documented, see the Renderers & Post-processing chapters).
  3. Compute-shader helpers (atomic*, barrier, attributeArray) are WebGPU-only — they no-op or error under the WebGL2 fallback.
  4. This is a curated subset — hundreds more TSL functions exist (noise, specialized lighting-model terms, denoising helpers used internally by the built-in materials); discover them via three/tsl autocomplete or the official TSL reference when this chapter doesn't have what you need.

Connects To

  • ch797 (TSL Language Basics): the operator/control-flow foundation these functions are built from.
  • ch798 (TSL Built-in Inputs): many of these functions consume built-in nodes like normalView/positionView internally.
  • PostProcessing / renderer Pass classes: see the Renderers & Post-processing topic group for the classic (non-Node) EffectComposer pipeline these functions parallel.