0 votes

Hi,

I am learning shader this week and I am trying to make my sprite glowing.
However, when the sprite overlapped with each other, some of their parts go transparent (I don't know the word to describe it).

I am using the fragment method to add color to the untransparent part to make a glow effect.

My shader code is down below.

shader_type canvas_item;

uniform vec4 glow_color : hint_color  = vec4(1.0);
void fragment() 
{

vec4 current_color = texture(TEXTURE,UV);

if(current_color.r > 0f)
{
    COLOR = current_color + glow_color /2.0
}
else
{
    COLOR = current_color
}
}

Does anyone know the name of the problem?
Thank you for your help :)

in Engine by (341 points)

1 Answer

+1 vote
Best answer

It would be incredibly helpful with an image showing when it works and when things break, but it might have to do with the fact that you modify the "COLOR"s alpha value try the following:

shader_type canvas_item;

uniform vec3 glow_color : hint_color  = vec3(1.0);
void fragment() 
{

vec4 current_color = texture(TEXTURE,UV);

if(current_color.r > 0f)
{
    COLOR.rgb = current_color.rgb + glow_color.rgb /2.0;
    COLOR.a = current_color.a;
}
else
{
    COLOR = current_color;
}
}
by (212 points)
selected by
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]engine.org with your username.