From 85c7f5c9c90317970592127c65ffb84cb9113b18 Mon Sep 17 00:00:00 2001 From: Imbris Date: Wed, 3 Feb 2021 17:02:11 -0500 Subject: [PATCH] Resolve validation errors with trying to use unsupported filtering modes --- voxygen/src/render/pipelines/clouds.rs | 3 +- voxygen/src/render/pipelines/lod_terrain.rs | 25 +++++++++++---- voxygen/src/render/renderer.rs | 35 ++++++++++++++------- 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/voxygen/src/render/pipelines/clouds.rs b/voxygen/src/render/pipelines/clouds.rs index 7b4244e33b..28c544b1ab 100644 --- a/voxygen/src/render/pipelines/clouds.rs +++ b/voxygen/src/render/pipelines/clouds.rs @@ -101,6 +101,7 @@ impl CloudsLayout { src_color: &wgpu::TextureView, src_depth: &wgpu::TextureView, sampler: &wgpu::Sampler, + depth_sampler: &wgpu::Sampler, locals: &Consts, ) -> BindGroup { let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { @@ -121,7 +122,7 @@ impl CloudsLayout { }, wgpu::BindGroupEntry { binding: 3, - resource: wgpu::BindingResource::Sampler(sampler), + resource: wgpu::BindingResource::Sampler(depth_sampler), }, wgpu::BindGroupEntry { binding: 4, diff --git a/voxygen/src/render/pipelines/lod_terrain.rs b/voxygen/src/render/pipelines/lod_terrain.rs index de601a49f2..d9688944d9 100644 --- a/voxygen/src/render/pipelines/lod_terrain.rs +++ b/voxygen/src/render/pipelines/lod_terrain.rs @@ -66,7 +66,7 @@ impl LodData { tgt_detail: u32, //border_color: gfx::texture::PackedColor, ) -> Self { - let mut create_texture = |format, data| { + let mut create_texture = |format, data, filter| { let texture_info = wgpu::TextureDescriptor { label: None, size: wgpu::Extent3d { @@ -86,8 +86,8 @@ impl LodData { 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, + mag_filter: filter, + min_filter: filter, mipmap_filter: wgpu::FilterMode::Nearest, border_color: Some(wgpu::SamplerBorderColor::TransparentBlack), ..Default::default() @@ -111,13 +111,26 @@ impl LodData { bytemuck::cast_slice(data), ) }; - let map = create_texture(wgpu::TextureFormat::Rgba8UnormSrgb, lod_base); + let map = create_texture( + wgpu::TextureFormat::Rgba8UnormSrgb, + lod_base, + wgpu::FilterMode::Linear, + ); // SamplerInfo { // border: border_color, - let alt = create_texture(wgpu::TextureFormat::Rg16Uint, lod_alt); + let alt = create_texture( + // TODO: figure out format that can be linearly filtered or change the shaders + wgpu::TextureFormat::Rg16Uint, + lod_alt, + wgpu::FilterMode::Nearest, + ); // SamplerInfo { // border: [0.0, 0.0, 0.0, 0.0].into(), - let horizon = create_texture(wgpu::TextureFormat::Rgba8Unorm, lod_horizon); + let horizon = create_texture( + wgpu::TextureFormat::Rgba8Unorm, + lod_horizon, + wgpu::FilterMode::Linear, + ); // SamplerInfo { // border: [1.0, 0.0, 1.0, 0.0].into(), diff --git a/voxygen/src/render/renderer.rs b/voxygen/src/render/renderer.rs index 9cc3fc2212..b55d24ac38 100644 --- a/voxygen/src/render/renderer.rs +++ b/voxygen/src/render/renderer.rs @@ -184,12 +184,14 @@ impl Locals { tgt_depth_view: &wgpu::TextureView, tgt_color_pp_view: &wgpu::TextureView, sampler: &wgpu::Sampler, + depth_sampler: &wgpu::Sampler, ) -> Self { let clouds_bind = layouts.clouds.bind( device, tgt_color_view, tgt_depth_view, sampler, + depth_sampler, &clouds_locals, ); let postprocess_bind = @@ -215,12 +217,14 @@ impl Locals { tgt_depth_view: &wgpu::TextureView, tgt_color_pp_view: &wgpu::TextureView, sampler: &wgpu::Sampler, + depth_sampler: &wgpu::Sampler, ) { self.clouds_bind = layouts.clouds.bind( device, tgt_color_view, tgt_depth_view, sampler, + depth_sampler, &self.clouds, ); self.postprocess_bind = @@ -249,6 +253,7 @@ pub struct Renderer { tgt_color_pp_view: wgpu::TextureView, sampler: wgpu::Sampler, + depth_sampler: wgpu::Sampler, shadow_map: ShadowMap, shadow_bind: ShadowTexturesBindGroup, @@ -458,17 +463,22 @@ impl Renderer { .bind_shadow_textures(&device, point, directed) }; - let sampler = device.create_sampler(&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: None, - ..Default::default() - }); + let create_sampler = |filter| { + device.create_sampler(&wgpu::SamplerDescriptor { + label: None, + address_mode_u: wgpu::AddressMode::ClampToEdge, + address_mode_v: wgpu::AddressMode::ClampToEdge, + address_mode_w: wgpu::AddressMode::ClampToEdge, + mag_filter: filter, + min_filter: filter, + mipmap_filter: wgpu::FilterMode::Nearest, + compare: None, + ..Default::default() + }) + }; + + let sampler = create_sampler(wgpu::FilterMode::Linear); + let depth_sampler = create_sampler(wgpu::FilterMode::Nearest); let noise_tex = Texture::new( &device, @@ -492,6 +502,7 @@ impl Renderer { &tgt_depth_view, &tgt_color_pp_view, &sampler, + &depth_sampler, ); Ok(Self { @@ -508,6 +519,7 @@ impl Renderer { tgt_color_pp_view, sampler, + depth_sampler, shadow_map, shadow_bind, @@ -589,6 +601,7 @@ impl Renderer { &self.tgt_depth_view, &self.tgt_color_pp_view, &self.sampler, + &self.depth_sampler, ); if let (ShadowMap::Enabled(shadow_map), ShadowMode::Map(mode)) =