combo.frag (1134B)
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 quadraticBezier(float x, vec2 ab) { 12 float epsilon = 0.00001; 13 float a = max(0.0, min(1.0, ab.x)); 14 float b = max(0.0, min(1.0, ab.y)); 15 16 if (a == 0.5) { 17 a += epsilon; 18 } 19 20 // solve t from x (an inverse operation) 21 float om2a = 1.0 - 2.0 * a; 22 float t = (sqrt(a * a + om2a * x) - a) / om2a; 23 return (1.0 - 2.0 * b) * (t * t) + (2.0 * b) * t; 24 } 25 26 void main() { 27 vec2 st = gl_FragCoord.xy / u_resolution; 28 29 float y = quadraticBezier(st.x, u_mouse / u_resolution); 30 float yy = (sin(st.x * PI / 2.0 + (u_time * 1.5)) / 2.0) + 0.5; 31 vec3 color = vec3(y); 32 vec3 color2 = vec3(yy); 33 float thickness = 0.02; 34 35 float plot = smoothstep(y - thickness, y, st.y) - smoothstep(y, y + thickness, st.y); 36 float plot2 = smoothstep(yy - thickness, yy, st.y) - smoothstep(yy, yy + thickness, st.y); 37 38 color = (1.0 - plot) + plot * vec3(1.0, 0.0, 1.0); 39 color2 = (1.0 - plot2) + plot2 * vec3(0.0, 1.0, 0.0); 40 41 gl_FragColor = vec4(color * color2, 1.0); 42 } 43