merged master
@ -0,0 +1,2 @@
|
||||
|
||||
- [Distance Transforms of Sampled Functions] (http://cs.brown.edu/~pff/papers/dt-final.pdf)
|
@ -0,0 +1,66 @@
|
||||
// Author @patriciogv - 2015
|
||||
// http://patriciogonzalezvivo.com
|
||||
|
||||
#ifdef GL_OES_standard_derivatives
|
||||
#extension GL_OES_standard_derivatives : enable
|
||||
#endif
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
#define PI 3.14159265359
|
||||
#define TWO_PI 6.28318530718
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// get distance field of a polygon in the center
|
||||
// where N is the number of sides of it
|
||||
// ================================
|
||||
float shapeDF (vec2 st, int N) {
|
||||
st = st *2.-1.;
|
||||
float a = atan(st.x,st.y)+PI;
|
||||
float r = TWO_PI/float(N);
|
||||
return cos(floor(.5+a/r)*r-a)*length(st);
|
||||
}
|
||||
|
||||
// draw a polygon in the center
|
||||
// where N is the number of sides of it
|
||||
// ================================
|
||||
float shape (vec2 st, int N, float width) {
|
||||
return 1.0-aastep(width,shapeDF(st,N));
|
||||
}
|
||||
|
||||
// draw the border of a polygon in the center
|
||||
// where N is the number of sides of it
|
||||
// ================================
|
||||
float shapeBorder (vec2 st, int N, float size, float width) {
|
||||
return shape(st,N,size)-shape(st,N,size-width);
|
||||
}
|
||||
|
||||
void main(){
|
||||
vec2 st = gl_FragCoord.xy/u_resolution.xy;
|
||||
st.x *= u_resolution.x/u_resolution.y;
|
||||
vec3 color = vec3(0.0);
|
||||
color.r += shapeBorder(st, 3, .1, .06);
|
||||
|
||||
vec2 offset = vec2(.0,-.1);
|
||||
color += shapeBorder(st+offset+vec2(.045,.125), 3, .05, .03);
|
||||
color += shapeBorder(st+offset+vec2(-.045,.125), 3, .05, .03);
|
||||
color += shapeBorder(st+offset+vec2(0.,0.05), 3, .05, .03);
|
||||
|
||||
gl_FragColor = vec4(color,1.0);
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
// Author @patriciogv - 2015
|
||||
// http://patriciogonzalezvivo.com
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
#define PI 3.14159265359
|
||||
#define TWO_PI 6.28318530718
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
|
||||
float shape(vec2 st, float N){
|
||||
st = st *2.-1.;
|
||||
float a = atan(st.x,st.y)+PI;
|
||||
float r = TWO_PI/floor(N);
|
||||
return cos(floor(.5+a/r)*r-a)*length(st);
|
||||
}
|
||||
|
||||
void main(){
|
||||
vec2 st = gl_FragCoord.xy/u_resolution.xy;
|
||||
st.x *= u_resolution.x/u_resolution.y;
|
||||
vec3 color = vec3(0.0);
|
||||
|
||||
float sides = u_time*.5;
|
||||
float minSides = 3.;
|
||||
float maxSides = 6.;
|
||||
|
||||
float d = mix(shape(st,minSides+mod(sides,maxSides)),
|
||||
shape(st,minSides+mod(sides+1.,maxSides)),
|
||||
pow(fract(sides),20.));
|
||||
|
||||
// Size
|
||||
d = step(.4,d);
|
||||
|
||||
gl_FragColor = vec4(vec3(1.0-d),1.0);
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
// Author @patriciogv ( patriciogonzalezvivo.com ) - 2015
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform float u_time;
|
||||
|
||||
float box(vec2 _st, vec2 _size){
|
||||
_size = vec2(0.5) - _size*0.5;
|
||||
vec2 uv = smoothstep(_size,
|
||||
_size+vec2(0.0001),
|
||||
_st);
|
||||
uv *= smoothstep(_size,
|
||||
_size+vec2(0.0001),
|
||||
vec2(1.0)-_st);
|
||||
return uv.x*uv.y;
|
||||
}
|
||||
|
||||
void main(){
|
||||
vec2 st = gl_FragCoord.xy/u_resolution.xy;
|
||||
|
||||
float pct = box(st, vec2(0.9,0.3)) + box(st, vec2(0.3,0.9));
|
||||
gl_FragColor = vec4( vec3(1.-pct),pct );
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
// Author @patriciogv ( patriciogonzalezvivo.com ) - 2015
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
|
||||
vec2 tile(vec2 _st, float _zoom){
|
||||
_st *= _zoom;
|
||||
return fract(_st);
|
||||
}
|
||||
|
||||
float circle(vec2 _st, float _radius){
|
||||
vec2 pos = vec2(0.5)-_st;
|
||||
_radius *= 0.75;
|
||||
return 1.-smoothstep(_radius-(_radius*0.05),_radius+(_radius*0.05),dot(pos,pos)*3.14);
|
||||
}
|
||||
|
||||
void main(){
|
||||
|
||||
vec2 st = gl_FragCoord.xy/u_resolution.xy;
|
||||
st.x *= u_resolution.x/u_resolution.y;
|
||||
|
||||
float pct = 0.0;
|
||||
vec2 st_i = floor(st*10.);
|
||||
pct += step(0.5,abs(mod(st_i.x,2.)-mod(st_i.y+1.,2.)));
|
||||
|
||||
gl_FragColor = vec4(vec3(pct),1.0);
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
// Author @patriciogv ( patriciogonzalezvivo.com ) - 2015
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
uniform sampler2D u_tex0;
|
||||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
|
||||
float rows = 10.0;
|
||||
|
||||
vec2 brickTile(vec2 _st, float _zoom){
|
||||
_st *= _zoom;
|
||||
if (fract(_st.y * 0.5) > 0.5){
|
||||
_st.x += 0.5;
|
||||
}
|
||||
return fract(_st);
|
||||
}
|
||||
|
||||
float circle(vec2 _st, float _radius){
|
||||
vec2 pos = vec2(0.5)-_st;
|
||||
_radius *= 0.75;
|
||||
return 1.-smoothstep(_radius-(_radius*0.01),_radius+(_radius*0.01),dot(pos,pos)*3.14);
|
||||
}
|
||||
|
||||
void main(){
|
||||
|
||||
vec2 st = gl_FragCoord.xy/u_resolution.xy;
|
||||
st.x *= u_resolution.x/u_resolution.y;
|
||||
vec2 pos = st;
|
||||
|
||||
st = brickTile(st,50.);
|
||||
|
||||
float pattern = texture2D(u_tex0,pos).r;
|
||||
pattern = circle(st, pattern);
|
||||
|
||||
gl_FragColor = vec4(1.-vec3(pattern),1.0);
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
// Author @patriciogv ( patriciogonzalezvivo.com ) - 2015
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
|
||||
vec2 tile(vec2 _st, float _zoom){
|
||||
_st *= _zoom;
|
||||
return fract(_st);
|
||||
}
|
||||
|
||||
float circle(vec2 _st, float _radius){
|
||||
vec2 pos = vec2(0.5)-_st;
|
||||
_radius *= 0.75;
|
||||
return 1.-smoothstep(_radius-(_radius*0.05),_radius+(_radius*0.05),dot(pos,pos)*3.14);
|
||||
}
|
||||
|
||||
void main(){
|
||||
|
||||
vec2 st = gl_FragCoord.xy/u_resolution.xy;
|
||||
st.x *= u_resolution.x/u_resolution.y;
|
||||
st = tile(st,5.);
|
||||
float size = .45;
|
||||
float pct = circle(st,size);
|
||||
st = abs(st-.5);
|
||||
pct += circle(st,size);
|
||||
|
||||
gl_FragColor = vec4(vec3(pct),1.0);
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
// Author @patriciogv ( patriciogonzalezvivo.com ) - 2015
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
|
||||
vec2 tile(vec2 _st, float _zoom){
|
||||
_st *= _zoom;
|
||||
return fract(_st);
|
||||
}
|
||||
|
||||
float circle(vec2 _st, float _radius){
|
||||
vec2 pos = vec2(0.5)-_st;
|
||||
_radius *= 0.75;
|
||||
return 1.-smoothstep(_radius-(_radius*0.05),_radius+(_radius*0.05),dot(pos,pos)*3.14);
|
||||
}
|
||||
|
||||
void main(){
|
||||
|
||||
vec2 st = gl_FragCoord.xy/u_resolution.xy;
|
||||
st.x *= u_resolution.x/u_resolution.y;
|
||||
st = tile(st,5.);
|
||||
vec3 color = vec3(circle(st, 0.2));
|
||||
|
||||
gl_FragColor = vec4(color,1.0);
|
||||
}
|
After Width: | Height: | Size: 1.1 MiB |
After Width: | Height: | Size: 807 B |
@ -0,0 +1,156 @@
|
||||
// Author @patriciogv - 2015
|
||||
// http://patriciogonzalezvivo.com
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform float u_time;
|
||||
|
||||
float random (in float x) { return fract(sin(x)*1e4);}
|
||||
float random (in vec2 st) { return fract(1e4 * sin(17.0 * st.x + st.y * 0.1) * (0.1 + abs(sin(st.y * 13.0 + st.x)))); }
|
||||
|
||||
float binChar (vec2 ipos, float n) {
|
||||
float remain = mod(n,33554432.);
|
||||
for (float i = 0.0; i < 15.0; i++) {
|
||||
if ( floor(i/3.) == ipos.y && mod(i,3.) == ipos.x ) {
|
||||
return step(1.0,mod(remain,2.));
|
||||
}
|
||||
remain = ceil(remain/2.);
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
float char (vec2 st, float n) {
|
||||
st.x = st.x*2.-0.5;
|
||||
st.y = st.y*1.2-0.1;
|
||||
|
||||
vec2 grid = vec2(3.,5.);
|
||||
|
||||
vec2 ipos = floor(st*grid);
|
||||
vec2 fpos = fract(st*grid);
|
||||
|
||||
n = floor(mod(n,10.));
|
||||
float digit = 0.0;
|
||||
if (n < 1. ) { digit = 31600.; }
|
||||
else if (n < 2. ) { digit = 9363.0; }
|
||||
else if (n < 3. ) { digit = 31184.0; }
|
||||
else if (n < 4. ) { digit = 31208.0; }
|
||||
else if (n < 5. ) { digit = 23525.0; }
|
||||
else if (n < 6. ) { digit = 29672.0; }
|
||||
else if (n < 7. ) { digit = 29680.0; }
|
||||
else if (n < 8. ) { digit = 31013.0; }
|
||||
else if (n < 9. ) { digit = 31728.0; }
|
||||
else if (n < 10. ) { digit = 31717.0; }
|
||||
float pct = binChar(ipos, digit);
|
||||
|
||||
vec2 borders = vec2(1.);
|
||||
// borders *= step(0.01,fpos.x) * step(0.01,fpos.y); // inner
|
||||
borders *= step(0.0,st)*step(0.0,1.-st); // outer
|
||||
|
||||
return step(.5,1.0-pct) * borders.x * borders.y;
|
||||
}
|
||||
|
||||
float binBar (vec2 ipos, float n) {
|
||||
float remain = mod(n,128.);
|
||||
for(float i = 0.0; i < 8.0; i++){
|
||||
if ( mod(i,10.) == ipos.x ) {
|
||||
return step(1.0,mod(remain,2.));
|
||||
}
|
||||
remain = ceil(remain/2.);
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
// Standard UPC-E Barcode reference from
|
||||
// https://en.wikipedia.org/wiki/Universal_Product_Code
|
||||
float bar (vec2 st, float n, bool L) {
|
||||
vec2 grid = vec2(7.,1.);
|
||||
|
||||
if (L) { st = 1.0-st; }
|
||||
|
||||
vec2 ipos = floor(st*grid);
|
||||
vec2 fpos = fract(st*grid);
|
||||
n = floor(mod(n,10.));
|
||||
float digit = 0.0;
|
||||
if (n < 1. ) { digit = 114.; }
|
||||
else if (n < 2. ) { digit = 102.0; }
|
||||
else if (n < 3. ) { digit = 108.0; }
|
||||
else if (n < 4. ) { digit = 66.0; }
|
||||
else if (n < 5. ) { digit = 92.0; }
|
||||
else if (n < 6. ) { digit = 78.0; }
|
||||
else if (n < 7. ) { digit = 80.0; }
|
||||
else if (n < 8. ) { digit = 68.0; }
|
||||
else if (n < 9. ) { digit = 72.0; }
|
||||
else if (n < 10. ) { digit = 116.0; }
|
||||
float pct = binBar(ipos, digit+1.);
|
||||
|
||||
if (L) { pct = 1.-pct; }
|
||||
|
||||
return step(.5,pct);
|
||||
}
|
||||
|
||||
float bar (vec2 st, float n) {
|
||||
return bar(st,n,true);
|
||||
}
|
||||
|
||||
float barStart (vec2 st) {
|
||||
vec2 grid = vec2(7.,1.);
|
||||
vec2 ipos = floor((1.0-st)*grid);
|
||||
float digit = 122.0;
|
||||
float pct = binBar(ipos, digit+1.);
|
||||
return step(.5,1.0-pct);
|
||||
}
|
||||
|
||||
float barEnd(vec2 st) {
|
||||
vec2 grid = vec2(7.,1.);
|
||||
vec2 ipos = floor((1.0-st)*grid);
|
||||
float digit = 85.0;
|
||||
float pct = binBar(ipos, digit+1.);
|
||||
return step(.5,1.0-pct);
|
||||
}
|
||||
|
||||
float barCode(vec2 st, float rows, float value) {
|
||||
rows = ceil(rows);
|
||||
vec2 ipos = floor(st*rows);
|
||||
vec2 fpos = fract(st*rows);
|
||||
|
||||
value = value*pow(10.,ipos.x)*0.0000000001+0.1;
|
||||
|
||||
if (ipos.x == 0.0 ) {
|
||||
return barStart(fpos);
|
||||
} else if (ipos.x == rows-1.) {
|
||||
return barEnd(fpos);
|
||||
} else {
|
||||
if (ipos.y == 0.0) {
|
||||
return 1.0-char(fpos,value);
|
||||
} else {
|
||||
return bar(fpos,value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void main(){
|
||||
vec2 st = gl_FragCoord.st/u_resolution.xy;
|
||||
|
||||
st *= 3.;
|
||||
vec2 ipos = floor(st);
|
||||
vec2 fpos = fract(st);
|
||||
fpos.y *= u_resolution.y/u_resolution.x;
|
||||
|
||||
vec3 color = vec3(0.0);
|
||||
|
||||
if (ipos.x == 1. && ipos.y == 1.) {
|
||||
float value = 0.0;
|
||||
// value = 123456789.0;
|
||||
value += floor(u_time);
|
||||
value = random(floor(u_time*10.))*1000000000.;
|
||||
|
||||
color += barCode(fpos,12.,value);
|
||||
} else {
|
||||
color += 1.;
|
||||
}
|
||||
|
||||
gl_FragColor = vec4( color , 1.0);
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
// Author @patriciogv - 2015
|
||||
// http://patriciogonzalezvivo.com
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform float u_time;
|
||||
|
||||
float random (in float x) { return fract(sin(x)*1e4);}
|
||||
float random (in vec2 st){ return fract(sin(dot(st.xy ,vec2(12.9898,78.233))) * 43758.5453); }
|
||||
|
||||
float bin(vec2 ipos, float n){
|
||||
float remain = mod(n,33554432.);
|
||||
for(float i = 0.0; i < 25.0; i++){
|
||||
if ( floor(i/3.) == ipos.y && mod(i,3.) == ipos.x ) {
|
||||
return step(1.0,mod(remain,2.));
|
||||
}
|
||||
remain = ceil(remain/2.);
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
float char(vec2 st, float n){
|
||||
st.x = st.x*2.-0.5;
|
||||
st.y = st.y*1.2-0.1;
|
||||
|
||||
vec2 grid = vec2(3.,5.);
|
||||
|
||||
vec2 ipos = floor(st*grid);
|
||||
vec2 fpos = fract(st*grid);
|
||||
|
||||
n = floor(mod(n,10.));
|
||||
float digit = 0.0;
|
||||
if (n < 1. ) { digit = 31600.; }
|
||||
else if (n < 2. ) { digit = 9363.0; }
|
||||
else if (n < 3. ) { digit = 31184.0; }
|
||||
else if (n < 4. ) { digit = 31208.0; }
|
||||
else if (n < 5. ) { digit = 23525.0; }
|
||||
else if (n < 6. ) { digit = 29672.0; }
|
||||
else if (n < 7. ) { digit = 29680.0; }
|
||||
else if (n < 8. ) { digit = 31013.0; }
|
||||
else if (n < 9. ) { digit = 31728.0; }
|
||||
else if (n < 10. ) { digit = 31717.0; }
|
||||
float pct = bin(ipos, digit);
|
||||
|
||||
vec2 borders = vec2(1.);
|
||||
// borders *= step(0.01,fpos.x) * step(0.01,fpos.y); // inner
|
||||
borders *= step(0.0,st)*step(0.0,1.-st); // outer
|
||||
|
||||
return step(.5,1.0-pct) * borders.x * borders.y;
|
||||
}
|
||||
|
||||
void main(){
|
||||
vec2 st = gl_FragCoord.st/u_resolution.xy;
|
||||
st.x *= u_resolution.x/u_resolution.y;
|
||||
|
||||
float rows = 34.0;
|
||||
vec2 ipos = floor(st*rows);
|
||||
vec2 fpos = fract(st*rows);
|
||||
|
||||
ipos += vec2(0.,floor(u_time*20.*random(ipos.x+1.)));
|
||||
float pct = random(ipos);
|
||||
vec3 color = vec3(char(fpos,100.*pct));
|
||||
color = mix(color,vec3(color.r,0.,0.),step(.99,pct));
|
||||
|
||||
gl_FragColor = vec4( color , 1.0);
|
||||
}
|
@ -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 img-glitch.frag --u_tex $FILE -s $i -o frame-$COUNTER.png`
|
||||
let COUNTER=COUNTER+1
|
||||
done
|
||||
|
||||
convert -delay 3.5 -loop 1 frame-*.png animated.gif
|
@ -0,0 +1,42 @@
|
||||
// Author @patriciogv - 2015
|
||||
// http://patriciogonzalezvivo.com
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
|
||||
float random (in float x) { return fract(sin(x)*1e4); }
|
||||
float noise (in float x) {
|
||||
float i = floor(x);
|
||||
float f = fract(x);
|
||||
float u = f * f * (3.0 - 2.0 * f);
|
||||
return mix(random(i), random(i + 1.0), u);
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 st = gl_FragCoord.xy/u_resolution.xy;
|
||||
st.x *= u_resolution.x/u_resolution.y;
|
||||
|
||||
vec3 color = vec3(0.0);
|
||||
|
||||
vec2 grid = vec2(20.0,2.0);
|
||||
|
||||
float t = u_time*max(grid.x,grid.y)*.5;
|
||||
|
||||
vec2 ipos = floor(st*grid);
|
||||
vec2 fpos = fract(st*grid);
|
||||
|
||||
float offset = ipos.x+floor(t);
|
||||
float value = pow(noise(offset*0.2),2.)+noise(offset*0.9)*.5;
|
||||
|
||||
if (mod(ipos.y,2.) == 0.) {
|
||||
fpos.y = 1.0-fpos.y;
|
||||
}
|
||||
color += step(fpos.y*1.5,value)*step(.5,fpos.x);
|
||||
|
||||
gl_FragColor = vec4(color,1.0);
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
// Author @patriciogv - 2015
|
||||
// http://patriciogonzalezvivo.com
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
uniform sampler2D u_tex;
|
||||
uniform vec2 u_resolution;
|
||||
uniform float u_time;
|
||||
|
||||
float random(in float x){ return fract(sin(x)*43758.5453); }
|
||||
float random(in vec2 st){ return fract(sin(dot(st.xy ,vec2(12.9898,78.233))) * 43758.5453); }
|
||||
|
||||
float noise(in vec2 x) {
|
||||
vec2 i = floor(x);
|
||||
vec2 f = fract(x);
|
||||
|
||||
float a = random(i);
|
||||
float b = random(i + vec2(1.0, 0.0));
|
||||
float c = random(i + vec2(0.0, 1.0));
|
||||
float d = random(i + vec2(1.0, 1.0));
|
||||
|
||||
vec2 u = f * f * (3.0 - 2.0 * f);
|
||||
return mix(a, b, u.x) + (c - a) * u.y * (1.0 - u.x) + (d - b) * u.x * u.y;
|
||||
}
|
||||
|
||||
float fbm( in vec2 p ){
|
||||
float s = 0.0;
|
||||
float m = 0.0;
|
||||
float a = 0.5;
|
||||
for(int i=0; i<2; i++ ){
|
||||
s += a * noise(p);
|
||||
m += a;
|
||||
a *= 0.5;
|
||||
p *= 2.0;
|
||||
}
|
||||
return s/m;
|
||||
}
|
||||
|
||||
void main(){
|
||||
vec2 st = gl_FragCoord.st/u_resolution.xy;
|
||||
float aspect = u_resolution.x/u_resolution.y;
|
||||
|
||||
vec2 grain_st = st-.5;
|
||||
float grain = 0.0;
|
||||
grain = mix(1., 0.9, dot(grain_st,grain_st) + (fbm(gl_FragCoord.xy*0.6)*0.1) );
|
||||
|
||||
// Random blocks
|
||||
vec2 blocks_st = floor(st*vec2(5.*random(floor(u_time*10.)),10.*(1.+random(floor(u_time*3.))) ));
|
||||
float t = u_time*2.+random(blocks_st);
|
||||
float time_i = floor(t);
|
||||
float time_f = fract(t);
|
||||
float block = step(0.9,random(blocks_st+time_i))*(1.0-time_f);
|
||||
vec2 offset = vec2(block*0.01,block*0.005)+(1.0-grain)*.08;
|
||||
|
||||
vec4 color = vec4(1.);
|
||||
color.r = texture2D(u_tex,st+offset).r;
|
||||
color.g = texture2D(u_tex,st).r;
|
||||
color.b = texture2D(u_tex,st-offset).r;
|
||||
|
||||
color.a = max(texture2D(u_tex,st+offset).a,max(texture2D(u_tex,st).a, texture2D(u_tex,st-offset).a));
|
||||
|
||||
if (block > .5) {
|
||||
color.rgb = abs(block*grain-color.rgb);
|
||||
}
|
||||
|
||||
color.rgb *= 0.4+sin((st.y*3.1415+u_time)*500.);
|
||||
|
||||
gl_FragColor = color;
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
// Author @patriciogv - 2015
|
||||
// http://patriciogonzalezvivo.com
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
#define PI 3.1415926535897932384626433832795
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
|
||||
float random (in vec2 _st) {
|
||||
return fract(sin(dot(_st.xy,
|
||||
vec2(12.9898,78.233)))*
|
||||
43758.5453123);
|
||||
}
|
||||
|
||||
vec2 tile(vec2 _st, float _zoom){
|
||||
_st *= _zoom;
|
||||
return fract(_st);
|
||||
}
|
||||
|
||||
float circle(vec2 _st, float _radius){
|
||||
vec2 pos = vec2(0.5)-_st;
|
||||
_radius *= 0.75;
|
||||
return 1.-smoothstep(_radius-(_radius*0.01),_radius+(_radius*0.01),dot(pos,pos)*3.14);
|
||||
}
|
||||
|
||||
float box(vec2 _st, vec2 _size){
|
||||
_size = vec2(0.5)-_size*0.5;
|
||||
vec2 uv = smoothstep(_size-vec2(0.0001),_size,_st);
|
||||
uv *= smoothstep(_size-vec2(0.0001),_size,vec2(1.0)-_st);
|
||||
return uv.x*uv.y;
|
||||
}
|
||||
|
||||
vec3 pattern(inout vec2 st){
|
||||
st *= 5.0;
|
||||
st.x += u_time*0.5;
|
||||
vec3 normal = vec3(0.0);
|
||||
|
||||
vec2 ivec = floor(st); // integer
|
||||
vec2 fvec = fract(st); // fraction
|
||||
|
||||
vec2 pos = fvec;
|
||||
float index = random(ivec);
|
||||
|
||||
if(index > 0.5){
|
||||
normal.x = step(0.5,pos.y)*2.-1.;
|
||||
normal *= (1.0-vec3(box(fvec,vec2(1.0,0.95))));
|
||||
} else {
|
||||
normal.y = step(0.5,pos.x)*2.-1.;
|
||||
normal *= (1.0-vec3(box(fvec,vec2(0.95,1.))));
|
||||
}
|
||||
|
||||
st = fvec;
|
||||
return normal;
|
||||
}
|
||||
|
||||
void main(){
|
||||
vec2 st = gl_FragCoord.xy/u_resolution.xy;
|
||||
st.x *= u_resolution.x/u_resolution.y;
|
||||
|
||||
vec3 normal = pattern(st);
|
||||
|
||||
st = tile(st,2.);
|
||||
|
||||
vec2 pos = st-0.5;
|
||||
float a = atan(pos.y,pos.x);
|
||||
|
||||
normal += vec3(cos(a),sin(a),0.)*circle(st,0.4);
|
||||
normal *= 1.0-circle(st,0.26);
|
||||
normal.b = 1.0;
|
||||
|
||||
gl_FragColor = vec4(normal*0.5+0.5,1.0);
|
||||
}
|
@ -0,0 +1,178 @@
|
||||
// Author @patriciogv - 2015
|
||||
// http://patriciogonzalezvivo.com
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform float u_time;
|
||||
|
||||
float random(in float x){ return fract(sin(x)*43758.5453); }
|
||||
float random(in vec2 st){ return fract(sin(dot(st.xy ,vec2(12.9898,78.233))) * 43758.5453); }
|
||||
|
||||
float noise(in vec2 x) {
|
||||
vec2 i = floor(x);
|
||||
vec2 f = fract(x);
|
||||
|
||||
float a = random(i);
|
||||
float b = random(i + vec2(1.0, 0.0));
|
||||
float c = random(i + vec2(0.0, 1.0));
|
||||
float d = random(i + vec2(1.0, 1.0));
|
||||
|
||||
vec2 u = f * f * (3.0 - 2.0 * f);
|
||||
return mix(a, b, u.x) + (c - a) * u.y * (1.0 - u.x) + (d - b) * u.x * u.y;
|
||||
}
|
||||
|
||||
float fbm( in vec2 p ){
|
||||
float s = 0.0;
|
||||
float m = 0.0;
|
||||
float a = 0.5;
|
||||
for(int i=0; i<2; i++ ){
|
||||
s += a * noise(p);
|
||||
m += a;
|
||||
a *= 0.5;
|
||||
p *= 2.0;
|
||||
}
|
||||
return s/m;
|
||||
}
|
||||
|
||||
float bin(vec2 ipos, float n){
|
||||
float remain = mod(n,33554432.);
|
||||
for(float i = 0.0; i < 25.0; i++){
|
||||
if ( floor(i/3.) == ipos.y && mod(i,3.) == ipos.x ) {
|
||||
return step(1.0,mod(remain,2.));
|
||||
}
|
||||
remain = ceil(remain/2.);
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
float char(vec2 st, float n){
|
||||
st.x = st.x*2.-0.5;
|
||||
st.y = st.y*1.2-0.1;
|
||||
|
||||
vec2 grid = vec2(3.,5.);
|
||||
|
||||
vec2 ipos = floor(st*grid);
|
||||
vec2 fpos = fract(st*grid);
|
||||
|
||||
n = floor(mod(n,10.));
|
||||
float digit = 0.0;
|
||||
if (n < 1. ) { digit = 31600.; }
|
||||
else if (n < 2. ) { digit = 9363.0; }
|
||||
else if (n < 3. ) { digit = 31184.0; }
|
||||
else if (n < 4. ) { digit = 31208.0; }
|
||||
else if (n < 5. ) { digit = 23525.0; }
|
||||
else if (n < 6. ) { digit = 29672.0; }
|
||||
else if (n < 7. ) { digit = 29680.0; }
|
||||
else if (n < 8. ) { digit = 31013.0; }
|
||||
else if (n < 9. ) { digit = 31728.0; }
|
||||
else if (n < 10. ) { digit = 31717.0; }
|
||||
float pct = bin(ipos, digit);
|
||||
|
||||
vec2 borders = vec2(1.);
|
||||
// borders *= step(0.01,fpos.x) * step(0.01,fpos.y); // inner
|
||||
borders *= step(0.0,st)*step(0.0,1.-st); // outer
|
||||
|
||||
return step(.5,1.0-pct) * borders.x * borders.y;
|
||||
}
|
||||
|
||||
float grid(vec2 st, float res) {
|
||||
vec2 grid = fract(st*res);
|
||||
return 1.-(step(res,grid.x) * step(res,grid.y));
|
||||
}
|
||||
|
||||
float superGrid(vec2 st) {
|
||||
return 1.*grid(st,0.01) +
|
||||
0.5*grid(st,0.02) +
|
||||
0.6*grid(st,0.1);
|
||||
}
|
||||
|
||||
float box(in vec2 st, in vec2 size){
|
||||
size = vec2(0.5) - size*0.5;
|
||||
vec2 uv = smoothstep(size,
|
||||
size+vec2(0.001),
|
||||
st);
|
||||
uv *= smoothstep(size,
|
||||
size+vec2(0.001),
|
||||
vec2(1.0)-st);
|
||||
return uv.x*uv.y;
|
||||
}
|
||||
|
||||
float cross(in vec2 st, vec2 size){
|
||||
return clamp(box(st, vec2(size.x*0.5,size.y*0.125)) +
|
||||
box(st, vec2(size.y*0.125,size.x*0.5)),0.,1.);
|
||||
}
|
||||
|
||||
void main(){
|
||||
vec2 st = gl_FragCoord.st/u_resolution.xy;
|
||||
float aspect = u_resolution.x/u_resolution.y;
|
||||
|
||||
vec2 grain_st = st-.5;
|
||||
vec3 color = vec3(0.0);
|
||||
float grain = 0.0;
|
||||
grain = mix(1., 0.8, dot(grain_st,grain_st) + (fbm(gl_FragCoord.xy*0.6)*0.1) );
|
||||
|
||||
// Fix Aspect ration
|
||||
st -= .5;
|
||||
st.x *= aspect;
|
||||
|
||||
// Zoom
|
||||
st *= 2.8;
|
||||
|
||||
// Random blocks
|
||||
vec2 blocks_st = floor((st-.25)*6.);
|
||||
float t = u_time*.3+random(blocks_st);
|
||||
float time_i = floor(t);
|
||||
float time_f = fract(t);
|
||||
float block = step(0.9,random(blocks_st+time_i))*(1.0-time_f);
|
||||
vec2 offset = vec2(block*0.02,block*0.001)+(1.0-grain)*.08;
|
||||
|
||||
// Grid
|
||||
vec2 grid_st = st*300.;
|
||||
|
||||
vec3 grid_chroma = vec3(0.0);
|
||||
grid_chroma.r = superGrid(grid_st+offset*100.);
|
||||
grid_chroma.g = superGrid(grid_st);
|
||||
grid_chroma.b = superGrid(grid_st-offset*100.);
|
||||
color += vec3(0.1,0.08,0.08)*grid_chroma;
|
||||
|
||||
// Crosses
|
||||
vec2 crosses_st = st + .5;
|
||||
crosses_st *= 3.;
|
||||
vec2 crosses_st_f = fract(crosses_st);
|
||||
color *= 1.-cross(crosses_st_f,vec2(.2,.2));
|
||||
|
||||
vec3 cross_chroma = vec3(0.0);
|
||||
cross_chroma.r = cross(crosses_st_f+offset,vec2(.15,.15));
|
||||
cross_chroma.g = cross(crosses_st_f,vec2(.15,.15));
|
||||
cross_chroma.b = cross(crosses_st_f-offset,vec2(.15,.15));
|
||||
color += vec3(.7)*cross_chroma;
|
||||
|
||||
// Digits
|
||||
vec2 digits_st = mod(st*60.,20.);
|
||||
vec2 digits_st_i = floor(digits_st);
|
||||
float digits_n = ceil(block*5.);
|
||||
offset *= 10.;
|
||||
if (block > 0.0 &&
|
||||
digits_st_i.y == 1. &&
|
||||
digits_st_i.x > 0. && digits_st_i.x < digits_n ) {
|
||||
vec2 digits_st_f = fract(digits_st);
|
||||
float pct = random(digits_st_i+floor(crosses_st)+floor(u_time*20.));
|
||||
|
||||
color.r += block*char(digits_st_f+offset,100.*pct);
|
||||
color.g += block*char(digits_st_f,100.*pct);
|
||||
color.b += block*char(digits_st_f-offset,100.*pct);
|
||||
} else if ( block > 0.0 &&
|
||||
digits_st_i.y == 2. &&
|
||||
digits_st_i.x > 0. && digits_st_i.x < digits_n ) {
|
||||
vec2 digits_st_f = fract(digits_st);
|
||||
float pct = random(digits_st_i+floor(crosses_st)+floor(u_time*20.));
|
||||
|
||||
color.r += block*char(digits_st_f+offset,100.*pct);
|
||||
color.g += block*char(digits_st_f,100.*pct);
|
||||
color.b += block*char(digits_st_f-offset,100.*pct);
|
||||
}
|
||||
gl_FragColor = vec4( (1.0-color) * grain, 1.0);
|
||||
}
|
@ -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
|
@ -0,0 +1,64 @@
|
||||
// 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.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
|
||||
}
|
||||
|
||||
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 = 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,abs(sin(.5-S.b*3.1415*5.-t)));
|
||||
|
||||
gl_FragColor = vec4(color,1.0);
|
||||
}
|
@ -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);
|
||||
}
|
@ -0,0 +1,190 @@
|
||||
// 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) {
|
||||
return vec2(aastep(threshold, value.x),
|
||||
aastep(threshold, value.y));
|
||||
}
|
||||
|
||||
vec3 aastep(float threshold, vec3 value) {
|
||||
return vec3(aastep(threshold, value.x),
|
||||
aastep(threshold, value.y),
|
||||
aastep(threshold, value.z));
|
||||
}
|
||||
|
||||
float isoGrid(vec2 st, float pct) {
|
||||
vec3 S = simplexGrid(st);
|
||||
S = aastep(pct-.01,1.-S);
|
||||
return S.r + S.g + S.b;
|
||||
}
|
||||
|
||||
vec2 sphereCoords(vec2 _st, float _scale){
|
||||
float maxFactor = sin(1.570796327);
|
||||
vec2 uv = vec2(0.0);
|
||||
vec2 xy = 2.0 * _st.xy - 1.0;
|
||||
float d = length(xy);
|
||||
if (d < (2.0-maxFactor)){
|
||||
d = length(xy * maxFactor);
|
||||
float z = sqrt(1.0 - d * d);
|
||||
float r = atan(d, z) / 3.1415926535 * _scale;
|
||||
float phi = atan(xy.y, xy.x);
|
||||
|
||||
uv.x = r * cos(phi) + 0.5;
|
||||
uv.y = r * sin(phi) + 0.5;
|
||||
} else {
|
||||
uv = _st.xy;
|
||||
}
|
||||
return uv;
|
||||
}
|
||||
|
||||
//
|
||||
// Description : Array and textureless GLSL 2D/3D/4D simplex
|
||||
// noise functions.
|
||||
// Author : Ian McEwan, Ashima Arts.
|
||||
// Maintainer : ijm
|
||||
// Lastmod : 20110822 (ijm)
|
||||
// License : Copyright (C) 2011 Ashima Arts. All rights reserved.
|
||||
// Distributed under the MIT License. See LICENSE file.
|
||||
// https://github.com/ashima/webgl-noise
|
||||
//
|
||||
vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
|
||||
vec4 mod289(vec4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
|
||||
vec4 permute(vec4 x) { return mod289(((x*34.0)+1.0)*x); }
|
||||
vec4 taylorInvSqrt(vec4 r) { return 1.79284291400159 - 0.85373472095314 * r; }
|
||||
|
||||
float snoise(vec3 v) {
|
||||
const vec2 C = vec2(1.0/6.0, 1.0/3.0) ;
|
||||
const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);
|
||||
|
||||
// First corner
|
||||
vec3 i = floor(v + dot(v, C.yyy) );
|
||||
vec3 x0 = v - i + dot(i, C.xxx) ;
|
||||
|
||||
// Other corners
|
||||
vec3 g = step(x0.yzx, x0.xyz);
|
||||
vec3 l = 1.0 - g;
|
||||
vec3 i1 = min( g.xyz, l.zxy );
|
||||
vec3 i2 = max( g.xyz, l.zxy );
|
||||
|
||||
vec3 x1 = x0 - i1 + C.xxx;
|
||||
vec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y
|
||||
vec3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y
|
||||
|
||||
// Permutations
|
||||
i = mod289(i);
|
||||
vec4 p = permute( permute( permute(
|
||||
i.z + vec4(0.0, i1.z, i2.z, 1.0 ))
|
||||
+ i.y + vec4(0.0, i1.y, i2.y, 1.0 ))
|
||||
+ i.x + vec4(0.0, i1.x, i2.x, 1.0 ));
|
||||
|
||||
// Gradients: 7x7 points over a square, mapped onto an octahedron.
|
||||
// The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294)
|
||||
float n_ = 0.142857142857; // 1.0/7.0
|
||||
vec3 ns = n_ * D.wyz - D.xzx;
|
||||
|
||||
vec4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p,7*7)
|
||||
|
||||
vec4 x_ = floor(j * ns.z);
|
||||
vec4 y_ = floor(j - 7.0 * x_ ); // mod(j,N)
|
||||
|
||||
vec4 x = x_ *ns.x + ns.yyyy;
|
||||
vec4 y = y_ *ns.x + ns.yyyy;
|
||||
vec4 h = 1.0 - abs(x) - abs(y);
|
||||
|
||||
vec4 b0 = vec4( x.xy, y.xy );
|
||||
vec4 b1 = vec4( x.zw, y.zw );
|
||||
|
||||
vec4 s0 = floor(b0)*2.0 + 1.0;
|
||||
vec4 s1 = floor(b1)*2.0 + 1.0;
|
||||
vec4 sh = -step(h, vec4(0.0));
|
||||
|
||||
vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ;
|
||||
vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww ;
|
||||
|
||||
vec3 p0 = vec3(a0.xy,h.x);
|
||||
vec3 p1 = vec3(a0.zw,h.y);
|
||||
vec3 p2 = vec3(a1.xy,h.z);
|
||||
vec3 p3 = vec3(a1.zw,h.w);
|
||||
|
||||
//Normalise gradients
|
||||
vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));
|
||||
p0 *= norm.x;
|
||||
p1 *= norm.y;
|
||||
p2 *= norm.z;
|
||||
p3 *= norm.w;
|
||||
|
||||
// Mix final noise value
|
||||
vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0);
|
||||
m = m * m;
|
||||
return 42.0 * dot( m*m, vec4(dot(p0,x0), dot(p1,x1),
|
||||
dot(p2,x2), dot(p3,x3) ) );
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 st = gl_FragCoord.xy/u_resolution.xy;
|
||||
st.x *= u_resolution.x/u_resolution.y;
|
||||
vec3 color = vec3(0.0);
|
||||
|
||||
// Blend black the edge of the sphere
|
||||
float radius = 1.0-length( vec2(0.5)-st )*2.0;
|
||||
|
||||
// Scale the space to see the grid
|
||||
st = sphereCoords(st, 1.0);
|
||||
|
||||
float t = u_time*.5;
|
||||
float pct = clamp((snoise(vec3(st*2.,t))*.5+.5)*.8 + abs(sin(dot(st-.5,st-.5)*3.14+t))*.5,0.,1.);
|
||||
// color = vec3(pct);
|
||||
|
||||
st *= 1.733*20.;
|
||||
color = vec3(1.-isoGrid(st,.1+pct*.9));
|
||||
|
||||
color *= step(0.001,radius);
|
||||
|
||||
gl_FragColor = vec4(color,1.0);
|
||||
}
|
@ -0,0 +1,158 @@
|
||||
// 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) {
|
||||
return vec2(aastep(threshold, value.x),
|
||||
aastep(threshold, value.y));
|
||||
}
|
||||
|
||||
vec3 aastep(float threshold, vec3 value) {
|
||||
return vec3(aastep(threshold, value.x),
|
||||
aastep(threshold, value.y),
|
||||
aastep(threshold, value.z));
|
||||
}
|
||||
|
||||
//
|
||||
// Description : Array and textureless GLSL 2D/3D/4D simplex
|
||||
// noise functions.
|
||||
// Author : Ian McEwan, Ashima Arts.
|
||||
// Maintainer : ijm
|
||||
// Lastmod : 20110822 (ijm)
|
||||
// License : Copyright (C) 2011 Ashima Arts. All rights reserved.
|
||||
// Distributed under the MIT License. See LICENSE file.
|
||||
// https://github.com/ashima/webgl-noise
|
||||
//
|
||||
vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
|
||||
vec4 mod289(vec4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
|
||||
vec4 permute(vec4 x) { return mod289(((x*34.0)+1.0)*x); }
|
||||
vec4 taylorInvSqrt(vec4 r) { return 1.79284291400159 - 0.85373472095314 * r; }
|
||||
|
||||
float snoise(vec3 v) {
|
||||
const vec2 C = vec2(1.0/6.0, 1.0/3.0) ;
|
||||
const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);
|
||||
|
||||
// First corner
|
||||
vec3 i = floor(v + dot(v, C.yyy) );
|
||||
vec3 x0 = v - i + dot(i, C.xxx) ;
|
||||
|
||||
// Other corners
|
||||
vec3 g = step(x0.yzx, x0.xyz);
|
||||
vec3 l = 1.0 - g;
|
||||
vec3 i1 = min( g.xyz, l.zxy );
|
||||
vec3 i2 = max( g.xyz, l.zxy );
|
||||
|
||||
vec3 x1 = x0 - i1 + C.xxx;
|
||||
vec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y
|
||||
vec3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y
|
||||
|
||||
// Permutations
|
||||
i = mod289(i);
|
||||
vec4 p = permute( permute( permute(
|
||||
i.z + vec4(0.0, i1.z, i2.z, 1.0 ))
|
||||
+ i.y + vec4(0.0, i1.y, i2.y, 1.0 ))
|
||||
+ i.x + vec4(0.0, i1.x, i2.x, 1.0 ));
|
||||
|
||||
// Gradients: 7x7 points over a square, mapped onto an octahedron.
|
||||
// The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294)
|
||||
float n_ = 0.142857142857; // 1.0/7.0
|
||||
vec3 ns = n_ * D.wyz - D.xzx;
|
||||
|
||||
vec4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p,7*7)
|
||||
|
||||
vec4 x_ = floor(j * ns.z);
|
||||
vec4 y_ = floor(j - 7.0 * x_ ); // mod(j,N)
|
||||
|
||||
vec4 x = x_ *ns.x + ns.yyyy;
|
||||
vec4 y = y_ *ns.x + ns.yyyy;
|
||||
vec4 h = 1.0 - abs(x) - abs(y);
|
||||
|
||||
vec4 b0 = vec4( x.xy, y.xy );
|
||||
vec4 b1 = vec4( x.zw, y.zw );
|
||||
|
||||
vec4 s0 = floor(b0)*2.0 + 1.0;
|
||||
vec4 s1 = floor(b1)*2.0 + 1.0;
|
||||
vec4 sh = -step(h, vec4(0.0));
|
||||
|
||||
vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ;
|
||||
vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww ;
|
||||
|
||||
vec3 p0 = vec3(a0.xy,h.x);
|
||||
vec3 p1 = vec3(a0.zw,h.y);
|
||||
vec3 p2 = vec3(a1.xy,h.z);
|
||||
vec3 p3 = vec3(a1.zw,h.w);
|
||||
|
||||
//Normalise gradients
|
||||
vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));
|
||||
p0 *= norm.x;
|
||||
p1 *= norm.y;
|
||||
p2 *= norm.z;
|
||||
p3 *= norm.w;
|
||||
|
||||
// Mix final noise value
|
||||
vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0);
|
||||
m = m * m;
|
||||
return 42.0 * dot( m*m, vec4(dot(p0,x0), dot(p1,x1),
|
||||
dot(p2,x2), dot(p3,x3) ) );
|
||||
}
|
||||
|
||||
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 = u_time*.5;
|
||||
float pct = clamp((snoise(vec3(st*2.,t))*.5+.5)*.2 + abs(sin(dot(st-.5,st-.5)*3.14-t))*.5,0.,1.);
|
||||
|
||||
st *= 1.733*10.+5.*clamp(abs(sin(dot(st-.5,st-.5)*3.14+t*0.5))*.5,0.2,1.);
|
||||
vec3 S = simplexGrid(st);
|
||||
S = aastep(abs(sin(pct*3.1415+u_time)),S);
|
||||
pct = S.r * S.g * S.b;
|
||||
color = vec3(pct);
|
||||
gl_FragColor = vec4(color,1.0);
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
|
||||
http://github.prideout.net/coordinate-fields/
|
||||
|
||||
https://briansharpe.wordpress.com/2011/12/01/optimized-artifact-free-gpu-cellular-noise/
|
||||
http://www.rhythmiccanvas.com/research/papers/worley.pdf
|
||||
http://webstaff.itn.liu.se/~stegu/GLSL-cellular/GLSL-cellular-notes.pdf
|
||||
|
||||
http://www.iquilezles.org/www/articles/voronoise/voronoise.htm
|
||||
http://www.iquilezles.org/www/articles/smoothvoronoi/smoothvoronoi.htm
|
||||
http://www.iquilezles.org/www/articles/voronoilines/voronoilines.htm
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
$path = "..";
|
||||
$subtitle = ": More noise";
|
||||
$README = "README";
|
||||
$language = "";
|
||||
|
After Width: | Height: | Size: 1.1 MiB |
@ -0,0 +1,2 @@
|
||||
|
||||
http://heman.readthedocs.org/en/latest/generate.html#archipelagos
|
@ -1,8 +1,67 @@
|
||||
## Fractal Brownian Motion
|
||||
|
||||
http://www.iquilezles.org/www/articles/warp/warp.htm
|
||||
http://www.iquilezles.org/www/articles/morenoise/morenoise.htm
|
||||
|
||||
Noise is one of those subjects that you can dig and always find new exciting formulas. In fact noise tends to means different things for different people. Musicians will think in audio noise, communicators into interference, and astrophysics on cosmic microwave background. In fact noise could be interpreted as audio signals, and noise as well as sound can be constructed by the manipulation of the amplitud and frequency of the waves that compose it.
|
||||
|
||||
```glsl
|
||||
y = amplitud + sin( frequency );
|
||||
```
|
||||
|
||||
An interesting property of waves in general is that they can be add up. The following graph shows what happen if you add sine waves of different frequencies and amplitudes.
|
||||
|
||||
<div class="simpleFunction" data="
|
||||
float t = 0.01*(-u_time*130.0);
|
||||
y += sin(x*2.1 + t)*4.5;
|
||||
y += sin(x*1.72 + t*1.121)*4.0;
|
||||
y += sin(x*2.221 + t*0.437)*5.0;
|
||||
y += sin(x*3.1122+ t*4.269)*2.5;
|
||||
y *= 0.1;
|
||||
"></div>
|
||||
|
||||
Think on it as the surface of the ocean. Massive amount of water propagating waves across it surface. Waves of different heights (amplitud) and rhythms (frequencies) bouncing and interfering each other.
|
||||
|
||||
Musicians learn long time ago that there are sounds that play well with each other. Those sound, carried by waves of air, vibrate in such a particular way that the resultan sound seams to be bust and enhance. Those sounds are call [harmonics](http://en.wikipedia.org/wiki/Harmonic).
|
||||
|
||||
Back to code, we can add harmonics together and see how the resultant looks like. Try the following code on the previous graph.
|
||||
|
||||
```glsl
|
||||
y = 0.;
|
||||
for( int i = 0; i < 5; ++i) {
|
||||
y += sin(PI*x*float(i))/float(i);
|
||||
}
|
||||
y *= 0.6;
|
||||
```
|
||||
|
||||
As you can see in the above code, on every iteration the frequency increase by the double. By augmenting the number of iterations (chaining the 5 for a 10, a 20 or 50) the wave tends to break into smaller fractions, with more details and sharper fluctuations.
|
||||
|
||||
## Fractal Brownian Motion
|
||||
|
||||
So we try adding different waves together, and the result was chaotic, we add up harmonic waves and the result was a consistent fractal pattern. We can use the best of both worlds and add up harmonic noise waves to exacerbate a noise pattern.
|
||||
|
||||
By adding different octaves of increasing frequencies and decreasing amplitudes of noise we can obtain a bigger level of detail or granularity. This technique is call Fractal Brownian Motion and usually consist on a fractal sum of noise functions.
|
||||
|
||||
Take a look to the following example and progressively change the for loop to do 2,3,4,5,6,7 and 8 iterations. See want happens
|
||||
|
||||
<div class="simpleFunction" data="
|
||||
float a = 0.5;
|
||||
for( int i = 0; i < 1; ++i) {
|
||||
y += a * noise(x);
|
||||
x = x * 2.0;
|
||||
a *= 0.5;
|
||||
}"></div>
|
||||
|
||||
If we apply this one dimensional example to a bidimentional space it will look like the following example:
|
||||
|
||||
<div class="codeAndCanvas" data="2d-fbm.frag"></div>
|
||||
|
||||
## Using Fractal Brownian Motion
|
||||
|
||||
In this [article](http://www.iquilezles.org/www/articles/warp/warp.htm) Iñigo Quilez describe an interesting use of fractal brownian motion constructing patterns by adding successive results of fractal brownian motions.
|
||||
|
||||
Take a look to the code and how it looks
|
||||
|
||||
<div class="codeAndCanvas" data="clouds.frag"></div>
|
||||
|
||||
https://briansharpe.wordpress.com/2011/12/01/optimized-artifact-free-gpu-cellular-noise/
|
||||
http://www.rhythmiccanvas.com/research/papers/worley.pdf
|
||||
http://webstaff.itn.liu.se/~stegu/GLSL-cellular/GLSL-cellular-notes.pdf
|
||||
|
||||
http://www.iquilezles.org/www/articles/voronoise/voronoise.htm
|
||||
http://www.iquilezles.org/www/articles/smoothvoronoi/smoothvoronoi.htm
|
||||
http://www.iquilezles.org/www/articles/voronoilines/voronoilines.htm
|
Before Width: | Height: | Size: 36 KiB |
@ -1,67 +1,27 @@
|
||||
## Fractal Brownian Motion
|
||||
## Fractals
|
||||
|
||||
http://www.iquilezles.org/www/articles/warp/warp.htm
|
||||
http://www.iquilezles.org/www/articles/morenoise/morenoise.htm
|
||||
https://www.shadertoy.com/view/lsX3W4
|
||||
|
||||
Noise is one of those subjects that you can dig and always find new exciting formulas. In fact noise tends to means different things for different people. Musicians will think in audio noise, communicators into interference, and astrophysics on cosmic microwave background. In fact noise could be interpreted as audio signals, and noise as well as sound can be constructed by the manipulation of the amplitud and frequency of the waves that compose it.
|
||||
https://www.shadertoy.com/view/Mss3Wf
|
||||
|
||||
```glsl
|
||||
y = amplitud + sin( frequency );
|
||||
```
|
||||
https://www.shadertoy.com/view/4df3Rn
|
||||
|
||||
An interesting property of waves in general is that they can be add up. The following graph shows what happen if you add sine waves of different frequencies and amplitudes.
|
||||
https://www.shadertoy.com/view/Mss3R8
|
||||
|
||||
<div class="simpleFunction" data="
|
||||
float t = 0.01*(-u_time*130.0);
|
||||
y += sin(x*2.1 + t)*4.5;
|
||||
y += sin(x*1.72 + t*1.121)*4.0;
|
||||
y += sin(x*2.221 + t*0.437)*5.0;
|
||||
y += sin(x*3.1122+ t*4.269)*2.5;
|
||||
y *= 0.1;
|
||||
"></div>
|
||||
https://www.shadertoy.com/view/4dfGRn
|
||||
|
||||
Think on it as the surface of the ocean. Massive amount of water propagating waves across it surface. Waves of different heights (amplitud) and rhythms (frequencies) bouncing and interfering each other.
|
||||
https://www.shadertoy.com/view/lss3zs
|
||||
|
||||
Musicians learn long time ago that there are sounds that play well with each other. Those sound, carried by waves of air, vibrate in such a particular way that the resultan sound seams to be bust and enhance. Those sounds are call [harmonics](http://en.wikipedia.org/wiki/Harmonic).
|
||||
https://www.shadertoy.com/view/4dXGDX
|
||||
|
||||
Back to code, we can add harmonics together and see how the resultant looks like. Try the following code on the previous graph.
|
||||
https://www.shadertoy.com/view/XsXGz2
|
||||
|
||||
```glsl
|
||||
y = 0.;
|
||||
for( int i = 0; i < 5; ++i) {
|
||||
y += sin(PI*x*float(i))/float(i);
|
||||
}
|
||||
y *= 0.6;
|
||||
```
|
||||
https://www.shadertoy.com/view/lls3D7
|
||||
|
||||
As you can see in the above code, on every iteration the frequency increase by the double. By augmenting the number of iterations (chaining the 5 for a 10, a 20 or 50) the wave tends to break into smaller fractions, with more details and sharper fluctuations.
|
||||
https://www.shadertoy.com/view/XdB3DD
|
||||
|
||||
## Fractal Brownian Motion
|
||||
|
||||
So we try adding different waves together, and the result was chaotic, we add up harmonic waves and the result was a consistent fractal pattern. We can use the best of both worlds and add up harmonic noise waves to exacerbate a noise pattern.
|
||||
|
||||
By adding different octaves of increasing frequencies and decreasing amplitudes of noise we can obtain a bigger level of detail or granularity. This technique is call Fractal Brownian Motion and usually consist on a fractal sum of noise functions.
|
||||
|
||||
Take a look to the following example and progressively change the for loop to do 2,3,4,5,6,7 and 8 iterations. See want happens
|
||||
|
||||
<div class="simpleFunction" data="
|
||||
float a = 0.5;
|
||||
for( int i = 0; i < 1; ++i) {
|
||||
y += a * noise(x);
|
||||
x = x * 2.0;
|
||||
a *= 0.5;
|
||||
}"></div>
|
||||
|
||||
If we apply this one dimensional example to a bidimentional space it will look like the following example:
|
||||
|
||||
<div class="codeAndCanvas" data="2d-fbm.frag"></div>
|
||||
|
||||
## Using Fractal Brownian Motion
|
||||
|
||||
In this [article](http://www.iquilezles.org/www/articles/warp/warp.htm) Iñigo Quilez describe an interesting use of fractal brownian motion constructing patterns by adding successive results of fractal brownian motions.
|
||||
|
||||
Take a look to the code and how it looks
|
||||
|
||||
<div class="codeAndCanvas" data="clouds.frag"></div>
|
||||
https://www.shadertoy.com/view/XdBSWw
|
||||
|
||||
https://www.shadertoy.com/view/llfGD2
|
||||
|
||||
https://www.shadertoy.com/view/Mlf3RX
|
@ -1,27 +1,72 @@
|
||||
## Fractals
|
||||
# Image processing
|
||||
|
||||
https://www.shadertoy.com/view/lsX3W4
|
||||
## Textures
|
||||
|
||||
https://www.shadertoy.com/view/Mss3Wf
|
||||
![](01.jpg)
|
||||
|
||||
https://www.shadertoy.com/view/4df3Rn
|
||||
Graphic cards (GPUs) have special memory types for images. Usually on CPUs images are stores as arrays of bites but on GPUs store images as ```sampler2D``` which is more like a table (or matrix) of floating point vectors. More interestingly is that the values of this *table* of vectors are continously. That means that value between pixels are interpolated in a low level.
|
||||
|
||||
https://www.shadertoy.com/view/Mss3R8
|
||||
In order to use this feature we first need to *upload* the image from the CPU to the GPU, to then pass the ```id``` of the texture to the right [```uniform```](../05). All that happens outside the shader.
|
||||
|
||||
https://www.shadertoy.com/view/4dfGRn
|
||||
Once the texture is loaded and linked to a valid ```uniform sampler2D``` you can ask for specific color value at specific coordinates (formated on a [```vec2```](index.html#vec2.md) variable) usin the [```texture2D()```](index.html#texture2D.md) function which will return a color formated on a [```vec4```](index.html#vec4.md) variable.
|
||||
|
||||
https://www.shadertoy.com/view/lss3zs
|
||||
```glsl
|
||||
vec4 texture2D(sampler2D texture, vec2 coordinates)
|
||||
```
|
||||
|
||||
https://www.shadertoy.com/view/4dXGDX
|
||||
Check the following code where we load Hokusai's Wave (1830) as ```uniform sampler2D u_tex0``` and we call every pixel of it inside the billboard:
|
||||
|
||||
https://www.shadertoy.com/view/XsXGz2
|
||||
<div class="codeAndCanvas" data="texture.frag" data-imgs="hokusai.jpg"></div>
|
||||
|
||||
https://www.shadertoy.com/view/lls3D7
|
||||
If you pay attention you will note that the coordinates for the texture are normalized! What a surprise right? Textures coordenates are consisten with the rest of the things we had saw and their coordenates are between 0.0 and 1.0 whitch match perfectly with the normalized space coordinates we have been using.
|
||||
|
||||
https://www.shadertoy.com/view/XdB3DD
|
||||
Now that you have seen how we load correctly a texture is time to experiment to discover what we can do with it, by trying:
|
||||
|
||||
https://www.shadertoy.com/view/XdBSWw
|
||||
* Scaling the previus texture by half.
|
||||
* Rotating the previus texture 90 degrees.
|
||||
* Hooking the mouse position to the coordenates to move it.
|
||||
|
||||
https://www.shadertoy.com/view/llfGD2
|
||||
Why you should be excited about textures? Well first of all forget about the sad 255 values for channel, once your image is trasformed into a ```uniform sampler2D``` you have all the values between 0.0 and 1.0 (depending on what you set the ```precision``` to ). That's why shaders can make really beatiful post-processing effects.
|
||||
|
||||
https://www.shadertoy.com/view/Mlf3RX
|
||||
Second, the [```vec2()```](index.html#vec2.md) means you can get values even between pixels. As we said before the textures are a continum. This means that if you set up your texture correctly you can ask for values all arround the surface of your image and the values will smoothly vary from pixel to pixel with no jumps!
|
||||
|
||||
Finnally, you can setup your image to repeat in the edges, so if you give values over or lower of the normalized 0.0 and 1.0, the values will wrap around starting over.
|
||||
|
||||
All this features makes your images more like an infinit spandex fabric. You can streach and shrinks your texture without noticing the grid of bites they originally where compose of or the ends of it. To experience this take a look to the following code where we distort a texture using [the noise function we already made](../11/).
|
||||
|
||||
<div class="codeAndCanvas" data="texture-noise.frag" data-imgs="hokusai.jpg"></div>
|
||||
|
||||
## Texture resolution
|
||||
|
||||
Aboves examples play well with squared images, where both sides are equal and match our squared billboard. But for non-squared images things can be a little more tricky, and unfortunatly centuries of picturical art and photography found more pleasent to the eye non-squared proportions for images.
|
||||
|
||||
![Joseph Nicéphore Niépce (1826)](nicephore.jpg)
|
||||
|
||||
How we can solve this problem? Well we need to know the original proportions of the image to know how to streatch the texture correctly in order to have the original [*aspect ratio*](http://en.wikipedia.org/wiki/Aspect_ratio). For that the texture width and height is pass to the shader as an ```uniform```. Which in our example framework are pass as an ```uniform vec2``` with the same name of the texture followed with proposition ```Resolution```. Once we have this information on the shader he can get the aspect ration by dividing the ```width``` for the ```height``` of the texture resolution. Finally by multiplying this ratio to the coordinates on ```y``` we will shrink these axis to match the original proportions.
|
||||
|
||||
Uncomment line 21 of the following code to see this in action.
|
||||
|
||||
<div class="codeAndCanvas" data="texture-resolution.frag" data-imgs="nicephore.jpg"></div>
|
||||
|
||||
* What we need to do to center this image?
|
||||
|
||||
## Digital upholstery
|
||||
|
||||
![](03.jpg)
|
||||
|
||||
You may be thinking that this is unnesesary complicated... and you are probably right. Also this way of working with images leave a enought room to different hacks and creative tricks. Try to imagine that you are an upholster and by streaching and folding a fabric over a structure you can create better and new patterns and techniques.
|
||||
|
||||
![Eadweard's Muybridge study of motion](muybridge.jpg)
|
||||
|
||||
This level of craftsmanship links back to some of the first optical experiments ever made. For example on games *sprite animations* are very common, and is inevitably to see on it reminicence to phenakistoscope, zoetrope and praxinoscope.
|
||||
|
||||
This could seam simple but the posibilities of modifing textures coordinates is enormus. For example: .
|
||||
|
||||
<div class="codeAndCanvas" data="texture-sprite.frag" data-imgs="muybridge.jpg"></div>
|
||||
|
||||
Now is your turn:
|
||||
|
||||
* Can you make a kaleidoscope using what we have learn?
|
||||
* What other optical toys can you re-create using textures?
|
||||
|
||||
In the next chapters we will learn how to do some image processing using shaders. You will note that finnaly the complexity of shader makes sense, because was in a big sense designed to do this type of process. We will start doing some image operations!
|
Before Width: | Height: | Size: 516 KiB After Width: | Height: | Size: 516 KiB |
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 1.1 MiB |
Before Width: | Height: | Size: 148 KiB After Width: | Height: | Size: 148 KiB |
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 37 KiB |
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 66 KiB |
Before Width: | Height: | Size: 218 KiB After Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 105 KiB After Width: | Height: | Size: 177 KiB |
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 86 KiB After Width: | Height: | Size: 86 KiB |
@ -1,72 +1,18 @@
|
||||
# Image processing
|
||||
## Image operations
|
||||
|
||||
## Textures
|
||||
|
||||
![](01.jpg)
|
||||
### Invert
|
||||
|
||||
Graphic cards (GPUs) have special memory types for images. Usually on CPUs images are stores as arrays of bites but on GPUs store images as ```sampler2D``` which is more like a table (or matrix) of floating point vectors. More interestingly is that the values of this *table* of vectors are continously. That means that value between pixels are interpolated in a low level.
|
||||
<div class="codeAndCanvas" data="inv.frag" data-imgs="00.jpg,01.jpg"></div>
|
||||
|
||||
In order to use this feature we first need to *upload* the image from the CPU to the GPU, to then pass the ```id``` of the texture to the right [```uniform```](../05). All that happens outside the shader.
|
||||
### Add, Substract, Multiply and others
|
||||
|
||||
Once the texture is loaded and linked to a valid ```uniform sampler2D``` you can ask for specific color value at specific coordinates (formated on a [```vec2```](index.html#vec2.md) variable) usin the [```texture2D()```](index.html#texture2D.md) function which will return a color formated on a [```vec4```](index.html#vec4.md) variable.
|
||||
![](02.jpg)
|
||||
|
||||
```glsl
|
||||
vec4 texture2D(sampler2D texture, vec2 coordinates)
|
||||
```
|
||||
<div class="codeAndCanvas" data="operations.frag" data-imgs="00.jpg,01.jpg"></div>
|
||||
|
||||
Check the following code where we load Hokusai's Wave (1830) as ```uniform sampler2D u_tex0``` and we call every pixel of it inside the billboard:
|
||||
|
||||
<div class="codeAndCanvas" data="texture.frag" data-imgs="hokusai.jpg"></div>
|
||||
|
||||
If you pay attention you will note that the coordinates for the texture are normalized! What a surprise right? Textures coordenates are consisten with the rest of the things we had saw and their coordenates are between 0.0 and 1.0 whitch match perfectly with the normalized space coordinates we have been using.
|
||||
|
||||
Now that you have seen how we load correctly a texture is time to experiment to discover what we can do with it, by trying:
|
||||
|
||||
* Scaling the previus texture by half.
|
||||
* Rotating the previus texture 90 degrees.
|
||||
* Hooking the mouse position to the coordenates to move it.
|
||||
|
||||
Why you should be excited about textures? Well first of all forget about the sad 255 values for channel, once your image is trasformed into a ```uniform sampler2D``` you have all the values between 0.0 and 1.0 (depending on what you set the ```precision``` to ). That's why shaders can make really beatiful post-processing effects.
|
||||
|
||||
Second, the [```vec2()```](index.html#vec2.md) means you can get values even between pixels. As we said before the textures are a continum. This means that if you set up your texture correctly you can ask for values all arround the surface of your image and the values will smoothly vary from pixel to pixel with no jumps!
|
||||
|
||||
Finnally, you can setup your image to repeat in the edges, so if you give values over or lower of the normalized 0.0 and 1.0, the values will wrap around starting over.
|
||||
|
||||
All this features makes your images more like an infinit spandex fabric. You can streach and shrinks your texture without noticing the grid of bites they originally where compose of or the ends of it. To experience this take a look to the following code where we distort a texture using [the noise function we already made](../11/).
|
||||
|
||||
<div class="codeAndCanvas" data="texture-noise.frag" data-imgs="hokusai.jpg"></div>
|
||||
|
||||
## Texture resolution
|
||||
|
||||
Aboves examples play well with squared images, where both sides are equal and match our squared billboard. But for non-squared images things can be a little more tricky, and unfortunatly centuries of picturical art and photography found more pleasent to the eye non-squared proportions for images.
|
||||
|
||||
![Joseph Nicéphore Niépce (1826)](nicephore.jpg)
|
||||
|
||||
How we can solve this problem? Well we need to know the original proportions of the image to know how to streatch the texture correctly in order to have the original [*aspect ratio*](http://en.wikipedia.org/wiki/Aspect_ratio). For that the texture width and height is pass to the shader as an ```uniform```. Which in our example framework are pass as an ```uniform vec2``` with the same name of the texture followed with proposition ```Resolution```. Once we have this information on the shader he can get the aspect ration by dividing the ```width``` for the ```height``` of the texture resolution. Finally by multiplying this ratio to the coordinates on ```y``` we will shrink these axis to match the original proportions.
|
||||
|
||||
Uncomment line 21 of the following code to see this in action.
|
||||
|
||||
<div class="codeAndCanvas" data="texture-resolution.frag" data-imgs="nicephore.jpg"></div>
|
||||
|
||||
* What we need to do to center this image?
|
||||
|
||||
## Digital upholstery
|
||||
### PS Blending modes
|
||||
|
||||
![](03.jpg)
|
||||
|
||||
You may be thinking that this is unnesesary complicated... and you are probably right. Also this way of working with images leave a enought room to different hacks and creative tricks. Try to imagine that you are an upholster and by streaching and folding a fabric over a structure you can create better and new patterns and techniques.
|
||||
|
||||
![Eadweard's Muybridge study of motion](muybridge.jpg)
|
||||
|
||||
This level of craftsmanship links back to some of the first optical experiments ever made. For example on games *sprite animations* are very common, and is inevitably to see on it reminicence to phenakistoscope, zoetrope and praxinoscope.
|
||||
|
||||
This could seam simple but the posibilities of modifing textures coordinates is enormus. For example: .
|
||||
|
||||
<div class="codeAndCanvas" data="texture-sprite.frag" data-imgs="muybridge.jpg"></div>
|
||||
|
||||
Now is your turn:
|
||||
|
||||
* Can you make a kaleidoscope using what we have learn?
|
||||
* What other optical toys can you re-create using textures?
|
||||
|
||||
In the next chapters we will learn how to do some image processing using shaders. You will note that finnaly the complexity of shader makes sense, because was in a big sense designed to do this type of process. We will start doing some image operations!
|
||||
<div class="codeAndCanvas" data="blend.frag" data-imgs="04.jpg,05.jpg"></div>
|