This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Hi All. I have a simple shader where that uses Sampler2d with a noise texture.

In gdscript, I want to animate the offset parameter on the noise. I'm using this code:

func _physics_process(delta):
    time += delta
    self.material.set_shader_param("noise_img/noise/offset:x", time)

It prints correctly - the x offset parameter seems to be going up as expected. However, the noise is completely static. When I slide the x offset parameter in the editor, the noise is moving fine. The above code is not doing anything in runtime though, except print the correct value.

Interestingly, if use this:


to print the param, it remains static (unaffected by the set_shader_param).
It looks like it's not really assigning the value to the param after all?

BTW, not sure it matters but the shader itself is a fog() shader in Godot 4.

Godot version 4.0
in Engine by (516 points)

1 Answer

0 votes

I doubt shader will update information about change of sampler source like this. It is better to code offset manually inside shader as another uniform. Then You can add this uniformed offset to UV.x of your sampled noise. If You didn't understand this paste code of your shader and I will help You adapt it

by (8,188 points)

Thanks. I ended up doing what you suggested: I enabled repeat on the sampler2d and went uv.x*TIME*0.1 on the texture in the shader code

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.