Files
glsl_playground/basic/moving_tiles.glsl

55 lines
1.3 KiB
GLSL

#ifdef GL_ES
precision mediump float;
#endif
const float PI = 3.1415926535897932384626433832795;
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
vec2 movingTiles(vec2 _st, float _zoom, float _speed) {
_st *= _zoom;
float time = u_time*_speed;
if(fract(time)>0.5){
if (fract( _st.y * 0.5) > 0.5) _st.x += fract(time)*2.0;
else _st.x -= fract(time)*2.0;
} else {
if (fract(_st.x * 0.5) > 0.5) _st.y += fract(time)*2.0;
else _st.y -= fract(time)*2.0;
}
return fract(_st);
}
float circle(vec2 _st, float _radius) {
vec2 pos = vec2(0.5)-_st;
return smoothstep(1.0-_radius,1.0-_radius+_radius*0.2,1.-dot(pos,pos)*3.14);
}
vec2 brickTile(vec2 _st, float _zoom) {
_st *= _zoom;
_st.x += step(1., mod(_st.y,2.0)) * 0.5;
return fract(_st);
}
float box(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;
}
void main() {
vec2 st = gl_FragCoord.xy/u_resolution.xy;
st.x *= u_resolution.x/u_resolution.y;
st = movingTiles(st,10.,0.5);
st = brickTile(st, 0.5);
vec3 color = vec3(1.0-box(st, vec2(abs(sin(u_time))*0.8+0.1)));
gl_FragColor = vec4(color,1.0);
}