varyingProperty
varyingProperty provides a 'declare first, assign later' mechanism for passing data from the vertex to the fragment shader. It allows you to define a named, typed data 'slot,' and then assign its value separately, which is key for building modular and extensible materials.
Core Advantages
Its core advantage is decoupling and modularity. It allows different parts of a shader to communicate through a named 'data contract' without being directly coupled, enabling the creation of reusable, pluggable shader effects.
Common Uses
Defining data interfaces for pluggable material effects (like snow or outlines) to be reused across different materials.
Defining blend mask channels for layered materials, decoupling the mask calculation from the blending logic.
Acting as a 'visualization probe' for debugging by passing vertex-shader calculations (like velocity or tension) to be displayed as color in the fragment shader.
How to adjust
This node is a container; its behavior is entirely controlled by the node provided to its `.assign()` method. To change the visual effect, you must change the node being assigned. For example, assigning a rotated UV coordinate node instead of a standard one will cause the texture to rotate.
Code Examples
1// 1. Declare a data slot named 'v_worldPos'
2const v_worldPos = varyingProperty('vec3', 'v_worldPos');
3
4// 2. In vertex logic, assign a value to it
5v_worldPos.assign(positionWorld);
6
7// 3. In fragment logic, read and use the value
8const height = v_worldPos.y;