curve-through-point.frag (823B)
1 #ifdef GL_ES 2 precision mediump float; 3 #endif 4 5 #define PI 3.14159265359 6 7 uniform vec2 u_resolution; 8 uniform vec2 u_mouse; 9 uniform float u_time; 10 11 float quadraticThroughPoint(float x, vec2 ab) { 12 float epsilon = 0.00001; 13 float a = min(1.0 - epsilon, max(0.0 + epsilon, ab.x)); 14 float b = min(1.0, max(0.0, ab.y)); 15 float A = (1.0 - b) / (1.0 - a) - (b / a); 16 float B = (A * (a * a) - b) / a; 17 float y = A * (x * x) - B * (x); 18 return min(1.0, max(0.0, y)); 19 } 20 21 void main() { 22 vec2 st = gl_FragCoord.xy / u_resolution; 23 24 float y = quadraticThroughPoint(st.x, u_mouse / u_resolution); 25 vec3 color = vec3(y); 26 27 float plot = smoothstep(y - 0.02, y, st.y) - smoothstep(y, y + 0.02, st.y); 28 29 color = (1.0 - plot) * color + plot * vec3(1.0, 0.0, 1.0); 30 31 gl_FragColor = vec4(color, 1.0); 32 } 33