+1 vote

I am trying to use a shader to scroll background images at different speeds in a scene.

My scene structure is:

   > Sprite1 (with shader)
        >> AnimationPlayer (which animates uniforms of shader)
    > Sprite2 (with shader)
        >> AnimationPlayer (which animates uniforms of shader)

I am trying to use the same shader on each sprite, but to animate the uniforms of the shader separately for each sprite.

Unfortunately, even if I toggle resource_local_to_scene for the shader material, it still applies to both Sprites simultaneously. So both Sprites are being affected by the other's animation of the uniforms.

How can I animate the uniforms differently per Sprite, all while using the same shader code?

in Engine by (1,570 points)

1 Answer

+2 votes
Best answer

The shaders can stay the same, but it's the ShaderMaterials that hold the uniforms. So what you would do is make two different ShaderMaterialsthat share the same shader. In the editor you would right-click the material and tap "Make Unique". In script you would call matetial2 = material1.duplicate()

by (3,891 points)
selected by
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 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 webmaster@godotengine.org with your username.