Deck.transition('line',{dur:1.3,frag:`void main(){ float a=smoothstep(0.,.5,p), b=smoothstep(.5,1.,p); float s=p<.5?1.-a:b; // picture height: 1 -> 0 -> 1 float y=(vUv.y-.5)/max(s,.0005)+.5; vec2 uv=vec2(vUv.x,clamp(y,0.,1.)); vec3 c=p<.5?texture(tA,uv).rgb:texture(tB,uv).rgb; c*=step(abs(y-.5),.5)*(1.+1.5*(1.-s)); // squashed light gets denser float g=sin(p*3.14159); g*=g; c+=vec3(1.,.82,.55)*g*3.*(.003/(abs(vUv.y-.5)+.003)); // the single horizontal line of light o=vec4(c,1.); }`}); Deck.scene({ id:'aim', title:'Aim', enterWith:'line', post:{bloom:.7,threshold:1,vignette:.3,grain:.035,exposure:1,tone:'aces'}, beats:[{dur:3,hold:4},{dur:5,hold:5},{dur:6,hold:5},{dur:6,hold:5}], notes:[ 'Everything so far assumed one thing: that it aims where we meant it to. Alignment is the question of what it actually wants.', 'Suppose we get it almost right. One degree off. At ten metres that is seventeen centimetres. Every demo and every test happens at ten metres.', 'But the same degree keeps going. At the Moon you miss by about 6,700 kilometres, almost two whole Moons. At the nearest star you miss by 4,700 times the distance from the Earth to the Sun. It is only geometry: the tangent of one degree times the distance.', 'Follow the two lines out to the nearest star and they are nowhere near each other. Nothing went wrong along the way. The whole error was there at the start, too small to see. (Pause.) So the aim matters more than the speed. And there are two places it could land.' ], setup(d){ const U={uRo:[0,0,0],uTa:[0,0,0],uF:1.6,uBeam:0,uBeamA:0,uBow:1,uDraw:0,uSpace:0,uFar:0,uLen:0,uQuiet:0,uM:[0,0]}, q=[0,0]; // world point -> design units, same camera maths as the shader const project=(x,y,z)=>{ const o=U.uRo,t=U.uTa; let wx=t[0]-o[0],wy=t[1]-o[1],wz=t[2]-o[2],l=Math.hypot(wx,wy,wz); wx/=l;wy/=l;wz/=l; l=Math.hypot(wx,wz); const ux=wz/l,uz=-wx/l, vx=wy*uz,vy=wz*ux-wx*uz,vz=-wy*ux; x-=o[0];y-=o[1];z-=o[2]; const cz=x*wx+y*wy+z*wz; q[0]=960+1080*U.uF*(x*ux+z*uz)/cz; q[1]=540-1080*U.uF*(x*vx+y*vy+z*vz)/cz; return q }; const bracket=(c,x0,y0,x1,y1,a,col)=>{ if(a<=0)return; const dx=x1-x0,dy=y1-y0,l=Math.hypot(dx,dy)||1,nx=-dy/l*12,ny=dx/l*12,mx=x0+dx*.5,my=y0+dy*.5,h=a*.5; c.save(); c.globalAlpha=Math.min(1,a); c.strokeStyle=col; c.lineWidth=3; c.lineCap='round'; c.beginPath(); c.moveTo(mx-dx*h,my-dy*h); c.lineTo(mx+dx*h,my+dy*h); c.moveTo(x0-nx,y0-ny); c.lineTo(x0+nx,y0+ny); c.moveTo(x1-nx,y1-ny); c.lineTo(x1+nx,y1+ny); c.stroke(); c.restore(); }; return { U, project, bracket, hall:d.pass(`uniform vec3 uRo,uTa; uniform float uF,uBeam,uBeamA,uBow,uDraw,uSpace,uFar,uLen,uQuiet; uniform vec2 uM; const vec3 S=vec3(.8018,.5345,-.2673); // unit vector toward the low sun, outside the right wall const vec3 SUN=vec3(1.,.72,.42); const vec3 AMB=vec3(.42,.35,.27); float seg(vec2 a,vec2 b,vec2 c){ vec2 pa=a-b,ba=c-b; return length(pa-ba*sat(dot(pa,ba)/dot(ba,ba))); } float win(vec2 a){ // tall arched, gridded window; a.x along the wall, a.y height vec2 w=vec2(mod(a.x,2.4)-1.2,a.y); float dd=min(sdBox(w-vec2(0.,1.95),vec2(.7,1.25)),length(w-vec2(0.,3.2))-.7); vec2 g=abs(fract(w/.35+.5)-.5)*.35; return smoothstep(.03,-.03,dd)*smoothstep(.02,.035,min(g.x,g.y)); } float bwin(vec2 a){ return win(vec2(a.x-.7,a.y))*step(1.,a.x)*step(a.x,2.8); } // one window on the back wall, right of the target float lit(vec3 q){ float tt=(4.-q.x)/S.x; vec2 a=q.zy+S.zy*tt; return win(a)*step(a.x,9.7)*step(-4.,a.x); } // is this point in a window's light? vec3 wallc(vec2 a){ float post=step(abs(fract(a.x/2.4+.5)-.5),.04); vec3 wood=vec3(.2,.125,.07)*(.7+.5*fbm(a*vec2(3.,14.))); vec3 pl=vec3(.44,.38,.28)*(.9+.15*fbm(a*2.)); return mix(pl,wood,max(max(post,step(a.y,1.)),step(abs(a.y-3.),.08))); } float lineD(vec3 ro,vec3 rd,vec3 a,vec3 b,out float sc){ // distance from the view ray to a segment, and where along it vec3 ba=b-a,oa=ro-a; float l2=dot(ba,ba),bd=dot(ba,rd),od=dot(oa,rd),ob=dot(oa,ba); sc=sat((ob-bd*od)/max(l2-bd*bd,1e-5)); vec3 pt=a+ba*sc; float tr=max(dot(pt-ro,rd),0.); return length(ro+rd*tr-pt); } float crat(vec2 u,float sc){ vec2 g=u*sc,id=floor(g),f=fract(g)-.5; float rn=hash12(id+sc); vec2 o2=(vec2(hash12(id+3.1),hash12(id+7.7))-.5)*.4; float dd=length(f-o2)/(.12+.2*rn); return (-.3*smoothstep(1.,.7,dd)+.3*smoothstep(.3,0.,abs(dd-1.))*dot(normalize(f-o2+1e-4),vec2(.77,-.63)))*step(.35,rn); } vec3 hall(vec2 p){ vec3 w=normalize(uTa-uRo),u=normalize(cross(vec3(0.,1.,0.),w)),v=cross(w,u),rd=normalize(p.x*u+p.y*v+uF*w),ro=uRo; rd+=vec3(1e-4)*step(abs(rd),vec3(1e-4)); vec3 tb=(mix(vec3(-4.,0.,-8.),vec3(4.,4.6,11.),step(0.,rd))-ro)/rd; // inside of the room box float t=min(tb.x,min(tb.y,tb.z)); vec3 q=ro+rd*t; vec3 n=vec3(0.,1.,0.),alb=vec3(.1),em=vec3(0.); float ao=1.-.5*smoothstep(2.,4.6,q.y); if(t==tb.y){ if(rd.y<0.){ float id=floor(q.x/.16),f=fract(q.x/.16); // plank floor, polished alb=vec3(.36,.2,.09)*(.65+.5*hash12(vec2(id,3.)))*(.75+.5*fbm(vec2(q.x*40.,q.z*1.2+id*7.))); alb*=.5+.5*smoothstep(0.,.05,min(f,1.-f)); vec3 rr=vec3(rd.x,-rd.y,rd.z); if(rr.z>0.){ vec3 pb=q+rr*(11.-q.z)/rr.z; em=vec3(1.,.8,.55)*1.4*bwin(pb.xy)*(.05+.5*pow(1.-abs(rd.y),4.)); } } else { n=vec3(0.,-1.,0.); alb=vec3(.1,.07,.045)*(.6+.4*step(.3,fract(q.z/1.5))); } } else if(t==tb.x){ if(rd.x>0.){ n=vec3(-1.,0.,0.); alb=wallc(q.zy); float wn=win(q.zy)*step(q.z,9.7)*step(-4.,q.z); float tree=smoothstep(1.1,1.9,q.y+.5*fbm(vec2(q.z*2.,2.))); alb*=1.-wn; em=mix(vec3(.25,.3,.12),vec3(1.,.82,.58)*2.2,tree)*wn; } else { n=vec3(1.,0.,0.); alb=wallc(q.zy); } } else { n=vec3(0.,0.,-1.); alb=wallc(q.xy); float bw=bwin(q.xy); float tree=smoothstep(1.2,2.,q.y+.5*fbm(vec2(q.x*2.5,5.))); alb*=1.-bw; em=mix(vec3(.2,.25,.1),vec3(1.,.85,.62)*1.5,tree)*bw; } float tT=(9.6-ro.z)/rd.z; // the target and its stand, 10 m from the bow if(rd.z>0.&&tT>0.&&tT0.){ float s1,s2; vec3 O=vec3(0.,1.3,-.4); float d1=lineD(ro,rd,O,vec3(.17,1.3,9.6),s1), d2=lineD(ro,rd,O,vec3(0.,1.3,9.6),s2); col+=vec3(1.,.55,.2)*uBeamA*smoothstep(uBeam,uBeam-.03,s1)*(.00005/(d1*d1+.00002)); // the shot col+=vec3(.5,.7,1.)*uBeamA*smoothstep(uBeam,uBeam-.03,s2)*(.000012/(d2*d2+.00002)); } // the intent vec2 dq=design(vUv); col*=1.-.5*smoothstep(900.,300.,dq.x)*smoothstep(620.,200.,dq.y); // calm corner for the headline if(uBow>0.){ vec2 bp=p-vec2((1.-uBow)*.95+.004*sin(uTime*.7),.003*sin(uTime*.9)); float nx=mix(.76,.95,uDraw); float lim=max(abs(length(bp-vec2(1.32,0.))-.9)-.013-.007*smoothstep(.1,0.,abs(bp.y+.03)),bp.x-1.); float dd=min(lim,min(seg(bp,vec2(.667,.62),vec2(nx,-.03)),seg(bp,vec2(.667,-.62),vec2(nx,-.03)))-.0025); dd=min(dd,seg(bp,vec2(nx,-.03),vec2(nx-.62,-.03))-.0045); dd=min(dd,length((bp-vec2(.44,-.06))*vec2(1.,.75))-.04); dd=min(dd,seg(bp,vec2(.47,-.08),vec2(1.1,-.24))-.036); col=mix(col,vec3(.012,.009,.007),smoothstep(.004,-.003,dd)); } // drawn bow, near and dark return col; } vec3 space(vec2 p){ vec2 eo=mix(vec2(-.86,-.08),vec2(-.8,-.26),uFar); float zm=mix(1.,6.,uFar); vec2 q=(p-eo)*zm; const vec2 DI=vec2(.9997,.025), NI=vec2(-.025,.9997), DA=vec2(.9534,.3017); vec3 c=vec3(.012,.016,.034)+vec3(.03,.035,.07)*smoothstep(.3,.9,fbm(p*1.6+vec2(4.,1.)+q*.03)); vec2 sg=(p-eo*.5)*mix(1.,.8,uFar)*46., si=floor(sg); float st=hash12(si); vec2 sf=fract(sg)-.5-(vec2(hash12(si+5.),hash12(si+9.))-.5)*.6; c+=vec3(.7,.8,1.)*step(.8,st)*smoothstep(.12,0.,length(sf))*(.3+1.5*fract(st*37.))*(.75+.25*sin(uTime*1.5+st*90.)); vec2 ev=q-vec2(-.45,0.); float de=(length(ev)-.45)/zm; // Earth's night limb, where the lines start vec3 ec=vec3(.004,.006,.012)+vec3(1.,.5,.15)*.5*smoothstep(.62,.8,fbm(ev*24.))*step(.5,hash12(floor(ev*300.))); c=mix(c,ec,smoothstep(.002,-.002,de)); c+=vec3(.25,.5,1.)*(1.2*exp(-abs(de)*220.)+.25*exp(-max(de,0.)*30.)); vec2 md=(q-vec2(1.076,.183))/.09; float r2=dot(md,md); // the Moon, sitting inside the gap if(r2<1.2){ vec3 n=vec3(md,sqrt(max(1.-r2,0.))); float dif=sat(dot(n,vec3(-.55,.45,.7))); vec2 mu=md*(1.+.25*r2); float al=.34+.16*fbm(mu*2.5+7.)+crat(mu,3.5)+.6*crat(mu+5.3,8.); vec3 mc=vec3(.95,.92,.86)*max(al,.05)*dif*1.3+vec3(.006,.008,.014); c=mix(c,mc,smoothstep(.002,-.002,(sqrt(r2)-1.)*.09/zm)); } vec2 qr=q-vec2(1.2,.03); float rl=length(qr), reach=smoothstep(1.15,1.25,uLen); // reticle at the aim point float ring=smoothstep(.0025,.0008,abs(rl-.05)/zm); float tk=smoothstep(.0025,.0008,min(abs(qr.x),abs(qr.y))/zm)*step(.035,rl)*step(rl,.075); c+=vec3(.6,.8,1.)*1.3*(ring+tk)*reach*(1.-.7*uFar); float aI=dot(q,DI),aA=dot(q,DA),qt=1.-.45*uQuiet; float dI=(aI<0.?length(q):abs(dot(q,NI)))/zm, dA=(aA<0.?length(q):abs(q.x*DA.y-q.y*DA.x))/zm; c+=vec3(.55,.75,1.)*qt*smoothstep(uLen,uLen-.1,aI)*(.0000022/(dI*dI+.0000022)); // intended c+=vec3(1.,.55,.2)*qt*smoothstep(uLen,uLen-.1,aA)*(.000005/(dA*dA+.000002)); // actual vec2 sd=(q-vec2(8.697,.2175))/zm; float sl=dot(sd,sd); // the nearest star, on the intended line c+=vec3(1.,.88,.7)*(.00012/(sl+.00003)+.5*exp(-abs(sd.y)*500.)*exp(-abs(sd.x)*14.)+.5*exp(-abs(sd.x)*500.)*exp(-abs(sd.y)*14.)); return c*(1.-.2*uQuiet); } void main(){ vec2 p=(design(vUv)-vec2(960.,540.))*vec2(1.,-1.)/1080.; vec3 c=vec3(0.); if(uSpace<1.) c=hall(p); if(uSpace>0.) c=mix(c,space(p+uM*.004),smoothstep(.25,1.,uSpace)); o=vec4(c,1.); }`,'aim hall') } }, draw(s,d,r){ const U=r.U,E=d.E,L=E.lin,c=d.ctx2d, k1=s.k(1,0,2.6), sp=s.k(2,0,2.4), far=s.k(3,.3,4.2), en=1-E.io3(s.enter), mx=s.mouse.x, my=s.mouse.y; U.uRo[0]=-.5-.5*k1+.6*sp+.04*Math.sin(s.t*.2)+mx*.08; U.uRo[1]=1.5+.3*k1-.3*sp+my*.04; U.uRo[2]=-1-1.2*en+8.2*k1+1.5*sp; U.uTa[0]=.6-1.35*k1+.85*sp; U.uTa[1]=1.6-.25*k1-.05*sp; U.uTa[2]=9.6; U.uF=1.6-.4*k1+1.5*sp; U.uBeam=.7+.34*s.k(1,2.6,3.8,E.out3); U.uBeamA=s.k(1,2.4,2.8,L); U.uBow=1-s.k(1,0,1.4); U.uDraw=s.k(0,.3,3); U.uSpace=sp; U.uFar=far; U.uLen=3*s.k(2,1.4,4.6)+13*far; U.uQuiet=s.k(3,4.5,6); U.uM[0]=mx; U.uM[1]=my; r.hall.draw(U); const cream='#f3ead6', ink='#1b140e'; // beat 2: dimension bracket between the gold and the hit, glued to the target by the shared camera let g=r.project(0,1.3,9.6); const gx=g[0],gy=g[1]; g=r.project(.17,1.3,9.6); const hx=g[0],hy=g[1]; const a1=s.k(1,3.8,4.6,L)*(1-s.k(2,0,.5,L)); if(a1>0){ d.rect(gx-1,gy-96,2,84,ink,a1); d.rect(hx-1,hy-96,2,84,ink,a1); r.bracket(c,gx,gy-84,hx,hy-84,a1,ink); } d.text('10 metres: 17 cm',{x:(gx+hx)/2,y:gy-146,size:28,font:'mono',color:ink,align:'center',style:'fade',show:s.k(1,4,5,L),hide:s.k(2,0,.5,L)}); // beats 3 and 4: brackets in the space picture (same mapping as the shader's q) const ex=-.86+.06*far, ey=-.08-.18*far, zm=1+5*far, ox=960+1080*(ex-mx*.004), oy=540-1080*(ey-my*.004), sc=1080/zm; const a2=s.k(2,4.4,5.2,L)*(1-s.k(3,0,.6,L)); r.bracket(c,ox+1.2*sc,oy-.03*sc,ox+1.1913*sc,oy-.377*sc,a2,cream); d.text('6,700 km',{x:ox+1.2*sc+30,y:oy-.2*sc-22,size:38,font:'mono',color:cream,style:'fade',show:s.k(2,4.8,5.8,L),hide:s.k(3,0,.6,L)}); const a3=s.k(3,4.2,5,L); r.bracket(c,ox+8.697*sc,oy-.2175*sc,ox+8.634*sc,oy-2.733*sc,a3,cream); const au=d.text('4,700 au',{x:ox+8.67*sc+30,y:oy-1.47*sc-34,size:38,font:'mono',color:cream,style:'fade',show:s.k(3,4.6,5.6,L)}); d.text('nearest star',{x:au.x,y:au.y+au.h+10,size:24,font:'mono',color:'#9aa3b5',style:'fade',show:s.k(3,4.8,5.8,L)}); d.text('illustration, not to scale',{x:150,y:962,size:28,font:'mono',color:'#9aa3b5',style:'fade',show:s.k(2,2.6,3.6,L)}); d.text('What does\nit want?',{x:150,y:150,size:130,color:cream,show:s.k(0,.4,1.8,L),hide:s.k(1,0,.6,L)}); d.text('Miss by\none degree.',{x:150,y:150,size:120,color:cream,show:s.k(1,.9,2.2,L),hide:s.k(2,0,.6,L)}); } });