memoscan
← all memos

Memo 0x47fce4a3…07ee46 on Ethereum

orm float u_time;\nout vec4 color;\n\nconst float PI = 3.141592;\n\nvec3 sdgCircle( in vec2 p, in float r ){\n float d = length(p);\n return vec3( d-r, p/d );\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_res;\n\n vec2 dirToSun = gl_FragCoord.xy - u_sunPos;\n vec3 sdg = sdgCircle( dirToSun, u_sunRad );\n\n float dist = sdg.x / u_sunRad;\n vec2 sp = uv - ( u_sunPos / u_res );\n\tfloat f = abs( 1.0 - ( pow( abs( dist ), 0.2 ) ) ) + 1.0;\n float srf = 0.0;\n\n float sr = u_sunRad;\n\n if( dist <= 0.0 ){\n vec4 spots = texture( u_forces, uv );\n vec2 sg = spots.xy;\n vec2 sgp = vec2( spots.y, -spots.x );\n float sd = spots.z;\n float sa = atan( sg.y, sg.x );\n float sm = smoothstep( 600.0, 50.0, u_sunRad ) * 0.4 + 0.1;\n\n vec2 suv;\n \t\tsuv.x = ( sp.x ) * f + 0.5;\n \t\tsuv.y = ( sp.y ) * f + 0.5;\n\n vec4 ccd = texture( u_noiseClouds, ( ( suv - 0.5 ) * 0.9 + 0.5 ) + sg * 0.01 );\n float c0 = ccd.x - 0.2;\n float c1 = ccd.y - 0.2;\n float c2 = ccd.z - 0.2;\n float c3 = ccd.w - 0.2;\n\n vec4 cnd = texture( u_noiseClouds, suv + vec2( c0, c1 ) + sg * 0.05 * sin( sa * 15.0 ) );\n float n0 = cnd.x - 0.25;\n float n1 = cnd.y - 0.25;\n float n2 = cnd.z - 0.25;\n float n3 = cnd.w - 0.25;\n\n float prox = smoothstep( sr * 0.02 * n1 + sr * 0.03 * n2, sr * 0.001, sd + 15.0 + c2 * 3.0 );\n float prox2 = smoothstep( sr * 0.2 * n1 + sr * 0.17 * n2 + n0, sr * 0.01, sd + 12.0 + c1 * 8.0 );\n float dark = smoothstep( 0.0, ( n2 + n1 ) * sr * 0.01 * n1, sd + 10.0 + c0 * 13.0 );\n dark -= ( sin( sa * sr * 0.03 ) * 0.5 + 0.5 ) * prox * n2 * 6.0;\n dark = max( 0.1, dark );\n\n srf = c0 * 0.2 + c1 * 0.1 + c2 * 0.1 + c3 * 0.1 + ( sin( c3 * c2 * 150.0 ) * 0.1 + 0.1 ); // complex base layer\n srf *= ( n0 + n1 + n2 + n3 ); // complex base layer\n srf *= 1.3;\n srf *= 1.0 - clamp( prox2 * c0 * c1 * c2 * 15.0, 0.0, 1.0 ); // spot darkening\n srf *= sin( ( 1.0 - c3 ) * 25.0 ) * 0.4 + 0.7;\n srf *= ( 1.0 - n3 ) * 0.3 + 0.7;\n srf += pow( prox2, 13.0 ) * n1 * n2 * n3 * 5.0; // spot lightening\n srf = abs( srf - 0.25 ) + 0.25;\n float noisy = sin( srf * 20.0 ) * 0.5 + 0.5;\n srf = mix( srf, noisy, n3 - n2 ) + 0.1;\n srf = clamp( srf + 0.2, 0.0, 1.0 );\n }\n\n color = vec4( sdg, srf );\n}"),attributes:{position:{data:Cn,size:2},uv:{data:Ln,size:2}},count:3}),On.fb=d(e,{width:an.height,height:an.height,type:e.FLOAT,internalFormat:e.RGBA32F,tiling:e.REPEAT})},kn=(n,e)=>{On.renderer.bindVAOs(),n.bindFramebuffer(n.FRAMEBUFFER,On.fb.write.fb),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,On.fb.read.targetTexture),n.activeTexture(n.TEXTURE1),n.bindTexture(n.TEXTURE_2D,An.fb.read.targetTexture),n.activeTexture(n.TEXTURE2),n.bindTexture(n.TEXTURE_2D,In.fb.read.targetTexture),On.renderer.bindUniform("u_framebuffer",0),On.renderer.bindUniform("u_forces",1),On.renderer.bindUniform("u_noiseClouds",2),On.renderer.bindUniform("u_sunPos",an.sunPos),On.renderer.bindUniform("u_sunRad",an.sunRad),On.renderer.bindUniform("u_res",[On.fb.width,On.fb.height]),On.renderer.bindUniform("u_rf0",an.rf0),On.renderer.bindUniform("u_rf1",an.rf1),On.renderer.bindUniform("u_ruv",[123.45*an.rf0,123.45*an.rf1]),On.renderer.render(On.fb.width,On.fb.height),On.fb.swap()},Gn=c(),Nn={},Vn=1/an.mapSize,qn=e=>{const r=an.numParticles,t=new Float32Array(2*r),o=new Float32Array(2*r),a=new Float32Array(4*r);for(let n=0;n<2*r;n+=2){let e=Gn.random_num(-Math.PI,Math.PI),r=Math.pow(Gn.random_dec(),.25)*an.sunRad;t[n]=an.sunPos[0]+Math.cos(e)*r,t[n+1]=an.sunPos[1]+Math.sin(e)*r,o[n]=2*Gn.random_dec()-1+1e-4,o[n+1]=2*Gn.random_dec()-1+1e-4,a[2*n]=5*Gn.random_dec(),a[2*n+1]=5*Gn.random_dec()+5,a[2*n+2]=Gn.random_dec(),a[2*n+3]=.1*Math.pow(Gn.random_num(.2,1),5)}Nn.renderer=s(e,{vert:n("#version 300 es\n#define GLSLIFY 1\n\nlayout(location=0) in vec2 a_position;\nlayout(location=1) in vec2 a_velocity;\nlayout(location=2) in vec4 a_extras;\n\nout vec2 v_position;\nout vec2 v_velocity;\nout vec4 v_extras;\nout vec3 v_color;\n\nuniform sampler2D u_particlemap;\nuniform sampler2D u_dvmap;\nuniform sampler2D u_sunTex;\nuniform sampler2D u_forceTex;\n\nuniform vec2 u_sunPos;\nuniform float u_sunRad;\n\nuniform float u_renderPer;\nuniform vec2 u_res;\n\nuniform float u_frame;\nuniform float u_haziness;\nuniform float u_activity;\nuniform float u_intensity;\nuniform float u_flareIntensity;\nuniform float u_rand;\nuniform vec2 u_invRes;\nuniform float u_rf0;\nuniform float u_rf1;\n\nconst float dt = 0.0002;\nfloat u_speedMin = 0.01;\n\n#define PI 3.14159265359\n#define TAU 6.28318530718\n\nvec3 getNormal( vec4 sdf ){\n float x = dot( vec2( 1.0, 0.0 ), sdf.yz );\n float y = dot( vec2( 0.0, 1.0 ), sdf.yz );\n float z = 1.0 - ( sdf.w - abs( sdf.x ) )/sdf.w;\n vec3 n = normalize( vec3( sqrt( abs( x ) ) * sign( x ) * ( 1.0 - z ), sqrt( abs( y ) ) * sign( y ) * ( 1.0 - z ), z ) );\n return n;\n}\n\n// Grab from https://www.shadertoy.com/view/4djSRW\n#define MOD3 vec3(.1031,.11369,.13787)\nfloat hash12(vec2 p) {\n vec3 p3 = fract(vec3(p.xyx) * .1031);\n p3 += dot(p3, p3.yzx + 33.33);\n return fract((p3.x + p3.y) * p3.z);\n}\n\nvec2 hash22(vec2 p) {\n\tvec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973));\n p3 += dot(p3, p3.yzx+33.33);\n return fract((p3.xx+p3.yz)*p3.zy);\n}\n\nvec4 derivative( vec4 state, inout float density, inout float densityMult, inout vec4 sunData, in float speedMax ){\n vec2 uv = state.xy;\n\n vec4 dv = texture( u_dvmap, uv );\n density = dv.x;\n vec2 avgVelocity = dv.zw / max( density, 1.0 );\n\n float sunDist = sunData.x;\n vec2 sunGrad = normalize( sunData.yz );\n float sunGradMag = ( 1.0 / ( sunDist ) );\n\n vec4 forceData = texture( u_forceTex, uv );\n float forceDist = forceData.z;\n vec2 forceGrad = normalize( forceData.xy );\n float forceGradMag = ( 1.0 / ( forceDist ) );\n\n vec3 normal = getNormal( sunData );\n\n vec4 extras = a_extras;\n float agePer = extras.x/extras.y;\n float rf0 = extras.z;\n\n float dm = smoothstep( 100.0, 1200.0, u_sunRad ) * 0.2 + 0.05;\n float sv1 = sin( forceGrad.y * 15.7 * sin( forceGrad.x * ( ( mix( u_rf0, rf0, u_renderPer * u_renderPer ) + 0.2 ) * 25.0 ) ) );\n float sv2 = sin( forceGrad.y * ( u_rf1 + 0.5 ) * 3.3 );\n vec2 vel0 = forceGrad * forceGradMag * ( sv1 * sv2 ) * u_intensity * u_sunRad;\n vec2 vel1 = sunGrad * sunGradMag * u_intensity * u_sunRad * 0.1;\n vec2 customVel = mix( vel0 + vel1 * 0.25, -vel1 * 0.5, agePer ) * u_flareIntensity;\n\n float attract = 0.06 * dm;\n float repel = 0.12 * dm;\n float align = 0.5 * dm;\n float leading = 0.5;\n densityMult = 0.1 * dm;\n\n vec2 xy = state.xy + leading * dt * state.zw;\n\n vec3 dvm = texture( u_dvmap, xy ).xzw;\n xy = state.xy + dt * 2.0 * leading * dvm.yz / dvm.x;\n\n float dE = texture( u_dvmap, state.xy + vec2( u_invRes.x, 0 ) ).x;\n float dW = texture( u_dvmap, state.xy + vec2( -u_invRes.x, 0 ) ).x;\n float dN = texture( u_dvmap, state.xy + vec2( 0, u_invRes.y ) ).x;\n float dS = texture( u_dvmap, state.xy + vec2( 0, -u_invRes.y ) ).x;\n vec2 densityGrad = vec2( dE - dW, dN - dS ) / u_invRes;\n\n vec4 avgPosValues = texture( u_particlemap, xy );\n float density1= texture( u_dvmap, xy ).x;\n\n vec2 avgPos = vec2(\n state.x < 0.5 ? avgPosValues.x : avgPosValues.z,\n state.y < 0.5 ? avgPosValues.y : avgPosValues.w\n ) / max( density1, 1e-8 );\n\n // The magic numbers!\n float repulsion = 1.4 * repel;\n float follow = 5000.0 * align;\n float cohesion = 1700000.0 * attract;\n float velEnforce = 100.0 * ( 1.5 - u_activity );\n\n float vmag = length( state.zw );\n \n vec2 randLoc = state.xy * 1. + u_rand * 100.0;\n vec2 rand = hash22(randLoc) - .5;\n\n vec2 v = customVel;\n - densityGrad * repulsion\n + ( avgVelocity - state.zw ) * follow\n + ( avgPos - state.xy ) * cohesion / max( 0.01, leading )\n + state.zw * ( speedMax - vmag ) * velEnforce\n + 20000.0 * rand * ( 0.3 + u_haziness * 0.5 );\n\n return vec4( state.zw, v );\n}\n\nvoid main() {\n // get extras\n vec4 extras = a_extras;\n float age = extras.x;\n float life = extras.y;\n float rf0 = extras.z;\n\n float densityMult = 0.01;\n float density = 0.0;\n float speedMax = smoothstep( 50.0, 1000.0, u_sunRad ) * 15.0;\n vec4 state = vec4( a_position / u_res, a_velocity );\n \n vec4 sunData = texture( u_sunTex, state.xy );\n state += dt * derivative( state, density, densityMult, sunData, speedMax );\n vec2 uv = state.xy;\n vec2 pos = state.xy * u_res;\n vec2 vel = state.zw;\n\n // limit speed\n float speed = length( vel );\n float maxSpeed = speedMax * ( smoothstep( 100.0, 500.0, u_sunRad ) * 0.8 + 0.2 ) + rf0 * 10.0;\n if( speed > maxSpeed ){\n vel = normalize( vel ) * maxSpeed;\n } else if( speed < u_speedMin ){\n vel = normalize( vel ) * u_speedMin;\n }\n \n int oob = 0;\n float b = 0.0;\n if( pos.y < b || pos.y > u_res.y - b ) oob = 1;\n if( pos.x < b || pos.x > u_res.x - b ) oob = 1;\n if( age < 0.0 || age > life ) oob = 1;\n if( sunData.x < 0.0 ) oob = 1;\n\n if( oob == 1 ){\n float angle = hash12( pos * 0.01 ) * 0.5 + hash12( pos * 0.05 ) * 0.5 * TAU * 5.0;\n float radius = u_sunRad + u_sunRad * ( rf0 * 0.015 );\n vec2 dir = vec2( cos( angle ), sin( angle ) );\n vec2 newPos = u_sunPos + dir * radius;\n pos = newPos;\n vel = dir * 0.001;\n }\n\n v_position = pos;\n v_velocity = vel * 0.9975;\n\n if( u_frame < 5.0 ) {\n v_velocity = a_velocity;\n }\n \n vec2 position = a_position / u_res * 2.0 - 1.0;\n v_extras = a_extras;\n if( oob == 1 ){\n v_extras.x = 0.0;\n }\n v_extras.x += 0.0333;\n\n vec2 velDir = normalize( v_velocity.xy );\n float angle = atan( velDir.y, velDir.x );\n v_color = vec3( 1.0 );\n\n float fadeOut = pow( u_renderPer, 0.5 );\n float ps = max( extras.w, 0.1 ) * u_flareIntensity * fadeOut;\n\n gl_PointSize = ps;\n gl_Position = v