Fn
Allows developers to create reusable GLSL functions using JavaScript syntax, encapsulating them as TSL nodes for seamless integration into the node network.
Core Advantages
Encapsulates complex computational logic (like math formulas, procedural patterns) into a single, reusable node, significantly improving code readability, maintainability, and abstraction, while avoiding the tedious work of manually connecting nodes or writing raw GLSL strings.
Common Uses
Encapsulating complex math or physics formulas (e.g., PBR functions)
Creating procedural pattern generators (e.g., checkerboards, stripes)
Building reusable utility functions (e.g., lerp, remap)
Abstracting conditional logic flows (e.g., safe division)
How to adjust
Fn itself is not adjustable. Its purpose is to create new, configurable nodes. For example, you can use Fn to create a 'PulsingHalo' node and define input parameters like `speed` and `radius`. In the main program, by changing the uniform values passed to these parameters, you can control the halo's pulsation speed and size in real-time, achieving rich visual variations.
Code Examples
1// Create a safe division function to avoid division by zero.
2const safeDivide = Fn(( { a, b } ) =>
3 If( b.lessThan( 1e-6 ), 0, a.div( b ) )
4).once();