From 362a14d7498016d385f5cf97324d40e7ea707c11 Mon Sep 17 00:00:00 2001 From: Imbris Date: Sun, 6 Dec 2020 15:22:44 -0500 Subject: [PATCH] No cube spam --- voxygen/src/render/pipelines/mod.rs | 4 +- voxygen/src/render/renderer.rs | 79 +++++++++++++++++++++++++- voxygen/src/render/renderer/binding.rs | 4 +- 3 files changed, 82 insertions(+), 5 deletions(-) diff --git a/voxygen/src/render/pipelines/mod.rs b/voxygen/src/render/pipelines/mod.rs index 1c3a49a6e2..d601fd64c0 100644 --- a/voxygen/src/render/pipelines/mod.rs +++ b/voxygen/src/render/pipelines/mod.rs @@ -367,7 +367,7 @@ impl GlobalsLayouts { visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, ty: wgpu::BindingType::Sampler { filtering: true, - comparison: false, + comparison: true, }, count: None, }, @@ -387,7 +387,7 @@ impl GlobalsLayouts { visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, ty: wgpu::BindingType::Sampler { filtering: true, - comparison: false, + comparison: true, }, count: None, }, diff --git a/voxygen/src/render/renderer.rs b/voxygen/src/render/renderer.rs index a94b12ed27..e4019e5b72 100644 --- a/voxygen/src/render/renderer.rs +++ b/voxygen/src/render/renderer.rs @@ -229,7 +229,9 @@ pub struct Renderer { sampler: wgpu::Sampler, shadow_map: Option, - //dummy_shadow_tex: wgpu::TextureView, + dummy_shadow_cube_tex: Texture, + dummy_shadow_tex: Texture, + layouts: Layouts, figure_pipeline: figure::FigurePipeline, @@ -333,6 +335,9 @@ impl Renderer { let shaders = Shaders::load_expect(""); + let (dummy_shadow_cube_tex, dummy_shadow_tex) = + Self::create_dummy_shadow_tex(&device, &queue); + let layouts = { let global = GlobalsLayouts::new(&device); @@ -476,6 +481,8 @@ impl Renderer { sampler, shadow_map, + dummy_shadow_cube_tex, + dummy_shadow_tex, layouts, @@ -688,6 +695,76 @@ impl Renderer { )) } + fn create_dummy_shadow_tex(device: &wgpu::Device, queue: &wgpu::Queue) -> (Texture, Texture) { + let make_tex = |view_dim, depth| { + let tex = wgpu::TextureDescriptor { + label: None, + size: wgpu::Extent3d { + width: 4, + height: 4, + depth, + }, + mip_level_count: 1, + sample_count: 1, + dimension: wgpu::TextureDimension::D2, + format: wgpu::TextureFormat::Depth24Plus, + usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::RENDER_ATTACHMENT, + }; + + let view = wgpu::TextureViewDescriptor { + label: None, + format: Some(wgpu::TextureFormat::Depth24Plus), + dimension: Some(view_dim), + aspect: wgpu::TextureAspect::DepthOnly, + base_mip_level: 0, + level_count: None, + base_array_layer: 0, + array_layer_count: None, + }; + + let sampler_info = wgpu::SamplerDescriptor { + label: None, + address_mode_u: wgpu::AddressMode::ClampToEdge, + address_mode_v: wgpu::AddressMode::ClampToEdge, + address_mode_w: wgpu::AddressMode::ClampToEdge, + mag_filter: wgpu::FilterMode::Linear, + min_filter: wgpu::FilterMode::Linear, + mipmap_filter: wgpu::FilterMode::Nearest, + compare: Some(wgpu::CompareFunction::LessEqual), + ..Default::default() + }; + + Texture::new_raw(device, &tex, &view, &sampler_info) + }; + + let cube_tex = make_tex(wgpu::TextureViewDimension::Cube, 6); + let tex = make_tex(wgpu::TextureViewDimension::D2, 1); + + // Clear to 1.0 + let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor { + label: Some("Dummy shadow tex clearing encoder"), + }); + let mut clear = |tex: &Texture| { + encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + color_attachments: &[], + depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachmentDescriptor { + attachment: &tex.view, + depth_ops: Some(wgpu::Operations { + load: wgpu::LoadOp::Clear(1.0), + store: true, + }), + stencil_ops: None, + }), + }); + }; + clear(&cube_tex); + clear(&tex); + drop(clear); + queue.submit(std::iter::once(encoder.finish())); + + (cube_tex, tex) + } + /// Create textures and views for shadow maps. // This is a one-use type and the two halves are not guaranteed to remain identical, so we // disable the type complexity lint. diff --git a/voxygen/src/render/renderer/binding.rs b/voxygen/src/render/renderer/binding.rs index e67a6890b9..9469e4c78b 100644 --- a/voxygen/src/render/renderer/binding.rs +++ b/voxygen/src/render/renderer/binding.rs @@ -15,9 +15,9 @@ impl Renderer { ) -> GlobalsBindGroup { let (point_shadow_map, directed_shadow_map) = match &self.shadow_map { Some(shadow_map) => (&shadow_map.point_depth, &shadow_map.directed_depth), - None => (&self.noise_tex, &self.noise_tex), + None => (&self.dummy_shadow_cube_tex, &self.dummy_shadow_tex), }; - dbg!(self.shadow_map.is_some()); + self.layouts.global.bind( &self.device, global_model,