0 votes

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:
https://imgur.com/a/pOFmE9w

in Engine by (12 points)

1 Answer

+1 vote
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

by (1,863 points)

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.

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 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 webmaster@godotengine.org with your username.