replaceDefaultUV
replaceDefaultUV installs a context that overrides the default UV coordinates used by texture lookups. Instead of modifying each texture node individually, it intercepts the built-in UV used for sampling and replaces it with the UV returned by your callback.
Core Advantages
It lets you centralize UV logic for an entire material: you can globally scale, offset, rotate, animate, or remap the default UVs for all textures that rely on them, without touching each texture(...) call or changing the underlying mesh attributes. This makes UV behavior easy to reuse, toggle, and debug.
Common Uses
Applying a global UV scroll / rotation / scale animation to all textures that use the default UV, without editing each sampler.
Switching all default-UV textures to a different coordinate space (for example screen-space UVs, polar mapping, or custom projections).
Branching on the given textureNode inside the callback to use different UV mappings for different textures (e.g. one mapping for baseColor, another for normal map).
How to adjust
The behavior of replaceDefaultUV is entirely defined by the callback you provide: it receives a textureNode and must return a vec2 UV expression. Any sampling that relies on the default UV will use this result instead. Within the callback you can scale, offset, rotate, or mirror uv(), or construct more advanced mappings by combining time, positionWorld, screenUV, and other nodes. You can also branch on textureNode to give different textures different UV rules. To enable or disable the effect, assign or clear material.contextNode. Note that texture calls that pass an explicit custom UV are typically not affected by this default-UV replacement context.
Code Examples
1// Attach a context to the material: replace default UVs with a scrolling UV
2material.contextNode = replaceDefaultUV( ( textureNode ) => {
3 // Base mesh UV
4 const baseUV = uv();
5
6 // Scroll UVs along U over time
7 const t = time.mul( 0.1 );
8 const scrollUV = baseUV.add( vec2( t, 0.0 ) );
9
10 // Return the new UVs to be used as the default
11 return scrollUV;
12} );