Resolve validation errors with trying to use unsupported filtering modes

This commit is contained in:
Imbris 2021-02-03 17:02:11 -05:00
parent 6228430002
commit 85c7f5c9c9
3 changed files with 45 additions and 18 deletions

View File

@ -101,6 +101,7 @@ impl CloudsLayout {
src_color: &wgpu::TextureView, src_color: &wgpu::TextureView,
src_depth: &wgpu::TextureView, src_depth: &wgpu::TextureView,
sampler: &wgpu::Sampler, sampler: &wgpu::Sampler,
depth_sampler: &wgpu::Sampler,
locals: &Consts<Locals>, locals: &Consts<Locals>,
) -> BindGroup { ) -> BindGroup {
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
@ -121,7 +122,7 @@ impl CloudsLayout {
}, },
wgpu::BindGroupEntry { wgpu::BindGroupEntry {
binding: 3, binding: 3,
resource: wgpu::BindingResource::Sampler(sampler), resource: wgpu::BindingResource::Sampler(depth_sampler),
}, },
wgpu::BindGroupEntry { wgpu::BindGroupEntry {
binding: 4, binding: 4,

View File

@ -66,7 +66,7 @@ impl LodData {
tgt_detail: u32, tgt_detail: u32,
//border_color: gfx::texture::PackedColor, //border_color: gfx::texture::PackedColor,
) -> Self { ) -> Self {
let mut create_texture = |format, data| { let mut create_texture = |format, data, filter| {
let texture_info = wgpu::TextureDescriptor { let texture_info = wgpu::TextureDescriptor {
label: None, label: None,
size: wgpu::Extent3d { size: wgpu::Extent3d {
@ -86,8 +86,8 @@ impl LodData {
address_mode_u: wgpu::AddressMode::ClampToEdge, address_mode_u: wgpu::AddressMode::ClampToEdge,
address_mode_v: wgpu::AddressMode::ClampToEdge, address_mode_v: wgpu::AddressMode::ClampToEdge,
address_mode_w: wgpu::AddressMode::ClampToEdge, address_mode_w: wgpu::AddressMode::ClampToEdge,
mag_filter: wgpu::FilterMode::Linear, mag_filter: filter,
min_filter: wgpu::FilterMode::Linear, min_filter: filter,
mipmap_filter: wgpu::FilterMode::Nearest, mipmap_filter: wgpu::FilterMode::Nearest,
border_color: Some(wgpu::SamplerBorderColor::TransparentBlack), border_color: Some(wgpu::SamplerBorderColor::TransparentBlack),
..Default::default() ..Default::default()
@ -111,13 +111,26 @@ impl LodData {
bytemuck::cast_slice(data), 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 { // SamplerInfo {
// border: border_color, // 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 { // SamplerInfo {
// border: [0.0, 0.0, 0.0, 0.0].into(), // 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 { // SamplerInfo {
// border: [1.0, 0.0, 1.0, 0.0].into(), // border: [1.0, 0.0, 1.0, 0.0].into(),

View File

@ -184,12 +184,14 @@ impl Locals {
tgt_depth_view: &wgpu::TextureView, tgt_depth_view: &wgpu::TextureView,
tgt_color_pp_view: &wgpu::TextureView, tgt_color_pp_view: &wgpu::TextureView,
sampler: &wgpu::Sampler, sampler: &wgpu::Sampler,
depth_sampler: &wgpu::Sampler,
) -> Self { ) -> Self {
let clouds_bind = layouts.clouds.bind( let clouds_bind = layouts.clouds.bind(
device, device,
tgt_color_view, tgt_color_view,
tgt_depth_view, tgt_depth_view,
sampler, sampler,
depth_sampler,
&clouds_locals, &clouds_locals,
); );
let postprocess_bind = let postprocess_bind =
@ -215,12 +217,14 @@ impl Locals {
tgt_depth_view: &wgpu::TextureView, tgt_depth_view: &wgpu::TextureView,
tgt_color_pp_view: &wgpu::TextureView, tgt_color_pp_view: &wgpu::TextureView,
sampler: &wgpu::Sampler, sampler: &wgpu::Sampler,
depth_sampler: &wgpu::Sampler,
) { ) {
self.clouds_bind = layouts.clouds.bind( self.clouds_bind = layouts.clouds.bind(
device, device,
tgt_color_view, tgt_color_view,
tgt_depth_view, tgt_depth_view,
sampler, sampler,
depth_sampler,
&self.clouds, &self.clouds,
); );
self.postprocess_bind = self.postprocess_bind =
@ -249,6 +253,7 @@ pub struct Renderer {
tgt_color_pp_view: wgpu::TextureView, tgt_color_pp_view: wgpu::TextureView,
sampler: wgpu::Sampler, sampler: wgpu::Sampler,
depth_sampler: wgpu::Sampler,
shadow_map: ShadowMap, shadow_map: ShadowMap,
shadow_bind: ShadowTexturesBindGroup, shadow_bind: ShadowTexturesBindGroup,
@ -458,17 +463,22 @@ impl Renderer {
.bind_shadow_textures(&device, point, directed) .bind_shadow_textures(&device, point, directed)
}; };
let sampler = device.create_sampler(&wgpu::SamplerDescriptor { let create_sampler = |filter| {
label: None, device.create_sampler(&wgpu::SamplerDescriptor {
address_mode_u: wgpu::AddressMode::ClampToEdge, label: None,
address_mode_v: wgpu::AddressMode::ClampToEdge, address_mode_u: wgpu::AddressMode::ClampToEdge,
address_mode_w: wgpu::AddressMode::ClampToEdge, address_mode_v: wgpu::AddressMode::ClampToEdge,
mag_filter: wgpu::FilterMode::Linear, address_mode_w: wgpu::AddressMode::ClampToEdge,
min_filter: wgpu::FilterMode::Linear, mag_filter: filter,
mipmap_filter: wgpu::FilterMode::Nearest, min_filter: filter,
compare: None, mipmap_filter: wgpu::FilterMode::Nearest,
..Default::default() compare: None,
}); ..Default::default()
})
};
let sampler = create_sampler(wgpu::FilterMode::Linear);
let depth_sampler = create_sampler(wgpu::FilterMode::Nearest);
let noise_tex = Texture::new( let noise_tex = Texture::new(
&device, &device,
@ -492,6 +502,7 @@ impl Renderer {
&tgt_depth_view, &tgt_depth_view,
&tgt_color_pp_view, &tgt_color_pp_view,
&sampler, &sampler,
&depth_sampler,
); );
Ok(Self { Ok(Self {
@ -508,6 +519,7 @@ impl Renderer {
tgt_color_pp_view, tgt_color_pp_view,
sampler, sampler,
depth_sampler,
shadow_map, shadow_map,
shadow_bind, shadow_bind,
@ -589,6 +601,7 @@ impl Renderer {
&self.tgt_depth_view, &self.tgt_depth_view,
&self.tgt_color_pp_view, &self.tgt_color_pp_view,
&self.sampler, &self.sampler,
&self.depth_sampler,
); );
if let (ShadowMap::Enabled(shadow_map), ShadowMode::Map(mode)) = if let (ShadowMap::Enabled(shadow_map), ShadowMode::Map(mode)) =