diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-12-06 19:13:20 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-12-06 19:13:20 -0500 |
commit | 2227e40af76aa10d87bbcce0f7df73d98407881b (patch) | |
tree | 02509a67a6095474cdd60df6a26b3dd4c80373de /assets | |
parent | 950b3c95590aea7420e7dd4c7ae21ba0a0805ea6 (diff) |
finish platform shader & ball shader
Diffstat (limited to 'assets')
-rw-r--r-- | assets/ball_f.glsl | 19 | ||||
-rw-r--r-- | assets/ball_v.glsl | 9 | ||||
-rw-r--r-- | assets/platform_f.glsl | 2 | ||||
-rw-r--r-- | assets/platform_v.glsl | 3 |
4 files changed, 32 insertions, 1 deletions
diff --git a/assets/ball_f.glsl b/assets/ball_f.glsl new file mode 100644 index 0000000..e3dfdb3 --- /dev/null +++ b/assets/ball_f.glsl @@ -0,0 +1,19 @@ +varying vec4 color; +varying vec2 pos; +uniform vec2 center; +uniform float radius; + +void main() { + float dist_squared = dot(pos - center, pos - center); + float threshold = 0.9 * radius; // radius border starts at + float thickness = radius - threshold; + + if (dist_squared > threshold * threshold && dist_squared < radius * radius) { + float dist = sqrt(dist_squared); + float v = (dist - threshold) / thickness; + v = 2.0 * v - 1.0; + gl_FragColor = color * (1.0 - v * v); + } else { + discard; + } +} diff --git a/assets/ball_v.glsl b/assets/ball_v.glsl new file mode 100644 index 0000000..7908bc7 --- /dev/null +++ b/assets/ball_v.glsl @@ -0,0 +1,9 @@ +varying vec4 color; +varying vec2 pos; +uniform mat4 transform; + +void main() { + gl_Position = transform * gl_Vertex; + pos = gl_Vertex.xy; + color = gl_Color; +} diff --git a/assets/platform_f.glsl b/assets/platform_f.glsl index 1969a46..82c8740 100644 --- a/assets/platform_f.glsl +++ b/assets/platform_f.glsl @@ -5,11 +5,13 @@ uniform float thickness; void main() { // thanks to https://www.youtube.com/watch?v=PMltMdi1Wzg + // (calculates distance to line segment p1-p2) 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; + v *= v; gl_FragColor = color * v; } diff --git a/assets/platform_v.glsl b/assets/platform_v.glsl index 472f9df..8f57aab 100644 --- a/assets/platform_v.glsl +++ b/assets/platform_v.glsl @@ -4,9 +4,10 @@ varying vec4 color; varying vec2 p1, p2; varying vec2 pos; uniform float thickness; +uniform mat4 transform; void main() { - gl_Position = gl_Vertex; + gl_Position = transform * gl_Vertex; pos = gl_Vertex.xy; color = gl_Color; #if 1 |