From 418765d59540537dc059f6ae7e7f5f0feb60a6d2 Mon Sep 17 00:00:00 2001 From: SeanOMik Date: Sat, 30 Nov 2024 12:05:34 -0500 Subject: [PATCH] render: use depth buffer --- .../src/render/graph/passes/sprite.rs | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/crates/lyra-game/src/render/graph/passes/sprite.rs b/crates/lyra-game/src/render/graph/passes/sprite.rs index 743cae4..141d90b 100644 --- a/crates/lyra-game/src/render/graph/passes/sprite.rs +++ b/crates/lyra-game/src/render/graph/passes/sprite.rs @@ -15,9 +15,7 @@ use wgpu::util::DeviceExt; use crate::{ render::{ - graph::{Node, NodeDesc, NodeType, SlotAttribute}, - resource::{FragmentState, RenderPipeline, RenderPipelineDescriptor, VertexState}, - vertex::Vertex2D, + graph::{Node, NodeDesc, NodeType, SlotAttribute}, resource::{FragmentState, RenderPipeline, RenderPipelineDescriptor, VertexState}, texture::RenderTexture, vertex::Vertex2D }, sprite::{AtlasSprite, Sprite}, }; @@ -294,7 +292,13 @@ impl Node for SpritePass { write_mask: wgpu::ColorWrites::ALL, })], }), - depth_stencil: None, + depth_stencil: Some(wgpu::DepthStencilState { + format: RenderTexture::DEPTH_FORMAT, + depth_write_enabled: true, + depth_compare: wgpu::CompareFunction::Less, + stencil: wgpu::StencilState::default(), // TODO: stencil buffer + bias: wgpu::DepthBiasState::default(), + }), primitive: wgpu::PrimitiveState { cull_mode: Some(wgpu::Face::Back), ..Default::default() @@ -421,6 +425,12 @@ impl Node for SpritePass { let vt = graph.view_target(); let view = vt.render_view(); + let depth_view = graph + .slot_value(BasePassSlots::DepthTextureView) + .unwrap() + .as_texture_view() + .expect("BasePassSlots::DepthTextureView was not a TextureView slot"); + let camera_bg = graph.bind_group(BasePassSlots::Camera); { @@ -440,7 +450,14 @@ impl Node for SpritePass { store: wgpu::StoreOp::Store, }, })], - depth_stencil_attachment: None, + depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment { + view: depth_view, + depth_ops: Some(wgpu::Operations { + load: wgpu::LoadOp::Clear(1.0), + store: wgpu::StoreOp::Store, + }), + stencil_ops: None, + }), timestamp_writes: None, occlusion_query_set: None, });