Last active
February 5, 2019 23:55
-
-
Save larsch/eba1b8d89e5f77782e7b0a2675c49453 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vec3 hsv2rgb(vec3 c) { | |
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); | |
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); | |
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); | |
} | |
float rand(vec2 co){ | |
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); | |
} | |
vec4 get_color(vec2 p) { | |
vec4 sum; | |
const int blobs = 64; | |
for (int i = 0; i < blobs; ++i) { | |
float scale = 1.0; | |
float period = 1000.0 + float(i) * 297.2; | |
period *= scale; | |
float w = mod(iFrame, period) / period; | |
w += float(i) / float(blobs); | |
float angle = w * 6.28318530717958647693; | |
float period2 = 1000.0 + float(i) * 230.7; | |
period2 *= scale; | |
float w2 = mod(iFrame, period2) / period2; | |
w2 -= float(i) / float(blobs); | |
float angle2 = w2 * 6.28318530717958647693; | |
vec2 ce = 40.0 * vec2(cos(angle), sin(angle2)); | |
float dist = sqrt(pow(p.x - ce.x,2.0) + pow(p.y - ce.y, 2.0)); | |
vec3 color = hsv2rgb(vec3(30.1428 * float(i)/float(blobs), 1.0, 1.0)); | |
float max_alpha = 0.3; | |
vec4 col4; | |
float size = 3.0 + 8.0 * rand(vec2(period, period2)); | |
float fade_size = 0.5 * size; | |
if (dist < size - fade_size) { | |
sum += vec4(color, max_alpha); | |
} else if (dist < size) { | |
float fade_level = 1.0 - (dist - size + fade_size) / fade_size; | |
float fade_pixel = (6.28 * fade_level - sin(6.28 * fade_level)) / 6.28; | |
sum += vec4(color * fade_pixel, fade_pixel * max_alpha); | |
} | |
} | |
return sum; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment