expression
Allows embedding a short, custom GLSL code snippet directly into the TSL node graph, injecting TSL nodes as variables via an object.
Core Advantages
Its core value is providing ultimate flexibility and extensibility. It allows developers to implement any complex formula or algorithm not covered by built-in nodes with concise code, while requiring explicit output type setting for type safety.
Common Uses
Implementing complex procedural patterns (e.g., domain warping noise)
Creating custom lighting or falloff models
Performing unique color operations (e.g., custom blend modes)
Using GLSL-specific functions not directly wrapped by TSL
How to adjust
Adjusted by changing the nodes injected into the `params` object. For instance, in the pulse wave example, increasing the `frequency` uniform makes the waves denser, while decreasing the `speed` uniform slows down the wave's propagation.
Code Examples
1// Create a dynamic pulse wave using a GLSL expression
2const pulse = expression(
3 'sin(distance(uv, vec2(0.5)) * frequency - time * speed)',
4 {
5 uv: uv(),
6 frequency: uniform(20.0),
7 time: timer(),
8 speed: uniform(3.0)
9 }
10).setNodeType('float'); // Explicitly setting the return type is crucial