#version 300 es
precision highp float;
uniform vec2 uResolution;
out vec4 outColor;
float norm(float v, float min, float max) {
return (v - min) / (max - min);
}
float map(float v, float min1, float max1, float min2, float max2) {
return mix(min2, max2, norm(v, min1, max1));
}
float circleSdf(vec2 xy, vec2 center, float radius) {
vec2 fromCenter = xy - center;
return pow(dot(fromCenter, fromCenter), 0.5) - radius;
}
float circle(vec2 xy, vec2 center, float radius, float spread) {
float sdf = circleSdf(xy, center, radius);
return smoothstep(radius - radius * spread, radius + radius * spread, sdf);
}
void main() {
vec2 pos = gl_FragCoord.xy / uResolution.xy;
pos *= 2.0;
pos -= 1.0;
float aspect = uResolution.x / uResolution.y;
pos.x *= aspect;
float fromCenter = distance(pos, vec2(0.0));
float maxRadius = 0.2;
float radius = map(fromCenter, 0.0, 1.0, 0.0, maxRadius);
pos *= 7.0;
vec2 center = vec2(0.5, 0.5);
outColor.rgb = vec3(1.0 - circle(fract(pos + 0.5), center, radius, 0.1));
outColor.a = 1.0;
}