#version 300 es
precision highp float;
uniform vec2 uResolution;
uniform float uTime;
out vec4 outColor;
float smoothedge(float shape) {
return smoothstep(0.0, 1.0 / uResolution.x, shape);
}
float rect(vec2 xy, vec2 center, float width, float height) {
vec2 p = abs(xy - center);
vec2 v = vec2(width, height) * 0.5;
vec2 d = p - v;
return length(max(d, 0.0));
}
float mixUnion(float shape1, float shape2) {
return min(shape1, shape2);
}
float crossSymbol(vec2 xy, vec2 center, float size) {
float horizontal = rect(xy, center, size * 0.25, size);
float vertical = rect(xy, center, size, size * 0.25);
return mixUnion(horizontal, vertical);
}
mat2 scale2d(vec2 scale) {
return mat2(
scale.x, 0.0,
0.0, scale.y
);
}
void main() {
vec2 pos = (2.0 * gl_FragCoord.xy - uResolution.xy) / min(uResolution.x, uResolution.y);
vec2 center = vec2(-0.5);
pos -= center;
pos *= scale2d(vec2(sin(uTime) + 1.0));
pos += center;
float shape = crossSymbol(pos, center, 0.25);
vec3 color = vec3(pos.xy, 0.0);
outColor.rgb = vec3(color + smoothedge(shape));
outColor.a = 1.0;
}