Shader using gradient as alpha producing artifacts

Godot Version

4.3 beta3

Question

Hello everyone!
I’m trying to write an exhaust plume shader, and I’m using gradients to control both transparency and color. This is the shader:

shader_type spatial;

render_mode cull_disabled, shadows_disabled, ambient_light_disabled;
render_mode alpha_to_coverage;

uniform float exhaust_heat : hint_range(0, 1000);
uniform float throat_radius : hint_range(0, 1);
uniform float exhaust_spread : hint_range(0, 10);
uniform float exhaust_speed : hint_range(0, 10);
uniform float radius_oscilation : hint_range(0, 1);
uniform float scale_factor : hint_range(1, 10) = 1;
uniform sampler2D noise;
uniform sampler2D main_color;

float random() {
    return sin(dot(TIME, 12.9898) * 2.0) * radius_oscilation;
}

void vertex() {
    float vertex_position = VERTEX.y;
    float offset = throat_radius + vertex_position * (exhaust_spread + random());
    VERTEX = NORMAL * offset;
    VERTEX.y = vertex_position;
}

void fragment() {   
    vec2 uv_scale = vec2(scale_factor, 1.0);
    vec2 uv_offset = vec2(0.0, TIME * exhaust_speed);
    vec2 new_uv = (UV - vec2(0.5)) * uv_scale + vec2(0.5) + uv_offset;
    float noise_texture = dot(texture(noise, new_uv).rgb, vec3(0.5));

    vec4 gradient = texture(main_color, UV);
    ALBEDO = gradient.rgb;
    EMISSION = ALBEDO * exhaust_heat;
    ALPHA = noise_texture * gradient.a;
}

The look is exactly what I need, but there are these weird artifacts at the end of the gradient texture:

If I get closer to the end of the gradient, there are no artifacts, just a clean blend between the exhaust and the background:

My initial guess was that it had something to do with normals. I’ve tried a lot of different configurations: flat, smooth, auto-smooth, etc. All gave the same results. Then I tried disabling the LOD in Godot, still no luck. Now I’m guessing that it may have something to do with mipmaps? I don’t know where else to look.

This is my gradient texture, by the way:

Another thing I’ve noticed is that the larger the gradient texture resolution, the less visible this artifact becomes. However, 1024x1024 is already pretty big for a gradient.

Solved!

I had to add the repeat_disable hint to the gradient sampler!

1 Like

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