#version 130 out vec4 fragColor; uniform vec2 res; uniform float time; const float sharpness = 300; const float PI = 3.14159265358979323846; mat2 rot(float a) { return mat2( cos(a), -sin(a), sin(a), cos(a) ); } float poly(float n, vec2 m, float r, float rt, vec2 p) { vec2 diff = (m - p) * rot(rt); float d = length(diff); float alpha = PI / n; float gamma = mod(abs(atan(diff.x, diff.y)), alpha*2); if (gamma > alpha) gamma -= 2*alpha; float r2 = r * cos(alpha) / cos(gamma); return clamp((r2 - d)*sharpness, 0.0, 1.0); } float poly_d(float n, vec2 m, float r, float rt, vec2 p) { return poly(n, m, r, rt, p) - poly(n, m, r - 1/sharpness, rt, p); } void main(void) { vec2 m = res/2; float s = min(m.x, m.y); vec2 p = (gl_FragCoord.xy - m) / s; float scene = 0; float c; c = poly_d(5 - 3*cos(time/1000), vec2(0, 0), 0.5, PI * time/1000, p); scene = abs(scene - c); c = poly_d(5 - 3*cos(time/1000), vec2(0, 0), 0.5, -PI * time/1000, p); scene = abs(scene - c); fragColor = vec4(vec3(1, 1, 1) * scene, 1); }