ShaderNode
A special metaprogramming node that allows you to use JavaScript logic (e.g., if/else) to dynamically construct and organize the shader node graph.
Core Advantages
Enables metaprogramming for shaders, serving as the ultimate abstraction tool for encapsulating complex effects, creating configurable materials, and bridging dynamic JS logic with static GLSL code.
Common Uses
Creating configurable "Uber Materials"
Encapsulating complex procedural effects like water or fire
Implementing custom lighting models, such as toon shading
Building multi-functional utility nodes
How to adjust
By changing the JavaScript properties passed to the node before compilation (e.g., a boolean value), you can trigger different logic branches within its internal `jsFunc`. This fundamentally alters the generated GLSL code structure, for instance, switching from sampling one texture to sampling a completely different one.
Code Examples
1new ShaderNode( ( inputs ) => {
2 // This is in JS, not GLSL!
3 if ( inputs.useSecondaryTexture === true ) {
4 return texture( secondaryTexture );
5 } else {
6 return texture( primaryTexture );
7 }
8} )