From 2bb276d4ed15277cb0172353250fd7e92bf12840 Mon Sep 17 00:00:00 2001 From: Martin Michalec Date: Wed, 11 Feb 2026 07:50:35 +0300 Subject: add resources --- res/shaders/glsl330/quadratic-bezier.fs | 53 +++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 res/shaders/glsl330/quadratic-bezier.fs (limited to 'res/shaders/glsl330/quadratic-bezier.fs') diff --git a/res/shaders/glsl330/quadratic-bezier.fs b/res/shaders/glsl330/quadratic-bezier.fs new file mode 100644 index 0000000..cac602f --- /dev/null +++ b/res/shaders/glsl330/quadratic-bezier.fs @@ -0,0 +1,53 @@ +#version 330 core + +uniform float time; +uniform vec2 resolution; +uniform vec2 mouse; + +out vec4 color; + +float +quadratic_bezier (float x, vec2 a) +{ + float epsilon = 0.00001; + a.x = clamp (a.x, 0, 1); + a.y = clamp (a.y, 0, 1); + if (a.x == .5) + a += epsilon; + + // solve t from x (an inverse operation) + float om2a = 1 - 2*a.x; + float t = (sqrt (a.x*a.x + om2a*x) - a.x)/om2a; + float y = (1 - 2*a.y)*(t*t) + 2*a.y*t; + return y; +} + +float +line_segment (vec2 p, vec2 a, vec2 b) +{ + vec2 pa = p - a; + vec2 ba = b - a; + float h = clamp (dot (pa, ba)/dot (ba, ba), 0, 1); + return smoothstep (0, 1/resolution.x, length (pa - ba*h)); +} + +void +main () +{ + vec2 st = gl_FragCoord.xy/resolution; + float px = 1/resolution.y; + + // control point + // vec2 cp = mouse/resolution; + vec2 cp = vec2 (cos (time), sin (time))*0.45 + 0.5; + float l = quadratic_bezier(st.x, cp); + vec3 c = vec3 (smoothstep (l, l + px, st.y)); + + // draw control point + c = mix (vec3 (.5), c, line_segment (st, vec2 (0), cp)); + c = mix (vec3 (.5), c, line_segment (st, vec2 (1), cp)); + float d = distance (cp, st); + c = mix (vec3 (1, 0, 0), c, smoothstep (.01, .01 + px, d)); + + color = vec4 (c, 1); +} -- cgit v1.3