From 4eb5b153b999670cc070aa94944a7931aedc5838 Mon Sep 17 00:00:00 2001 From: hellerve Date: Mon, 5 Jun 2017 15:03:57 -0400 Subject: [PATCH] initial: added basic stuff --- README.md | 3 +++ basic/colorchange.glsl | 9 +++++++++ basic/colorchange_mouse.glsl | 12 ++++++++++++ basic/dancing_funs.glsl | 31 +++++++++++++++++++++++++++++++ basic/dancing_sine.glsl | 22 ++++++++++++++++++++++ basic/sunset.glsl | 21 +++++++++++++++++++++ 6 files changed, 98 insertions(+) create mode 100644 README.md create mode 100644 basic/colorchange.glsl create mode 100644 basic/colorchange_mouse.glsl create mode 100644 basic/dancing_funs.glsl create mode 100644 basic/dancing_sine.glsl create mode 100644 basic/sunset.glsl diff --git a/README.md b/README.md new file mode 100644 index 0000000..348641d --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# GLSL playground + +A few sketches I made while working throught [The Book of Shaders](https://thebookofshaders.com/). diff --git a/basic/colorchange.glsl b/basic/colorchange.glsl new file mode 100644 index 0000000..0fb217e --- /dev/null +++ b/basic/colorchange.glsl @@ -0,0 +1,9 @@ +#ifdef GL_ES +precision mediump float; +#endif + +uniform float u_time; + +void main() { + gl_FragColor = vec4(abs(sin(u_time)),0.5,abs(tan(u_time*0.5)),1.0); +} diff --git a/basic/colorchange_mouse.glsl b/basic/colorchange_mouse.glsl new file mode 100644 index 0000000..378cd78 --- /dev/null +++ b/basic/colorchange_mouse.glsl @@ -0,0 +1,12 @@ +#ifdef GL_ES +precision mediump float; +#endif + +uniform vec2 u_resolution; +uniform vec2 u_mouse; +uniform float u_time; + +void main() { + vec2 st = (gl_FragCoord.xy+u_mouse)/(u_resolution*vec2(2, 2)); + gl_FragColor = vec4(st.x, st.y, abs(sin(u_time)*0.8), 1.0); +} diff --git a/basic/dancing_funs.glsl b/basic/dancing_funs.glsl new file mode 100644 index 0000000..49a9e12 --- /dev/null +++ b/basic/dancing_funs.glsl @@ -0,0 +1,31 @@ +#ifdef GL_ES +precision mediump float; +#endif + +#define PI 3.14159265359 + +uniform vec2 u_resolution; +uniform float u_time; + +float plot (vec2 st, float pct){ + return smoothstep( pct-0.01, pct, st.y) - + smoothstep( pct, pct+0.01, st.y); +} + +void main() { + vec2 st = gl_FragCoord.xy/u_resolution.xy; + vec3 color = vec3(0.0); + + vec3 pct = vec3(st.x); + + pct.r = smoothstep(0.0,1.0, st.x*abs(sin(u_time))); + pct.g = sin(st.x*PI*u_time); + pct.b = pow(st.x*abs(cos(u_time)),0.5); + + // Plot transition lines for each channel + color = mix(vec3(0.0),vec3(1.0,0.0,0.0),plot(st,pct.r)); + color = mix(color,vec3(0.0,1.0,0.0),plot(st,pct.g)); + color = mix(color,vec3(0.0,0.0,1.0),plot(st,pct.b)); + + gl_FragColor = vec4(color,1.0); +} diff --git a/basic/dancing_sine.glsl b/basic/dancing_sine.glsl new file mode 100644 index 0000000..143d69c --- /dev/null +++ b/basic/dancing_sine.glsl @@ -0,0 +1,22 @@ +#ifdef GL_ES +precision mediump float; +#endif + +uniform vec2 u_resolution; +uniform float u_time; + +float plot(vec2 st, float pct){ + return smoothstep( pct-0.02, pct, st.y) - + smoothstep( pct, pct+0.02, st.y); +} + +void main() { + vec2 st = gl_FragCoord.xy/u_resolution; + + float y = sin(st.x*u_time); + + float pct = plot(st,y); + vec3 color = pct*vec3(0.0,1.0,0.0); + + gl_FragColor = vec4(color,1.0); +} diff --git a/basic/sunset.glsl b/basic/sunset.glsl new file mode 100644 index 0000000..86ed7c1 --- /dev/null +++ b/basic/sunset.glsl @@ -0,0 +1,21 @@ +#ifdef GL_ES +precision mediump float; +#endif + +uniform vec2 u_resolution; +uniform float u_time; + +void main() { + vec2 st = gl_FragCoord.xy/u_resolution.xy; + vec3 sun = vec3(1.0*abs(sin(u_time)), .0, 0.4*abs(cos(u_time))); + + vec3 pct = vec3(st.x); + + vec3 color = sun; + color *= vec3(step(0.4, st.y)); + if (step(0.4, st.y)<1.0) { + color = sun * vec3(smoothstep(0.2, 0.4, st.y)); + color += vec3(0.3,0.2,0.9); + } + gl_FragColor = vec4(color,1.0); +}