URL: http://glslsandbox.com/e#30478.0
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
// Crazy Portal // By: Brandon Fogerty // bfogerty at gmail dot com // xdpixel.com #ifdef GL_ES precision mediump float; #endif #extension GL_OES_standard_derivatives : enable uniform float time; uniform vec2 mouse; uniform vec2 resolution; // I didn't write this random function but I don't know who did... so thanks to whoever wrote this! vec2 random2f(vec2 p) { p = mod( p, 4.0 ); vec2 tmp = fract(vec2(sin(p.x * 591.32 + p.y * 154.077), cos(p.x * 391.32 + p.y * 49.077))); return vec2(.5+.5*sin(tmp.x*time+ p.y),.5+.5*cos(tmp.y*time + p.x)); } float voronoi( vec2 uv ) { uv.x = mod(uv.x,4.0); vec2 p = floor( uv ); vec2 f = fract( uv ); float res = 8.0; const float i = 1.0; for( float y = -i; y <= i; ++y ) { for( float x = -i; x <= i; ++x ) { vec2 b = vec2( x, y ); vec2 r = b - f + random2f( p + b ); float d = length( r ); res = min( res, d ); } } return res; } void main( void ) { vec2 uv = ( gl_FragCoord.xy / resolution.xy ) * 2.0 - 1.0; uv.x *= resolution.x / resolution.y; vec2 originalUV = uv; float a = 2.0 * atan( uv.x, uv.y ); a *= (3.0 / 3.141596); float r = length( uv ) * 0.5; float t = sin( time * 0.2 ) * 0.5 + 0.5; float z = mix( 2.5, 3.5, t ); uv = vec2( r * z, a ); vec3 finalColor = vec3(0.0); finalColor += vec3( voronoi(uv * 4.0), voronoi(uv * 3.0), voronoi(uv * 7.0) ); finalColor -= length(originalUV) * 0.3; finalColor *= 1.0-length(originalUV); gl_FragColor = vec4( finalColor, 1.0 ); } |