memoscan
← all memos

Memo 0xbc93e7f6…199ec1 on Ethereum

[0,()=>{console.log("Artist 42. Lars Wander -- platform 0");function t(t){return new URL(window.location.href).searchParams.get(t)}console.log("Made by Lars Wander https://larswander.com"),console.log("Licensed under CC BY-NC-SA 4.0");const e=tokenData.hash;console.log(tokenData.hash);class r{constructor(){this.useA=!1;let t=function(t){let e=parseInt(t.substring(0,8),16),r=parseInt(t.substring(8,16),16),n=parseInt(t.substring(16,24),16),i=parseInt(t.substring(24,32),16);return function(){e|=0,r|=0,n|=0,i|=0;let t=(e+r|0)+i|0;return i=i+1|0,e=r^r>>>9,r=n+(n<<3)|0,n=n<<21|n>>>11,n=n+t|0,(t>>>0)/4294967296}};this.prngA=new t(e.substring(2,34)),this.prngB=new t(e.substring(34,66));for(let t=0;t<1e6;t+=2)this.prngA(),this.prngB()}random(){return this.useA=!this.useA,this.useA?this.prngA():this.prngB()}}const n=new r,i=()=>n.random();function o(t,e){null==e&&(e=t,t=0),null==e&&(e=1);const r=e-t;return i()*r+t}function s(t){return null==t&&(t=.5),i()<t}const a=[.01,.1312,1.5806,7.7489,19.1068,27.2789,40.2367,43.3749,35.6146,22.4668,9.3318,1.7627,.4155,4.0426,12.3338,25.4684,39.3398,55.1236,70.52,84.6489,97.1482,99.1948,101.167,92.3319,75.0964,53.9294,36.1246,21.4712,12.2407,6.6892,3.2018,1.3875,.6874,.342,.1355,.0699,.0375,.0191],u=[0,.0164,.1655,.8051,1.9994,3.3546,6.5121,10.4722,15.1035,21.2723,29.3981,36.8978,50.3903,65.4035,79.829,94.2494,100.4376,103.1928,99.73,92.057,83.2302,68.9442,59.2511,47.3083,34.9129,23.6123,15.0491,8.6109,4.8369,2.6164,1.2447,.5369,.265,.1338,.0493,.028,.015,.0064],c=[.035,.5738,7.1169,35.6246,90.8624,134.661,206.3009,233.4076,205.6291,151.3409,89.5041,45.1892,23.8938,12.0738,6.3608,3.2845,1.4303,.4162,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],l=a.length,f=o(),h=o(),d=o(),_=o(),m=o(),x=s(.1)&&m>.4,v=o(),p=o(),y=o(),T=o(),g=o(),w=8,A=4,E=ot(.01,.07,f),b=E*ot(.1,.6,h),R=ot(.18,.3,_),S=180*ot(1,.7,_),M=ot(-.4,.14,m),z=ot(.01,.15,g),N=3/l,L=.12,P=ot(.89,ot(.65,.85,d),v),U=0,$=.7,I=t=>Math.pow(t,.25),F=ot(.21,.45,p),X=ot(.4,.55,p),D=Math.round(ot(5,8,d)),C=2,B=1,O=ot(.75,ot(.71,.69,v),y),G=.85,k=.75,Y=ot(1,1.5,T),H=(t("T")??"1,1").split(",").map((t=>Number(t))),q=(t("i")??"0,0").split(",").map((t=>Number(t)));console.table({RAY_EXTEND_T:f,RAY_NORMAL_T:h,SPECTRAL_SEPARATION_T:_,SPECTRAL_BIAS_T:m,SKEW_Z_T:T,SPECTRAL_LIGHT_SPREAD_T:g,SPHERE_COUNT:D,SPHERE_COUNT_T:d,MAX_SPHERE_SIZE_T:v,SECONDARY_RADIUS_MAX:P,DESAT_T:p,ZOOM_T:y});const W="#version 300 es\nprecision highp float;\n\nin vec2 a_coord;\n\nout vec2 v_tex;\n\nvoid main() {\n vec2 pos = (a_coord * 2.0) - 1.0;\n gl_Position = vec4(pos, 0.0, 1.0);\n v_tex = a_coord;\n}\n";function V(t){const e=t.getContext("webgl2",{preserveDrawingBuffer:!0});if(e){if(e.getExtension("EXT_color_buffer_float"))return e.pixelStorei(e.UNPACK_ALIGNMENT,1),e;alert("Unable to render to F16 buffer")}else alert("Unable to create webgl context")}function Z(t,e,r){const n=t.createShader(e);return t.shaderSource(n,r),t.compileShader(n),n}function K(t,e,r){const n=t.createProgram();return t.attachShader(n,e),t.attachShader(n,r),t.linkProgram(n),n}function j(t){const e=Array(t[0].length*t.length);for(let r=0;r<t[0].length;r++)for(let n=0;n<t.length;n++)e[r*t.length+n]=t[n][r];return e}class J{constructor(t,e,r,n){this.gl=t,this.width=e,this.height=r,this.texture=t.createTexture(),t.bindTexture(t.TEXTURE_2D,this.texture),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texImage2D(t.TEXTURE_2D,0,t.RGBA16F,e,r,0,t.RGBA,t.FLOAT,n),this.framebuffer=t.createFramebuffer(),t.bindFramebuffer(t.FRAMEBUFFER,this.framebuffer),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,this.texture,0)}read(){return this.texture}write(){return this.framebuffer}}class Q{constructor(t,e){this.pool=t,this.id=e}read(){return this.pool.getRead(this.id).read()}write(){return this.pool.getWrite(this.id).write()}flip(){this.pool.flip()}}class tt{constructor(t,e,r){this.gl=t,this.width=e,this.height=r,this.buffers=[new J(t,e,r,null)],this.writeIndex=0,this.owners=[],this.onLease=-1}add(t){return this.buffers.push(new J(this.gl,this.width,this.height,t)),this.owners.push(this.buffers.length-1),new Q(this,this.owners.length-1)}getRead(t){return this.buffers[this.owners[t]]}getWrite(t){return this.onLease=t,this.buffers[this.writeIndex]}flip(){const t=this.owners[this.onLease];this.owners[this.onLease]=this.writeIndex,this.writeIndex=t,this.onLease=-1}}function et(t,e,r,n){const{vertShader:i,width:o,height:s,coordBuffer:a}=n,u=K(t,i,Z(t,t.FRAGMENT_SHADER,e)),c=t.createVertexArray();t.bindVertexArray(c);const l=t.getAttribLocation(u,"a_coord"),f=a;t.bindBuffer(t.ARRAY_BUFFER,f),t.enableVertexAttribArray(l);var h=t.FLOAT;t.vertexAttribPointer(l,2,h,!1,0,0);const d={program:u,width:o,height:s,vertexArray:c};for(const e of r)d[e]=t.getUniformLocation(u,e);return d}function rt(t,e,r,n,i){const o=Z(t,t.VERTEX_SHADER,W),s=t.createBuffer();return t.bindBuffer(t.ARRAY_BUFFER,s),t.bufferData(t.ARRAY_BUFFER,new Float32Array([n.x,n.y,i.x,n.y,n.x,i.y,n.x,i.y,i.x,n.y,i.x,i.y]),t.STATIC_DRAW),{vertShader:o,width:e,height:r,coordBuffer:s}}function nt(t,e,r,n,i){t.bindFramebuffer(t.FRAMEBUFFER,n),t.viewport(0,0,e.width,e.height),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),t.useProgram(e.program),t.bindVertexArray(e.vertexArray),t.uniform2f(e.u_r,e.width,e.height),t.uniform1i(e.u_S0,0),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,r),i&&i(),t.drawArrays(t.TRIANGLES,0,6)}function it(t,e,r){return Math.max(t,Math.min(e,r))}function ot(t,e,r){return"number"==typeof t?t*(1-r)+e*r:t.lerpT(e,r)}function st(t,e=2){const r=10**e;return Math.round(t*r)/r}class at{constructor(t,e){isNaN(t)?null==t&&(this.x=0,this.y=0):(this.x=t,this.y=e)}dot(t){return this.x*t.x+this.y*t.y}lerpT(t,e){return this.mul(1-e).add(t.mul(e))}add(t){return new at(this.x+t.x,this.y+t.y)}sub(t){return new at(this.x-t.x,this.y-t.y)}mul(t){return new at(this.x*t,this.y*t)}div(t){return new at(this.x/t,this.y/t)}floor(){return new at(Math.floor(this.x),Math.floor(this.y))}dist(t){if(null==t)return Math.sqrt(this.x*this.x+this.y*this.y);{const e=this.x-t.x,r=this.y-t.y;return Math.sqrt(e*e+r*r)}}normalize(){const t=Math.sqrt(this.dot(this));return new at(this.x/t,this.y/t)}}function ut(t=null,e=null,r="main"){var n=document.createElement("canvas");n.style.width=t,n.style.height=e;const i=window.devicePixelRatio??1;return n.id=r,n.width=Math.floor(t*i),n.height=Math.floor(e*i),document.body.appendChild(n),n}function ct(t,e){const r=document.createElement("a");r.setAttribute("download",e),t.toBlob((function(t){r.setAttribute("href",URL.createObjectURL(t)),r.click()}))}class lt{constructor(t,e,r){this.x=t,this.y=e,this.z=r}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}cross(t){return new lt(this.y*t.z-this.z*t.y,this.x*t.z-this.z*t.x,this.x*t.y-this.y*t.x)}lerpT(t,e){return this.mul(1-e).add(t.mul(e))}add(t){return new lt(this.x+t.x,this.y+t.y,this.z+t.z)}sub(t){return new lt(this.x-t.x,this.y-t.y,this.z-t.z)}mul(t){return new lt(this.x*t,this.y*t,this.z*t)}mul3(t){return new lt(this.x*t.x,this.y*t.y,this.z*t.z)}div(t){return new lt(this.x/t,this.y/t,this.z/t)}rotateX(t){const e=Math.cos(t),r=Math.sin(t);return new lt(this.x,this.y*e-this.z*r,this.y*r+this.z*e)}rotateY(t){const e=Math.cos(t),r=Math.sin(t);return new lt(this.x*e+this.z*r,this.y,-this.x*r+this.z*e)}rotateZ(t){const e=Math.cos(t),r=Math.sin(t);return new lt(this.x*e-this.y*r,this.x*r+this.z*e,this.z)}dist(t){if(null==t)return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z);{const e=this.x-t.x,r=this.y-t.y,n=this.z-t.z;return Math.sqrt(e*e+r*r+n*n)}}normalize(){const t=this.dist();return 0===t?new lt(0,0,0):this.div(t)}toString(){return`(${st(this.x)}, ${st(this.y)}, ${st(this.z)})`}}const ft=j([a,u,c]),ht=new lt(0,0,-7);let dt=!0,_t=!1,mt=Number(t("N")??130);const xt=`#version 300 es\nprecision highp float; uniform sampler2D u_S0; uniform vec2 u_r; in vec2 v_tex; out vec4 o_col; vec3 aces_film(vec3 x) { float a = 2.4; float b = 0.03; float c = 2.4; float d = 0.59; float e = 0.14f; return clamp((x*(a*x+b))/(x*(c*x+d)+e), 0.0, 1.0); } vec3 desat(vec3 c, float t) { float avg = dot(c, vec3(1.0)) / 3.0; return mix(c, vec3(avg), t); } void main(void) { vec3 c = texture(u_S0, v_tex).xyz; float mag = length(aces_film(c)) / sqrt(3.0); float sat = mix(float(${F}), float(${X}), mag); o_col = vec4(aces_film(desat(c, sat)), 1.0); }\n`,vt=` const mat3 C = mat3( 3.2404542, -1.5371385, -0.4985314, -0.9692660, 1.8760108, 0.0415560, 0.0556434, -0.2040259, 1.0572252) / 2323.8695; const float N_AIR = 1.0; const float N_GLASS = 2.0; const float MAX_T = 10000.0; uniform sampler2D u_S0; uniform vec2 u_r; uniform vec3 u_obs[${l}]; uniform vec2 u_Ts; uniform vec2 u_Ti; uniform float u_st; uniform float u_t; uniform float u_s; uniform vec2 u_sxy; uniform vec3 u_eye; uniform float u_fov; uniform vec3 u_s_c[${D}]; uniform float u_s_r[${D}]; uniform vec4 u_ls[${C}]; in vec2 v_tex; out vec4 o_col; float PHI = 1.61803398; float PI = 3.14159265; float GN(in vec2 xy, in float seed) { return fract(tan(distance(xy * PHI, xy) * seed) * xy.x); } float N(in vec2 xy, inout float seed) { xy += u_sxy; xy *= u_r; seed = GN(xy, seed); return GN(xy, seed); } vec2 N2(in vec2 xy, inout float seed) { return vec2(N(xy, seed), N(xy, seed)); } vec3 col(in float S[${l}]) { vec3 T[${l}]; for (int f = 0; f < ${l}; f++) { T[f] = S[f] * u_obs[f]; } vec3 res = vec3(0.0); for (int f = 0; f < ${l} - 1; f++) { res += T[f] + T[f + 1]; } return res * C; } float cbp(float c, float w, float x) { x = abs(x - c); if (x > w) { return 0.0; } x /= w; return 1.0 - x * x * (3.0 - 2.0 * x); } vec2 sr(in vec3 ro, in vec3 rd, in vec3 ce, in float ra) { vec3 oc = ro - ce; float b = dot(oc, rd); float c = dot(oc, oc) - ra * ra; float h = b * b - c; if (h < 0.0) { return vec2(-1.0); } h = sqrt(h); return vec2(-b - h, -b + h); } vec3 sn(in vec3 p, in vec3 ce) { return normalize(p - ce); } vec2 gv() { return (u_Ti + v_tex) / u_Ts; } vec2 gm() { float a = float(0.75); float sd = float(0.85); vec2 ideal; if (u_r.x > u_r.y * a) { ideal = vec2(u_r.y * a, u_r.y); } else { ideal = vec2(u_r.x, u_r.x / a); } ideal *= sd; return (u_r - ideal) / 2.0; } void rord(in vec2 tex, out vec3 ro, out vec3 rd, out vec2 res) { ro = u_eye; res = u_r; float fov = u_fov; float scale = min(u_r.x, u_r.y); vec2 disp = tex * vec2(u_r.x / scale, u_r.y / scale); disp -= vec2(u_r.x / scale, u_r.y / scale) * 0.5; float z = 1.0 / tan(fov * 0.5); rd = vec3(disp, z); } float pr(in vec3 ro, in vec3 rd, in vec4 p) { return -(dot(ro, p.xyz) + p.w) / dot(rd, p.xyz); } vec3 pn(in vec4 p) { return p.xyz; } `,pt=`#version 300 es\nprecision highp float; ${vt} float ss(in vec2 v) { if (v.x >= 0.0) { return v.x; } else { return v.y; } } float its(in vec3 ro, in vec3 rd, in vec3 lpt, out vec3 pt, out vec3 norm, out float mat) { float mt = MAX_T; for (int i = 0; i < ${D}; i++) { float r = u_s_r[i]; if (r < 0.0) { break; } vec3 ce = u_s_c[i]; float it = ss(sr(ro, rd, ce, r)); if (it > 0.0 && it < mt) { mt = it; norm = sn(lpt, ce); mat = 1.0 + float(i); } } for (int i = 0; i < ${C}; i++) { vec4 l = u_ls[i]; if (length(l) == 0.0) { break; } float it = pr(ro, rd, l); if (it > 0.0 && it < mt) { mt = it; norm = pn(l); mat = -1.0; } } pt = ro + rd * mt; return mt; } float gior(in vec3 pt) { for (int i = ${D} - 1; i >= 0; i--) { float r = u_s_r[i]; if (r < 0.0) { break; } vec3 ce = u_s_c[i]; if (length(ce - pt) < r) { return N_GLASS + float(i); } } return N_AIR; } float cast_ray(in vec3 ro, in vec3 rd, in float nm, inout vec3 lpt) { float ior = N_AIR; for (int i = 0; i < 8; i++) { rd = normalize(rd); ro = ro + float(${E}) * rd; float mat; vec3 norm; vec3 pt; float d = its(ro, rd, lpt, pt, norm, mat); if (d >= MAX_T || d < 0.0) { return 0.0; } if (mat < 0.0) { float A = max(0.0, dot(norm, rd)); float c = 1.0 * float(i) / float(8); float lt = mat / -float(${C} - 1); float light_c = A + mix(-float(${z}), float(${z}), lt); return cbp(light_c, float(${R}), nm + float(${M}) + c) * A; } ro = pt; lpt = pt; float nior = gior(pt + 0.001 * rd); vec3 nrd = refract(rd, norm, ior / nior); if (dot(nrd, nrd) != 0.0) { rd = nrd; } ro = ro + float(${b}) * norm; ior = nior; } return 0.0; } void main(void) { float S[${l}]; for (int c = 0; c < ${l}; c++) { S[c] = 0.0; } vec3 ro; vec3 rd; vec2 res; vec2 tex = gv(); vec2 px = tex * u_r; vec2 margin = vec2(0.0, 0.0); vec2 to_edge = vec2(min(u_r.x - px.x, px.x), min(u_r.y - px.y, px.y)) - margin; if (to_edge.x < 0.0 || to_edge.y < 0.0) { o_col = vec4(100.0, 100.0, 100.0, 1.0); return; } rord(tex, ro, rd, res); float seed = u_s; int casts = 4; float w = float(${S}) / float(casts); vec3 lp = vec3(0.0); for (int i = 0; i < casts; i++) { vec2 aa = N2(tex, seed) / (u_r * u_Ts); vec3 trd = normalize(rd + vec3(aa, 0.0)); float nm = N(tex, seed); float A = cast_ray(ro, trd, nm, lp) * w; for (int c = 0; c < ${l}; c++) { float t = (float(c) + 0.5) / float(${l}); S[c] += cbp(${x?"1.0 - nm":"nm"}, float(${N}), t) * A; } } vec4 l_col = texture(u_S0, v_tex); vec4 n_col = vec4(col(S), 1.0); float t = 1.0 / u_st; o_col = l_col * (1.0 - t) + max(n_col * t, 0.0); }\n`;function yt(t,e,r){const n=rt(t,e,r,new at,new at(1,1)),i=new tt(t,e,r),o=i.add();return{spectralShader:et(t,pt,["u_r","u_obs","u_S0","u_st","u_t","u_s","u_sxy","u_s_r","u_s_c","u_eye","u_fov","u_ls","u_Ts","u_Ti"],n,!0),displayShader:et(t,xt,["u_r","u_S0"],n,!0),bufferPool:i,buffer:o,width:e,height:r}}function Tt(t,e,r,n,i,s){const a=i.map((t=>[t.center.x,t.center.y,t.center.z])).flat(),u=i.map((t=>t.radius));u.length<D&&u.push(-1);const c=s.map((t=>[t.norm.x,t.norm.y,t.norm.z,t.offset])).flat();for(;c.length<4*C;)c.push(0);nt(t,e,r.read(),r.write(),(()=>{t.uniform3fv(e.u_obs,ft),t.uniform1f(e.u_st,n),t.uniform1f(e.u_t,n/mt),t.uniform1f(e.u_s,o(-1,1)),t.uniform2f(e.u_sxy,o(-1,1),o(-1,1)),t.uniform3fv(e.u_s_c,a),t.uniform1fv(e.u_s_r,u),t.uniform3f(e.u_eye,ht.x,ht.y,ht.z),t.uniform1f(e.u_fov,O),t.uniform4fv(e.u_ls,c),t.uniform2f(e.u_Ts,H[1],H[0]),t.uniform2f(e.u_Ti,q[1],H[0]-q[0]-1)}))}function gt(t,e,r,n,i){t.canvas.width=e.width,t.canvas.height=e.height,Tt(t,e.spectralShader,e.buffer,r,n,i),e.buffer.flip(),nt(t,e.displayShader,e.buffer.read(),null,null)}class wt{constructor(t,e,r=3,n=[]){this.gen=t,this.rank=e,this.N=r,this.samples=n}sample(){let t=Number.MAX_VALUE,e=null;for(let r=0;r<this.N;r++){const r=this.gen(),n=this.samples.map((t=>this.rank(t,r))).reduce(((t,e)=>t+e),0);n<t&&(t=n,e=r)}return this.samples.push(e),e}}class At{constructor(t,e,r=[]){this.gen=t,this.filter=e,this.samples=r}sample(){let t=!1,e=null;for(;!t;)e=this.gen(),t=this.filter(e)&&this.samples.every((t=>this.filter(e,t)));return this.samples.push(e),e}}function Et(){let t=window.innerWidth,r=window.innerHeight;new at(0,0);const n=new at(t,r).floor(),[i,a]=[n.x,n.y],u=ut(i,a,"display"),c=V(u);if(!c)return;const l=yt(c,i,a),f=(new lt(0,1,0).cross(ht.normalize()),new lt(1,1.5,Y)),h=[{radius:1,center:(t=>{let e=o(.15,1),r=o(.15,1);const n=1*e/12*Math.PI*(s()?-1:1),i=1*r/12*Math.PI*(s()?-1:1);return new lt(0,0,t).rotateY(n).rotateX(i)})(.001)}],d=new wt((()=>{const t=h.length/(D-1),e=ot(P,L,I(t));return{center:(t=>{let e=o(),r=o();const n=e*Math.PI*2,i=r*Math.PI*2;return new lt(0,0,t).rotateY(n).rotateX(i)})(ot(0,$-e,Math.sqrt(o()))).mul3(f),radius:e}}),((t,e)=>{const r=t.center.x-e.center.x,n=t.center.y-e.center.y;return-1*(r*r+n*n)}),Math.floor(o(6,10)),[]);for(;h.length<D;)h.push(d.sample());const _=[ht.normalize()],m=new At((()=>new lt(0,0,1).rotateX(o(2*Math.PI)).rotateY(o(2*Math.PI))),((t,e)=>null==e?t.z<.49:t.dot(e)<.3),_),x=Array(C).fill(null).map((()=>({norm:m.sample().rotateX(0),offset:-50})));let v=1;!function t(){v>=mt+1?document.title="FULL_SPECTRUM":(gt(c,l,v,h,x),v++,document.title=`FULL_SPECTRUM (${st(v/mt*100,1)}%)`,window.requestAnimationFrame(t))}(),window.addEventListener("keydown",(t=>{if("d"==t.key){const t=q[0].toString().padStart(2,"0"),r=q[1].toString().padStart(2,"0");ct(u,`FULL_SPECTRUM_${e}_${t}x${r}`)}}))}Et(); }],