# Uniform update isn't reflected in ShaderMaterial

**URL:** <https://discourse.threejs.org/t/uniform-update-isnt-reflected-in-shadermaterial/7756>\
**Category:** Questions\
**Tags:** materials\
**Created:** [May 27, 2019, 8:40am UTC](https://discourse.threejs.org/t/uniform-update-isnt-reflected-in-shadermaterial/7756 "2019-05-27T08:40:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![a-barbieri](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/a-barbieri/32/5732_2.png) [@a-barbieri](https://discourse.threejs.org/u/a-barbieri)\
**Post date:** [May 27, 2019, 8:40am UTC](https://discourse.threejs.org/t/uniform-update-isnt-reflected-in-shadermaterial/7756/1 "2019-05-27T08:40:56Z")

</div>

Hi everyone,

I’ve been using ShaderMaterial many times. As stated in the [documentation](https://threejs.org/docs/index.html#api/en/materials/ShaderMaterial):

> Note that uniforms are refreshed on every frame, so updating the value of the uniform will immediately update the value available to the GLSL code.

Anyway if I change the uniform value I cannot see it reflected in my shader.

If you look at this codepen I’m trying to change background color based on current time. Nothing changes in the background colors, although the uniform value clearly does.

https://codepen.io/a-barbieri/embed/preview/arKpvJ?default-tabs=js%2Cresult&height=300&host=https%3A%2F%2Fcodepen.io&slug-hash=arKpvJ

Any clue?

---

<div class="post-metadata">

**Author:** ![prisoner849](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/prisoner849/32/535_2.png) [@prisoner849](https://discourse.threejs.org/u/prisoner849)\
**Post date:** [May 27, 2019, 9:00am UTC](https://discourse.threejs.org/t/uniform-update-isnt-reflected-in-shadermaterial/7756/2 "2019-05-27T09:00:37Z")

</div>

Hi!

`uniforms.u_current_time = clock.elapsedTime();`

has to be like this

`uniforms.u_current_time.value = clock.elapsedTime();`

Just out of curiousity, why don’t use `THREE.Clock()`?

---

<div class="post-metadata">

**Author:** ![atair](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@atair](https://discourse.threejs.org/u/atair)\
**Post date:** [May 27, 2019, 9:00am UTC](https://discourse.threejs.org/t/uniform-update-isnt-reflected-in-shadermaterial/7756/3 "2019-05-27T09:00:51Z")

</div>

try this:  
`backgroundMaterial.uniforms["u_current_time"].value = clock.elapsedTime() * 0.01;`

---

<div class="post-metadata">

**Author:** ![a-barbieri](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/a-barbieri/32/5732_2.png) [@a-barbieri](https://discourse.threejs.org/u/a-barbieri)\
**Post date:** [May 27, 2019, 9:39am UTC](https://discourse.threejs.org/t/uniform-update-isnt-reflected-in-shadermaterial/7756/4 "2019-05-27T09:39:37Z")

</div>

VALUE! I was missing ‘value’.  
Can’t belive was such a stupid mistake!

---

<div class="post-metadata">

**Author:** ![a-barbieri](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/a-barbieri/32/5732_2.png) [@a-barbieri](https://discourse.threejs.org/u/a-barbieri)\
**Post date:** [May 27, 2019, 9:50am UTC](https://discourse.threejs.org/t/uniform-update-isnt-reflected-in-shadermaterial/7756/5 "2019-05-27T09:50:12Z")

</div>

@prisoner849, we were using THREE.Clock() but we dropped it because we were so lost in the dark that we thought maybe it was the clock to be the cause of the issue.

At that time we also came across a [MrDoob comment](https://github.com/mrdoob/three.js/issues/9504#issuecomment-239646585) where he was expressing doubts about THREE.Clock.

We are actually re-implementing it now that we’ve solved the issue.

Thanks again for the prompt response.

---

<div class="post-metadata">

**Author:** ![a-barbieri](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/a-barbieri/32/5732_2.png) [@a-barbieri](https://discourse.threejs.org/u/a-barbieri)\
**Post date:** [May 27, 2019, 10:02am UTC](https://discourse.threejs.org/t/uniform-update-isnt-reflected-in-shadermaterial/7756/6 "2019-05-27T10:02:52Z")

</div>

Here the codepen updated with THREE.Clock for future reference

[https://codepen.io/a-barbieri/pen/arKWQZ](https://codepen.io/a-barbieri/pen/arKWQZ)
