OnMaterialUpdate
Registers a material-scoped callback that runs once per frame—when the first object using this material is rendered. Receives the current frame (e.g., material, renderer, camera, deltaTime). Must be declared inside a TSL Fn().
Core Advantages
A single, cheap hook per frame for material-wide work (counters, timers, caches). Avoids repeating the same update for every object that shares the material.
Common Uses
Increment material-wide time/counters without a custom render loop.
Lazy initialization or per-frame refresh of material caches.
Update scriptableValue/uniform-style inputs once per frame.
How to adjust
Keep logic minimal and side-effect-only. Use it to update JS-side values consumed by nodes (e.g., scriptableValue, material properties). It must be declared within Fn() to be wired into the builder stack.
Code Examples
1// Inside a TSL Fn()
2const graph = Fn(() => {
3 const uTime = scriptableValue(0.0);
4
5 OnMaterialUpdate((frame) => {
6 uTime.value += frame.deltaTime; // once per frame for this material
7 });
8
9 // Use the updated value in the graph
10 const pulse = uTime.mul(2.0).sin().abs();
11 material.colorNode = mix(color(0x223355), color(0xffffff), pulse);
12});