Different depth settings for shadows
This commit is contained in:
parent
86e1521128
commit
b978091cd4
3 changed files with 20 additions and 7 deletions
|
@ -18,6 +18,7 @@ impl RenderPass {
|
||||||
depth_format: Option<TextureFormat>,
|
depth_format: Option<TextureFormat>,
|
||||||
vertex_layouts: &[VertexBufferLayout],
|
vertex_layouts: &[VertexBufferLayout],
|
||||||
label: &str,
|
label: &str,
|
||||||
|
is_shadow: bool,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
let layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||||
label: Some((label.to_owned() + " pipeline Layout").as_str()),
|
label: Some((label.to_owned() + " pipeline Layout").as_str()),
|
||||||
|
@ -36,6 +37,7 @@ impl RenderPass {
|
||||||
vertex_layouts,
|
vertex_layouts,
|
||||||
shader,
|
shader,
|
||||||
label,
|
label,
|
||||||
|
is_shadow,
|
||||||
);
|
);
|
||||||
|
|
||||||
Self { pipeline }
|
Self { pipeline }
|
||||||
|
@ -49,6 +51,7 @@ impl RenderPass {
|
||||||
vertex_layouts: &[wgpu::VertexBufferLayout],
|
vertex_layouts: &[wgpu::VertexBufferLayout],
|
||||||
shader: wgpu::ShaderModuleDescriptor,
|
shader: wgpu::ShaderModuleDescriptor,
|
||||||
label: &str,
|
label: &str,
|
||||||
|
is_shadow: bool,
|
||||||
) -> wgpu::RenderPipeline {
|
) -> wgpu::RenderPipeline {
|
||||||
let shader = device.create_shader_module(shader);
|
let shader = device.create_shader_module(shader);
|
||||||
|
|
||||||
|
@ -93,9 +96,16 @@ impl RenderPass {
|
||||||
depth_stencil: depth_format.map(|format| wgpu::DepthStencilState {
|
depth_stencil: depth_format.map(|format| wgpu::DepthStencilState {
|
||||||
format,
|
format,
|
||||||
depth_write_enabled: true,
|
depth_write_enabled: true,
|
||||||
depth_compare: wgpu::CompareFunction::LessEqual,
|
depth_compare: if is_shadow { wgpu::CompareFunction::LessEqual } else { wgpu::CompareFunction::Less },
|
||||||
stencil: wgpu::StencilState::default(),
|
stencil: wgpu::StencilState::default(),
|
||||||
bias: wgpu::DepthBiasState::default(),
|
bias: if is_shadow {
|
||||||
|
wgpu::DepthBiasState {
|
||||||
|
constant: 2, // bilinear
|
||||||
|
slope_scale: 2.0,
|
||||||
|
clamp: 0.0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else { wgpu::DepthBiasState::default() },
|
||||||
}),
|
}),
|
||||||
multisample: wgpu::MultisampleState {
|
multisample: wgpu::MultisampleState {
|
||||||
count: 1,
|
count: 1,
|
||||||
|
|
|
@ -138,7 +138,7 @@ impl State {
|
||||||
&device,
|
&device,
|
||||||
&config,
|
&config,
|
||||||
"depth_texture",
|
"depth_texture",
|
||||||
Some(wgpu::CompareFunction::LessEqual),
|
Some(wgpu::CompareFunction::Less),
|
||||||
1,
|
1,
|
||||||
wgpu::TextureUsages::RENDER_ATTACHMENT,
|
wgpu::TextureUsages::RENDER_ATTACHMENT,
|
||||||
);
|
);
|
||||||
|
@ -373,6 +373,7 @@ impl State {
|
||||||
Some(Texture::DEPTH_FORMAT),
|
Some(Texture::DEPTH_FORMAT),
|
||||||
&[ModelVertex::desc(), InstanceRaw::desc()],
|
&[ModelVertex::desc(), InstanceRaw::desc()],
|
||||||
"light depth pass",
|
"light depth pass",
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
let geometry_pass = RenderPass::new(
|
let geometry_pass = RenderPass::new(
|
||||||
|
@ -389,6 +390,7 @@ impl State {
|
||||||
Some(Texture::DEPTH_FORMAT),
|
Some(Texture::DEPTH_FORMAT),
|
||||||
&[ModelVertex::desc(), InstanceRaw::desc()],
|
&[ModelVertex::desc(), InstanceRaw::desc()],
|
||||||
"geometry pass",
|
"geometry pass",
|
||||||
|
false,
|
||||||
);
|
);
|
||||||
|
|
||||||
let light_debug_pass = RenderPass::new(
|
let light_debug_pass = RenderPass::new(
|
||||||
|
@ -400,6 +402,7 @@ impl State {
|
||||||
Some(Texture::DEPTH_FORMAT),
|
Some(Texture::DEPTH_FORMAT),
|
||||||
&[ModelVertex::desc()],
|
&[ModelVertex::desc()],
|
||||||
"light debug pass",
|
"light debug pass",
|
||||||
|
false,
|
||||||
);
|
);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
@ -446,7 +449,7 @@ impl State {
|
||||||
&self.device,
|
&self.device,
|
||||||
&self.config,
|
&self.config,
|
||||||
"depth_texture",
|
"depth_texture",
|
||||||
Some(wgpu::CompareFunction::LessEqual),
|
Some(wgpu::CompareFunction::Less),
|
||||||
1,
|
1,
|
||||||
wgpu::TextureUsages::RENDER_ATTACHMENT,
|
wgpu::TextureUsages::RENDER_ATTACHMENT,
|
||||||
);
|
);
|
||||||
|
|
|
@ -37,9 +37,9 @@ impl Texture {
|
||||||
|
|
||||||
let view = texture.create_view(&wgpu::TextureViewDescriptor::default());
|
let view = texture.create_view(&wgpu::TextureViewDescriptor::default());
|
||||||
let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
|
let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
|
||||||
address_mode_u: wgpu::AddressMode::Repeat,
|
address_mode_u: wgpu::AddressMode::ClampToEdge,
|
||||||
address_mode_v: wgpu::AddressMode::Repeat,
|
address_mode_v: wgpu::AddressMode::ClampToEdge,
|
||||||
address_mode_w: wgpu::AddressMode::Repeat,
|
address_mode_w: wgpu::AddressMode::ClampToEdge,
|
||||||
mag_filter: wgpu::FilterMode::Linear,
|
mag_filter: wgpu::FilterMode::Linear,
|
||||||
min_filter: wgpu::FilterMode::Linear,
|
min_filter: wgpu::FilterMode::Linear,
|
||||||
mipmap_filter: wgpu::FilterMode::Nearest,
|
mipmap_filter: wgpu::FilterMode::Nearest,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue