Deck.transition('slam',{ dur:1.05, frag:`void main(){ if(p<=0.){o=texture(tA,vUv);return;} if(p>=1.){o=texture(tB,vUv);return;} float fall=pow(sat(p/.62),2.3); float hit=max(p-.62,0.); float bounce=.041*sin(hit*32.)*exp(-hit*15.)*step(.62,p); float edge=1.-fall+bounce+.055*(vUv.x-.5)*(1.-fall); vec2 b=vUv+vec2(.008*sin(hit*81.)*exp(-hit*17.)*step(.62,p),-edge); vec3 c=texture(tA,vUv).rgb*(1.-.48*exp(-abs(vUv.y-edge)*21.)); c=mix(c,texture(tB,clamp(b,0.,1.)).rgb,smoothstep(-.009,.002,b.y)); c=mix(c,vec3(.19,.105,.061),.85*exp(-abs(b.y)*170.)*(1.-smoothstep(.02,.23,hit))); float dust=smoothstep(.48,.72,vnoise(vec2(vUv.x*27.,vUv.y*53.-hit*22.))); c=mix(c,vec3(.79,.65,.48),dust*.59*exp(-abs(b.y)/( .035+hit*.65))*smoothstep(.47,.65,p)*(1.-smoothstep(.71,.99,p))); for(int i=0;i<6;i++){ float j=float(i), h=hash12(vec2(j,6.)), t=sat((p-.43)/.57); vec2 q=(vUv-vec2(h+(h-.5)*t*.43,.36+(j-2.)*.036-(.12+h*.54)*t))*vec2(uRes.x/uRes.y,1.); q=rot2(j*1.17+t*(5.+j))*q; float sheet=1.-smoothstep(-.001,.002,sdBox(q,vec2(.020+h*.019,.009+.011*abs(cos(j+8.*t))))); float crease=smoothstep(.006,-.008,q.x); c=mix(c,mix(vec3(.73,.65,.53),vec3(.95,.90,.78),crease),sheet*smoothstep(.01,.13,t)*(1.-smoothstep(.64,1.,t))); } o=vec4(c,1.); }` }); Deck.scene({ id:'dominoes',title:'Thirty steps',enterWith:'slam', post:{tone:'none',bloom:0,vignette:.12,grain:.018}, beats:[{dur:2.2,hold:4},{dur:6.6,hold:4},{dur:4.2,hold:5}], notes:[ 'Here is why people who study this expect it to be sudden. Suppose each AI can build the next one, and the next one is only one and a half times better. That does not sound like much.', 'A real domino can knock over one that is one and a half times its size. The first is a centimetre tall. Ten steps later it is thirty-eight centimetres. Twenty steps, twenty-two metres. Step thirty is 1.28 kilometres, taller than any building on Earth.', 'Nothing changed between the steps. Same push, same ratio, thirty times.' ], setup(d){ const U={uEye:[0,0,0],uAim:[0,0,0],uOrigin:[0,0],uClock:0,uTrack:0,uTown:0,uRoom:0,uFinal:0,uFirst:1}; return { U, bg:d.pass(` uniform vec3 uEye,uAim; uniform vec2 uOrigin; uniform float uClock,uTrack,uTown,uRoom,uFinal,uFirst; const vec3 sun=vec3(-.55,.76,.345); vec2 turn(vec2 v,float a){ float c=cos(a),s=sin(a); return vec2(c*v.x-s*v.y,s*v.x+c*v.y); } vec3 safeRay(vec3 r){return mix(vec3(-1.),vec3(1.),step(0.,r))*max(abs(r),vec3(.00001));} vec2 slabs(vec3 a,vec3 v,vec3 b){ vec3 lo=(-b-a)/v,hi=(b-a)/v; vec3 m=min(lo,hi),n=max(lo,hi); return vec2(max(m.x,max(m.y,m.z)),min(n.x,min(n.y,n.z))); } vec3 face(vec3 p,vec3 b){ vec3 f=abs(p)/b; if(f.x>max(f.y,f.z))return vec3(sign(p.x),0.,0.); if(f.y>f.z)return vec3(0.,sign(p.y),0.); return vec3(0.,0.,sign(p.z)); } float bar(vec2 p,vec2 xy,vec2 wh){ return 1.-smoothstep(-.013,.018,sdBox(p-xy,wh)-.014); } float glyph(vec2 p,int n){ int bits=63; if(n==1)bits=6; if(n==2)bits=91; if(n==3)bits=79; if(n==4)bits=102; if(n==5)bits=109; if(n==6)bits=125; if(n==7)bits=7; if(n==8)bits=127; if(n==9)bits=111; float k=0.; if((bits&1)!=0)k=max(k,bar(p,vec2(0.,.45),vec2(.225,.035))); if((bits&2)!=0)k=max(k,bar(p,vec2(.265,.225),vec2(.033,.181))); if((bits&4)!=0)k=max(k,bar(p,vec2(.265,-.225),vec2(.033,.181))); if((bits&8)!=0)k=max(k,bar(p,vec2(0.,-.45),vec2(.225,.035))); if((bits&16)!=0)k=max(k,bar(p,vec2(-.265,-.225),vec2(.033,.181))); if((bits&32)!=0)k=max(k,bar(p,vec2(-.265,.225),vec2(.033,.181))); if((bits&64)!=0)k=max(k,bar(p,vec2(0.),vec2(.225,.035))); return k; } vec3 porcelain(vec3 p,vec3 b,vec3 n,float h,int num){ vec3 ivory=vec3(.95,.901,.813); float k=0.; if(n.z>.5){ vec2 g=vec2(p.x,p.y-.105*h)/(.235*h); if(num<10){ g.x-=(num==1?.122:0.); k=glyph(g,num); }else{ k=max(glyph(g+vec2(.374,0.),num/10),glyph(g-vec2(.374,0.),num%10)); } float seam=abs(p.y+.17*h)/h; ivory-=.14*(1.-smoothstep(.002,.008,seam))*smoothstep(.9,.79,abs(p.x)/b.x); float inset=sdBox(p.xy,b.xy-vec2(.020*h)); ivory-=.08*(1.-smoothstep(.001,.008,abs(inset)/h)); ivory=mix(ivory,vec3(.231,.164,.12),k); } return ivory; } vec3 sky(vec3 rd){ float y=rd.y; vec3 c=mix(vec3(.94,.829,.670),vec3(.57,.70,.744),smoothstep(-.035,.62,y)); float bank=vnoise(vec2(rd.x*6.+rd.z*3.,y*15.+uTime*.018)); c=mix(c,vec3(.96,.91,.806),.25*smoothstep(.51,.81,bank)*smoothstep(.04,.23,y)); float u=atan(rd.x,-rd.z); float m=.036+.10*vnoise(vec2(u*7.,1.3))+.035*vnoise(vec2(u*23.,7.)); float m2=.009+.064*vnoise(vec2(u*11.+12.,4.))+.017*vnoise(vec2(u*46.,4.)); c=mix(c,vec3(.67,.65,.599),uTown*(1.-smoothstep(m-.003,m+.006,y))); c=mix(c,vec3(.53,.551,.526),uTown*(1.-smoothstep(m2-.003,m2+.005,y))); vec3 room=mix(vec3(.70,.50,.34),vec3(.94,.81,.64),smoothstep(-.08,.45,y+rd.x*.17)); float shaft=abs(rd.x+.36+rd.y*.51); room=mix(room,vec3(.98,.88,.72),.39*(1.-smoothstep(.22,.52,shaft))); return mix(room,c,uTown); } void main(){ vec2 q=design(vUv); vec2 p=(q-uOrigin)*vec2(1.,-1.)/1080.; vec3 w=normalize(uAim-uEye),x=normalize(cross(w,vec3(0.,1.,0.))),y=cross(x,w); vec3 rd=normalize(w*1.3+p.x*x+p.y*y), ro=uEye; vec3 ray=safeRay(rd); vec3 air=sky(rd),c=air; float floorT=rd.y<-.0001 ? -ro.y/rd.y : 200.; float best=min(200.,floorT); vec3 pt=ro+rd*min(floorT,200.); if(floorT<200.){ vec2 g=pt.xz; float grain=vnoise(g*vec2(2.8,120.))*.6+vnoise(g*vec2(.62,24.))*.4; vec3 desk=mix(vec3(.61,.396,.231),vec3(.82,.609,.385),grain); float stripe=abs(fract(g.y*.87+.27)-.5); desk*=1.-.22*(1.-smoothstep(.0,.014,stripe)); desk+=.11*exp(-dot(g-vec2(-1.,.3),g-vec2(-1.,.3))*.28); for(int j=0;j<5;j++){ float f=float(j),m=hash12(vec2(f,27.)); vec2 a=turn((g-vec2(-.63+f*.19,1.21+m*.43))*vec2(1.,1.45),m*6.); float ang=atan(a.y,a.x); float curl=abs(length(a)-(.043+.006*ang)); float sliver=(1.-smoothstep(.007,.013,curl))*smoothstep(-2.7,-2.45,ang)*(1.-smoothstep(2.4,2.7,ang)); desk=mix(desk,mix(vec3(.56,.28,.10),vec3(.94,.71,.42),smoothstep(.006,.010,curl)),sliver*.92); } vec3 boards=mix(desk,vec3(.745,.539,.355),.56); boards*=1.-.15*(1.-smoothstep(.006,.019,abs(fract(g.y*2.2)-.5))); vec3 field=mix(vec3(.69,.637,.492),vec3(.805,.755,.621),vnoise(g*.71)); float roadZ=abs(mod(g.y+1.12,2.24)-1.12); float roadX=abs(mod(g.x+1.02,2.04)-1.02); float road=max(1.-smoothstep(.18,.235,roadZ),1.-smoothstep(.093,.134,roadX)*smoothstep(.81,1.42,abs(g.y))); vec3 paving=vec3(.631,.605,.551)+.035*vnoise(g*13.); float dash=(1.-smoothstep(.011,.020,roadZ))*smoothstep(.47,.52,fract(g.x*1.9)); field=mix(field,paving,road)+vec3(.08,.07,.048)*dash; c=mix(mix(desk,boards,uRoom),field,uTown); } float shade=1.; vec3 obj=c,nrm=vec3(0.,1.,0.); float ceramic=0.; for(int i=0;i<8;i++){ float id=uFirst+float(i); if(id>29.)break; float h=.45*pow(1.5,id-1.-uTrack); if(h>4.7)break; float xpos=2.05*h-1.5725; float lean=1.44*pow(smoothstep(id-1.03,id+.06,uClock),1.24); float hw=h*.244; vec3 pivot=vec3(xpos+hw,0.,0.); vec3 a=ro-pivot; a.xy=turn(a.xy,lean)-vec2(-hw,h*.5); vec3 v=vec3(turn(rd.xy,lean),rd.z); vec3 b=vec3(hw,h*.5,h*.093); vec2 it=slabs(a,safeRay(v),b); if(it.x>0.&&it.x.001){ float h=mix(1.2,6.7,uFinal); vec3 b=vec3(.222*h,h*.5,.082*h); vec3 a=ro-vec3(mix(4.8,.60,uFinal),b.y,-.51); vec2 it=slabs(a,ray,b); if(it.x>0.&&it.x0.&&it.x.09){ vec2 cell=floor(ro.xz/vec2(1.02,1.12)); vec2 stepDir=sign(ray.xz); vec2 stride=abs(vec2(1.02,1.12)/ray.xz); vec2 edge=((cell+step(0.,ray.xz))*vec2(1.02,1.12)-ro.xz)/ray.xz; float start=0.; for(int i=0;i<23;i++){ if(start>min(best,29.))break; vec2 mid=(cell+.5)*vec2(1.02,1.12); float r=hash12(cell+7.),r2=hash12(cell+34.); if(abs(mid.y)>1.18 && r>.14){ float tall=step(5.4,abs(mid.y))*step(.78,r2); float houseH=(.16+.21*r)*mix(1.,7.8,tall)*smoothstep(.09,.88,uTown); vec2 size=vec2(.20+.14*r2,.23+.09*r); vec2 ctr=mid+vec2(r-.5,r2-.5)*.19; vec3 b=vec3(size.x,houseH*.5,size.y); vec3 a=ro-vec3(ctr.x,b.y,ctr.y); vec2 it=slabs(a,ray,b); if(it.x>0.&&it.x.005){ vec3 ar=ro-vec3(ctr.x,houseH+rh*.5,ctr.y); vec2 cap=slabs(ar,ray,vec3(size.x+.026,rh*.5,size.y+.028)); vec3 nn=vec3(0.,1.,0.); float slope=rh/(size.y+.028); for(int j=0;j<2;j++){ float z=float(j)*2.-1.; vec3 nr=vec3(0.,1.,z*slope); float dd=dot(rd,nr),hh=rh*.5-dot(ar,nr); if(abs(dd)<.00001){if(hh<0.)cap.y=-1.;} else if(dd>0.)cap.y=min(cap.y,hh/dd); else if(hh/dd>cap.x){cap.x=hh/dd;nn=normalize(nr);} } if(cap.x>0.&&cap.x.62){ for(int i=0;i<2;i++){ float j=float(i),cx=-2.+j*6.7,cz=-5.8-j*2.,ch=1.25+j*.53; for(int k=0;k<4;k++){ vec3 ctr=vec3(cx,ch*.5,cz),b=vec3(.018,ch*.5,.018); if(k==1){ctr=vec3(cx+.38,ch,cz);b=vec3(.81,.018,.023);} if(k==2){ctr=vec3(cx+.22,ch-.095,cz);b=vec3(.55,.012,.014);} if(k==3){ctr=vec3(cx+.95,ch-.23,cz);b=vec3(.008,.23,.008);} vec2 it=slabs(ro-ctr,ray,b); if(it.x>0.&&it.x.001){ const o=U.uEye,t=U.uAim; let wx=t[0]-o[0],wy=t[1]-o[1],wz=t[2]-o[2]; const len=Math.hypot(wx,wy,wz); wx/=len;wy/=len;wz/=len; const hor=Math.hypot(wx,wz),xx=-wz/hor,xz=wx/hor; const yx=-xz*wy,yy=xz*wx-xx*wz,yz=xx*wy; let x0=1e9,x1=-1e9,y0=1e9,y1=-1e9; for(let i=0;i<8;i++){ const x=-.65+((i&1)?.110:-.110)-o[0]; const y=((i&2)?.45:0)-o[1]; const z=((i&4)?.042:-.042)-o[2]; const f=1404/(wx*x+wy*y+wz*z); const px=U.uOrigin[0]+f*(xx*x+xz*z); const py=U.uOrigin[1]-f*(yx*x+yy*y+yz*z); x0=Math.min(x0,px);x1=Math.max(x1,px); y0=Math.min(y0,py);y1=Math.max(y1,py); } d.select(x0-12,y0-13,x1-x0+24,y1-y0+26,{a}); } const countShow=s.k(1,.84,1.55,L); if(countShow>0){ const n=final>.34?30:Math.min(27,Math.floor(clock+1.06)); const metres=.01*Math.pow(1.5,n-1); const height=n===30?'1.3 km':n===20?'22 m':metres<1?Math.round(metres*100)+' cm':Math.round(metres)+' m'; d.text(n===30?'30':String(n),{x:145,y:122,size:176,font:'mono',color:ink,show:countShow,style:'fade'}); d.text(height,{x:153,y:320,size:52,font:'mono',color:ink,show:countShow,style:'fade'}); } } });