From b1500890cb9013a329fe0be99144490ecdf39411 Mon Sep 17 00:00:00 2001 From: Patricio Gonzalez Vivo Date: Tue, 22 Dec 2015 17:19:21 -0500 Subject: [PATCH] sgrid --- 11/tmp/makegif.sh | 13 +++++ 11/tmp/simplex-pattern-01.frag | 7 ++- 11/tmp/simplex-pattern-02.frag | 87 ++++++++++++++++++++++++++++++++ 11/tmp/simplex-pattern-03.frag | 92 ++++++++++++++++++++++++++++++++++ 4 files changed, 195 insertions(+), 4 deletions(-) create mode 100755 11/tmp/makegif.sh create mode 100644 11/tmp/simplex-pattern-02.frag create mode 100644 11/tmp/simplex-pattern-03.frag diff --git a/11/tmp/makegif.sh b/11/tmp/makegif.sh new file mode 100755 index 0000000..d2edaf8 --- /dev/null +++ b/11/tmp/makegif.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +FILE=$1 +SEC=$2 + +COUNTER=0 +for i in `seq -w 0.01 .031 $SEC`; do + echo $i + `glslViewer $FILE -s $i -o frame-$COUNTER.png` + let COUNTER=COUNTER+1 +done + +convert -delay 3.5 -loop 1 frame-*.png animated.gif diff --git a/11/tmp/simplex-pattern-01.frag b/11/tmp/simplex-pattern-01.frag index ad2f1d5..c08a2e7 100644 --- a/11/tmp/simplex-pattern-01.frag +++ b/11/tmp/simplex-pattern-01.frag @@ -27,8 +27,6 @@ vec3 simplexGrid (vec2 st) { xyz.xy = 1.0-vec2(p.x,p.y-p.x); xyz.z = p.y; } else { - // xyz.yz = 1.0-vec2(p.x-p.y,p.y); - // xyz.x = p.x; xyz.zx = 1.-vec2(p.x-p.y,p.y); xyz.y = p.x; } @@ -51,15 +49,16 @@ void main() { vec2 st = gl_FragCoord.xy/u_resolution.xy; st.x *= u_resolution.x/u_resolution.y; vec3 color = vec3(0.0); - float t = smoothstep(0.,1.,abs(sin(u_time*0.4))); + float t = u_time*2.; // Scale the space to see the grid st *= 1.733; st *= 2.; vec3 S = simplexGrid(st*3.); + S.z += (S.x*S.y)*(0.5); // color = S; - color += step(.5,sin(.5-S.b*3.1415*6.)); + color += step(.5,abs(sin(.5-S.b*3.1415*5.-t))); gl_FragColor = vec4(color,1.0); } \ No newline at end of file diff --git a/11/tmp/simplex-pattern-02.frag b/11/tmp/simplex-pattern-02.frag new file mode 100644 index 0000000..ce86045 --- /dev/null +++ b/11/tmp/simplex-pattern-02.frag @@ -0,0 +1,87 @@ +// Author @patriciogv - 2015 - patriciogonzalezvivo.com + +#ifdef GL_OES_standard_derivatives +#extension GL_OES_standard_derivatives : enable +#endif + +#ifdef GL_ES +precision mediump float; +#endif + +uniform vec2 u_resolution; +uniform vec2 u_mouse; +uniform float u_time; + +vec2 skew (vec2 st) { + vec2 r = vec2(0.0); + r.x = 1.1547*st.x; + r.y = st.y+0.5*r.x; + return r; +} + +vec3 simplexGrid (vec2 st) { + vec3 xyz = vec3(0.0); + + vec2 p = fract(skew(st)); + if (p.x > p.y) { + xyz.xy = 1.0-vec2(p.x,p.y-p.x); + xyz.z = p.y; + } else { + xyz.yz = 1.0-vec2(p.x-p.y,p.y); + xyz.x = p.x; + // xyz.zx = 1.-vec2(p.x-p.y,p.y); + // xyz.y = p.x; + } + + return fract(xyz); +} + +// Antialiazed Step function +// from http://webstaff.itn.liu.se/~stegu/webglshadertutorial/shadertutorial.html +float aastep(float threshold, float value) { + #ifdef GL_OES_standard_derivatives + float afwidth = 0.7 * length(vec2(dFdx(value), dFdy(value))); + return smoothstep(threshold-afwidth, threshold+afwidth, value); + #else + return step(threshold, value); + #endif +} + +vec2 aastep(float threshold, vec2 value) { + #ifdef GL_OES_standard_derivatives + float afwidth = 0.7 * length(vec2(dFdx(value), dFdy(value))); + return smoothstep(threshold-afwidth, threshold+afwidth, value); + #else + return step(threshold, value); + #endif +} + +vec3 aastep(float threshold, vec3 value) { + #ifdef GL_OES_standard_derivatives + float afwidth = 0.7 * length(vec2(dFdx(value), dFdy(value))); + return smoothstep(threshold-afwidth, threshold+afwidth, value); + #else + return step(threshold, value); + #endif +} + +void main() { + vec2 st = gl_FragCoord.xy/u_resolution.xy; + st.x *= u_resolution.x/u_resolution.y; + vec3 color = vec3(0.0); + + // Scale the space to see the grid + float t = u_time*.5; + float pct = smoothstep(.1,.9, abs(sin(length(st-.5)*3.14-t)) ); + color = vec3(pct); + + st *= 1.733; + st *= 2.; + vec3 S = simplexGrid(st*3.); + + color = S; + color = aastep(pct-.01,1.-S); + color = 1.-vec3(color.r + color.g + color.b); + + gl_FragColor = vec4(color,1.0); +} \ No newline at end of file diff --git a/11/tmp/simplex-pattern-03.frag b/11/tmp/simplex-pattern-03.frag new file mode 100644 index 0000000..8e7e3df --- /dev/null +++ b/11/tmp/simplex-pattern-03.frag @@ -0,0 +1,92 @@ +// Author @patriciogv - 2015 - patriciogonzalezvivo.com + +#ifdef GL_OES_standard_derivatives +#extension GL_OES_standard_derivatives : enable +#endif + +#ifdef GL_ES +precision mediump float; +#endif + +uniform vec2 u_resolution; +uniform vec2 u_mouse; +uniform float u_time; + +vec2 skew (vec2 st) { + vec2 r = vec2(0.0); + r.x = 1.1547*st.x; + r.y = st.y+0.5*r.x; + return r; +} + +vec3 simplexGrid (vec2 st) { + vec3 xyz = vec3(0.0); + + vec2 p = fract(skew(st)); + if (p.x > p.y) { + xyz.xy = 1.0-vec2(p.x,p.y-p.x); + xyz.z = p.y; + } else { + xyz.yz = 1.0-vec2(p.x-p.y,p.y); + xyz.x = p.x; + // xyz.zx = 1.-vec2(p.x-p.y,p.y); + // xyz.y = p.x; + } + + return fract(xyz); +} + +// Antialiazed Step function +// from http://webstaff.itn.liu.se/~stegu/webglshadertutorial/shadertutorial.html +float aastep(float threshold, float value) { + #ifdef GL_OES_standard_derivatives + float afwidth = 0.7 * length(vec2(dFdx(value), dFdy(value))); + return smoothstep(threshold-afwidth, threshold+afwidth, value); + #else + return step(threshold, value); + #endif +} + +vec2 aastep(float threshold, vec2 value) { + #ifdef GL_OES_standard_derivatives + float afwidth = 0.7 * length(vec2(dFdx(value), dFdy(value))); + return smoothstep(threshold-afwidth, threshold+afwidth, value); + #else + return step(threshold, value); + #endif +} + +vec3 aastep(float threshold, vec3 value) { + #ifdef GL_OES_standard_derivatives + float afwidth = 0.7 * length(vec2(dFdx(value), dFdy(value))); + return smoothstep(threshold-afwidth, threshold+afwidth, value); + #else + return step(threshold, value); + #endif +} + +float isoGrid(vec2 st, float pct) { + vec3 S = simplexGrid(st); + S = aastep(pct-.01,1.-S); + return S.r + S.g + S.b; +} + +void main() { + vec2 st = gl_FragCoord.xy/u_resolution.xy; + st.x *= u_resolution.x/u_resolution.y; + vec3 color = vec3(0.0); + + // Scale the space to see the grid + float t = u_time*.5; + float pct = 1.;//smoothstep(.1,.9, abs(sin(length(st-.5)*3.14-t)) ); + color = vec3(pct); + + st *= 1.733; + float scale = 2.+mod(floor(u_time),3.); + vec3 A = vec3(1.-isoGrid(st*scale,pct)); + vec3 B = vec3(1.-isoGrid(st*(scale*2.),pct)); + + color = mix(A,B,fract(u_time)); + + gl_FragColor = vec4(color,1.0); +} \ No newline at end of file