Curve Graph
Shader to display a graph using respresenting a Curve resource.
Shader code
shader_type canvas_item;
uniform float line_thickness = 0.01;
uniform vec4 line_color : source_color = vec4(1, 1, 1, 1);
uniform vec4 bg_top_color : source_color = vec4(0.25, 0.25, 0.25, 1);
uniform vec4 bg_bottom_color : source_color = vec4(0.5, 0.5, 0.5, 1);
uniform sampler2D curve_texture : repeat_disable, filter_linear;
void fragment() {
float curve = texture(curve_texture, UV).r;
float line = curve - (1.0 - UV.y);
float top_bottom = ceil(clamp(line, 0.0, 1.0));
line = abs(line);
line = step(line, line_thickness * (1.0 + fwidth(curve) * 300.0)); // fwidth for uniform line thickness but i'm not sure if it's good enough
COLOR = mix(mix(bg_bottom_color, bg_top_color, top_bottom), line_color, line);
}