Better dithered gradient
An upgrade to the Smooth Gradient shader using a simpler and more efficient dithering algorithm.
Noise granularity uniform – the strength of the noise: the higher it is and the more noticeable the noise will be
Shader code
shader_type canvas_item;
render_mode unshaded;
uniform vec2 direction = vec2(0.0, -1.0);
uniform vec4 start_color : source_color;
uniform vec4 end_color : source_color;
uniform float noise_granularity = 5.0;
float random(vec2 seed, float pmin, float pmax)
{
return pmin + fract(sin(dot(seed.xy, vec2(12.9898, 78.233))) * 43758.5453123) * (pmax - pmin);
}
float get_delta(vec2 uv)
{
vec2 dir = normalize(direction);
return (dir.x < 0.0 ? (1.0 - uv.x) : uv.x) * dir.x * dir.x + (dir.y < 0.0 ? (1.0 - uv.y) : uv.y) * dir.y * dir.y;
}
void fragment()
{
float noise = noise_granularity / 255.0;
float delta = get_delta(UV) + random(UV, -noise, noise);
COLOR = mix(start_color, end_color, delta);
}