Avoid depth z-fighting

This commit is contained in:
Maximilian Ammann 2022-01-17 10:34:14 +01:00
parent 9bbf3deee7
commit 319694cf27
4 changed files with 12 additions and 5 deletions

View File

@ -64,7 +64,7 @@ pub fn create_map_render_pipeline_description<'a>(
depth_stencil: Some(wgpu::DepthStencilState {
format: DEPTH_TEXTURE_FORMAT,
depth_write_enabled: !update_stencil,
depth_compare: wgpu::CompareFunction::Less, // FIXME
depth_compare: wgpu::CompareFunction::Greater, // FIXME
stencil: wgpu::StencilState {
front: stencil_state,
back: stencil_state,

View File

@ -452,7 +452,7 @@ impl RenderState {
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment {
view: &self.depth_texture.view,
depth_ops: Some(wgpu::Operations {
load: wgpu::LoadOp::Clear(1.0),
load: wgpu::LoadOp::Clear(0.0),
store: true,
}),
stencil_ops: Some(wgpu::Operations {

View File

@ -25,9 +25,16 @@ fn main(
let z = 0.0;
let width = 3.0;
// The following code moves all "invisible" vertices to (0, 0, 0)
//if (color.w == 0.0) {
// return VertexOutput(color, vec4<f32>(0.0, 0.0, 0.0, 1.0));
//}
let world_pos = vec3<f32>(position + normal * width, z) + translate;
let position = globals.camera.view_proj * vec4<f32>(world_pos, 1.0);
var position = globals.camera.view_proj * vec4<f32>(world_pos, 1.0);
position.z = 1.0;
return VertexOutput(color, position);
}

View File

@ -45,7 +45,7 @@ fn main(
let world_pos = scaling * a_position + vec3<f32>(mask_offset, z);
let position = globals.camera.view_proj * vec4<f32>(world_pos, 1.0);
var position = globals.camera.view_proj * vec4<f32>(world_pos, 1.0);
position.z = 1.0;
return VertexOutput(debug_color, position);
}