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>,
|
||||
vertex_layouts: &[VertexBufferLayout],
|
||||
label: &str,
|
||||
is_shadow: bool,
|
||||
) -> Self {
|
||||
let layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||
label: Some((label.to_owned() + " pipeline Layout").as_str()),
|
||||
|
@ -36,6 +37,7 @@ impl RenderPass {
|
|||
vertex_layouts,
|
||||
shader,
|
||||
label,
|
||||
is_shadow,
|
||||
);
|
||||
|
||||
Self { pipeline }
|
||||
|
@ -49,6 +51,7 @@ impl RenderPass {
|
|||
vertex_layouts: &[wgpu::VertexBufferLayout],
|
||||
shader: wgpu::ShaderModuleDescriptor,
|
||||
label: &str,
|
||||
is_shadow: bool,
|
||||
) -> wgpu::RenderPipeline {
|
||||
let shader = device.create_shader_module(shader);
|
||||
|
||||
|
@ -93,9 +96,16 @@ impl RenderPass {
|
|||
depth_stencil: depth_format.map(|format| wgpu::DepthStencilState {
|
||||
format,
|
||||
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(),
|
||||
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 {
|
||||
count: 1,
|
||||
|
|
|
@ -138,7 +138,7 @@ impl State {
|
|||
&device,
|
||||
&config,
|
||||
"depth_texture",
|
||||
Some(wgpu::CompareFunction::LessEqual),
|
||||
Some(wgpu::CompareFunction::Less),
|
||||
1,
|
||||
wgpu::TextureUsages::RENDER_ATTACHMENT,
|
||||
);
|
||||
|
@ -373,6 +373,7 @@ impl State {
|
|||
Some(Texture::DEPTH_FORMAT),
|
||||
&[ModelVertex::desc(), InstanceRaw::desc()],
|
||||
"light depth pass",
|
||||
true,
|
||||
);
|
||||
|
||||
let geometry_pass = RenderPass::new(
|
||||
|
@ -389,6 +390,7 @@ impl State {
|
|||
Some(Texture::DEPTH_FORMAT),
|
||||
&[ModelVertex::desc(), InstanceRaw::desc()],
|
||||
"geometry pass",
|
||||
false,
|
||||
);
|
||||
|
||||
let light_debug_pass = RenderPass::new(
|
||||
|
@ -400,6 +402,7 @@ impl State {
|
|||
Some(Texture::DEPTH_FORMAT),
|
||||
&[ModelVertex::desc()],
|
||||
"light debug pass",
|
||||
false,
|
||||
);
|
||||
|
||||
Self {
|
||||
|
@ -446,7 +449,7 @@ impl State {
|
|||
&self.device,
|
||||
&self.config,
|
||||
"depth_texture",
|
||||
Some(wgpu::CompareFunction::LessEqual),
|
||||
Some(wgpu::CompareFunction::Less),
|
||||
1,
|
||||
wgpu::TextureUsages::RENDER_ATTACHMENT,
|
||||
);
|
||||
|
|
|
@ -37,9 +37,9 @@ impl Texture {
|
|||
|
||||
let view = texture.create_view(&wgpu::TextureViewDescriptor::default());
|
||||
let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
|
||||
address_mode_u: wgpu::AddressMode::Repeat,
|
||||
address_mode_v: wgpu::AddressMode::Repeat,
|
||||
address_mode_w: wgpu::AddressMode::Repeat,
|
||||
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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue