Optimize rendering a lil

This commit is contained in:
2026-10-02 19:35:16 -03:00
parent 4397bf2c90
commit 1511338a23
8 changed files with 15 additions and 0 deletions
+8
View File
@@ -60,6 +60,14 @@ export class LevelRenderer {
this.#visible.push(chunk);
}
}
// near to far, like sodium, so what's in front fills the depth buffer first and the gpu can skip shading what's
// behind it
const distance_sq = (chunk: Chunk) => {
const dx = (chunk.x + 0.5) * CHUNK_SIZE - camera.x;
const dz = (chunk.z + 0.5) * CHUNK_SIZE - camera.z;
return dx * dx + dz * dz;
};
this.#visible.sort((a, b) => distance_sq(a) - distance_sq(b));
set_current_texture(level.image.tex);