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
    print(self.material.get_shader_param("noise_img/noise/offset:x"))
    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:

print(self.material.get_shader_param("noise_img").noise.offset.x)

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 (515 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,097 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.