Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scale normal bias by texel size #26

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
15cdcd0
3d_scene_pipelined: Use a shallower directional light angle to provok…
superdump Jul 10, 2021
f7ac34d
cornell_box_pipelined: Remove bias tweaks
superdump Jul 10, 2021
eb99286
bevy_pbr2: Simplify shadow biases by moving them to linear depth
superdump Jul 10, 2021
f97942e
bevy_pbr2: Do not use DepthBiasState
superdump Jul 13, 2021
f53baab
bevy_pbr2: Do not use bilinear filtering for sampling depth textures
superdump Jul 13, 2021
f7315cc
pbr.wgsl: Remove unnecessary comment
superdump Jul 13, 2021
7df1bab
bevy_pbr2: Do manual shadow map depth comparisons for more flexibility
superdump Jul 13, 2021
0779593
examples: Add shadow_biases_pipelined example
superdump Jul 14, 2021
45f2d49
bevy_pbr2: Scale the point light normal bias by the shadow map texel …
superdump Jul 14, 2021
70910af
shadow_biases_pipelined: Add support for toggling directional / point…
superdump Jul 14, 2021
c78ea04
shadow_biases_pipelined: Cleanup
superdump Jul 14, 2021
0199071
bevy_pbr2: Scale the directional light normal bias by the shadow map …
superdump Jul 14, 2021
3cbbbcf
shadow_biases_pipelined: Fit the orthographic projection around the s…
superdump Jul 14, 2021
de3ead4
bevy_pbr2: Directional lights should have no shadows outside their pr…
superdump Jul 14, 2021
86fb4d2
bevy_pbr2: Fix the default directional light normal bias
superdump Jul 14, 2021
de5ca1a
Revert "bevy_pbr2: Do manual shadow map depth comparisons for more fl…
superdump Jul 14, 2021
8d12b50
shadow_biases_pipelined: Adjust directional light normal bias in 0.1 …
superdump Jul 14, 2021
ab1ef41
pbr.wgsl: Add a couple of clarifying comments
superdump Jul 15, 2021
b934f7b
Revert "bevy_pbr2: Do not use bilinear filtering for sampling depth t…
superdump Jul 17, 2021
c5a7e76
Merge branch 'pipelined-rendering' into scale-normal-bias-by-texel-size
superdump Jul 17, 2021
17e96ed
shadow_biases_pipelined: Print usage to terminal
superdump Jul 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "bevy_pbr2: Do manual shadow map depth comparisons for more fl…
…exibility"

This reverts commit 7df1bab.
  • Loading branch information
superdump committed Jul 14, 2021
commit de5ca1a2c3d1a1b858d59956af1c2806d0d1fdb8
4 changes: 2 additions & 2 deletions pipelined/bevy_pbr2/src/render/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl FromWorld for ShadowShaders {
mag_filter: FilterMode::Nearest,
min_filter: FilterMode::Nearest,
mipmap_filter: FilterMode::Nearest,
compare: None,
compare: Some(CompareFunction::LessEqual),
..Default::default()
}),
directional_light_sampler: render_device.create_sampler(&SamplerDescriptor {
Expand All @@ -210,7 +210,7 @@ impl FromWorld for ShadowShaders {
mag_filter: FilterMode::Nearest,
min_filter: FilterMode::Nearest,
mipmap_filter: FilterMode::Nearest,
compare: None,
compare: Some(CompareFunction::LessEqual),
..Default::default()
}),
}
Expand Down
4 changes: 2 additions & 2 deletions pipelined/bevy_pbr2/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl FromWorld for PbrShaders {
binding: 3,
visibility: ShaderStage::FRAGMENT,
ty: BindingType::Sampler {
comparison: false,
comparison: true,
filtering: false,
},
count: None,
Expand All @@ -109,7 +109,7 @@ impl FromWorld for PbrShaders {
binding: 5,
visibility: ShaderStage::FRAGMENT,
ty: BindingType::Sampler {
comparison: false,
comparison: true,
filtering: false,
},
count: None,
Expand Down
31 changes: 13 additions & 18 deletions pipelined/bevy_pbr2/src/render/pbr.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ var lights: Lights;
[[group(0), binding(2)]]
var point_shadow_textures: texture_depth_cube_array;
[[group(0), binding(3)]]
var point_shadow_textures_sampler: sampler;
var point_shadow_textures_sampler: sampler_comparison;
[[group(0), binding(4)]]
var directional_shadow_textures: texture_depth_2d_array;
[[group(0), binding(5)]]
var directional_shadow_textures_sampler: sampler;
var directional_shadow_textures_sampler: sampler_comparison;

[[group(2), binding(0)]]
var material: StandardMaterial;
Expand Down Expand Up @@ -407,14 +407,13 @@ fn fetch_point_shadow(light_id: i32, frag_position: vec4<f32>, surface_normal: v
let w = major_axis_magnitude;
let depth = z / w;

let shadow_map_depth = textureSampleLevel(point_shadow_textures, point_shadow_textures_sampler, frag_ls, i32(light_id), 0.0);
var shadow: f32;
if (depth < shadow_map_depth) {
shadow = 1.0;
} else {
shadow = 0.0;
}
return shadow;
// do the lookup, using HW PCF and comparison
// NOTE: Due to the non-uniform control flow above, we must use the Level variant of
// textureSampleCompare to avoid undefined behaviour due to some of the fragments in
// a quad (2x2 fragments) being processed not being sampled, and this messing with
// mip-mapping functionality. The shadow maps have no mipmaps so Level just samples
// from LOD 0.
return textureSampleCompareLevel(point_shadow_textures, point_shadow_textures_sampler, frag_ls, i32(light_id), depth);
}

fn fetch_directional_shadow(light_id: i32, frag_position: vec4<f32>, surface_normal: vec3<f32>) -> f32 {
Expand All @@ -441,14 +440,10 @@ fn fetch_directional_shadow(light_id: i32, frag_position: vec4<f32>, surface_nor
let light_local = offset_position_ndc.xy * flip_correction + vec2<f32>(0.5, 0.5);

let depth = offset_position_ndc.z;
let shadow_map_depth = textureSampleLevel(directional_shadow_textures, directional_shadow_textures_sampler, light_local, i32(light_id), 0.0);
var shadow: f32;
if (depth < shadow_map_depth) {
shadow = 1.0;
} else {
shadow = 0.0;
}
return shadow;
// do the lookup, using HW PCF and comparison
// NOTE: Due to non-uniform control flow above, we must use the level variant of the texture
// sampler to avoid use of implicit derivatives causing possible undefined behavior.
return textureSampleCompareLevel(directional_shadow_textures, directional_shadow_textures_sampler, light_local, i32(light_id), depth);
}

struct FragmentInput {
Expand Down