0 votes

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.

in Engine by (172 points)
edited by

1 Answer

0 votes
Best answer

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.

by (172 points)
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.