Mixing textures when one texture is missing

Godot Version

4.2

Question

Hi there, sorry but I can’t understand why my code does not work, I’m just trying to mix textures on a planemesh, the idea is that if one texture is mixing it does not affect the mix, but it does…

shader_type spatial;

uniform sampler2D A;
uniform sampler2D B;

void fragment() {
	vec4 _A = texture(A, UV);
	vec4 _B = vec4(0.0);
	
	if(textureSize(B,0).x !=0){
		_B=texture(B, UV);
	}
	
	ALBEDO = mix(_A, _B, _B.a).rgb;
}

This shows white instead the A texture.

I know I can mix some textures using Next Pass, but it gets very tricky if I want to mix more than 2, but at least I’ll like to understand why this code is not working.

Any idea?

Thanks in advance

Since I don’t have an answer for that, just to add that I solved this by creating a transparent material to be assigned to each sampler2D without a proper texture2D. For me the problem here was that a sampler2D needs to have something assigned, other wise the shader does not work well.

shader_type spatial;

uniform sampler2D A;
uniform sampler2D B;

void fragment() {
vec4 _A = texture(A, UV);
vec4 _B = texture(B, UV);

ALBEDO = mix(_A, _B, 0.5).rgb;

}