#version 300 es
precision highp float;
uniform vec2 uResolution;
uniform vec2 uMouse;
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 = (2.0 * gl_FragCoord.xy - uResolution.xy) / max(uResolution.x, uResolution.y);
vec2 mouse = (2.0 * uMouse.xy - uResolution.xy) / max(uResolution.x, uResolution.y);
mouse.y *= -1.0;
vec2 farCorner = vec2(
mouse.x == 0.0 ? 1.0 : -1.0 * sign(mouse.x),
mouse.y == 0.0 ? 1.0 : -1.0 * sign(mouse.y)
);
float fromMouse = distance(pos, mouse);
float fromMouseMax = distance(farCorner, mouse);
float maxRadius = 0.2;
float radius = map(fromMouse, 0.0, fromMouseMax, maxRadius, 0.0);
pos *= 10.0;
vec2 center = vec2(0.5, 0.5);
float pattern = 1.0 - circle(fract(pos + 0.5), center, radius, 0.1);
outColor.rgb = vec3(pattern);
outColor.a = 1.0;
}