@ -10,15 +10,15 @@ precision mediump float;
uniform vec2 u_resolution ;
uniform vec2 u_resolution ;
uniform float u_time ;
uniform float u_time ;
float shape ( vec2 st , in t N ) {
float shape ( vec2 st , floa t N ) {
st = st * 2. - 1. ;
st = st * 2. - 1. ;
float a = atan ( st . x , st . y ) + PI ;
float a = atan ( st . x , st . y ) + PI ;
float r = TWO_PI / float ( N ) ;
float r = TWO_PI / N ;
return cos( floor ( .5 + a / r ) * r - a ) * length ( st ) ;
return abs( cos( floor ( .5 + a / r ) * r - a ) * length ( st ) ) ;
}
}
float box ( vec2 st , vec2 size ) {
float box ( vec2 st , vec2 size ) {
return shape ( st * size , 4 ) ;
return shape ( st * size , 4. ) ;
}
}
float rect ( vec2 _st , vec2 _size ) {
float rect ( vec2 _st , vec2 _size ) {
@ -28,7 +28,7 @@ float rect(vec2 _st, vec2 _size){
return uv . x * uv . y ;
return uv . x * uv . y ;
}
}
float hex ( vec2 st , bool a , bool b , bool c , bool d , bool e , bool f ) {
float hex ( vec2 st , float a , float b , float c , float d , float e , float f ) {
st = st * vec2 ( 2. , 6. ) ;
st = st * vec2 ( 2. , 6. ) ;
vec2 fpos = fract ( st ) ;
vec2 fpos = fract ( st ) ;
@ -36,33 +36,34 @@ float hex(vec2 st, bool a, bool b, bool c, bool d, bool e, bool f){
if ( ipos . x == 1.0 ) fpos . x = 1. - fpos . x ;
if ( ipos . x == 1.0 ) fpos . x = 1. - fpos . x ;
if ( ipos . y < 1.0 ) {
if ( ipos . y < 1.0 ) {
return a? box ( fpos - vec2 ( 0.03 , 0. ) , vec2 ( 1. ) ) : box ( fpos , vec2 ( 0.84 , 1. ) ) ;
return mix( box ( fpos , vec2 ( 0.84 , 1. ) ) , box ( fpos - vec2 ( 0.03 , 0. ) , vec2 ( 1. ) ) , a ) ;
} else if ( ipos . y < 2.0 ) {
} else if ( ipos . y < 2.0 ) {
return b? box ( fpos - vec2 ( 0.03 , 0. ) , vec2 ( 1. ) ) : box ( fpos , vec2 ( 0.84 , 1. ) ) ;
return mix( box ( fpos , vec2 ( 0.84 , 1. ) ) , box ( fpos - vec2 ( 0.03 , 0. ) , vec2 ( 1. ) ) , b ) ;
} else if ( ipos . y < 3.0 ) {
} else if ( ipos . y < 3.0 ) {
return c? box ( fpos - vec2 ( 0.03 , 0. ) , vec2 ( 1. ) ) : box ( fpos , vec2 ( 0.84 , 1. ) ) ;
return mix( box ( fpos , vec2 ( 0.84 , 1. ) ) , box ( fpos - vec2 ( 0.03 , 0. ) , vec2 ( 1. ) ) , c ) ;
} else if ( ipos . y < 4.0 ) {
} else if ( ipos . y < 4.0 ) {
return d? box ( fpos - vec2 ( 0.03 , 0. ) , vec2 ( 1. ) ) : box ( fpos , vec2 ( 0.84 , 1. ) ) ;
return mix( box ( fpos , vec2 ( 0.84 , 1. ) ) , box ( fpos - vec2 ( 0.03 , 0. ) , vec2 ( 1. ) ) , d ) ;
} else if ( ipos . y < 5.0 ) {
} else if ( ipos . y < 5.0 ) {
return e? box ( fpos - vec2 ( 0.03 , 0. ) , vec2 ( 1. ) ) : box ( fpos , vec2 ( 0.84 , 1. ) ) ;
return mix( box ( fpos , vec2 ( 0.84 , 1. ) ) , box ( fpos - vec2 ( 0.03 , 0. ) , vec2 ( 1. ) ) , e ) ;
} else if ( ipos . y < 6.0 ) {
} else if ( ipos . y < 6.0 ) {
return f? box ( fpos - vec2 ( 0.03 , 0. ) , vec2 ( 1. ) ) : box ( fpos , vec2 ( 0.84 , 1. ) ) ;
return mix( box ( fpos , vec2 ( 0.84 , 1. ) ) , box ( fpos - vec2 ( 0.03 , 0. ) , vec2 ( 1. ) ) , f ) ;
}
}
return 0.0 ;
return 0.0 ;
}
}
float hex ( vec2 st , float N ) {
float hex ( vec2 st , float N ) {
bool b [ 6 ] ;
float b [ 6 ] ;
float remain = floor ( mod ( N , 64. ) ) ;
float remain = floor ( mod ( N , 64. ) ) ;
for ( int i = 0 ; i < 6 ; i + + ) {
for ( int i = 0 ; i < 6 ; i + + ) {
b [ i ] = mod ( remain , 2. ) == 1. ? true : false ;
b [ i ] = 0.0 ;
b [ i ] = step ( 1.0 , mod ( remain , 2. ) ) ;
remain = ceil ( remain / 2. ) ;
remain = ceil ( remain / 2. ) ;
}
}
return hex ( st , b [ 0 ] , b [ 1 ] , b [ 2 ] , b [ 3 ] , b [ 4 ] , b [ 5 ] ) ;
return hex ( st , b [ 0 ] , b [ 1 ] , b [ 2 ] , b [ 3 ] , b [ 4 ] , b [ 5 ] ) ;
}
}
void main ( ) {
void main ( ) {
vec2 st = gl_FragCoord . xy / u_resolution . xy ;
vec2 st = gl_FragCoord . xy / u_resolution . xy ;
st . y * = u_resolution . y / u_resolution . x ;
st . y * = u_resolution . y / u_resolution . x ;
st * = 10.0 ;
st * = 10.0 ;
@ -73,5 +74,5 @@ void main(){
float df = 1.0 ;
float df = 1.0 ;
df = hex ( fpos , ipos . x + ipos . y + t ) + ( 1.0 - rect ( fpos , vec2 ( 0.7 ) ) ) ;
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 ) ;
gl_FragColor + = vec4 ( mix ( vec3 ( 0. ) , vec3 ( 1. ) , step ( 0.7 , df ) ) , 1.0 ) ;
}
}