# What's the "proper" way to dynamically update defines on a material?

**URL:** <https://forum.babylonjs.com/t/whats-the-proper-way-to-dynamically-update-defines-on-a-material/62474>\
**Category:** Questions\
**Created:** [February 17, 2026, 2:54pm UTC](https://forum.babylonjs.com/t/whats-the-proper-way-to-dynamically-update-defines-on-a-material/62474 "2026-02-17T14:54:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rapid.tore.levenstam](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/rapid.tore.levenstam/32/43255_2.png) [@rapid.tore.levenstam](https://forum.babylonjs.com/u/rapid.tore.levenstam)\
**Post date:** [February 17, 2026, 2:54pm UTC](https://forum.babylonjs.com/t/whats-the-proper-way-to-dynamically-update-defines-on-a-material/62474/1 "2026-02-17T14:54:15Z")

</div>

Hello!

A bit of an open question here, but I’m looking for input of what approach you would recommend for updating ‘defines’ on a `ShaderMaterial` dynamically. I want to make sure we play nicely with the effect/mesh caching systems and rendering steps inside Babylon 🙂

Our setup is that we have custom shader materials that we use like any other in Babylon, and we have some configurations put behind the preprocessor. Some of these options are static for the lifetime of the application, others change a few times, and others will differ for different meshes (ie will require several parallel effects for one material in a frame).

Should be noted here that we do not consider parallel shader compilation at the moment, so it can be assumed to always be disabled 🙂

From experimentation, it seems like updating defines (using `Material.setDefine`) inside `Material.isReady` seems to work, but hard to tell if this is the “intended” way.

Thanks in advance 🙂  
-Tore

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [February 17, 2026, 5:45pm UTC](https://forum.babylonjs.com/t/whats-the-proper-way-to-dynamically-update-defines-on-a-material/62474/2 "2026-02-17T17:45:21Z")

</div>

cc @Evgeni_Popov

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [February 17, 2026, 9:31pm UTC](https://forum.babylonjs.com/t/whats-the-proper-way-to-dynamically-update-defines-on-a-material/62474/3 "2026-02-17T21:31:24Z")

</div>

Yes, you can change the defines of a `ShaderMaterial` at any time by calling `ShaderMaterial.setDefine`. You can call it in your own implementation of `isReady`, but in that case you should do it before calling the `isReady` function of the base class.

---

<div class="post-metadata">

**Author:** ![rapid.tore.levenstam](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/rapid.tore.levenstam/32/43255_2.png) [@rapid.tore.levenstam](https://forum.babylonjs.com/u/rapid.tore.levenstam)\
**Post date:** [February 18, 2026, 1:49pm UTC](https://forum.babylonjs.com/t/whats-the-proper-way-to-dynamically-update-defines-on-a-material/62474/4 "2026-02-18T13:49:17Z")

</div>

Great! Thanks for the info!

The mesh parameter of the function is optional, but seems like it’s always defined during rendering. Is this a behaviour you rely on internally for your own material implementations? Just want to know if it’s something we should count on or not 🙂

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [February 18, 2026, 7:18pm UTC](https://forum.babylonjs.com/t/whats-the-proper-way-to-dynamically-update-defines-on-a-material/62474/5 "2026-02-18T19:18:38Z")

</div>

Yes, you can assume **mesh** is always passed to the `isReady` function.
