URL: http://glslsandbox.com/e#27309.1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
// Colorful Voronoi // By: Brandon Fogerty // bfogerty at gmail dot com // xdpixel.com #ifdef GL_ES precision mediump float; #endif uniform float time; uniform vec2 mouse; uniform vec2 resolution; vec2 hash(vec2 p) { mat2 m = mat2( 13.85, 47.77, 99.41, 88.48 ); return fract(sin(m*p) * 46738.29); } float voronoi(vec2 p) { vec2 g = floor(p); vec2 f = fract(p); float distanceToClosestFeaturePoint = 1.0; for(int y = -1; y <= 1; y++) { for(int x = -1; x <= 1; x++) { vec2 latticePoint = vec2(x, y); float currentDistance = distance(latticePoint + hash(g+latticePoint), f); distanceToClosestFeaturePoint = min(distanceToClosestFeaturePoint, currentDistance); } } return distanceToClosestFeaturePoint; } void main( void ) { vec2 uv = ( gl_FragCoord.xy / resolution.xy ) * 2.0 - 1.0; uv.x *= resolution.x / resolution.y; float offset = voronoi(uv*10.0 + vec2(time)); float t = 1.0/abs(((uv.x + sin(uv.y + time)) + offset) * 30.0); float r = voronoi( uv * 1.0 ) * 10.0; vec3 finalColor = vec3(10.0 * uv.y, 2.0, 1.0 * r) * t; gl_FragColor = vec4(finalColor, 1.0 ); } |