memoscan
← all memos

Memo 0x8b8ab327…1590e5 on Ethereum

c3( 100000.0, 0.0, 0.0 ); \n float myRadius = 1.0;\n\n for( int i=0; i<u_numBeads; i++ ){\n vec3 bead = beads[i];\n vec2 p = bead.xy;\n float r = bead.z;\n vec2 dir = gl_FragCoord.xy - p;\n vec3 sdg = sdgCircle( dir, r );\n float dist = length( dir );\n mySdg = sdgMin( sdg, mySdg );\n\n if( dist < r ){\n myRadius = r;\n }\n }\n\n vec4 sdfData = vec4( mySdg.x, mySdg.yz, myRadius );\n\n color = sdfData;\n}").replace("%%beads%%",ze),attributes:{position:{data:Ee,size:2},uv:{data:Re,size:2}},count:3}),Pe.fb=d(e,{width:an.height,height:an.height,type:e.FLOAT,internalFormat:e.RGBA32F})},De=n=>{Pe.renderer.bindVAOs(),n.bindFramebuffer(n.FRAMEBUFFER,Pe.fb.write.fb),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,Pe.fb.read.targetTexture),Pe.renderer.bindUniform("u_framebuffer",0),Pe.renderer.bindUniform("u_numBeads",Ae),Pe.renderer.bindUniform("u_res",[Pe.fb.width,Pe.fb.height]),Pe.renderer.render(Pe.fb.width,Pe.fb.height),Pe.fb.swap()},Ie=new Float32Array([-1,-1,3,-1,-1,3]),Me=new Float32Array([0,0,2,0,0,2]),Be={};let Ce=Math.min(Math.max(an.sunRad-50,0)/1500,1);const Le=e=>{Be.renderer=s(e,{vert:n(sn),frag:n("#version 300 es\nprecision highp float;\n#define GLSLIFY 1\nin vec2 v_uv;\nout vec4 color;\n\nuniform vec2 u_res;\nuniform float u_renderPer;\n\nuniform sampler2D u_pointCloud;\nuniform sampler2D u_sunTex;\nuniform sampler2D u_planetsTex;\nuniform sampler2D u_beadsTex;\nuniform sampler2D u_sky;\nuniform sampler2D u_noiseClouds;\n\nuniform vec2 u_sunPos;\nuniform float u_sunRad;\nuniform float u_sunRadPer;\nuniform int u_bailyBeads;\nuniform float u_cityHaze;\nuniform float u_cloudiness;\nuniform float u_flareIntensity;\nuniform int u_environmentId;\nuniform float u_groundLevel;\nuniform float u_rf0;\nuniform float u_rf1;\nuniform float u_atmos;\nuniform vec3 u_multi;\n\n#define PI 3.14159265\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( x * ( 1.0 - z ), y * ( 1.0 - z ), z ) );\n return n;\n}\n\nfloat linear( in float minVal, in float maxVal, in float val ){\n float v = clamp( ( val - minVal ) / ( maxVal - minVal ), 0.0, 1.0 );\n return v;\n}\n\nvoid main() {\n vec2 frag = gl_FragCoord.xy;\n vec2 uv = frag / u_res;\n\n float haze = u_cityHaze;\n float cloudy = u_cloudiness * 0.5;\n\n vec4 sunData = texture( u_sunTex, uv );\n float sd = sunData.x;\n float surf = sunData.w;\n float sr = u_sunRad;\n float sunRadPer = u_sunRadPer; // small sun = 0.0, huge sun = 1.0;\n float sunSide = smoothstep( -0.001, 0.001, sd );\n\n // GET SKY\n float skyTex = texture( u_sky, uv ).x;\n\n // GET PLANETS TEX\n vec4 planets = texture( u_planetsTex, uv );\n float planetDist = planets.x;\n float planetRad = planets.w;\n vec3 planetN = getNormal( planets );\n float planetRadPer = smoothstep( 5.0, 800.0, planetRad ) * 0.8 + 0.2;\n\n // GET NOISE CLOUDS\n vec4 clouds = texture( u_noiseClouds, uv );\n float cn0 = clouds.x;\n float cn1 = clouds.y;\n float cn2 = clouds.z;\n float cn3 = clouds.w; \n\n // set initial color\n float cd = skyTex * smoothstep( 0.0, 1.0, sd );\n cd -= clouds.x * u_cloudiness * 0.2;\n \n // SUN PARTICLES\n float particles = min( texture( u_pointCloud, uv ).x, 1.0 ) * 0.9;\n cd += particles * 0.1 + pow( particles, 10.0 ) * 2.0 * cn2;\n cd = clamp( cd, 0.0, 1.0 );\n\n // SUN SURFACE\n float sdPer = 1.0 - ( -sd / sr );\n float sun = surf;\n sun += pow( sdPer, 2.0 ) * 0.1;\n sun += pow( sdPer, 15.0 ) * 0.35 * sunRadPer; // brighten sun edge at high radii\n sun += u_cloudiness * 0.25 + u_flareIntensity * 0.05;\n sun = mix( sun, cd, sunSide );\n\n // SUN CORONA\n float cg0 = linear( sr * 5.0, -sr * 0.5, sd );\n float cg1 = linear( sr * 0.5, -sr * 0.5, sd );\n float cg2 = linear( max( cn1, cn2 ) * sr * 0.07, 0.0, sd );\n float ss0 = 1.0 - linear( 0.0, sr * 18.0, sd );\n float ss1 = 1.0 - linear( 0.0, sr * 5.0, sd );\n float ss2 = 1.0 - linear( 0.0, sr * 0.4, sd );\n float ss3 = 1.0 - linear( 0.0, sr * 0.01, sd );\n float corona = ss0 * ss0 * 0.35 + 0.1;\n corona += ss1 * ss1 * 0.15;\n corona += ss2 * ss2 * 0.15;\n corona += ss3 * ss3 * 0.15;\n corona += pow( ss3 * ss3 * cn1 * cn2 * 2.0, 2.0 );\n corona += cg2 * ( 1.0 - sunRadPer ) * 0.25;\n corona += smoothstep( cn3 * cn2 * sr * 0.1, -sr * 0.025, sd ) * sunRadPer * 0.8;\n\n // RENDER SUN AND CORONA\n cd += sun * u_multi.y * ( 1.0 - sunSide ) + corona * u_multi.z * sunSide;\n\n \n // Baily's Beads\n float beadsCd = 0.0;\n if( u_bailyBeads == 1 ){\n vec4 beads = texture( u_beadsTex, uv );\n float beadDist = beads.x;\n float beadRad = beads.w;\n beadsCd = pow( smoothstep( beadRad * 6.0, -beadRad, beadDist ), 15.0 ) * 2.0;\n cd += beadsCd;\n }\n \n // render planets\n {\n float distPer = smoothstep( sr * -0.15, sr * 0.15, sd );\n vec2 dirToSun = u_sunPos - frag;\n float distToSun = length( vec2( dirToSun ) );\n float planetPer = smoothstep( 800.0, 50.0, planetDist ) * 0.25 * ( 1.0 - planetRadPer ) + 0.1;\n float rimGlow = smoothstep( sr * 20.0, 0.0, distToSun + sr );\n float planetEdge = smoothstep( 1.0, -4.0, planetDist );\n float pc = smoothstep( -planetRad, planetRad * 0.05, planetDist );\n float pb = pow( pc, 2.0 ) * 0.2;\n pb += pow( pc, 4.0 ) * 0.2;\n pb += pow( pc, 11.0 ) * 0.3;\n cd = mix( cd, cg0 * planetPer, planetEdge );\n cd += pb * cg1 * planetEdge * 0.2 * planetRadPer;\n\n float dp = max( 0.0, dot( vec3( normalize( dirToSun ), -u_renderPer * 15.0 ), planetN ) * rimGlow );\n cd += dp * distPer * planetEdge * 0.75;\n cd += smoothstep( -planetRad * 0.025, 0.0, planetDist ) * 0.2 * planetEdge * u_atmos;\n cd += rimGlow * 0.1 * planetEdge;\n cd += smoothstep( -8.0, 1.0, planetDist ) * 0.2 * planetEdge;\n }\n \n // landscape\n if( u_environmentId > 0 ){\n float reflectMask = pow( sin( uv.x * PI ), 21.0 );\n reflectMask += pow( sin( uv.x * PI ), 5.0 ) * 0.2;\n float gl = u_groundLevel;\n float skyMask = smoothstep( gl, gl + haze*0.04, uv.y );\n float seaMask = 1.0 - skyMask;\n\n float pnh1 = texture( u_noiseClouds, vec2( uv.x * 0.1, uv.y * 2.0 ) ).w * 0.5;\n float pnh2 = texture( u_noiseClouds, vec2( uv.x * 0.03, uv.y * 2.0 ) ).w * 0.5;\n float wispy0 = texture( u_noiseClouds, vec2( uv.x * 0.05, uv.y * 0.5 ) ).x;\n float wispy1 = texture( u_noiseClouds, vec2( uv.x * 0.1, uv.y * 1.5 ) ).x;\n\n float seaGrad = smoothstep( 0.0, gl, uv.y );\n\n if( u_environmentId == 1 ){ // ocean\n float nn = cn0 * 0.004 + cn0 * 0.002 + cn2 * 0.001 + 0.005;\n float gl0 = gl + nn - sin( uv.x * PI + 0.75 ) * 0.015;\n float lm = smoothstep( gl0, gl0 + haze*0.1, uv.y );\n float cloudyMask = cloudy * skyMask;\n\n cd *= skyMask;\n cd += ( pow( smoothstep( gl + ( cloudy + 1.0 ), gl, uv.y ), 3.0 ) ) * wispy0 * 0.3 * skyMask; // horizon glow\n cd += sin( smoothstep( gl + 0.2, gl - 0.2, uv.y ) * PI ) * cloudyMask * wispy1;\n cd += sin( smoothstep( gl-0.1, gl+0.3, uv.y ) * PI ) * cloudyMask * cn1 * 0.15;\n cd += sin( smoothstep( gl-0.1, gl+0.6, uv.y ) * PI ) * cloudyMask * cn0 * 0.3;\n cd += seaMask * 0.02; // sea base color\n cd += seaGrad * 0.1 * seaMask; // sea noisy gradient to horizon\n cd += ( pow( smoothstep( gl + haze, gl, uv.y ), 4.0 ) ) * haze * skyMask; // horizon glow\n cd += ( pow( smoothstep( gl + haze * 2.0, gl, uv.y ), 2.0 ) ) * max( u_cloudiness, 0.2 ) * sqrt( reflectMask ) * skyMask; // horizon glow\n cd += pow( 1.0 - abs( uv.y - gl ), 23.0 ) * 0.1;\n \n cd += pnh1 * pnh2 * reflectMask * seaMask * seaGrad * 0.3; // reflection\n cd += reflectMask * seaMask * 0.45 + pnh2 * smoothstep( gl * 0.3, gl, uv.y ) * seaMask * 0.3; // sugimoto\n cd -= sin( smoothstep( gl + 0.02, gl - 0.05, uv.y ) * PI ) * wispy1 * 0.2 * seaMask * u_cloudiness; // darker waters\n \n if( u_cloudiness > 0.2 ){\n float clouds0 = cn2 * sin( smoothstep( gl + 0.02 + cn1 * 0.05, gl + ( cn0 * 0.05 + cn2 * 0.05 ), uv.y + cn2 * 0.01 ) * PI );\n float clouds1 = cn0 * sin( smoothstep( gl + 0.02 + cn1 * 0.06, gl + ( cn0 * 0.2 + cn2 * 0.1 ) * cn0 + 0.05, uv.y + cn2 * 0.003 ) * PI );\n float clouds2 = cn0 * sin( smoothstep( gl + 0.02 + cn0 * 0.03, gl + ( cn0 * 0.3 + cn2 * 0.2 ) * cn0 + 0.1, uv.y + cn2 * 0.001 ) * PI );\n float cFinal = clouds0 * cn0 * 0.4 + clouds1 * cn1 * 1.4 + clouds2 * 0.35;\n cd += cFinal * u_cloudiness * cn0;\n }\n\n } else if( u_environmentId == 2 ){ // hills\n cd += pow( smoothstep( 0.9, gl, uv.y ), 1.0 ) * 0.1; // horizon glow\n cd += smoothstep( gl + max( u_cityHaze, 0.1 ) * 3.0, gl, uv.y ) * 0.2;\n float origCd = cd;\n int numHills = 4;\n for( int i=0; i<numHills; i++ ){\n float per = float(i) / float( numHills - 1 );\n float nn = ( cos( sin( uv.x * ( 16.0 + per * 3.0 ) + per * 4.95 + cn0 * 0.7 + u_rf0 * 52.0 ) )/( PI * 0.35 ) ) * 0.03;\n nn += sin( uv.x * ( 5.0 - per * 1.0 ) + per * 5.7 + ( cn0 + cn1 + cn2 * 0.5 ) * 0.5 + u_rf1 * 22.0 ) * 0.05;\n float gl0 = gl + nn * ( 1.0 - per * 0.7 ) - per * 0.05;\n float lm = smoothstep( gl0, gl0+0.0025, uv.y );\n cd = mix( origCd, cd, lm );\n cd -= ( 1.0 - lm ) * ( 0.1 + reflectMask * 0.03 ) * ( per * 0.5 );\n }\n }\n }\n \n // thick clouds\n cd -= ( cn0 * 0.5 - cn1 * 0.3 ) * cloudy;\n float rf0 = u_rf0 * 0.5 + 0.25;\n float cgrad = smoothstep( rf0 - cn0 * 0.25 + uv.x * 0.2, rf0 + cn0 * 0.25 + uv.x * 0.2, uv.y ) * u_cloudiness;\n cd -= ( cn0 * 0.5 - cn1 * 0.3 ) * cgrad;\n\n // fg light pollution\n cd += ( 1.0 - uv.y + cn2 * 0.02 ) * ( haze +