Created
May 30, 2017 11:23
-
-
Save mfandl/075365dcdd84b2b4b7877b43f2b7e065 to your computer and use it in GitHub Desktop.
Godot engine line distance fragment shader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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