render: use depth buffer

This commit is contained in:
SeanOMik 2024-11-30 12:05:34 -05:00 committed by SeanOMik
parent fa6511bff1
commit 418765d595
1 changed files with 22 additions and 5 deletions

View File

@ -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,
});