Geo renderer improvements
This commit is contained in:
+20
-1
@@ -42,6 +42,8 @@ let canvas_format: GPUTextureFormat;
|
||||
|
||||
let pipeline_2d: GPURenderPipeline;
|
||||
let pipeline_3d: GPURenderPipeline;
|
||||
// the same, drawing both sides of each face, see set_face_culling
|
||||
let pipeline_3d_no_cull: GPURenderPipeline;
|
||||
let terrain_pipelines: Record<RenderLayer, GPURenderPipeline>;
|
||||
let instance_pipelines: { cutout: GPURenderPipeline; translucent: GPURenderPipeline };
|
||||
// 0 1 2 0 2 3 for every quad, shared by all solid and cutout chunk meshes
|
||||
@@ -76,6 +78,7 @@ let current_texture: GPUTexture | null = null;
|
||||
export let white_tex: GPUTexture | null = null;
|
||||
|
||||
let mode3d = false;
|
||||
let cull_faces = true;
|
||||
|
||||
let camera: Camera | undefined;
|
||||
|
||||
@@ -496,6 +499,14 @@ export function set_render_time(ticks: number) {
|
||||
render_time = ticks % RENDER_TIME_PERIOD;
|
||||
}
|
||||
|
||||
// whether 3d drawing leaves out faces seen from behind, true unless turned off. off draws both sides, like entity
|
||||
// models do, where a flat cube's one face is seen from either side and an open box shows its inside
|
||||
export function set_face_culling(cull: boolean) {
|
||||
if (cull_faces === cull) return;
|
||||
flush_batch();
|
||||
cull_faces = cull;
|
||||
}
|
||||
|
||||
export function end_mode_3d() {
|
||||
if (!mode3d) {
|
||||
return;
|
||||
@@ -832,7 +843,7 @@ function draw(buffer: GPUBuffer, offset: number, vertex_count: number) {
|
||||
|
||||
const render_pass = ensure_pass();
|
||||
|
||||
const pipeline = mode3d ? pipeline_3d : pipeline_2d;
|
||||
const pipeline = mode3d ? (cull_faces ? pipeline_3d : pipeline_3d_no_cull) : pipeline_2d;
|
||||
if (current_pipeline !== pipeline) {
|
||||
render_pass.setPipeline(pipeline);
|
||||
current_pipeline = pipeline;
|
||||
@@ -1035,6 +1046,14 @@ function create_pipelines() {
|
||||
primitive: primitive_3d,
|
||||
depthStencil: depth_3d,
|
||||
});
|
||||
pipeline_3d_no_cull = device.createRenderPipeline({
|
||||
layout,
|
||||
vertex,
|
||||
fragment,
|
||||
multisample,
|
||||
primitive: { ...primitive_3d, cullMode: "none" },
|
||||
depthStencil: depth_3d,
|
||||
});
|
||||
|
||||
const terrain_module = device.createShaderModule({ code: terrain_shader_src });
|
||||
const terrain_layout = device.createPipelineLayout({
|
||||
|
||||
Reference in New Issue
Block a user