Visual Shader simple alpha blend

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

I am trying to resume a project where I wrote a simple alpha blend thingy in the visual shader of Godot 2 to create rounded texture edges.

If I include the image texture in my visual shader it works as intended, if I just use the blend mask my original image disappears . Connecting a color input to the color output (thats how I did it in Godot 2) doesn’t help
What is the correct way to do th!is?

screenshots:

:bust_in_silhouette: Reply From: rakkarage
shader_type canvas_item;

uniform vec4 color: hint_color;
uniform sampler2D mask: hint_albedo;
uniform float scale = 2.0;
uniform vec2 pivot = vec2(0.5, 0.5);

void fragment() {
	COLOR.rgb = color.rgb;
	COLOR.a = 1.0 - texture(mask, (UV - pivot) * vec2(scale, scale) + pivot).a;
}

here is a shader where i combine alpha from one texture with color from another
so just set the output alpha to 1-alpha or alpha-1 i think?

click the eye for preview too to see the output can help sometimes

Thx for the help. After getting used to the shader code it’s rather easy:

shader_type canvas_item;

uniform sampler2D mask: hint_albedo;

void fragment() {
	vec4 color = texture(TEXTURE,UV).rgba;
	vec4 shader = texture(mask, UV).rgba;
    COLOR.rgb = color.rgb;
	COLOR.a = shader.r;
}

Once I got that working I also figured out how to do it in the visual shader: ignore the color input and instead route the texture input into a texture block in “samplerPort” mode. This gives a usable rgb output of the original texture. Route this into the color output and rgb of the mask texture into apha output.

costagomez | 2020-05-26 18:59