# ShaderMaterial Recompile: Fragment Code Updates, but New Uniforms Are Ignored

**URL:** <https://forum.babylonjs.com/t/shadermaterial-recompile-fragment-code-updates-but-new-uniforms-are-ignored/61756>\
**Category:** Bugs\
**Tags:** shader, shadermaterial\
**Created:** [December 11, 2025, 12:00pm UTC](https://forum.babylonjs.com/t/shadermaterial-recompile-fragment-code-updates-but-new-uniforms-are-ignored/61756 "2025-12-11T12:00:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sharp](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sharp/32/1325_2.png) [@sharp](https://forum.babylonjs.com/u/sharp)\
**Post date:** [December 11, 2025, 12:00pm UTC](https://forum.babylonjs.com/t/shadermaterial-recompile-fragment-code-updates-but-new-uniforms-are-ignored/61756/1 "2025-12-11T12:00:24Z")

</div>

I am trying to create a dynamic `ShaderMaterial` that **allows both the fragment shader source and the set of uniforms to be modified at runtime.** Defining the uniforms in the constructor works correctly, but I have not been able to update the uniform list dynamically after instantiation.

**Working demo (click on the sphere) :** _[A ShaderMaterial where uniforms declared in the constructor update correctly when the shader is recompiled.](https://playground.babylonjs.com/#ECJVP3#11)_

However, the next playground shows the issue: when the uniforms are _not_ declared in the constructor, I cannot add them later at runtime:

**Broken demo:** _[A ShaderMaterial whose fragment code updates, but where dynamically adding uniforms fails.](https://playground.babylonjs.com/#ECJVP3#09)_

I attempted the following:

```auto
this.options.uniforms = ['worldViewProjection', 'plane'];

```

and:

```auto
this.getEffect().uniforms = ['worldViewProjection', 'plane'];

```

prior to recompilation, but neither approach succeeded.

Is there a supported way to update uniforms dynamically?

---

<div class="post-metadata">

**Author:** ![sharp](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sharp/32/1325_2.png) [@sharp](https://forum.babylonjs.com/u/sharp)\
**Post date:** [December 11, 2025, 12:18pm UTC](https://forum.babylonjs.com/t/shadermaterial-recompile-fragment-code-updates-but-new-uniforms-are-ignored/61756/2 "2025-12-11T12:18:49Z")

</div>

Update on the investigation: it doesn’t seem to be an issue with the uniform declaration, as I can see the uniform in Spector. It’s more likely related to actually setting the uniform…

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/2/1/214b5877035b35f526bc84df921f2641d004f23b.png)

---

<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:** [December 11, 2025, 2:02pm UTC](https://forum.babylonjs.com/t/shadermaterial-recompile-fragment-code-updates-but-new-uniforms-are-ignored/61756/3 "2025-12-11T14:02:37Z")

</div>

This is not supported (and we can’t allow it, because an effect can be shared by multiple materials).

A material (effect) is defined, among others, by the list of uniforms. If the list changes, a new effect must be created. You should simply create a new instance of the material with the new uniform list / shader code.
