Uniform update isn't reflected in ShaderMaterial

Hi everyone,

I’ve been using ShaderMaterial many times. As stated in the documentation:

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.

Any clue?

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()?

3 Likes

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

1 Like

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

1 Like

@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 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.

1 Like

Here the codepen updated with THREE.Clock for future reference

https://codepen.io/a-barbieri/pen/arKWQZ