shaders

assortment of fragment shaders.
Log | Files | Refs | README | LICENSE

commit e0e2a8ba8fac3fd35ed446a0db17d439c8fa050d
parent 6487ca220d0eff32b0cde7aa024bdb75b4b36012
Author: mpizzzle <m@michaelpercival.xyz>
Date:   Mon,  7 Sep 2020 16:51:07 +0100

added bezier curve, whippy thing

Diffstat:
Abezier.frag | 38++++++++++++++++++++++++++++++++++++++
Amiyagi3.frag | 23+++++++++++++++++++++++
2 files changed, 61 insertions(+), 0 deletions(-)

diff --git a/bezier.frag b/bezier.frag @@ -0,0 +1,38 @@ +#ifdef GL_ES +precision mediump float; +#endif + +#define PI 3.14159265359 + +uniform vec2 u_resolution; +uniform vec2 u_mouse; +uniform float u_time; + +float quadraticBezier(float x, vec2 ab) { + float epsilon = 0.00001; + float a = max(0.0, min(1.0, ab.x)); + float b = max(0.0, min(1.0, ab.y)); + + if (a == 0.5) { + a += epsilon; + } + + // solve t from x (an inverse operation) + float om2a = 1.0 - 2.0 * a; + float t = (sqrt(a * a + om2a * x) - a) / om2a; + return (1.0 - 2.0 * b) * (t * t) + (2.0 * b) * t; +} + +void main() { + vec2 st = gl_FragCoord.xy / u_resolution; + + float y = quadraticBezier(st.x, u_mouse / u_resolution); + vec3 color = vec3(y); + + float plot = smoothstep(y - 0.02, y, st.y) - smoothstep(y, y + 0.02, st.y); + + color = (1.0 - plot) * color + plot * vec3(1.0, 0.0, 1.0); + + gl_FragColor = vec4(color, 1.0); +} + diff --git a/miyagi3.frag b/miyagi3.frag @@ -0,0 +1,23 @@ +#ifdef GL_ES +precision mediump float; +#endif + +#define PI 3.14159265359 + +uniform vec2 u_resolution; +uniform vec2 u_mouse; +uniform float u_time; + +void main() { + vec2 st = gl_FragCoord.xy / u_resolution; + + float y = (sin(st.x * PI / 2.0 + (u_time * 3.)) / st.x / 8.0) + 0.5; + vec3 color = vec3(y); + + float pct = smoothstep(y - 0.02, y, st.y) - smoothstep(y, y + 0.02, st.y); + + color = (1.0 - pct) * color + pct * vec3(1.0, 0.0, 1.0); + + gl_FragColor = vec4(color, 1.0); +} +