uniformFlow
Wraps a node so that it and all its dependencies are evaluated under a uniform control-flow context. It does not change numeric results; it only affects compile-time uniformity analysis to satisfy WGSL/Metal validation for derivatives and implicit-derivative texture ops.
Core Advantages
Enables safe use of fwidth/dFdx/dFdy and implicit-derivative texture sampling inside conditionals or loops by promoting the relevant subgraph to uniform control flow, removing “not in uniform control flow” errors with minimal graph changes.
Common Uses
Provide uniform control flow for expressions used with fwidth/dFdx/dFdy to anti-alias stripes, fine normals, etc.
Wrap UVs or intermediates when sampling textures inside branches that may rely on implicit derivatives.
Fix cross-backend uniformity validation issues on WebGPU/WGSL or Metal.
Explicitly delineate subgraphs that must run uniformly so the compiler can safely hoist or reorder them.
How to adjust
Wrap only the smallest necessary subgraph (typically the signal measured by derivatives or the UV used for sampling) to avoid hoisting heavy work out of branches. If uniformity errors persist, move uniformFlow(...) outward one level until they vanish. No parameters; adjust by adding, removing, or relocating the wrapper.
Code Examples
1// JS: Wrap the high-frequency signal with uniformFlow before computing derivatives
2const material = new MeshStandardNodeMaterial();
3
4// High-frequency stripes
5const stripes = sin( uv().x.mul( 40.0 ) );
6
7// Some backends require derivatives to be in uniform control flow
8const edge = fwidth( uniformFlow( stripes ) );
9
10// Anti-aliased mask
11const mask = smoothstep( 0.0, edge, abs( stripes ) );
12
13// Blend two colors by the mask
14material.colorNode = mix( color( 0x1565C0 ), color( 0x90CAF9 ), mask );
15
16mesh.material = material;