code
Allows for the direct insertion of a native GLSL code snippet into the TSL node graph, serving as the official 'escape hatch' for custom logic.
Core Advantages
Its core value is seamlessly combining the ultimate flexibility of native GLSL with the high-level modularity of the TSL node system. You can implement any complex algorithm or effect that standard nodes cannot achieve, while still retaining the advantages of a node-based workflow.
Common Uses
Creating custom procedural textures (e.g., Worley noise, fractals)
Implementing advanced vertex animations (e.g., realistic flag waving)
Writing Non-Photorealistic Rendering (NPR) shading models (e.g., toon shading)
Integrating and encapsulating third-party GLSL utility functions
How to adjust
Adjusted in two ways: 1. Directly modify the GLSL code string to fundamentally change its behavior (e.g., changing `uv.x` to `uv.y` to alter stripe direction). 2. Change the input nodes, for instance, replacing the `scale` input that controls stripe count from a fixed `uniform(10.0)` to a `timerLocal()` to dynamically animate the number of stripes.
Code Examples
1// 'uv' and 'scale' variables are automatically provided by the subsequent arguments
2const stripes = code(
3 'float p = step(0.5, fract(uv.x * scale)); return vec3(p);',
4 uv(),
5 uniform(10.0)
6);