Why not working shaders?

Godot Version

3

I am trying to make my planet to glow and the line2d node but it just goes to be invisible


without shader

same with line2d

My star shader code

shader_type canvas_item;

uniform float glow_strength : hint_range(0.0, 5.0) = 3.0;
uniform vec4 glow_color : hint_color = vec4(1.0, 1.0, 0.0, 1.0); // Yellow color for visibility

void fragment() {
    // The UV coordinates of the current fragment
    vec2 uv = SCREEN_UV;
    // Center of the sprite
    vec2 center = vec2(0.5, 0.5);
    
    // Compute the distance from the center
    float dist = length(uv - center);
    
    // Define glow radius and thickness
    float radius = 0.5; // Radius for glow effect
    float thickness = 0.05; // Thickness of the glow

    // Create a smooth circle
    float glow = smoothstep(radius - thickness, radius, dist) - smoothstep(radius, radius + thickness, dist);
    
    // Apply the glow color and strength
    COLOR = glow_color * glow * glow_strength;
}
shader_type canvas_item;

uniform float glow_strength : hint_range(0.0, 5.0) = 3.0;
uniform vec4 glow_color : hint_color = vec4(1.0, 1.0, 0.0, 1.0); // Yellow color for better visibility

void fragment() {
    // Center the line effect
    vec2 uv = SCREEN_UV;
    vec2 center = vec2(0.5, 0.5);
    
    // Compute the distance from the center
    float dist = length(uv - center);
    
    // Define line width and glow parameters
    float line_width = 0.05; // Width of the line
    float radius = 0.1; // Glow radius around the line
    float thickness = 0.02; // Thickness of the glow

    // Check if the current fragment is within the line width
    float line = smoothstep(line_width - thickness, line_width, dist) - smoothstep(line_width, line_width + thickness, dist);
    
    // Apply the glow color and strength
    COLOR = glow_color * line * glow_strength;
}

Line2d
Any ideas ???

1 Like

Does it work better addatively with COLOR += glow_color * glow * glow_strength? I don’t think you intend to use SCREEN_UV, try UV instead?

2 Likes

I am trying now

now its just an cube and my line2d is visible now but not glowing

i fixed that but there is no neon glow effect

shader_type canvas_item;

uniform float glow_strength : hint_range(0.0, 5.0) = 3.0;
uniform vec4 glow_color : hint_color = vec4(1.0, 1.0, 0.0, 1.0); // Neon yellow color for glow

void fragment() {
    // Sample the texture at the current UV coordinate
    vec4 tex_color = texture(TEXTURE, UV);

    // Calculate the distance from the center of the texture
    vec2 uv_center = vec2(0.5);
    vec2 uv_offset = UV - uv_center;
    float dist = length(uv_offset);

    // Define parameters for glow effect
    float glow_radius = 0.5; // Controls the glow spread
    float glow_thickness = 0.1; // Controls the thickness of the glow

    // Create a radial glow effect
    float glow = smoothstep(glow_radius - glow_thickness, glow_radius, dist) - smoothstep(glow_radius, glow_radius + glow_thickness, dist);

    // Apply the glow color and strength
    vec4 glow_effect = glow_color * glow * glow_strength;

    // Combine the original texture color with the glow effect
    COLOR = tex_color + glow_effect;

    // Preserve the original alpha value
    COLOR.a = tex_color.a;
}
1 Like

Wow its working but i think the problem is that my star is animatedsprite 2d and m shader only working on 1 frame so there is this


only for 1 second

i fixed this too but i want to make an effect like my start is giving light but now i understand that with neon effect i cant because its looks like this


Its looks like i just change the color but i want to add some light effect to it

1 Like


I cant fix this any idea ?

That’s a great star! I think it just needs to be rounded out

Check out the circles section of this book, you were using a similar signed distance function in your samples, maybe it has gotten away though

1 Like

Thanks i will check out

I think its looking better


but still not good

shader_type canvas_item;

uniform vec4 glow_color : hint_color = vec4(1.0, 1.0, 0.0, 1.0); // Glow color
uniform float glow_size = 30.0; // Size of the glow effect

void fragment() {
    // Normalize coordinates
    vec2 st = UV;
    
    // Distance from the center of the sprite
    float pct = distance(st, vec2(0.5));

    // Create a radial glow effect
    float glow = smoothstep(glow_size / 2.0, glow_size, glow_size - pct * glow_size);

    // Sample the sprite texture
    vec4 sprite_color = texture(TEXTURE, UV);
    
    // Combine sprite color with glow effect
    vec4 glow_effect = glow_color * glow;
    COLOR = sprite_color + glow_effect;
}

There are some white artefacts around my star.

Hi i just found video on youtube about this https://www.youtube.com/watch?v=14X_2WYZvRI and thats what i need but anyway thanks for that shaders information that was helpful

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.