You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
thebookofshaders/09/iching-01.frag

92 lines
2.8 KiB
GLSL

// Author @patriciogv ( patriciogonzalezvivo.com ) - 2015
// Title: IChing series
#ifdef GL_ES
precision mediump float;
#endif
// Copyright (c) Patricio Gonzalez Vivo, 2015 - http://patriciogonzalezvivo.com/
// I am the sole copyright owner of this Work.
//
// You cannot host, display, distribute or share this Work in any form,
// including physical and digital. You cannot use this Work in any
// commercial or non-commercial product, website or project. You cannot
// sell this Work and you cannot mint an NFTs of it.
// I share this Work for educational purposes, and you can link to it,
// through an URL, proper attribution and unmodified screenshot, as part
// of your educational material. If these conditions are too restrictive
// please contact me and we'll definitely work it out.
#define PI 3.14159265359
#define TWO_PI 6.28318530718
uniform vec2 u_resolution;
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/N;
return abs(cos(floor(.5+a/r)*r-a)*length(st));
}
float box(vec2 st, vec2 size){
return shape(st*size,4.);
}
float rect(vec2 _st, vec2 _size){
_size = vec2(0.5)-_size*0.5;
vec2 uv = smoothstep(_size,_size+vec2(1e-4),_st);
uv *= smoothstep(_size,_size+vec2(1e-4),vec2(1.0)-_st);
return uv.x*uv.y;
}
float hex(vec2 st, float a, float b, float c, float d, float e, float f){
st = st*vec2(2.,6.);
vec2 fpos = fract(st);
vec2 ipos = floor(st);
if (ipos.x == 1.0) fpos.x = 1.-fpos.x;
if (ipos.y < 1.0){
return mix(box(fpos, vec2(0.84,1.)),box(fpos-vec2(0.03,0.),vec2(1.)),a);
} else if (ipos.y < 2.0){
return mix(box(fpos, vec2(0.84,1.)),box(fpos-vec2(0.03,0.),vec2(1.)),b);
} else if (ipos.y < 3.0){
return mix(box(fpos, vec2(0.84,1.)),box(fpos-vec2(0.03,0.),vec2(1.)),c);
} else if (ipos.y < 4.0){
return mix(box(fpos, vec2(0.84,1.)),box(fpos-vec2(0.03,0.),vec2(1.)),d);
} else if (ipos.y < 5.0){
return mix(box(fpos, vec2(0.84,1.)),box(fpos-vec2(0.03,0.),vec2(1.)),e);
} else if (ipos.y < 6.0){
return mix(box(fpos, vec2(0.84,1.)),box(fpos-vec2(0.03,0.),vec2(1.)),f);
}
return 0.0;
}
float hex(vec2 st, float N){
float b[6];
float remain = floor(mod(N,64.));
for(int i = 0; i < 6; i++){
b[i] = 0.0;
b[i] = step(1.0,mod(remain,2.));
remain = ceil(remain/2.);
}
return hex(st,b[0],b[1],b[2],b[3],b[4],b[5]);
}
void main(){
vec2 st = gl_FragCoord.xy/u_resolution.xy;
st.y *= u_resolution.y/u_resolution.x;
st *= 10.0;
vec2 fpos = fract(st);
vec2 ipos = floor(st);
float t = u_time*5.0;
float df = 1.0;
df = hex(fpos,ipos.x+ipos.y+t)+(1.0-rect(fpos,vec2(0.7)));
gl_FragColor = vec4(mix(vec3(0.),vec3(1.),step(0.7,df)),1.0);
}