Skip to content

Instantly share code, notes, and snippets.

@mfandl
Created May 30, 2017 11:23
Show Gist options
  • Save mfandl/075365dcdd84b2b4b7877b43f2b7e065 to your computer and use it in GitHub Desktop.
Save mfandl/075365dcdd84b2b4b7877b43f2b7e065 to your computer and use it in GitHub Desktop.
Godot engine line distance fragment shader
color current_color = tex(TEXTURE, UV);
float cross2(vec2 a, vec2 b ){
return a.x * b.y - a.y * b.x;
}
float dist_to_line(vec2 point, vec2 line_begin, vec2 line_end) {
vec2 c1 = line_end - line_begin;
vec2 c2 = point - line_begin;
float area = cross2(c2, c1);
return area / length(c1);
};
vec2 start = 0.2 * vec2(sin(TIME * 2), sin(TIME * 2));
vec2 line_a = start + vec2(0.2, 1);
vec2 line_b = start + vec2(0.7, 0);
float width = 0.1 + 0.1 * (cos(sin(10 + TIME * 2)));
COLOR = current_color;
float dist = abs(dist_to_line(UV, line_a, line_b));
if (dist < width) {
COLOR += color(1, 1, 1, 1) * sign(current_color.a) * smoothstep(0, 0.2, 1 - (dist / width));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment