From 6e9e3fa445d94c4ac7e3eaba1373bab1bc7056ba Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Mon, 6 May 2024 17:09:13 +0200 Subject: [PATCH] enable depth texture --- kubi/src/rendering/world.rs | 15 ++++++++++++--- kubi/src/rendering/world/pipeline.rs | 13 ++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/kubi/src/rendering/world.rs b/kubi/src/rendering/world.rs index 829705c..3df4b11 100644 --- a/kubi/src/rendering/world.rs +++ b/kubi/src/rendering/world.rs @@ -7,7 +7,7 @@ use crate::{ settings::GameSettings, world::{ChunkMeshStorage, ChunkStorage}, }; -use super::{camera::{self, CameraUniformBuffer}, RenderCtx}; +use super::{camera::{self, CameraUniformBuffer}, depth::DepthTexture, RenderCtx}; mod pipeline; mod vertex; @@ -29,12 +29,13 @@ pub fn init_world_render_state(storages: AllStoragesView) { pub fn draw_world( ctx: &mut RenderCtx, mut state: UniqueViewMut, + camera_ubo: UniqueView, + depth: UniqueView, textures: UniqueView, camera: View, chunks: UniqueView, meshes: NonSendSync>, - camera_ubo: UniqueView, - settings: UniqueView, + //settings: UniqueView, ) { let camera = camera.iter().next().expect("No cameras in the scene"); @@ -48,6 +49,14 @@ pub fn draw_world( store: wgpu::StoreOp::Store, }, })], + depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment { + view: &depth.depth_view, + depth_ops: Some(wgpu::Operations { + load: wgpu::LoadOp::Clear(1.0), + store: wgpu::StoreOp::Store, + }), + stencil_ops: None, + }), ..Default::default() }); diff --git a/kubi/src/rendering/world/pipeline.rs b/kubi/src/rendering/world/pipeline.rs index 80fe6b1..040ed4d 100644 --- a/kubi/src/rendering/world/pipeline.rs +++ b/kubi/src/rendering/world/pipeline.rs @@ -1,11 +1,12 @@ -use shipyard::{Unique, UniqueView}; +use shipyard::UniqueView; use crate::{ prefabs::TexturePrefabs, - rendering::{camera::CameraUniformBuffer, world::ChunkVertex, Renderer} + rendering::{camera::CameraUniformBuffer, depth::DepthTexture, world::ChunkVertex, Renderer} }; pub fn init_world_pipeline( ren: UniqueView, + depth: UniqueView, textures: UniqueView, camera_ubo: UniqueView, ) -> wgpu::RenderPipeline { @@ -52,7 +53,13 @@ pub fn init_world_pipeline( polygon_mode: wgpu::PolygonMode::Fill, conservative: false, }, - depth_stencil: None, + depth_stencil: Some(wgpu::DepthStencilState { + format: depth.depth_texture.format(), + depth_write_enabled: true, + depth_compare: wgpu::CompareFunction::Less, + stencil: wgpu::StencilState::default(), + bias: wgpu::DepthBiasState::default(), + }), multisample: wgpu::MultisampleState::default(), multiview: None, })