diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-12-05 23:57:53 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-12-05 23:57:53 -0500 |
commit | 950b3c95590aea7420e7dd4c7ae21ba0a0805ea6 (patch) | |
tree | 3fe285820ef7bce254fbd0b22f3f3c7bbb6c3a7d /assets | |
parent | 50fb1482f6dd3d738ba5fd23dfa6789c0f397c92 (diff) |
shader
Diffstat (limited to 'assets')
-rw-r--r-- | assets/platform_f.glsl | 15 | ||||
-rw-r--r-- | assets/platform_v.glsl | 19 |
2 files changed, 34 insertions, 0 deletions
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 +} |