Occlusion culling
This commit is contained in:
@@ -28,6 +28,7 @@ import { ChunkWorkerPool } from "../chunk_workers.ts";
|
||||
import type { FaceGroup, FromChunkWorker, SectionLight } from "../workers/chunk_messages.ts";
|
||||
import { create_index_buffer, create_vertex_buffer, destroy_buffer, Texture } from "../renderer/mod.ts";
|
||||
import { crosses_planes } from "../workers/translucent_sort.ts";
|
||||
import { ALL_VISIBLE } from "../workers/visibility.ts";
|
||||
import { Camera } from "../camera.ts";
|
||||
import type { Entity } from "../entity/entity.ts";
|
||||
import type { ModelJson } from "@/common/block_models.ts";
|
||||
@@ -72,6 +73,12 @@ export interface RenderSection {
|
||||
translucent_sort?: TranslucentSort;
|
||||
// from its last mesh, see get_light. undefined until it's been meshed
|
||||
light?: SectionLight;
|
||||
// from its last mesh, which faces see which, see client/workers/visibility.ts. all of them until it's been meshed
|
||||
visibility: number;
|
||||
// the last search for what the camera can see that reached it, and the faces it was reached through, see
|
||||
// client/rendering/occlusion.ts
|
||||
search: number;
|
||||
incoming: number;
|
||||
}
|
||||
|
||||
export interface ChunkMesh {
|
||||
@@ -135,6 +142,8 @@ export class ClientLevel {
|
||||
#sorted = new Set<RenderSection>();
|
||||
// the sections with quads or visuals, the only ones there are to draw
|
||||
drawn = new Set<RenderSection>();
|
||||
// bumped whenever a chunk comes or goes or a section is meshed, which can change what the camera sees
|
||||
sections_version = 0;
|
||||
second_timer = 0;
|
||||
tick_timer = 0;
|
||||
// world time in ticks, counted here between the server's updates. see common/time.ts
|
||||
@@ -241,9 +250,20 @@ export class ClientLevel {
|
||||
} else {
|
||||
const chunk: Chunk = { x, z, column, sky, biome_colors, sections: [] };
|
||||
for (let index = 0; index < column.sections.length; index++) {
|
||||
chunk.sections.push({ chunk, index, mesh_version: 0, meshes: {}, min_y: Infinity, max_y: -Infinity });
|
||||
chunk.sections.push({
|
||||
chunk,
|
||||
index,
|
||||
mesh_version: 0,
|
||||
meshes: {},
|
||||
min_y: Infinity,
|
||||
max_y: -Infinity,
|
||||
visibility: ALL_VISIBLE,
|
||||
search: 0,
|
||||
incoming: 0,
|
||||
});
|
||||
}
|
||||
this.chunks.set(chunk_key(x, z), chunk);
|
||||
this.sections_version += 1;
|
||||
}
|
||||
// and its neighbors, whose border faces and light depend on it
|
||||
this.#mark_dirty_around(x, z, this.shape.min_y, this.shape.max_y);
|
||||
@@ -511,6 +531,7 @@ export class ClientLevel {
|
||||
}
|
||||
this.#dirty.delete(chunk);
|
||||
this.chunks.delete(key);
|
||||
this.sections_version += 1;
|
||||
this.block_data.delete(key);
|
||||
this.visuals.unload(cx, cz);
|
||||
for (const [position, { x, z }] of this.break_progress) {
|
||||
@@ -684,7 +705,9 @@ export class ClientLevel {
|
||||
continue;
|
||||
}
|
||||
this.#delete_mesh(section);
|
||||
this.sections_version += 1;
|
||||
section.light = mesh.light;
|
||||
section.visibility = mesh.visibility;
|
||||
section.min_y = mesh.min_y;
|
||||
section.max_y = mesh.max_y;
|
||||
// with no quads or visuals its bounds are empty
|
||||
|
||||
Reference in New Issue
Block a user