perf: compile district shaders at the on-ramp instead of mid-drive

This commit is contained in:
2026-10-10 19:03:37 +03:00
parent 565deccd25
commit 7e6f0abbaa

View File

@@ -246,6 +246,9 @@ export function createDistricts(
); );
const dummy = new THREE.Object3D(); const dummy = new THREE.Object3D();
// Draw freshly installed (still flat) pieces for a couple of frames so their
// shader programs compile while parked at the on-ramp, not mid-drive.
let warmFrames = 0;
const install = (piece: DistrictPiece, body: Geometry, light: Geometry) => { const install = (piece: DistrictPiece, body: Geometry, light: Geometry) => {
const entry = state.get(piece); const entry = state.get(piece);
if (!entry) return; if (!entry) return;
@@ -275,6 +278,7 @@ export function createDistricts(
mesh.instanceMatrix.needsUpdate = true; mesh.instanceMatrix.needsUpdate = true;
entry.meshes.push(mesh); entry.meshes.push(mesh);
group.add(mesh); group.add(mesh);
warmFrames = 2;
} }
}; };
@@ -303,6 +307,8 @@ export function createDistricts(
group, group,
update(distance, energy, section, elapsed, dt) { update(distance, energy, section, elapsed, dt) {
current = section; current = section;
const warming = warmFrames > 0;
if (warming) warmFrames -= 1;
shared.uDistance.value = distance; shared.uDistance.value = distance;
shared.uEnergy.value = energy; shared.uEnergy.value = energy;
shared.uTime.value = elapsed; shared.uTime.value = elapsed;
@@ -313,7 +319,7 @@ export function createDistricts(
const rate = target > entry.rise.value ? 0.9 : 1.4; const rate = target > entry.rise.value ? 0.9 : 1.4;
entry.rise.value += (target - entry.rise.value) * (1 - Math.exp(-dt * rate)); entry.rise.value += (target - entry.rise.value) * (1 - Math.exp(-dt * rate));
if (Math.abs(target - entry.rise.value) < 0.002) entry.rise.value = target; if (Math.abs(target - entry.rise.value) < 0.002) entry.rise.value = target;
const visible = entry.rise.value > 0.002; const visible = warming || entry.rise.value > 0.002;
for (const mesh of entry.meshes) mesh.visible = visible; for (const mesh of entry.meshes) mesh.visible = visible;
} }
}, },