From 170b1627c9f3ef40ee8434f1444889921a6974eb Mon Sep 17 00:00:00 2001 From: hulingjun <166984918+hulingjun@users.noreply.github.com> Date: Sun, 6 Sep 2026 10:10:24 +0800 Subject: [PATCH 1/7] Optimize full-detail garden rendering with conservative spatial batches --- .github/workflows/archive-check.yml | 6 +++ app/garden/SeasonGarden.tsx | 8 ++-- app/garden/instance-batches.mjs | 39 +++++++++++++++++++ app/garden/presentation.mjs | 21 ++++++++-- app/garden/world.mjs | 57 ++++++++++++++++++---------- scripts/garden-perf-page.mjs | 49 ++++++++++++++++++++++++ scripts/garden-perf.html | 1 + scripts/garden-performance-check.mjs | 50 ++++++++++++++++++++++++ scripts/seasons.test.mjs | 29 ++++++++++++++ 9 files changed, 234 insertions(+), 26 deletions(-) create mode 100644 app/garden/instance-batches.mjs create mode 100644 scripts/garden-perf-page.mjs create mode 100644 scripts/garden-perf.html create mode 100644 scripts/garden-performance-check.mjs diff --git a/.github/workflows/archive-check.yml b/.github/workflows/archive-check.yml index 433f16a..f2e528c 100644 --- a/.github/workflows/archive-check.yml +++ b/.github/workflows/archive-check.yml @@ -9,10 +9,12 @@ permissions: jobs: validate: runs-on: ubuntu-latest + timeout-minutes: 25 steps: - uses: actions/checkout@v4 with: persist-credentials: false + fetch-depth: 0 - uses: actions/setup-node@v4 with: node-version: 22 @@ -54,6 +56,10 @@ jobs: run: node scripts/garden-browser-check.mjs env: GALLERY_TOOLS_DIR: ${{ runner.temp }}/gallery-tools + - name: Compare full-detail performance with the previous release + run: node scripts/garden-performance-check.mjs + env: + GALLERY_TOOLS_DIR: ${{ runner.temp }}/gallery-tools - name: Save visual review evidence if: always() uses: actions/upload-artifact@v4 diff --git a/app/garden/SeasonGarden.tsx b/app/garden/SeasonGarden.tsx index 508709c..99a6f7d 100644 --- a/app/garden/SeasonGarden.tsx +++ b/app/garden/SeasonGarden.tsx @@ -62,16 +62,16 @@ export default function SeasonGarden(){ const c=control.current,dt=last?Math.min((now-last)/1000,.1):0;last=now; if(!c.paused){time+=dt;if(c.automatic)c.elapsed+=dt;} if(c.revision!==previousRevision){ - previousRevision=c.revision;dirty=true;renderer.shadowMap.needsUpdate=true; + previousRevision=c.revision;dirty=true; if(c.reset!==previousReset){previousReset=c.reset;home();} } orbit.enableDamping=!c.paused&&!reduce.matches; - renderer.shadowMap.autoUpdate=!c.paused; + renderer.shadowMap.autoUpdate=false; const changed=orbit.update(); if(changed)dirty=true; - if(dirty||(!c.paused&&now-lastRender>(low?33:24))){ + if((dirty||(!c.paused&&now-lastRender>(low?33:24)))&&presentation.ready()){ const sampled=sampleSeason(c.elapsed); - model.updateGarden(world,sampled,time); + if(model.updateGarden(world,sampled,time))renderer.shadowMap.needsUpdate=true; presentation.render(); const labelKey=sampled.from+":"+sampled.to; if(labelKey!==previousLabel){previousLabel=labelKey;setSeason(sampled);} diff --git a/app/garden/instance-batches.mjs b/app/garden/instance-batches.mjs new file mode 100644 index 0000000..9b0a118 --- /dev/null +++ b/app/garden/instance-batches.mjs @@ -0,0 +1,39 @@ +import * as T from "three"; +// Spatial batches retain every instance and use THREE's separate camera/light +// frustum tests. Never toggle visibility based on the viewer's camera. +export function batchInstances(source,cellSize,padding=0){ + const cells=new Map(),matrix=new T.Matrix4(); + for(let i=0;i{ + mesh.instanceMatrix.array.set(source.instanceMatrix.array.subarray(index*16,index*16+16),i*16); + if(source.instanceColor)mesh.instanceColor.array.set(source.instanceColor.array.subarray(index*3,index*3+3),i*3); + }); + mesh.computeBoundingSphere();mesh.boundingSphere.radius+=padding; + mesh.frustumCulled=true;mesh.updateMatrix();mesh.matrixAutoUpdate=false; + group.add(mesh);batches.push({mesh,indices}); + } + group.updateMatrix();group.matrixAutoUpdate=false; + return {group,batches,source}; +} +export function syncBatches(batch,colors=true){ + const source=batch.source; + for(const {mesh,indices} of batch.batches){ + const m=mesh.instanceMatrix.array,c=mesh.instanceColor?.array,sm=source.instanceMatrix.array,sc=source.instanceColor?.array; + for(let i=0;i{ + dummy.position.copy(s.petioleEnd);dummy.quaternion.copy(s.quaternion);dummy.scale.setScalar(s.scale);dummy.updateMatrix(); + leaves.setMatrixAt(i,dummy.matrix);dummy.matrix.toArray(baseMatrices,i*16);leaves.setColorAt(i,color.set("#ffffff")); + }); + const leafBatches=batchInstances(leaves,1.7,.12),petioleBatches=batchInstances(petioles,1.7); + group.remove(leaves,petioles);group.add(leafBatches.group,petioleBatches.group); const snow=new T.Mesh(bark.geometry,new T.MeshStandardMaterial({color:"#e7edf0",roughness:1,transparent:true,opacity:0,polygonOffset:true,polygonOffsetFactor:-1})); snow.material.onBeforeCompile=shader=>{ shader.vertexShader="varying float gardenUp;\n"+shader.vertexShader; @@ -235,7 +244,7 @@ export function buildGarden(low=false,assets={}){ }; snow.material.depthWrite=false; snow.scale.setScalar(1.018);group.add(snow); - trees.push({group,bark,leaves,petioles,seeds,shoots,snow}); + trees.push({group,bark,leaves,petioles,seeds,shoots,snow,baseMatrices,leafBatches,petioleBatches}); } // Grass blades form the clearing, not a floating pedestal. const grassGeo=new T.PlaneGeometry(.045,.4,1,4);grassGeo.translate(0,.2,0); @@ -248,17 +257,17 @@ export function buildGarden(low=false,assets={}){ const az=random()*TAU,r=Math.sqrt(random())*12,x=Math.cos(az)*r,z=Math.sin(az)*r; dummy.position.set(x,terrainY(x,z),z);dummy.rotation.set((random()-.5)*.4,random()*TAU, (random()-.5)*.4);dummy.scale.setScalar(.3+random()*.9);dummy.updateMatrix();grass.setMatrixAt(i,dummy.matrix); } - scene.add(grass); + const grassBatches=batchInstances(grass,3);scene.add(grassBatches.group); const count=low?180:440,seeds=[],positions=new Float32Array(count*3),rainPositions=new Float32Array(count*6); for(let i=0;inew T.Color(a[key]).lerp(new T.Color(b[key]),mix); const weight=i=>(from===i?1-mix:0)+(to===i?mix:0); const spring=weight(0),summer=weight(1),autumn=weight(2),winter=weight(3); w.wind.value=time;w.snowWeight.value=winter; - const sunshine=new T.Vector3(.32,.25+summer*.035-winter*.07+Math.sin(time*.055)*.018,-.92).normalize(); + const sunshine=w.scratch.sun.set(.32,.25+summer*.035-winter*.07+Math.sin(time*.055)*.018,-.92).normalize(); w.sky.material.uniforms.sunPosition.value.copy(sunshine);w.light.position.copy(sunshine).multiplyScalar(25); - const key=[from,to,mix.toFixed(3)].join(":"); if(w.seasonKey!==key){ w.seasonKey=key;w.scene.background.copy(blend("sky"));w.scene.fog.color.copy(blend("fog")); w.scene.fog.near=28;w.scene.fog.far=110; w.ground.material.color.copy(blend("ground")); w.grass.material.color.copy(blend("ground")).multiplyScalar(.72); - w.grass.visible=winter<.95; + w.grass.visible=winter<.95;w.grassBatches.group.visible=w.grass.visible; w.light.color.copy(blend("sun")); w.sky.material.uniforms.rayleigh.value=1.4+autumn*.7-winter*.4; w.sky.material.uniforms.turbidity.value=3+spring*2+winter*4; w.surfaces.bark.color.set("#d0c2ae"); - const c1=blend("leaf"),c2=blend("tip"),dummy=new T.Object3D(),color=new T.Color(); + const c1=blend("leaf"),c2=blend("tip"); for(const tree of w.trees){ tree.snow.material.opacity=winter*.9;tree.snow.visible=winter>.01;tree.petioles.visible=winter<.99; + tree.petioleBatches.group.visible=tree.petioles.visible; + tree.leafBatches.group.visible=winter<1; + const matrices=tree.leaves.instanceMatrix.array,colors=tree.leaves.instanceColor.array,base=tree.baseMatrices; for(let i=0;im.material.color.set("#728b78").lerp(w.scene.fog.color,.2+i*.18)); w.falling.visible=autumn>.01;w.fallen.visible=autumn>.01; @@ -316,13 +329,16 @@ export function updateGarden(w,state,time){ const y=((s.y-time*8*s.speed)%13+13)%13; w.rainPositions[k]=s.x;w.rainPositions[k+1]=y;w.rainPositions[k+2]=s.z;w.rainPositions[k+3]=s.x+.07;w.rainPositions[k+4]=y+.35;w.rainPositions[k+5]=s.z; } - w.particles.geometry.attributes.position.needsUpdate=true;w.rain.geometry.attributes.position.needsUpdate=true; - const dummy=new T.Object3D(),color=new T.Color(); + w.particles.visible=w.particleMat.uniforms.alpha.value>0;w.rain.visible=w.rainMat.opacity>0; + if(w.particles.visible)w.particles.geometry.attributes.position.needsUpdate=true;if(w.rain.visible)w.rain.geometry.attributes.position.needsUpdate=true; + const {dummy,color,origin}=w.scratch; + if(w.falling.visible){ + for(const tree of w.trees)tree.group.updateWorldMatrix(true,false); for(let i=0;i{if(o.geometry)geometries.add(o.geometry);if(o.material)(Array.isArray(o.material)?o.material:[o.material]).forEach(m=>materials.add(m));}); for(const m of Object.values(w.surfaces))materials.add(m); + for(const tree of w.trees){materials.add(tree.petioles.material);geometries.add(tree.petioles.geometry);} materials.add(w.leafDepth);geometries.forEach(g=>g.dispose());materials.forEach(m=>m.dispose());textures.forEach(t=>t.dispose()); } diff --git a/scripts/garden-perf-page.mjs b/scripts/garden-perf-page.mjs new file mode 100644 index 0000000..a7efc15 --- /dev/null +++ b/scripts/garden-perf-page.mjs @@ -0,0 +1,49 @@ +import * as T from "three"; +const query=new URLSearchParams(location.search),model=await import(query.get("model")); +const assets=await model.loadGardenAssets(),world=model.buildGarden(false,assets); +const renderer=new T.WebGLRenderer({antialias:true,alpha:false,powerPreference:"high-performance"}); +renderer.setSize(1000,700);renderer.setPixelRatio(1); +renderer.toneMapping=T.ACESFilmicToneMapping;renderer.toneMappingExposure=1.05; +renderer.shadowMap.enabled=true;renderer.shadowMap.type=T.PCFSoftShadowMap; +document.body.style.margin="0";document.body.appendChild(renderer.domElement); +const camera=new T.PerspectiveCamera(40,1000/700,.2,250),gl=renderer.getContext(); +const stats=values=>{const s=values.toSorted((a,b)=>a-b);return {p50:s[Math.floor(s.length*.5)],p95:s[Math.min(s.length-1,Math.floor(s.length*.95))]};}; +const state=(season,mix=0)=>({from:season,to:mix?(season+1)%4:season,mix}); +function pose(view){ + if(view==="overview"){camera.position.set(2.28,5.25,19);camera.lookAt(0,2.4,0);} + if(view==="detail"){camera.position.set(-2.6,4.9,7);camera.lookAt(-2.6,4,0);} + if(view==="edge"){camera.position.set(-6,4,5.5);camera.lookAt(-6,4,0);} + camera.updateMatrixWorld();camera.updateProjectionMatrix(); +} +window.measure=async(view,season,mix=0)=>{ + pose(view);const sample=state(season,mix); + const cpu=[],completed=[],counts=[]; + for(let i=0;i<12;i++){ + const time=12+i/60,start=performance.now();model.updateGarden(world,sample,time);const simulated=performance.now(); + renderer.info.autoReset=false;renderer.info.reset();renderer.render(world.scene,camera); + gl.finish();const end=performance.now(); + if(i>=4){cpu.push(simulated-start);completed.push(end-start);counts.push({...renderer.info.render});} + } + // A deterministic frame for image equivalence, independent of timing. + model.updateGarden(world,sample,12);renderer.render(world.scene,camera);gl.finish(); + return {view,season,mix,cpuMs:stats(cpu),completedFrameMs:stats(completed),draw:counts.at(-1)}; +}; +window.cpuMeasure=()=>{ + const results={}; + for(const [name,step] of [["hold",0],["transition",.003],["paused",null]]){ + const values=[];model.updateGarden(world,state(0),12); + for(let round=0;round<6;round++){ + const start=performance.now(); + for(let i=0;i<120;i++)model.updateGarden(world,state(0,step===null?0:step*i),step===null?12:12+i/60); + if(round)values.push((performance.now()-start)/120); + }results[name]=stats(values); + } + return results; +}; +window.inventory=()=>{ + const geometries=[]; + world.scene.traverse(o=>{if(o.isMesh){const vertices=o.geometry.attributes.position.count,triangles=o.geometry.index?o.geometry.index.count/3:vertices/3;geometries.push({vertices,triangles,count:o.isInstancedMesh?o.count:1});}}); + return {leaves:world.trees.reduce((sum,t)=>sum+t.leaves.count,0),petioles:world.trees.reduce((sum,t)=>sum+t.petioles.count,0),grass:world.grass.count, + allocatedTriangles:geometries.reduce((sum,g)=>sum+g.triangles*g.count,0),shadowSize:world.light.shadow.mapSize.toArray(),pixelRatio:renderer.getPixelRatio()}; +}; +window.ready=true; diff --git a/scripts/garden-perf.html b/scripts/garden-perf.html new file mode 100644 index 0000000..6114b25 --- /dev/null +++ b/scripts/garden-perf.html @@ -0,0 +1 @@ + diff --git a/scripts/garden-performance-check.mjs b/scripts/garden-performance-check.mjs new file mode 100644 index 0000000..992d963 --- /dev/null +++ b/scripts/garden-performance-check.mjs @@ -0,0 +1,50 @@ +import {createServer} from "vite"; +import {writeFile,mkdir,unlink,readFile} from "node:fs/promises"; +import {resolve,join} from "node:path"; +import {execFileSync} from "node:child_process"; +import {createRequire} from "node:module"; +import assert from "node:assert/strict"; +const require=createRequire(join(resolve(process.env.GALLERY_TOOLS_DIR),"perf.cjs")); +const {chromium}=require("playwright"),sharp=require("sharp"); +const baselineCommit="4f28563b02b9afaa30ccd76eb0c3a5ce9c7fb1dc"; +const baselinePath=resolve("scripts/.garden-perf-baseline.mjs"),output=resolve("garden-qa/performance"); +await mkdir(output,{recursive:true}); +await writeFile(baselinePath,execFileSync("git",["show",baselineCommit+":app/garden/world.mjs"])); +const server=await createServer({configFile:false,root:process.cwd(),publicDir:resolve("github-pages/public"),server:{host:"127.0.0.1",port:4174,strictPort:true}}); +await server.listen(); +const browser=await chromium.launch({headless:true,args:["--use-angle=swiftshader","--enable-unsafe-swiftshader","--disable-dev-shm-usage"]}); +const results={},errors=[]; +try{ + for(const [name,module] of [["before","/scripts/.garden-perf-baseline.mjs"],["after","/app/garden/world.mjs"]]){ + const context=await browser.newContext({viewport:{width:1000,height:700},deviceScaleFactor:1}); + const page=await context.newPage();page.on("pageerror",e=>errors.push(e.message)); + await page.goto("http://127.0.0.1:4174/scripts/garden-perf.html?model="+encodeURIComponent(module),{waitUntil:"networkidle"}); + await page.waitForFunction(()=>window.ready,{},{timeout:120000}); + const inventory=await page.evaluate(()=>window.inventory()),cpu=await page.evaluate(()=>window.cpuMeasure()),frames=[]; + for(const [label,view,season,mix] of [["summer-home","overview",1,0],["summer-detail","detail",1,0],["summer-edge","edge",1,0],["winter-detail","detail",3,0],["transition-detail","detail",0,.5]]){ + frames.push({label,...await page.evaluate(args=>window.measure(...args),[view,season,mix])}); + await page.screenshot({path:join(output,name+"-"+label+".png"),timeout:90000}); + } + results[name]={inventory,cpu,frames};await context.close(); + } + const comparisons=[]; + for(let i=0;i12)large++;} + const meanPixelDifference=sum/imageA.length,fractionOver12=large/imageA.length; + comparisons.push({label,frameSpeedup:a.completedFrameMs.p50/b.completedFrameMs.p50,trianglesBefore:a.draw.triangles,trianglesAfter:b.draw.triangles,meanPixelDifference,fractionOver12}); + assert.ok(meanPixelDifference<1.2&&fractionOver12<.018,"No lost detail or shadows in "+label); + } + assert.deepEqual(results.after.inventory,results.before.inventory,"All allocated geometry, instances and quality settings are unchanged"); + assert.ok(results.after.cpu.paused.p50x.label==="summer-detail").trianglesAfterx.label==="summer-detail").trianglesBefore,"Close-up omits only frustum-invisible instances"); + assert.deepEqual(errors,[]); + await writeFile(join(output,"report.json"),JSON.stringify({passed:true,baselineCommit,results,comparisons,errors},null,2)); + console.log(JSON.stringify({passed:true,comparisons,cpu:results.after.cpu},null,2)); +}finally{ + await writeFile(join(output,"raw-results.json"),JSON.stringify({results,errors},null,2)); + await browser.close();await server.close();await unlink(baselinePath); +} diff --git a/scripts/seasons.test.mjs b/scripts/seasons.test.mjs index 4e14692..54d888a 100644 --- a/scripts/seasons.test.mjs +++ b/scripts/seasons.test.mjs @@ -90,3 +90,32 @@ test("fine twig UVs never fold or mirror their normal map",()=>{ g.dispose(); } }); + +test("performance batches retain every full-detail instance and conservative bounds",()=>{ + const world=buildGarden(false); + assert.equal(world.trees.reduce((sum,t)=>sum+t.leaves.count,0),7920); + assert.equal(world.grass.count,10000);assert.deepEqual(world.light.shadow.mapSize.toArray(),[2048,2048]); + for(const batch of [...world.trees.flatMap(t=>[t.leafBatches,t.petioleBatches]),world.grassBatches]){ + const seen=new Set(),matrix=new Matrix4(); + for(const {mesh,indices} of batch.batches){ + assert.equal(mesh.geometry,batch.source.geometry);assert.equal(mesh.material,batch.source.material); + assert.equal(mesh.castShadow,batch.source.castShadow);assert.equal(mesh.receiveShadow,batch.source.receiveShadow); + assert.equal(mesh.frustumCulled,true); + for(let i=0;iworld.trees.flatMap(t=>t.leafBatches.batches.map(b=>b.mesh.instanceMatrix.version)).concat(world.particles.geometry.attributes.position.version,world.rain.geometry.attributes.position.version,world.falling.instanceMatrix.version); + const before=versions(); + for(let i=0;i<100;i++)assert.equal(updateGarden(world,sampleSeason(22),12),false); + assert.deepEqual(versions(),before,"Camera-only updates make no buffer uploads"); + updateGarden(world,sampleSeason(66),13);for(const t of world.trees)assert.equal(t.leafBatches.group.visible,false); + assert.equal(world.rain.visible,false); + updateGarden(world,sampleSeason(0),14);assert.equal(world.particles.visible,false); + disposeGarden(world); +}); From 1a289f119ae6c98d60a4ac143fbe98b14d39e9c3 Mon Sep 17 00:00:00 2001 From: hulingjun <166984918+hulingjun@users.noreply.github.com> Date: Sun, 6 Sep 2026 10:14:07 +0800 Subject: [PATCH 2/7] Preserve normal GPU pipelining and check zoom with weather actively animating --- app/garden/SeasonGarden.tsx | 2 +- app/garden/presentation.mjs | 21 +++------------------ scripts/garden-browser-check.mjs | 13 +++++++++++++ 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/app/garden/SeasonGarden.tsx b/app/garden/SeasonGarden.tsx index 99a6f7d..f37f838 100644 --- a/app/garden/SeasonGarden.tsx +++ b/app/garden/SeasonGarden.tsx @@ -69,7 +69,7 @@ export default function SeasonGarden(){ renderer.shadowMap.autoUpdate=false; const changed=orbit.update(); if(changed)dirty=true; - if((dirty||(!c.paused&&now-lastRender>(low?33:24)))&&presentation.ready()){ + if(dirty||(!c.paused&&now-lastRender>(low?33:24))){ const sampled=sampleSeason(c.elapsed); if(model.updateGarden(world,sampled,time))renderer.shadowMap.needsUpdate=true; presentation.render(); diff --git a/app/garden/presentation.mjs b/app/garden/presentation.mjs index 1816078..fca48d6 100644 --- a/app/garden/presentation.mjs +++ b/app/garden/presentation.mjs @@ -1,20 +1,5 @@ -// Keep full-quality frames, but never queue stale camera views behind a busy -// GPU. A zero-timeout fence poll yields to input without blocking the CPU. +// A single physical-material scene. Direct rendering preserves ACES/output color +// management and avoids the former cartoon/ink full-screen shader passes. export function createPresentation(renderer,scene,camera){ - const gl=renderer.getContext();let fence=null; - const supported=typeof gl.fenceSync==="function"; - return { - resize(){}, - ready(){ - if(!fence)return true; - const status=gl.clientWaitSync(fence,0,0); - if(status===gl.TIMEOUT_EXPIRED)return false; - gl.deleteSync(fence);fence=null;return true; - }, - render(){ - renderer.render(scene,camera); - if(supported){fence=gl.fenceSync(gl.SYNC_GPU_COMMANDS_COMPLETE,0);gl.flush();} - }, - dispose(){if(fence)gl.deleteSync(fence);fence=null;} - }; + return {resize(){},render(){renderer.render(scene,camera);},dispose(){}}; } diff --git a/scripts/garden-browser-check.mjs b/scripts/garden-browser-check.mjs index b619a46..2f86a37 100644 --- a/scripts/garden-browser-check.mjs +++ b/scripts/garden-browser-check.mjs @@ -55,6 +55,19 @@ try{ // Keep camera verification independent of Chromium's extra WebGL readback. results.push("Desktop: drag rotate, wheel zoom, right pan, exact reset, paused interaction"); + // Exercise zoom while full weather/shadows are animating, not just paused QA. + const frozenTime=Number(await scene.getAttribute("data-weather-time")); + await page.getByRole("button",{name:"播放天气",exact:true}).click(); + await page.waitForFunction(t=>Number(document.querySelector(".garden-canvas").dataset.weatherTime)>t+.05,frozenTime); + const activeBefore=await camera();await page.mouse.move(x,y); + for(let i=0;i<5;i++)await page.mouse.wheel(0,-70); + await page.waitForFunction(c=>document.querySelector(".garden-canvas").dataset.camera!==c,activeBefore); + await page.getByRole("button",{name:"暂停天气",exact:true}).click();await page.waitForTimeout(500); + const pausedTime=await scene.getAttribute("data-weather-time"); + const pausedBefore=await camera();await page.mouse.wheel(0,200); + await page.waitForFunction(c=>document.querySelector(".garden-canvas").dataset.camera!==c,pausedBefore); + assert.equal(await scene.getAttribute("data-weather-time"),pausedTime); + results.push("Active-weather wheel zoom, pause, and further paused zoom remain responsive"); assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth),true); await context.close(); // Mobile uses real Chromium touch events, not synthetic mouse aliases. From 9011416cdc5e9621320cbc7fafab2045e54040b8 Mon Sep 17 00:00:00 2001 From: hulingjun <166984918+hulingjun@users.noreply.github.com> Date: Sun, 6 Sep 2026 10:19:14 +0800 Subject: [PATCH 3/7] Target the canvas in resumed zoom checks and measure performance before interaction QA --- .github/workflows/archive-check.yml | 8 ++++---- scripts/garden-browser-check.mjs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/archive-check.yml b/.github/workflows/archive-check.yml index f2e528c..3ae34c9 100644 --- a/.github/workflows/archive-check.yml +++ b/.github/workflows/archive-check.yml @@ -52,14 +52,14 @@ jobs: sudo apt-get install -y fonts-noto-cjk npm install --prefix "$RUNNER_TEMP/gallery-tools" --no-package-lock --no-save sharp@0.35.4 playwright@1.63.0 "$RUNNER_TEMP/gallery-tools/node_modules/.bin/playwright" install --with-deps chromium - - name: Check realistic seasons, attachments and camera interactions in cloud Chromium - run: node scripts/garden-browser-check.mjs - env: - GALLERY_TOOLS_DIR: ${{ runner.temp }}/gallery-tools - name: Compare full-detail performance with the previous release run: node scripts/garden-performance-check.mjs env: GALLERY_TOOLS_DIR: ${{ runner.temp }}/gallery-tools + - name: Check realistic seasons, attachments and camera interactions in cloud Chromium + run: node scripts/garden-browser-check.mjs + env: + GALLERY_TOOLS_DIR: ${{ runner.temp }}/gallery-tools - name: Save visual review evidence if: always() uses: actions/upload-artifact@v4 diff --git a/scripts/garden-browser-check.mjs b/scripts/garden-browser-check.mjs index 2f86a37..9da960d 100644 --- a/scripts/garden-browser-check.mjs +++ b/scripts/garden-browser-check.mjs @@ -64,7 +64,7 @@ try{ await page.waitForFunction(c=>document.querySelector(".garden-canvas").dataset.camera!==c,activeBefore); await page.getByRole("button",{name:"暂停天气",exact:true}).click();await page.waitForTimeout(500); const pausedTime=await scene.getAttribute("data-weather-time"); - const pausedBefore=await camera();await page.mouse.wheel(0,200); + const pausedBefore=await camera();await page.mouse.move(x,y);await page.mouse.wheel(0,200); await page.waitForFunction(c=>document.querySelector(".garden-canvas").dataset.camera!==c,pausedBefore); assert.equal(await scene.getAttribute("data-weather-time"),pausedTime); results.push("Active-weather wheel zoom, pause, and further paused zoom remain responsive"); From 4fb9fc362fea3e35f715e7fc30be034785bf859f Mon Sep 17 00:00:00 2001 From: hulingjun <166984918+hulingjun@users.noreply.github.com> Date: Sun, 6 Sep 2026 10:28:56 +0800 Subject: [PATCH 4/7] Bound software-renderer benchmark sampling and save per-view progress --- scripts/garden-perf-page.mjs | 10 +++++----- scripts/garden-performance-check.mjs | 3 +++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/scripts/garden-perf-page.mjs b/scripts/garden-perf-page.mjs index a7efc15..808992b 100644 --- a/scripts/garden-perf-page.mjs +++ b/scripts/garden-perf-page.mjs @@ -18,11 +18,11 @@ function pose(view){ window.measure=async(view,season,mix=0)=>{ pose(view);const sample=state(season,mix); const cpu=[],completed=[],counts=[]; - for(let i=0;i<12;i++){ + for(let i=0;i<5;i++){ const time=12+i/60,start=performance.now();model.updateGarden(world,sample,time);const simulated=performance.now(); renderer.info.autoReset=false;renderer.info.reset();renderer.render(world.scene,camera); gl.finish();const end=performance.now(); - if(i>=4){cpu.push(simulated-start);completed.push(end-start);counts.push({...renderer.info.render});} + if(i>=2){cpu.push(simulated-start);completed.push(end-start);counts.push({...renderer.info.render});} } // A deterministic frame for image equivalence, independent of timing. model.updateGarden(world,sample,12);renderer.render(world.scene,camera);gl.finish(); @@ -32,10 +32,10 @@ window.cpuMeasure=()=>{ const results={}; for(const [name,step] of [["hold",0],["transition",.003],["paused",null]]){ const values=[];model.updateGarden(world,state(0),12); - for(let round=0;round<6;round++){ + for(let round=0;round<4;round++){ const start=performance.now(); - for(let i=0;i<120;i++)model.updateGarden(world,state(0,step===null?0:step*i),step===null?12:12+i/60); - if(round)values.push((performance.now()-start)/120); + for(let i=0;i<60;i++)model.updateGarden(world,state(0,step===null?0:step*i),step===null?12:12+i/60); + if(round)values.push((performance.now()-start)/60); }results[name]=stats(values); } return results; diff --git a/scripts/garden-performance-check.mjs b/scripts/garden-performance-check.mjs index 992d963..916a5cd 100644 --- a/scripts/garden-performance-check.mjs +++ b/scripts/garden-performance-check.mjs @@ -21,8 +21,11 @@ try{ await page.goto("http://127.0.0.1:4174/scripts/garden-perf.html?model="+encodeURIComponent(module),{waitUntil:"networkidle"}); await page.waitForFunction(()=>window.ready,{},{timeout:120000}); const inventory=await page.evaluate(()=>window.inventory()),cpu=await page.evaluate(()=>window.cpuMeasure()),frames=[]; + console.log("Loaded "+name,JSON.stringify({inventory,cpu})); for(const [label,view,season,mix] of [["summer-home","overview",1,0],["summer-detail","detail",1,0],["summer-edge","edge",1,0],["winter-detail","detail",3,0],["transition-detail","detail",0,.5]]){ frames.push({label,...await page.evaluate(args=>window.measure(...args),[view,season,mix])}); + console.log(name+" "+label,JSON.stringify(frames.at(-1))); + await writeFile(join(output,name+"-progress.json"),JSON.stringify({inventory,cpu,frames},null,2)); await page.screenshot({path:join(output,name+"-"+label+".png"),timeout:90000}); } results[name]={inventory,cpu,frames};await context.close(); From aac80ada6023d55d49f59adec077fb5ea756de65 Mon Sep 17 00:00:00 2001 From: hulingjun <166984918+hulingjun@users.noreply.github.com> Date: Sun, 6 Sep 2026 10:39:12 +0800 Subject: [PATCH 5/7] Keep whole-tree batching and measure real completed GPU work without reducing detail --- app/garden/SeasonGarden.tsx | 1 + app/garden/instance-batches.mjs | 39 ---------------------------- app/garden/world.mjs | 19 +++++++------- scripts/garden-browser-check.mjs | 3 ++- scripts/garden-perf-page.mjs | 14 ++++++---- scripts/garden-performance-check.mjs | 3 ++- scripts/seasons.test.mjs | 22 +++++----------- 7 files changed, 30 insertions(+), 71 deletions(-) delete mode 100644 app/garden/instance-batches.mjs diff --git a/app/garden/SeasonGarden.tsx b/app/garden/SeasonGarden.tsx index f37f838..e8831f6 100644 --- a/app/garden/SeasonGarden.tsx +++ b/app/garden/SeasonGarden.tsx @@ -78,6 +78,7 @@ export default function SeasonGarden(){ element.dataset.season=sampled.label; element.dataset.seasonMix=sampled.mix.toFixed(4); element.dataset.weatherTime=time.toFixed(3); + element.dataset.weatherPaused=String(c.paused); element.dataset.camera=camera.position.toArray().concat(orbit.target.toArray()).map((n:number)=>n.toFixed(3)).join(","); dirty=false;lastRender=now; } diff --git a/app/garden/instance-batches.mjs b/app/garden/instance-batches.mjs deleted file mode 100644 index 9b0a118..0000000 --- a/app/garden/instance-batches.mjs +++ /dev/null @@ -1,39 +0,0 @@ -import * as T from "three"; -// Spatial batches retain every instance and use THREE's separate camera/light -// frustum tests. Never toggle visibility based on the viewer's camera. -export function batchInstances(source,cellSize,padding=0){ - const cells=new Map(),matrix=new T.Matrix4(); - for(let i=0;i{ - mesh.instanceMatrix.array.set(source.instanceMatrix.array.subarray(index*16,index*16+16),i*16); - if(source.instanceColor)mesh.instanceColor.array.set(source.instanceColor.array.subarray(index*3,index*3+3),i*3); - }); - mesh.computeBoundingSphere();mesh.boundingSphere.radius+=padding; - mesh.frustumCulled=true;mesh.updateMatrix();mesh.matrixAutoUpdate=false; - group.add(mesh);batches.push({mesh,indices}); - } - group.updateMatrix();group.matrixAutoUpdate=false; - return {group,batches,source}; -} -export function syncBatches(batch,colors=true){ - const source=batch.source; - for(const {mesh,indices} of batch.batches){ - const m=mesh.instanceMatrix.array,c=mesh.instanceColor?.array,sm=source.instanceMatrix.array,sc=source.instanceColor?.array; - for(let i=0;i{ shader.vertexShader="varying float gardenUp;\n"+shader.vertexShader; @@ -244,7 +245,7 @@ export function buildGarden(low=false,assets={}){ }; snow.material.depthWrite=false; snow.scale.setScalar(1.018);group.add(snow); - trees.push({group,bark,leaves,petioles,seeds,shoots,snow,baseMatrices,leafBatches,petioleBatches}); + trees.push({group,bark,leaves,petioles,seeds,shoots,snow,baseMatrices}); } // Grass blades form the clearing, not a floating pedestal. const grassGeo=new T.PlaneGeometry(.045,.4,1,4);grassGeo.translate(0,.2,0); @@ -257,7 +258,7 @@ export function buildGarden(low=false,assets={}){ const az=random()*TAU,r=Math.sqrt(random())*12,x=Math.cos(az)*r,z=Math.sin(az)*r; dummy.position.set(x,terrainY(x,z),z);dummy.rotation.set((random()-.5)*.4,random()*TAU, (random()-.5)*.4);dummy.scale.setScalar(.3+random()*.9);dummy.updateMatrix();grass.setMatrixAt(i,dummy.matrix); } - const grassBatches=batchInstances(grass,3);scene.add(grassBatches.group); + grass.computeBoundingSphere();grass.frustumCulled=true;scene.add(grass); const count=low?180:440,seeds=[],positions=new Float32Array(count*3),rainPositions=new Float32Array(count*6); for(let i=0;i.01;tree.petioles.visible=winter<.99; - tree.petioleBatches.group.visible=tree.petioles.visible; - tree.leafBatches.group.visible=winter<1; + tree.leaves.visible=winter<1; const matrices=tree.leaves.instanceMatrix.array,colors=tree.leaves.instanceColor.array,base=tree.baseMatrices; for(let i=0;im.material.color.set("#728b78").lerp(w.scene.fog.color,.2+i*.18)); w.falling.visible=autumn>.01;w.fallen.visible=autumn>.01; diff --git a/scripts/garden-browser-check.mjs b/scripts/garden-browser-check.mjs index 9da960d..0365d5a 100644 --- a/scripts/garden-browser-check.mjs +++ b/scripts/garden-browser-check.mjs @@ -62,7 +62,8 @@ try{ const activeBefore=await camera();await page.mouse.move(x,y); for(let i=0;i<5;i++)await page.mouse.wheel(0,-70); await page.waitForFunction(c=>document.querySelector(".garden-canvas").dataset.camera!==c,activeBefore); - await page.getByRole("button",{name:"暂停天气",exact:true}).click();await page.waitForTimeout(500); + await page.getByRole("button",{name:"暂停天气",exact:true}).click(); + await page.waitForFunction(()=>document.querySelector(".garden-canvas").dataset.weatherPaused==="true"); const pausedTime=await scene.getAttribute("data-weather-time"); const pausedBefore=await camera();await page.mouse.move(x,y);await page.mouse.wheel(0,200); await page.waitForFunction(c=>document.querySelector(".garden-canvas").dataset.camera!==c,pausedBefore); diff --git a/scripts/garden-perf-page.mjs b/scripts/garden-perf-page.mjs index 808992b..7a79a60 100644 --- a/scripts/garden-perf-page.mjs +++ b/scripts/garden-perf-page.mjs @@ -1,5 +1,5 @@ import * as T from "three"; -const query=new URLSearchParams(location.search),model=await import(query.get("model")); +const query=new URLSearchParams(location.search),model=await import(/* @vite-ignore */ query.get("model")); const assets=await model.loadGardenAssets(),world=model.buildGarden(false,assets); const renderer=new T.WebGLRenderer({antialias:true,alpha:false,powerPreference:"high-performance"}); renderer.setSize(1000,700);renderer.setPixelRatio(1); @@ -7,6 +7,10 @@ renderer.toneMapping=T.ACESFilmicToneMapping;renderer.toneMappingExposure=1.05; renderer.shadowMap.enabled=true;renderer.shadowMap.type=T.PCFSoftShadowMap; document.body.style.margin="0";document.body.appendChild(renderer.domElement); const camera=new T.PerspectiveCamera(40,1000/700,.2,250),gl=renderer.getContext(); +const pixel=new Uint8Array(4); +// Chromium intentionally implements WebGL finish as flush. Synchronous CPU +// readback is required for this benchmark to include completed GPU work. +const complete=()=>gl.readPixels(0,0,1,1,gl.RGBA,gl.UNSIGNED_BYTE,pixel); const stats=values=>{const s=values.toSorted((a,b)=>a-b);return {p50:s[Math.floor(s.length*.5)],p95:s[Math.min(s.length-1,Math.floor(s.length*.95))]};}; const state=(season,mix=0)=>({from:season,to:mix?(season+1)%4:season,mix}); function pose(view){ @@ -18,14 +22,14 @@ function pose(view){ window.measure=async(view,season,mix=0)=>{ pose(view);const sample=state(season,mix); const cpu=[],completed=[],counts=[]; - for(let i=0;i<5;i++){ + for(let i=0;i<4;i++){ const time=12+i/60,start=performance.now();model.updateGarden(world,sample,time);const simulated=performance.now(); renderer.info.autoReset=false;renderer.info.reset();renderer.render(world.scene,camera); - gl.finish();const end=performance.now(); - if(i>=2){cpu.push(simulated-start);completed.push(end-start);counts.push({...renderer.info.render});} + complete();const end=performance.now(); + if(i>=1){cpu.push(simulated-start);completed.push(end-start);counts.push({...renderer.info.render});} } // A deterministic frame for image equivalence, independent of timing. - model.updateGarden(world,sample,12);renderer.render(world.scene,camera);gl.finish(); + model.updateGarden(world,sample,12);renderer.render(world.scene,camera);complete(); return {view,season,mix,cpuMs:stats(cpu),completedFrameMs:stats(completed),draw:counts.at(-1)}; }; window.cpuMeasure=()=>{ diff --git a/scripts/garden-performance-check.mjs b/scripts/garden-performance-check.mjs index 916a5cd..9de8daa 100644 --- a/scripts/garden-performance-check.mjs +++ b/scripts/garden-performance-check.mjs @@ -43,7 +43,8 @@ try{ } assert.deepEqual(results.after.inventory,results.before.inventory,"All allocated geometry, instances and quality settings are unchanged"); assert.ok(results.after.cpu.paused.p50x.label==="summer-detail").trianglesAfterx.label==="summer-detail").trianglesBefore,"Close-up omits only frustum-invisible instances"); + for(let i=0;ix.label==="winter-detail").trianglesAfterx.label==="winter-detail").trianglesBefore,"Zero-area winter leaves are not submitted"); assert.deepEqual(errors,[]); await writeFile(join(output,"report.json"),JSON.stringify({passed:true,baselineCommit,results,comparisons,errors},null,2)); console.log(JSON.stringify({passed:true,comparisons,cpu:results.after.cpu},null,2)); diff --git a/scripts/seasons.test.mjs b/scripts/seasons.test.mjs index 54d888a..07d33fb 100644 --- a/scripts/seasons.test.mjs +++ b/scripts/seasons.test.mjs @@ -91,30 +91,22 @@ test("fine twig UVs never fold or mirror their normal map",()=>{ } }); -test("performance batches retain every full-detail instance and conservative bounds",()=>{ +test("performance caches retain full detail with conservative per-tree bounds",()=>{ const world=buildGarden(false); assert.equal(world.trees.reduce((sum,t)=>sum+t.leaves.count,0),7920); assert.equal(world.grass.count,10000);assert.deepEqual(world.light.shadow.mapSize.toArray(),[2048,2048]); - for(const batch of [...world.trees.flatMap(t=>[t.leafBatches,t.petioleBatches]),world.grassBatches]){ - const seen=new Set(),matrix=new Matrix4(); - for(const {mesh,indices} of batch.batches){ - assert.equal(mesh.geometry,batch.source.geometry);assert.equal(mesh.material,batch.source.material); - assert.equal(mesh.castShadow,batch.source.castShadow);assert.equal(mesh.receiveShadow,batch.source.receiveShadow); - assert.equal(mesh.frustumCulled,true); - for(let i=0;i[t.leaves,t.petioles]),world.grass]){ + assert.equal(mesh.frustumCulled,true);const matrix=new Matrix4(); + for(let i=0;iworld.trees.flatMap(t=>t.leafBatches.batches.map(b=>b.mesh.instanceMatrix.version)).concat(world.particles.geometry.attributes.position.version,world.rain.geometry.attributes.position.version,world.falling.instanceMatrix.version); + const versions=()=>world.trees.map(t=>t.leaves.instanceMatrix.version).concat(world.particles.geometry.attributes.position.version,world.rain.geometry.attributes.position.version,world.falling.instanceMatrix.version); const before=versions(); for(let i=0;i<100;i++)assert.equal(updateGarden(world,sampleSeason(22),12),false); assert.deepEqual(versions(),before,"Camera-only updates make no buffer uploads"); - updateGarden(world,sampleSeason(66),13);for(const t of world.trees)assert.equal(t.leafBatches.group.visible,false); + updateGarden(world,sampleSeason(66),13);for(const t of world.trees)assert.equal(t.leaves.visible,false); assert.equal(world.rain.visible,false); updateGarden(world,sampleSeason(0),14);assert.equal(world.particles.visible,false); disposeGarden(world); From 2d5af17c3b68e5780a4cb9cfce8d8c1f1f0426b5 Mon Sep 17 00:00:00 2001 From: hulingjun <166984918+hulingjun@users.noreply.github.com> Date: Sun, 6 Sep 2026 10:51:46 +0800 Subject: [PATCH 6/7] Avoid repeated PBR shading behind identical opaque leaf depth --- app/garden/world.mjs | 11 +++++++++-- scripts/garden-perf-page.mjs | 2 +- scripts/garden-performance-check.mjs | 2 +- scripts/seasons.test.mjs | 7 +++++++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/garden/world.mjs b/app/garden/world.mjs index b711fd8..727b74a 100644 --- a/app/garden/world.mjs +++ b/app/garden/world.mjs @@ -236,6 +236,13 @@ export function buildGarden(low=false,assets={}){ // tests these bounds against its own light frustum, not the viewer's. leaves.computeBoundingSphere();leaves.boundingSphere.radius+=.12;leaves.frustumCulled=true; petioles.computeBoundingSphere();petioles.frustumCulled=true; + // Populate the nearest opaque leaf depth before expensive PBR lighting. + // Both passes use the identical geometry, transform buffer, alpha test and wind. + const depthOnly=new T.MeshDepthMaterial({map:assets.leaf||null,alphaTest:.42,side:T.DoubleSide,colorWrite:false,depthWrite:true}); + windShader(depthOnly,wind); + const leafPrepass=new T.InstancedMesh(leafGeo,depthOnly,seeds.length); + leafPrepass.instanceMatrix=leaves.instanceMatrix;leafPrepass.boundingSphere=leaves.boundingSphere; + leafPrepass.renderOrder=1;leaves.renderOrder=2;leafPrepass.userData.depthPrepass=true;group.add(leafPrepass); const snow=new T.Mesh(bark.geometry,new T.MeshStandardMaterial({color:"#e7edf0",roughness:1,transparent:true,opacity:0,polygonOffset:true,polygonOffsetFactor:-1})); snow.material.onBeforeCompile=shader=>{ shader.vertexShader="varying float gardenUp;\n"+shader.vertexShader; @@ -245,7 +252,7 @@ export function buildGarden(low=false,assets={}){ }; snow.material.depthWrite=false; snow.scale.setScalar(1.018);group.add(snow); - trees.push({group,bark,leaves,petioles,seeds,shoots,snow,baseMatrices}); + trees.push({group,bark,leaves,petioles,seeds,shoots,snow,baseMatrices,leafPrepass}); } // Grass blades form the clearing, not a floating pedestal. const grassGeo=new T.PlaneGeometry(.045,.4,1,4);grassGeo.translate(0,.2,0); @@ -303,7 +310,7 @@ export function updateGarden(w,state,time){ const c1=blend("leaf"),c2=blend("tip"); for(const tree of w.trees){ tree.snow.material.opacity=winter*.9;tree.snow.visible=winter>.01;tree.petioles.visible=winter<.99; - tree.leaves.visible=winter<1; + tree.leaves.visible=winter<1;tree.leafPrepass.visible=tree.leaves.visible; const matrices=tree.leaves.instanceMatrix.array,colors=tree.leaves.instanceColor.array,base=tree.baseMatrices; for(let i=0;i{ }; window.inventory=()=>{ const geometries=[]; - world.scene.traverse(o=>{if(o.isMesh){const vertices=o.geometry.attributes.position.count,triangles=o.geometry.index?o.geometry.index.count/3:vertices/3;geometries.push({vertices,triangles,count:o.isInstancedMesh?o.count:1});}}); + world.scene.traverse(o=>{if(o.isMesh&&!o.userData.depthPrepass){const vertices=o.geometry.attributes.position.count,triangles=o.geometry.index?o.geometry.index.count/3:vertices/3;geometries.push({vertices,triangles,count:o.isInstancedMesh?o.count:1});}}); return {leaves:world.trees.reduce((sum,t)=>sum+t.leaves.count,0),petioles:world.trees.reduce((sum,t)=>sum+t.petioles.count,0),grass:world.grass.count, allocatedTriangles:geometries.reduce((sum,g)=>sum+g.triangles*g.count,0),shadowSize:world.light.shadow.mapSize.toArray(),pixelRatio:renderer.getPixelRatio()}; }; diff --git a/scripts/garden-performance-check.mjs b/scripts/garden-performance-check.mjs index 9de8daa..c2c5b0c 100644 --- a/scripts/garden-performance-check.mjs +++ b/scripts/garden-performance-check.mjs @@ -43,7 +43,7 @@ try{ } assert.deepEqual(results.after.inventory,results.before.inventory,"All allocated geometry, instances and quality settings are unchanged"); assert.ok(results.after.cpu.paused.p50x.label==="winter-detail").trianglesAfterx.label==="winter-detail").trianglesBefore,"Zero-area winter leaves are not submitted"); assert.deepEqual(errors,[]); await writeFile(join(output,"report.json"),JSON.stringify({passed:true,baselineCommit,results,comparisons,errors},null,2)); diff --git a/scripts/seasons.test.mjs b/scripts/seasons.test.mjs index 07d33fb..bbfe9ae 100644 --- a/scripts/seasons.test.mjs +++ b/scripts/seasons.test.mjs @@ -103,6 +103,13 @@ test("performance caches retain full detail with conservative per-tree bounds",( } updateGarden(world,sampleSeason(22),12); const versions=()=>world.trees.map(t=>t.leaves.instanceMatrix.version).concat(world.particles.geometry.attributes.position.version,world.rain.geometry.attributes.position.version,world.falling.instanceMatrix.version); + for(const tree of world.trees){ + assert.equal(tree.leafPrepass.geometry,tree.leaves.geometry); + assert.equal(tree.leafPrepass.instanceMatrix,tree.leaves.instanceMatrix); + assert.equal(tree.leafPrepass.boundingSphere,tree.leaves.boundingSphere); + assert.equal(tree.leafPrepass.material.alphaTest,tree.leaves.material.alphaTest); + assert.equal(tree.leafPrepass.castShadow,false);assert.equal(tree.leafPrepass.material.colorWrite,false); + } const before=versions(); for(let i=0;i<100;i++)assert.equal(updateGarden(world,sampleSeason(22),12),false); assert.deepEqual(versions(),before,"Camera-only updates make no buffer uploads"); From f2ba166b4f36df5a399171365eec4cb8f75513a5 Mon Sep 17 00:00:00 2001 From: hulingjun <166984918+hulingjun@users.noreply.github.com> Date: Sun, 6 Sep 2026 11:06:30 +0800 Subject: [PATCH 7/7] Publish the exact verified full-detail cache/culling tree; discard slower depth experiment --- app/garden/world.mjs | 11 ++--------- scripts/garden-perf-page.mjs | 2 +- scripts/garden-performance-check.mjs | 2 +- scripts/seasons.test.mjs | 7 ------- 4 files changed, 4 insertions(+), 18 deletions(-) diff --git a/app/garden/world.mjs b/app/garden/world.mjs index 727b74a..b711fd8 100644 --- a/app/garden/world.mjs +++ b/app/garden/world.mjs @@ -236,13 +236,6 @@ export function buildGarden(low=false,assets={}){ // tests these bounds against its own light frustum, not the viewer's. leaves.computeBoundingSphere();leaves.boundingSphere.radius+=.12;leaves.frustumCulled=true; petioles.computeBoundingSphere();petioles.frustumCulled=true; - // Populate the nearest opaque leaf depth before expensive PBR lighting. - // Both passes use the identical geometry, transform buffer, alpha test and wind. - const depthOnly=new T.MeshDepthMaterial({map:assets.leaf||null,alphaTest:.42,side:T.DoubleSide,colorWrite:false,depthWrite:true}); - windShader(depthOnly,wind); - const leafPrepass=new T.InstancedMesh(leafGeo,depthOnly,seeds.length); - leafPrepass.instanceMatrix=leaves.instanceMatrix;leafPrepass.boundingSphere=leaves.boundingSphere; - leafPrepass.renderOrder=1;leaves.renderOrder=2;leafPrepass.userData.depthPrepass=true;group.add(leafPrepass); const snow=new T.Mesh(bark.geometry,new T.MeshStandardMaterial({color:"#e7edf0",roughness:1,transparent:true,opacity:0,polygonOffset:true,polygonOffsetFactor:-1})); snow.material.onBeforeCompile=shader=>{ shader.vertexShader="varying float gardenUp;\n"+shader.vertexShader; @@ -252,7 +245,7 @@ export function buildGarden(low=false,assets={}){ }; snow.material.depthWrite=false; snow.scale.setScalar(1.018);group.add(snow); - trees.push({group,bark,leaves,petioles,seeds,shoots,snow,baseMatrices,leafPrepass}); + trees.push({group,bark,leaves,petioles,seeds,shoots,snow,baseMatrices}); } // Grass blades form the clearing, not a floating pedestal. const grassGeo=new T.PlaneGeometry(.045,.4,1,4);grassGeo.translate(0,.2,0); @@ -310,7 +303,7 @@ export function updateGarden(w,state,time){ const c1=blend("leaf"),c2=blend("tip"); for(const tree of w.trees){ tree.snow.material.opacity=winter*.9;tree.snow.visible=winter>.01;tree.petioles.visible=winter<.99; - tree.leaves.visible=winter<1;tree.leafPrepass.visible=tree.leaves.visible; + tree.leaves.visible=winter<1; const matrices=tree.leaves.instanceMatrix.array,colors=tree.leaves.instanceColor.array,base=tree.baseMatrices; for(let i=0;i{ }; window.inventory=()=>{ const geometries=[]; - world.scene.traverse(o=>{if(o.isMesh&&!o.userData.depthPrepass){const vertices=o.geometry.attributes.position.count,triangles=o.geometry.index?o.geometry.index.count/3:vertices/3;geometries.push({vertices,triangles,count:o.isInstancedMesh?o.count:1});}}); + world.scene.traverse(o=>{if(o.isMesh){const vertices=o.geometry.attributes.position.count,triangles=o.geometry.index?o.geometry.index.count/3:vertices/3;geometries.push({vertices,triangles,count:o.isInstancedMesh?o.count:1});}}); return {leaves:world.trees.reduce((sum,t)=>sum+t.leaves.count,0),petioles:world.trees.reduce((sum,t)=>sum+t.petioles.count,0),grass:world.grass.count, allocatedTriangles:geometries.reduce((sum,g)=>sum+g.triangles*g.count,0),shadowSize:world.light.shadow.mapSize.toArray(),pixelRatio:renderer.getPixelRatio()}; }; diff --git a/scripts/garden-performance-check.mjs b/scripts/garden-performance-check.mjs index c2c5b0c..9de8daa 100644 --- a/scripts/garden-performance-check.mjs +++ b/scripts/garden-performance-check.mjs @@ -43,7 +43,7 @@ try{ } assert.deepEqual(results.after.inventory,results.before.inventory,"All allocated geometry, instances and quality settings are unchanged"); assert.ok(results.after.cpu.paused.p50x.label==="winter-detail").trianglesAfterx.label==="winter-detail").trianglesBefore,"Zero-area winter leaves are not submitted"); assert.deepEqual(errors,[]); await writeFile(join(output,"report.json"),JSON.stringify({passed:true,baselineCommit,results,comparisons,errors},null,2)); diff --git a/scripts/seasons.test.mjs b/scripts/seasons.test.mjs index bbfe9ae..07d33fb 100644 --- a/scripts/seasons.test.mjs +++ b/scripts/seasons.test.mjs @@ -103,13 +103,6 @@ test("performance caches retain full detail with conservative per-tree bounds",( } updateGarden(world,sampleSeason(22),12); const versions=()=>world.trees.map(t=>t.leaves.instanceMatrix.version).concat(world.particles.geometry.attributes.position.version,world.rain.geometry.attributes.position.version,world.falling.instanceMatrix.version); - for(const tree of world.trees){ - assert.equal(tree.leafPrepass.geometry,tree.leaves.geometry); - assert.equal(tree.leafPrepass.instanceMatrix,tree.leaves.instanceMatrix); - assert.equal(tree.leafPrepass.boundingSphere,tree.leaves.boundingSphere); - assert.equal(tree.leafPrepass.material.alphaTest,tree.leaves.material.alphaTest); - assert.equal(tree.leafPrepass.castShadow,false);assert.equal(tree.leafPrepass.material.colorWrite,false); - } const before=versions(); for(let i=0;i<100;i++)assert.equal(updateGarden(world,sampleSeason(22),12),false); assert.deepEqual(versions(),before,"Camera-only updates make no buffer uploads");