glslFn
Allows defining a complete GLSL function as a string, encapsulating it into a function template that can be called multiple times within the TSL node graph.
Core Advantages
Its core value is enabling true code reuse (DRY principle) and modularity. It lets you build a library of custom, readable functions (e.g., `rotateUV`, `rgbToHsv`), keeping the main node graph clean and focused on high-level logic.
Common Uses
Creating coordinate transformation tools (e.g., a 2D rotation function)
Encapsulating color space conversion algorithms (e.g., RGB to HSV)
Defining Signed Distance Field (SDF) primitives
Implementing custom easing or animation functions
How to adjust
The effect is adjusted by changing the TSL nodes passed as arguments to the `.call()` method. For a `rotateUV` function, passing a `timerLocal()` node to the `angle` parameter creates a continuous rotation, while passing a `uniform(float)` allows for manual control of the rotation angle.
Code Examples
1// 1. Define a reusable rotation function
2const rotateUVFn = glslFn(`
3 vec2 rotate(vec2 uv, float angle) {
4 mat2 m = mat2(cos(angle), -sin(angle), sin(angle), cos(angle));
5 return m * (uv - 0.5) + 0.5;
6 }
7`);
8
9// 2. Call it with TSL nodes as arguments
10const rotatedUV = rotateUVFn.call({
11 uv: uv(),
12 angle: timerLocal()
13});