perf: compile district shaders at the on-ramp instead of mid-drive
This commit is contained in:
@@ -246,6 +246,9 @@ export function createDistricts(
|
||||
);
|
||||
|
||||
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 entry = state.get(piece);
|
||||
if (!entry) return;
|
||||
@@ -275,6 +278,7 @@ export function createDistricts(
|
||||
mesh.instanceMatrix.needsUpdate = true;
|
||||
entry.meshes.push(mesh);
|
||||
group.add(mesh);
|
||||
warmFrames = 2;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -303,6 +307,8 @@ export function createDistricts(
|
||||
group,
|
||||
update(distance, energy, section, elapsed, dt) {
|
||||
current = section;
|
||||
const warming = warmFrames > 0;
|
||||
if (warming) warmFrames -= 1;
|
||||
shared.uDistance.value = distance;
|
||||
shared.uEnergy.value = energy;
|
||||
shared.uTime.value = elapsed;
|
||||
@@ -313,7 +319,7 @@ export function createDistricts(
|
||||
const rate = target > entry.rise.value ? 0.9 : 1.4;
|
||||
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;
|
||||
const visible = entry.rise.value > 0.002;
|
||||
const visible = warming || entry.rise.value > 0.002;
|
||||
for (const mesh of entry.meshes) mesh.visible = visible;
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user