How to use same shader on multiple sprites in a scene?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Diet Estus

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

My scene structure is:

Node2D
   > 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?

:bust_in_silhouette: Reply From: SIsilicon

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