shaders

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

commit d608712bb19f4732d4b835a9c6623562c54b1d2a
parent e0e2a8ba8fac3fd35ed446a0db17d439c8fa050d
Author: mpizzzle <m@michaelpercival.xyz>
Date:   Mon,  7 Sep 2020 17:07:33 +0100

added function to draw a quadratic through given point (mouse coordinates)

Diffstat:
Acurve-through-point.frag | 33+++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+), 0 deletions(-)

diff --git a/curve-through-point.frag b/curve-through-point.frag @@ -0,0 +1,33 @@ +#ifdef GL_ES +precision mediump float; +#endif + +#define PI 3.14159265359 + +uniform vec2 u_resolution; +uniform vec2 u_mouse; +uniform float u_time; + +float quadraticThroughPoint(float x, vec2 ab) { + float epsilon = 0.00001; + float a = min(1.0 - epsilon, max(0.0 + epsilon, ab.x)); + float b = min(1.0, max(0.0, ab.y)); + float A = (1.0 - b) / (1.0 - a) - (b / a); + float B = (A * (a * a) - b) / a; + float y = A * (x * x) - B * (x); + return min(1.0, max(0.0, y)); +} + +void main() { + vec2 st = gl_FragCoord.xy / u_resolution; + + float y = quadraticThroughPoint(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); +} +