From 950b3c95590aea7420e7dd4c7ae21ba0a0805ea6 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Sat, 5 Dec 2020 23:57:53 -0500 Subject: shader --- assets/platform_f.glsl | 15 +++++++++++++++ assets/platform_v.glsl | 19 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 assets/platform_f.glsl create mode 100644 assets/platform_v.glsl (limited to 'assets') diff --git a/assets/platform_f.glsl b/assets/platform_f.glsl new file mode 100644 index 0000000..1969a46 --- /dev/null +++ b/assets/platform_f.glsl @@ -0,0 +1,15 @@ +varying vec4 color; +varying vec2 p1, p2; +varying vec2 pos; +uniform float thickness; + +void main() { + // thanks to https://www.youtube.com/watch?v=PMltMdi1Wzg + float h = clamp(dot(pos-p1, p2-p1) / dot(p2-p1, p2-p1), 0.0, 1.0); + float d = length(pos - p1 - (p2-p1) * h); + + float v = max(thickness - d, 0.0); + v /= thickness; + + gl_FragColor = color * v; +} diff --git a/assets/platform_v.glsl b/assets/platform_v.glsl new file mode 100644 index 0000000..472f9df --- /dev/null +++ b/assets/platform_v.glsl @@ -0,0 +1,19 @@ +// "position" within line (0,0) = bottom-left corner, (1,1) = top-right corner +attribute vec2 vertex_p1, vertex_p2; +varying vec4 color; +varying vec2 p1, p2; +varying vec2 pos; +uniform float thickness; + +void main() { + gl_Position = gl_Vertex; + pos = gl_Vertex.xy; + color = gl_Color; +#if 1 + p1 = vertex_p1 + thickness * normalize(vertex_p2 - vertex_p1); + p2 = vertex_p2 + thickness * normalize(vertex_p1 - vertex_p2); +#else + p1 = vertex_p1; + p2 = vertex_p2; +#endif +} -- cgit v1.2.3