URL: http://glslsandbox.com/e#32259.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 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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
// Trinity // By: Brandon Fogerty // bfogerty at gmail dot com // xdpixel.com //"For God so loved the world, that he gave his only Son, // that whoever believes in him should not perish but have eternal life." (John 3:16) // "Go therefore and make disciples of all nations, baptizing them in // the name of the Father and of the Son and of the Holy Spirit, // teaching them to observe all that I have commanded you. // And behold, I am with you always, to the end of the age." - King Jesus (Matthew 28:19-20) #ifdef GL_ES precision mediump float; #endif #extension GL_OES_standard_derivatives : enable uniform float time; uniform vec2 mouse; uniform vec2 resolution; #define Resolution resolution #define Time time #define HorizontalAmplitude 0.30 #define VerticleAmplitude 0.20 #define HorizontalSpeed 0.90 #define VerticleSpeed 1.50 #define ParticleMinSize 1.76 #define ParticleMaxSize 1.61 #define ParticleBreathingSpeed 0.30 #define ParticleColorChangeSpeed 0.70 #define ParticleCount 2.0 #define ParticleColor1 vec3(9.0, 5.0, 3.0) #define ParticleColor2 vec3(1.0, 3.0, 9.0) float hash( float x ) { return fract( sin( x ) * 43758.5453 ); } float noise( vec2 uv ) // Thanks Inigo Quilez { vec3 x = vec3( uv.xy, 0.0 ); vec3 p = floor( x ); vec3 f = fract( x ); f = f*f*(3.0 - 2.0*f); float offset = 57.0; float n = dot( p, vec3(1.0, offset, offset*2.0) ); return mix( mix( mix( hash( n + 0.0 ), hash( n + 1.0 ), f.x ), mix( hash( n + offset), hash( n + offset+1.0), f.x ), f.y ), mix( mix( hash( n + offset*2.0), hash( n + offset*2.0+1.0), f.x), mix( hash( n + offset*3.0), hash( n + offset*3.0+1.0), f.x), f.y), f.z); } float snoise( vec2 uv ) { return noise( uv ) * 2.0 - 1.0; } float perlinNoise( vec2 uv ) { float n = noise( uv * 1.0 ) * 128.0 + noise( uv * 2.0 ) * 64.0 + noise( uv * 4.0 ) * 32.0 + noise( uv * 8.0 ) * 16.0 + noise( uv * 16.0 ) * 8.0 + noise( uv * 32.0 ) * 4.0 + noise( uv * 64.0 ) * 2.0 + noise( uv * 128.0 ) * 1.0; float noiseVal = n / ( 1.0 + 2.0 + 4.0 + 8.0 + 16.0 + 32.0 + 64.0 + 128.0 ); noiseVal = abs(noiseVal * 2.0 - 1.0); return noiseVal; } float fBm( vec2 uv, float lacunarity, float gain ) { float sum = 0.0; float amp = 7.0; for( int i = 0; i < 2; ++i ) { sum += ( perlinNoise( uv ) ) * amp; amp *= gain; uv *= lacunarity; } return sum; } vec3 particles( vec2 pos ) { vec3 c = vec3( 0, 0, 0 ); float noiseFactor = fBm( pos, 0.01, 0.1); for( float i = 1.0; i < ParticleCount+1.0; ++i ) { float cs = cos( time * HorizontalSpeed * (i/ParticleCount) + noiseFactor ) * HorizontalAmplitude; float ss = sin( time * VerticleSpeed * (i/ParticleCount) + noiseFactor ) * VerticleAmplitude; vec2 origin = vec2( cs , ss ); float t = sin( time * ParticleBreathingSpeed * i ) * 0.5 + 0.5; float particleSize = mix( ParticleMinSize, ParticleMaxSize, t ); float d = clamp( sin( length( pos - origin ) + particleSize ), 0.0, particleSize); float t2 = sin( time * ParticleColorChangeSpeed * i ) * 0.5 + 0.5; vec3 color = mix( ParticleColor1, ParticleColor2, t2 ); c += color * pow( d, 10.0 ); } return c; } float line( vec2 a, vec2 b, vec2 p ) { vec2 aTob = b - a; vec2 aTop = p - a; float t = dot( aTop, aTob ) / dot( aTob, aTob); t = clamp( t, 0.0, 1.0); float d = length( p - (a + aTob * t) ); d = 1.0 / d; return clamp( d, 0.0, 1.0 ); } void main( void ) { float aspectRatio = resolution.x / resolution.y; vec2 uv = ( gl_FragCoord.xy / resolution.xy ); vec2 signedUV = uv * 2.0 - 1.0; signedUV.x *= aspectRatio; float freqA = mix( 0.4, 1.2, sin(time + 30.0) * 0.5 + 0.5 ); float freqB = mix( 0.4, 1.2, sin(time + 20.0) * 0.5 + 0.5 ); float freqC = mix( 0.4, 1.2, sin(time + 10.0) * 0.5 + 0.5 ); float scale = 100.0; const float v = 70.0; vec3 finalColor = vec3( 0.0 ); finalColor = (particles( sin( abs(signedUV) ) ) * length(signedUV)) * 0.20; float t = line( vec2(-v, -v), vec2(0.0, v), signedUV * scale ); finalColor += vec3( 8.0 * t, 2.0 * t, 4.0 * t) * freqA; t = line( vec2(0.0, v), vec2(v, -v), signedUV * scale ); finalColor += vec3( 2.0 * t, 8.0 * t, 4.0 * t) * freqB; t = line( vec2(-v, -v), vec2(v, -v), signedUV * scale ); finalColor += vec3( 2.0 * t, 4.0 * t, 8.0 * t) * freqC; scale = scale * 1.2; t = line( vec2(0.0, v * 0.2), vec2(0.0, -v * 0.8), signedUV * scale ); finalColor += vec3( 8.0 * t, 4.0 * t, 2.0 * t) * 0.5; t = line( vec2(-v * 0.3, -v*0.1), vec2(v * 0.3, -v*0.1), signedUV * scale ); finalColor += vec3( 8.0 * t, 4.0 * t, 2.0 * t) * 0.4; gl_FragColor = vec4( finalColor, 1.0 ); } |