Shaders on different nodes seem to be overwriting each other

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

I’m using shaders to mask 4 different sprites that cover the same area. After the masks are applied, each sprite should only be showing in its individual corner, and therefore all 4 sprites that were originally covering the same area should be visible. However, it seems that only the last sprite to be rendered is visible, even though it is only covering it’s own corner and therefore should not be covering any of the other sprites. Here is (roughly) the shader code:

shader_type canvas_item;

uniform sampler2D mask;

void fragment() {
    COLOR = texture(TEXTURE, UV) * texture(mask, UV);

The mask uses white for areas that should be rendered, and transparency for areas that should not be rendered.

I am using 4 instances of the same scene, initialized with different parameters–maybe that’s part of my problem?

Any help is appreciated.

:bust_in_silhouette: Reply From: Bush2Tree

Upon further digging, the issue is that I am using the same shader for each instance. When setting the shader mask with set_shader_param, I am setting the mask for all 4 instances, since they all technically use the same shader. The solution is to create a separate shader for each instance.