From 90d184279e28fac1141e679552d53ff0573a79b9 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 05:34:36 +0000 Subject: [PATCH 1/5] Boostball: Carbon Star, an exclusive goal explosion for Carbon (first pass) Exclusive gifts table in captains.js, the catalogue line, kit.js listing for captains, the Locker for Carbon, and carbon-star.js drawing the effect. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DfCR7RPoK1UNAvb7iRuPWn --- e63334287a3deaa3/boostball/carbon-star.js | 437 ++++++++++++++++++++++ e63334287a3deaa3/boostball/es.js | 6 +- e63334287a3deaa3/boostball/index.html | 135 ++++++- e63334287a3deaa3/boostball/kit.js | 28 +- e63334287a3deaa3/captains.js | 47 ++- e63334287a3deaa3/cosmetics.js | 1 + e63334287a3deaa3/shop/index.html | 5 +- 7 files changed, 636 insertions(+), 23 deletions(-) create mode 100644 e63334287a3deaa3/boostball/carbon-star.js diff --git a/e63334287a3deaa3/boostball/carbon-star.js b/e63334287a3deaa3/boostball/carbon-star.js new file mode 100644 index 00000000..3437f521 --- /dev/null +++ b/e63334287a3deaa3/boostball/carbon-star.js @@ -0,0 +1,437 @@ +/* + * Boostball: Carbon Star, a goal explosion made for one player (an exclusive gift, see ../captains.js GIFTS and the + * README). Carbon has it, and the captains may wear it too; nobody else is offered it. + * + * index.html fetches this file only when it can be needed: the player signed in here has the gift, or a car in the room + * arrives wearing it. Then it calls window.BoostballCarbonStar(G) once with what it lends (CSAPI in index.html) and gets + * back play(), update(), stop() and the little preview used by the Locker and the captains' Kit. index.html decides + * WHO it plays for (the scorer's account must have the gift, whatever the scorer's data claims); this file only draws. + * + * What it looks like (our own design, in our own palette: near-black and indigo space, ember red and amber for the + * star, a little cool teal in the lattice): + * 1. A dying star: a hot core flares in the goal mouth with long thin rays, then collapses to a point (0 to 0.6 s). + * 2. A ripple races out from the goal and crosses the whole map in about 0.7 s. Behind it the arena is space: the floor + * is a faint honeycomb lattice (carbon's own pattern) floating over the void, every wall, goal, stand, light tower + * and pad is a thin glowing outline, and the sky is a slowly turning nebula full of stars with a red-amber carbon + * star hanging over the scoring goal. + * 3. The cars and the ball are white glowing outlines with a little star dust trailing behind them. + * 4. It holds through the celebration and cross-fades back to the normal arena before the kickoff (index.html says + * how long is left: holdLeft()), and everything is put back exactly as it was. + * No full-screen flash and no strobing for anyone. With the browser's reduced-motion setting there is no flare and no + * ripple: the arena cross-fades into space and back. On Fast graphics and on phones the sky has fewer layers of cloud + * and stars and the star dust is thinner (G.low()). + * + * HOW IT IS DRAWN. The arena's own objects are never changed. Each solid part of the map gets a stand-in mesh sharing + * its geometry, painted with the sky seen through it ("space"), so it hides what is behind it, and every hard edge of the + * map is one merged line set; together they read as an outline drawing of the arena floating in space. Thin parts (the + * glass walls, nets, glows, lines) are hidden as the ripple passes them. Once the ripple has covered everything, the + * arena itself is hidden, so the frame costs about what a normal one does. The cars' and ball's meshes have their + * material swapped for one outline material while it lasts and put back afterwards. Everything here is made once and + * kept (a pool): after a goal the stand-ins leave the scene and nothing new is left behind. + * + * Looks only: nothing here reads or writes the physics, the ball, the score or the room. + */ +window.BoostballCarbonStar=function(G){ +'use strict'; +const THREE=G.THREE,V3=THREE.Vector3; +const clamp=(v,a,b)=>vb?b:v,sm=(a,b,x)=>{x=clamp((x-a)/(b-a),0,1);return x*x*(3-2*x)},rand=(a,b)=>a+Math.random()*(b-a); + +// --------------------------------------------------------------------------------------------------------------------- +// Shaders. One "space" function paints the sky; the stand-ins, the floor and the insides of the outlined cars all use +// it with the direction from the camera, so they line up seamlessly with the sky behind them. +// --------------------------------------------------------------------------------------------------------------------- +const SPACE=` +uniform float uTime,uTurn,uStarK;uniform vec3 uStar; +float h31(vec3 p){p=fract(p*vec3(.1031,.1030,.0973));p+=dot(p,p.yxz+33.33);return fract((p.x+p.y)*p.z);} +float vn(vec3 p){vec3 i=floor(p),f=fract(p);f=f*f*(3.-2.*f); + return mix(mix(mix(h31(i),h31(i+vec3(1.,0.,0.)),f.x),mix(h31(i+vec3(0.,1.,0.)),h31(i+vec3(1.,1.,0.)),f.x),f.y), + mix(mix(h31(i+vec3(0.,0.,1.)),h31(i+vec3(1.,0.,1.)),f.x),mix(h31(i+vec3(0.,1.,1.)),h31(i+vec3(1.,1.,1.)),f.x),f.y),f.z);} +float fbm(vec3 p){float v=0.,a=.5;for(int i=0;i0.){ // the carbon star: a cool red giant in a sooty shell + vec3 sd=normalize(uStar-cameraPosition); + float k=sqrt(max(0.,2.*(1.-dot(d,sd))))/(.07*uStarK+.0001); + vec3 t1=normalize(cross(sd,vec3(0.,1.,0.))),t2=cross(t1,sd);float an=atan(dot(d,t2),dot(d,t1)); + if(k<1.){float l=sqrt(1.-k*k);vec3 disc=mix(vec3(.5,.07,.03),vec3(1.,.52,.2),l)*(.82+.36*vn(d*240.+uTime*.15));col=mix(col,disc,uStarK);} + else{ + col*=mix(1.,.45+.55*smoothstep(1.,1.7,k),uStarK); // the soot around it hides the stars behind + float ray=pow(abs(cos(an*2.+uTime*.04)),28.)+pow(abs(cos(an*3.+1.3-uTime*.03)),46.)*.6; + col+=(vec3(1.,.3,.1)*exp(-(k-1.)*2.4)*.55+vec3(.55,.12,.05)*exp(-k*.55)*.3+vec3(1.,.48,.2)*ray*exp(-k*.42)*.22)*uStarK; + } + } + return col; +}`; +// how the ripple reveals things: inside radius uR of the goal (uP) it is space; uSky takes the rest (far ground, sky) +const MASK=`uniform vec3 uP;uniform float uR,uW,uSky,uMix; +float inside(float d){return max(1.-smoothstep(uR-2.,uR+1.,d),uSky);} +float front(float d){return exp(-pow((d-uR+uW*.5)/uW,2.))*(1.-uSky)*step(.01,uR);}`; +const VS_W=`varying vec3 vW,vN;uniform float uPull; +void main(){vec4 w=modelMatrix*vec4(position,1.);vW=w.xyz;vN=normalize(mat3(modelMatrix)*normal);vec4 mv=viewMatrix*w;mv.xyz*=uPull;gl_Position=projectionMatrix*mv;}`; +// the stand-ins: space seen through them; up-facing parts of the pitch get the lattice +const FS_VOID=SPACE+MASK+` +varying vec3 vW,vN;uniform vec2 uPitch;uniform float uFloorY,uCell,uCircle; +float lattice(vec2 p,out float node){ + vec2 q=p/uCell;const vec2 s=vec2(1.,1.7320508); + vec4 hc=floor(vec4(q,q-vec2(.5,1.))/s.xyxy)+.5;vec4 h=vec4(q-hc.xy*s,q-(hc.zw+.5)*s); + vec2 g=dot(h.xy,h.xy)0.){ + float node,ln=lattice(vW.xz,node); + float edge=smoothstep(0.,6.,uPitch.x-abs(vW.x))*smoothstep(0.,6.,uPitch.y-abs(vW.z)); + float pulse=smoothstep(.86,1.,fract((uTime*26.-d)/64.))*smoothstep(0.,40.,d); // slow ember swells keep moving outward + float mark=(1.-smoothstep(.12,.32,abs(vW.z)))+(1.-smoothstep(.12,.32,abs(length(vW.xz)-uCircle))); + col=col*.72+(vec3(.1,.55,.55)*ln*.42+vec3(.55,1.,.92)*node*.55+vec3(.25,.85,.8)*mark*.16+vec3(1.,.5,.2)*pulse*(ln*.6+node))*edge + +vec3(.04,.11,.13)*pow(1.-abs(dir.y),5.); + } + col+=mix(vec3(1.,.4,.14),vec3(.3,.95,.9),.3)*f*(.5+.7*up); + gl_FragColor=vec4(col,m*uMix); +}`; +// the map's edges: thin lines, cool white, warmer on the scoring goal +const VS_LINE=`attribute float aK;varying vec3 vW;varying float vK; +void main(){vec4 w=modelMatrix*vec4(position,1.);vW=w.xyz;vK=aK;vec4 mv=viewMatrix*w;mv.xyz*=.994;gl_Position=projectionMatrix*mv;}`; +const FS_LINE=MASK+`varying vec3 vW;varying float vK;uniform vec4 uGoal; +void main(){float d=distance(vW,uP); + float g=step(uGoal.y-.5,vW.z*uGoal.x)*step(abs(vW.x),uGoal.z)*step(vW.y,uGoal.w); + vec3 c=mix(vec3(.62,.86,1.),vec3(1.,.62,.3),g)*vK; + gl_FragColor=vec4(c*(inside(d)*.95+front(d)*1.6),uMix);}`; +// the cars and the ball: a white rim, and space inside, as if they were made of glass +const VS_RIM=`varying vec3 vW,vNv,vV; +void main(){vec4 w=modelMatrix*vec4(position,1.);vW=w.xyz;vec4 mv=viewMatrix*w;vV=mv.xyz;vNv=normalize(normalMatrix*normal);gl_Position=projectionMatrix*mv;}`; +const FS_RIM=SPACE+`varying vec3 vW,vNv,vV; +void main(){vec3 n=normalize(vNv);float fr=1.-abs(dot(n,normalize(-vV)));float rim=pow(fr,2.3); + gl_FragColor=vec4(space(normalize(vW-cameraPosition))*.8+vec3(.93,.96,1.)*(rim*1.4+.045),1.);}`; +// star dust behind the cars: points that move on their own in the vertex shader (written once, when emitted) +const VS_DUST=`attribute vec3 aV;attribute vec2 aT,aS;uniform float uTime,uScale;varying float vA,vS; +void main(){float t=uTime-aT.x,age=t/aT.y;if(age<0.||age>1.){gl_Position=vec4(2.,2.,2.,1.);gl_PointSize=0.;vA=0.;return;} + vec3 p=position+aV*t*(1.-.4*age)+vec3(0.,.35*t,0.);vec4 mv=modelViewMatrix*vec4(p,1.);gl_Position=projectionMatrix*mv; + gl_PointSize=aS.x*(1.-age*.5)*uScale/max(1.,-mv.z);vA=(1.-age)*min(1.,age*10.);vS=aS.y;}`; +const FS_DUST=`varying float vA,vS; +void main(){vec2 c=gl_PointCoord-.5;float r=length(c),core=1.-smoothstep(0.,.5,r); + float gl=max(0.,1.-abs(c.x)*12.)*max(0.,1.-abs(c.y)*2.2)+max(0.,1.-abs(c.y)*12.)*max(0.,1.-abs(c.x)*2.2); + vec3 col=mix(vec3(1.),vS<.5?vec3(.45,1.,.92):vec3(1.,.6,.28),fract(vS*2.)*.7); + gl_FragColor=vec4(col,(core*core+gl*.45)*vA);}`; +// the dying star at the goal mouth: a core, long thin rays and a soft halo (never the whole screen) +const VS_UV=`varying vec2 vUv;void main(){vUv=uv;gl_Position=projectionMatrix*modelViewMatrix*vec4(position,1.);}`; +const FS_FLARE=`varying vec2 vUv;uniform float uI,uRay,uRot,uCore; +void main(){vec2 q=(vUv-.5)*2.;float r=length(q),a=atan(q.y,q.x); + float core=exp(-r*r/(uCore*uCore+1e-4)),halo=exp(-r*7.)*.42+exp(-r*2.6)*.1; + float ray=pow(abs(cos(3.*(a-uRot))),90.)*exp(-r/(.2*uRay+1e-3))+pow(abs(cos(2.*(a+uRot*.6)+.4)),150.)*exp(-r/(.3*uRay+1e-3))*.7; + float streak=exp(-abs(q.y)*85.)*exp(-abs(q.x)/(.62*uRay+1e-3))*.75; + vec3 col=vec3(1.,.88,.7)*core+vec3(1.,.48,.2)*(halo+ray*.9+streak); + gl_FragColor=vec4(col*uI*(1.-smoothstep(.8,1.,r)),1.);}`; + +// --------------------------------------------------------------------------------------------------------------------- +// One effect over one scene (the arena, or the preview's little pitch) +// --------------------------------------------------------------------------------------------------------------------- +// o: {scene, renderer, camera(), map() (the map's top objects), cars() (car models {g, flame, shadow}), balls(), +// junk() (things to hide while it lasts: shadows, skid marks, the normal particles), low(), reduced(), holdLeft() +// (seconds until it must be gone, or null), audio(), shake(a), pitch {x, z, floorY, circle, cell, w (ripple front width), +// goalW, goalH, AL}, star(p) (where the carbon star hangs for a goal at p), main} +function Effect(o){ + const U={uTime:{value:0},uTurn:{value:0},uStarK:{value:0},uStar:{value:new V3()},uP:{value:new V3()},uR:{value:0},uW:{value:o.pitch.w}, + uSky:{value:0},uMix:{value:0},uPull:{value:.998},uPitch:{value:new THREE.Vector2(o.pitch.x,o.pitch.z)},uFloorY:{value:o.pitch.floorY}, + uCell:{value:o.pitch.cell},uCircle:{value:o.pitch.circle},uGoal:{value:new THREE.Vector4(1,o.pitch.AL,o.pitch.goalW+1.5,o.pitch.goalH+1.5)}, + uScale:{value:400},uI:{value:0},uRay:{value:0},uRot:{value:0},uCore:{value:.1}}; + let low=!!o.low(); + const defs=()=>({OCT:low?3:4,LOW:low?1:0}); + const sh=(vs,fs,extra)=>new THREE.ShaderMaterial(Object.assign({vertexShader:vs,fragmentShader:fs,uniforms:U,defines:defs(),extensions:{derivatives:true}},extra)); + const voidMat=sh(VS_W,FS_VOID,{transparent:true,side:THREE.DoubleSide}); + const lineMat=sh(VS_LINE,FS_LINE,{transparent:true,depthWrite:false,blending:THREE.AdditiveBlending}); + const rimMat=sh(VS_RIM,FS_RIM,{side:THREE.DoubleSide}); + const dustMat=sh(VS_DUST,FS_DUST,{transparent:true,depthWrite:false,blending:THREE.AdditiveBlending}); + const flareMat=sh(VS_UV,FS_FLARE,{transparent:true,depthTest:false,depthWrite:false,blending:THREE.AdditiveBlending}); + const MATS=[voidMat,lineMat,rimMat,dustMat,flareMat]; + const group=new THREE.Group();group.name='carbon-star'; + let built=null; + + // the stand-ins and the outline: made the first time (or ahead of time by warm()), then kept + function build(){ + if(built)return built; + const occ=[],thin=[],tops=o.map(),pos=[],ks=[],_a=new V3(),_s=new THREE.Sphere(); + for(const t of tops)t.updateMatrixWorld(true); + const edges=(x,k)=>{ + const g=x.geometry;if(!g||!g.attributes||!g.attributes.position)return; + if(!g.boundingSphere)g.computeBoundingSphere();if(g.boundingSphere.radius>900)return; // the sky and the far ground have no edges + if((g.index?g.index.count:g.attributes.position.count)/3>40000)return; + const e=new THREE.EdgesGeometry(g,26),p=e.attributes.position; + for(let i=0;i{ + if(x.isMesh){ + const m=x.material,solid=!Array.isArray(m)&&!m.transparent&&m.blending!==THREE.AdditiveBlending; + const g=x.geometry;if(!g.boundingSphere)g.computeBoundingSphere(); + _s.copy(g.boundingSphere).applyMatrix4(x.matrixWorld); + if(solid){ + const s=new THREE.Mesh(g,voidMat);s.matrixAutoUpdate=false;s.matrix.copy(x.matrixWorld);s.frustumCulled=x.frustumCulled; + if(_s.radius>900)s.renderOrder=1; // the sky and the far ground last, so nearer things hide them for free + group.add(s);occ.push(s); + }else thin.push({x,c:_s.center.clone(),r:_s.radius}); + edges(x,solid?1:.8); + }else if(x.isLine||x.isPoints||x.isSprite){x.updateMatrixWorld();thin.push({x,c:new V3().setFromMatrixPosition(x.matrixWorld),r:0})} + }); + const lg=new THREE.BufferGeometry();lg.setAttribute('position',new THREE.Float32BufferAttribute(pos,3));lg.setAttribute('aK',new THREE.Float32BufferAttribute(ks,1)); + const lines=new THREE.LineSegments(lg,lineMat);lines.frustumCulled=false;lines.renderOrder=5;group.add(lines); + // star dust: a pool of points, used round and round + const N=low?160:384,dg=new THREE.BufferGeometry(); + const A=(n,k)=>{const a=new THREE.BufferAttribute(new Float32Array(n*k),k);a.setUsage(THREE.DynamicDrawUsage);return a}; + dg.setAttribute('position',A(N,3));dg.setAttribute('aV',A(N,3));dg.setAttribute('aT',A(N,2));dg.setAttribute('aS',A(N,2)); + for(let i=0;i{if(!vis.has(x))vis.set(x,x.visible);x.visible=false}; + const show=x=>{if(vis.has(x)){x.visible=vis.get(x);vis.delete(x)}}; + const parts=g=>{let k=kids.get(g);if(!k){k=[];g.traverse(x=>{if(x!==g)k.push(x)});kids.set(g,k)}return k}; + function outline(m,on){ + for(const x of parts(m.g)){ + if(x.isSprite||x===m.flame){if(on)hide(x);else show(x);continue} + if(!x.isMesh)continue; + if(on){if(x.material!==rimMat){mats.set(x,x.material);x.material=rimMat}} + else if(x.material===rimMat&&mats.has(x)){x.material=mats.get(x);mats.delete(x)} + } + if(m.shadow){if(on)hide(m.shadow);else show(m.shadow)} + } + function ballOutline(b,on){ + const L=[b,...b.children]; + for(const x of L){if(!x.isMesh)continue;if(on){if(x.material!==rimMat){mats.set(x,x.material);x.material=rimMat}}else if(x.material===rimMat&&mats.has(x)){x.material=mats.get(x);mats.delete(x)}} + } + + // ---- the sound: a soft boom, a deep swell and a shimmer, all quiet ---- + let voices=[]; + function sound(){ + const A=o.audio();if(!A)return; + try{ + const c=A.actx,t=c.currentTime,v=o.main?1:.6,out=A.master; + A.tone(t,1.2,'sine',70,30,.24*v);A.noise(t,.9,170,.7,.12*v,'lowpass'); + const voice=(f,g,at,peak,end,type,f1)=>{const os=c.createOscillator(),gn=c.createGain();os.type=type||'sine';os.frequency.setValueAtTime(f,t+at);if(f1)os.frequency.linearRampToValueAtTime(f1,t+peak); + gn.gain.setValueAtTime(.0001,t+at);gn.gain.exponentialRampToValueAtTime(g*v,t+peak);gn.gain.exponentialRampToValueAtTime(.0001,t+end);os.connect(gn);gn.connect(out);os.start(t+at);os.stop(t+end+.05); + voices.push({os,gn});os.onended=()=>{try{gn.disconnect()}catch(e){}voices=voices.filter(x=>x.os!==os)}}; + voice(46,.075,.15,1.4,3.8,'sine',49);voice(69,.045,.2,1.5,3.6,'sine',73.5);voice(98,.018,.3,1.6,3.2,'triangle',98); // the swell + [1567.98,2093,2349.32,3135.96,3520].forEach((f,i)=>voice(f,.011,.35+i*.13,.65+i*.13,2.9+i*.12)); // the shimmer + }catch(e){} + } + function hush(){const A=o.audio();if(!A)return;const t=A.actx.currentTime;for(const x of voices){try{x.gn.gain.cancelScheduledValues(t);x.gn.gain.setTargetAtTime(.0001,t,.06);x.os.stop(t+.3)}catch(e){}}voices=[]} + + // ---- playing ---- + const S={live:false,t:0,p:new V3(),sg:1,rmax:300,covered:false,fading:false,fadeT:0,fadeLen:.8,red:false,shadowAuto:null}; + const DEF_HOLD=3.4,FADE=.8,RIP0=.22,RIP=.7; + function play(p){ + const hl=o.holdLeft();if(hl!==null&&hl<1.2)return false; // too close to the kickoff to be worth it: the plain fireball + if(S.live)stop(); + const lw=!!o.low();if(lw!==low){low=lw;for(const m of MATS){m.defines=defs();m.needsUpdate=true}} + const b=build(); + S.live=true;S.t=0;S.p.copy(p);S.sg=p.z>0?1:-1;S.covered=false;S.fading=false;S.red=!!o.reduced(); + U.uP.value.copy(p);U.uR.value=S.red?1e5:0;U.uSky.value=S.red?1:0;U.uMix.value=S.red?0:1;U.uStarK.value=0;U.uI.value=0; + U.uStar.value.copy(o.star(p));U.uGoal.value.x=S.sg; + S.rmax=0;for(const s of b.occ){if(s.renderOrder)continue;const g=s.geometry,c=g.boundingSphere.center.clone().applyMatrix4(s.matrix);S.rmax=Math.max(S.rmax,c.distanceTo(p)+g.boundingSphere.radius*.8)} + S.rmax=Math.max(S.rmax,60); + voidMat.transparent=true; + o.scene.add(group); + b.flare.visible=true; + sound(); + if(!S.red&&o.shake)o.shake(.35); + return true; + } + const _q=new V3(),_f=new V3(),_v=new V3(); + function update(dt){ + if(!S.live)return; + const b=built;S.t+=dt;const t=S.t; + U.uTime.value+=dt;U.uTurn.value+=dt*.035; + const cam=o.camera(); + U.uScale.value=o.renderer.domElement.height/(2*Math.tan(cam.fov*Math.PI/360)); + // when to fade back: index.html knows how long the celebration has left + const hl=o.holdLeft(),left=hl===null?DEF_HOLD-t:hl; + if(!S.fading&&left<=FADE&&t>.3){ + S.fading=true;S.fadeT=t;S.fadeLen=clamp(left,.15,FADE);S.mix0=U.uMix.value; + if(S.covered){for(const x of b.tops)show(x);voidMat.transparent=true;if(o.main&&S.shadowAuto!==null){o.renderer.shadowMap.autoUpdate=S.shadowAuto;S.shadowAuto=null}} + } + // the ripple, or (reduced motion) a plain cross-fade + if(S.red){U.uMix.value=S.fading?S.mix0*(1-sm(0,1,(t-S.fadeT)/S.fadeLen)):sm(0,1,t/1.1)} + else{ + const k=clamp((t-RIP0)/RIP,0,1);U.uR.value=t