#version 300 es
precision highp float;
uniform vec2 uResolution;
uniform float uTime;
out vec4 outColor;
const float PI = 3.1415926;
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 rotate2d(float angle) {
return mat2(
cos(angle), -sin(angle),
sin(angle), cos(angle)
);
}
void main() {
vec2 pos = (2.0 * gl_FragCoord.xy - uResolution.xy) / min(uResolution.x, uResolution.y);
vec2 center = vec2(-0.5);
pos -= center;
pos *= rotate2d(sin(uTime) * PI);
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;
}