varying
The varying node acts as a bridge to pass data calculated in the vertex shader (e.g., coordinates, normals) to the fragment shader. The GPU automatically interpolates this data smoothly across the surface of a polygon.
Core Advantages
Its core advantage is performance optimization. By performing calculations in the less expensive vertex shader (e.g., coordinate transforms) and passing the results, it avoids redundant, expensive calculations for every single pixel in the fragment shader, significantly boosting rendering efficiency.
Common Uses
Passing modified or animated UV coordinates for effects like flowing water.
Sending world-space positions to the fragment shader for procedural fog or terrain-layered shaders.
Providing interpolated normals, view directions, and other key geometric info for per-pixel lighting calculations.
How to adjust
The varying node itself has no parameters to tune; its effect is determined entirely by its input node. To change the effect, modify the node being passed in. For example, changing the input from `varying(uv())` to `varying(uv().add(offsetNode))` will create a dynamic texture coordinate offset effect.
Code Examples
1// "Send" the world normal in the vertex shader context
2const v_normalWorld = varying(normalWorld);
3
4// "Receive" and use it in the fragment shader context to calculate a rim light
5const rim = dot(v_normalWorld, viewDirection);
6const rimLight = smoothstep(0.0, 0.5, 1.0 - rim);