URL: http://glslsandbox.com/e#25448.3
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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
// Energy Field // By: Brandon Fogerty // bfogerty at gmail dot com // xdpixel.com // Special thanks to Inigo Quilez for noise! #ifdef GL_ES precision mediump float; #endif uniform float time; uniform vec2 resolution; float hash( float n ) { return fract(sin(n)*753.5453123); } // Slight modification of iq's noise function. float noise( in vec2 x ) { vec2 p = floor(x); vec2 f = fract(x); f = f*f*(3.0-2.0*f); float n = p.x + p.y*157.0; return mix( mix( hash(n+ 0.0), hash(n+ 1.0),f.x), mix( hash(n+157.0), hash(n+158.0),f.x), f.y); } float fbm(vec2 p, vec3 a) { float v = 0.0; v += noise(p*a.x)*.5; v += noise(p*a.y)*.25; v += noise(p*a.z)*.125; return v; } vec3 drawLines( vec2 uv, vec3 fbmOffset, vec3 color1, vec3 color2 ) { float timeVal = time * 0.1; vec3 finalColor = vec3( 0.0 ); for( int i=0; i < 3; ++i ) { float indexAsFloat = float(i); float amp = 40.0 + (indexAsFloat*5.0); float period = 2.0 + (indexAsFloat+2.0); float thickness = mix( 0.9, 1.0, noise(uv*10.0) ); float t = abs( 0.9 / (sin(uv.x + fbm( uv + timeVal * period, fbmOffset )) * amp) * thickness ); finalColor += t * color1; } for( int i=0; i < 5; ++i ) { float indexAsFloat = float(i); float amp = 40.0 + (indexAsFloat*7.0); float period = 2.0 + (indexAsFloat+8.0); float thickness = mix( 0.7, 1.0, noise(uv*10.0) ); float t = abs( 0.8 / (sin(uv.x + fbm( uv + timeVal * period, fbmOffset )) * amp) * thickness ); finalColor += t * color2 * 0.6; } return finalColor; } void main( void ) { vec2 uv = ( gl_FragCoord.xy / resolution.xy ) * 2.0 - 1.0; uv.x *= resolution.x/resolution.y; uv.xy = uv.yx; vec3 lineColor1 = vec3( 2.3, 0.5, .5 ); vec3 lineColor2 = vec3( 0.3, 0.5, 2.5 ); vec3 finalColor = vec3(0.0); float t = sin( time ) * 0.5 + 0.5; float pulse = mix( 0.10, 0.20, t); finalColor += drawLines( uv, vec3( 1.0, 20.0, 30.0), lineColor1, lineColor2 ) * pulse; finalColor += drawLines( uv, vec3( 1.0, 2.0, 4.0), lineColor1, lineColor2 ); gl_FragColor = vec4( finalColor, 1.0 ); } |