-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Receiver plane depth bias #10188
Open
superdump
wants to merge
4
commits into
bevyengine:main
Choose a base branch
from
superdump:receiver-plane-depth-bias
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+264
−109
Open
Receiver plane depth bias #10188
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a8782ac
shadow_biases: Support moving the light position and resetting biases
superdump 72e5f9c
Simplifications
robtfm 4393d36
Use transparent background for text and every other sphere is on the …
superdump d791872
Implement Receiver Plane Depth Bias [Isidoro06]
superdump File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ fn sample_shadow_map_hardware(light_local: vec2<f32>, depth: f32, array_index: i | |
} | ||
|
||
// https://web.archive.org/web/20230210095515/http://the-witness.net/news/2013/09/shadow-mapping-summary-part-1 | ||
fn sample_shadow_map_castano_thirteen(light_local: vec2<f32>, depth: f32, array_index: i32) -> f32 { | ||
fn sample_shadow_map_castano_thirteen(light_local: vec2<f32>, depth: f32, receiver_plane_depth_bias: vec2<f32>, array_index: i32) -> f32 { | ||
let shadow_map_size = vec2<f32>(textureDimensions(view_bindings::directional_shadow_textures)); | ||
let inv_shadow_map_size = 1.0 / shadow_map_size; | ||
|
||
|
@@ -53,17 +53,26 @@ fn sample_shadow_map_castano_thirteen(light_local: vec2<f32>, depth: f32, array_ | |
|
||
var sum = 0.0; | ||
|
||
sum += uw0 * vw0 * sample_shadow_map_hardware(base_uv + (vec2(u0, v0) * inv_shadow_map_size), depth, array_index); | ||
sum += uw1 * vw0 * sample_shadow_map_hardware(base_uv + (vec2(u1, v0) * inv_shadow_map_size), depth, array_index); | ||
sum += uw2 * vw0 * sample_shadow_map_hardware(base_uv + (vec2(u2, v0) * inv_shadow_map_size), depth, array_index); | ||
|
||
sum += uw0 * vw1 * sample_shadow_map_hardware(base_uv + (vec2(u0, v1) * inv_shadow_map_size), depth, array_index); | ||
sum += uw1 * vw1 * sample_shadow_map_hardware(base_uv + (vec2(u1, v1) * inv_shadow_map_size), depth, array_index); | ||
sum += uw2 * vw1 * sample_shadow_map_hardware(base_uv + (vec2(u2, v1) * inv_shadow_map_size), depth, array_index); | ||
|
||
sum += uw0 * vw2 * sample_shadow_map_hardware(base_uv + (vec2(u0, v2) * inv_shadow_map_size), depth, array_index); | ||
sum += uw1 * vw2 * sample_shadow_map_hardware(base_uv + (vec2(u1, v2) * inv_shadow_map_size), depth, array_index); | ||
sum += uw2 * vw2 * sample_shadow_map_hardware(base_uv + (vec2(u2, v2) * inv_shadow_map_size), depth, array_index); | ||
let sample_offset_u0_v0 = (vec2(u0, v0) * inv_shadow_map_size); | ||
sum += uw0 * vw0 * sample_shadow_map_hardware(base_uv + sample_offset_u0_v0, depth + dot(sample_offset_u0_v0, receiver_plane_depth_bias), array_index); | ||
let sample_offset_u1_v0 = (vec2(u1, v0) * inv_shadow_map_size); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not directly related but we could make this a loop by putting uw, u, vw, v into vec3s (vecs don't have the constant index requirement apparently). |
||
sum += uw1 * vw0 * sample_shadow_map_hardware(base_uv + sample_offset_u1_v0, depth + dot(sample_offset_u1_v0, receiver_plane_depth_bias), array_index); | ||
let sample_offset_u2_v0 = (vec2(u2, v0) * inv_shadow_map_size); | ||
sum += uw2 * vw0 * sample_shadow_map_hardware(base_uv + sample_offset_u2_v0, depth + dot(sample_offset_u2_v0, receiver_plane_depth_bias), array_index); | ||
|
||
let sample_offset_u0_v1 = (vec2(u0, v1) * inv_shadow_map_size); | ||
sum += uw0 * vw1 * sample_shadow_map_hardware(base_uv + sample_offset_u0_v1, depth + dot(sample_offset_u0_v1, receiver_plane_depth_bias), array_index); | ||
let sample_offset_u1_v1 = (vec2(u1, v1) * inv_shadow_map_size); | ||
sum += uw1 * vw1 * sample_shadow_map_hardware(base_uv + sample_offset_u1_v1, depth + dot(sample_offset_u1_v1, receiver_plane_depth_bias), array_index); | ||
let sample_offset_u2_v1 = (vec2(u2, v1) * inv_shadow_map_size); | ||
sum += uw2 * vw1 * sample_shadow_map_hardware(base_uv + sample_offset_u2_v1, depth + dot(sample_offset_u2_v1, receiver_plane_depth_bias), array_index); | ||
|
||
let sample_offset_u0_v2 = (vec2(u0, v2) * inv_shadow_map_size); | ||
sum += uw0 * vw2 * sample_shadow_map_hardware(base_uv + sample_offset_u0_v2, depth + dot(sample_offset_u0_v2, receiver_plane_depth_bias), array_index); | ||
let sample_offset_u1_v2 = (vec2(u1, v2) * inv_shadow_map_size); | ||
sum += uw1 * vw2 * sample_shadow_map_hardware(base_uv + sample_offset_u1_v2, depth + dot(sample_offset_u1_v2, receiver_plane_depth_bias), array_index); | ||
let sample_offset_u2_v2 = (vec2(u2, v2) * inv_shadow_map_size); | ||
sum += uw2 * vw2 * sample_shadow_map_hardware(base_uv + sample_offset_u2_v2, depth + dot(sample_offset_u2_v2, receiver_plane_depth_bias), array_index); | ||
|
||
return sum * (1.0 / 144.0); | ||
} | ||
|
@@ -79,7 +88,7 @@ fn map(min1: f32, max1: f32, min2: f32, max2: f32, value: f32) -> f32 { | |
return min2 + (value - min1) * (max2 - min2) / (max1 - min1); | ||
} | ||
|
||
fn sample_shadow_map_jimenez_fourteen(light_local: vec2<f32>, depth: f32, array_index: i32, texel_size: f32) -> f32 { | ||
fn sample_shadow_map_jimenez_fourteen(light_local: vec2<f32>, depth: f32, receiver_plane_depth_bias: vec2<f32>, array_index: i32, texel_size: f32) -> f32 { | ||
let shadow_map_size = vec2<f32>(textureDimensions(view_bindings::directional_shadow_textures)); | ||
|
||
let random_angle = 2.0 * PI * interleaved_gradient_noise(light_local * shadow_map_size); | ||
|
@@ -104,22 +113,85 @@ fn sample_shadow_map_jimenez_fourteen(light_local: vec2<f32>, depth: f32, array_ | |
let sample_offset8 = (rotation_matrix * vec2( 0.1250, 0.0000)) * uv_offset_scale; | ||
|
||
var sum = 0.0; | ||
sum += sample_shadow_map_hardware(light_local + sample_offset1, depth, array_index); | ||
sum += sample_shadow_map_hardware(light_local + sample_offset2, depth, array_index); | ||
sum += sample_shadow_map_hardware(light_local + sample_offset3, depth, array_index); | ||
sum += sample_shadow_map_hardware(light_local + sample_offset4, depth, array_index); | ||
sum += sample_shadow_map_hardware(light_local + sample_offset5, depth, array_index); | ||
sum += sample_shadow_map_hardware(light_local + sample_offset6, depth, array_index); | ||
sum += sample_shadow_map_hardware(light_local + sample_offset7, depth, array_index); | ||
sum += sample_shadow_map_hardware(light_local + sample_offset8, depth, array_index); | ||
sum += sample_shadow_map_hardware( | ||
light_local + sample_offset1, | ||
depth + dot(sample_offset1, receiver_plane_depth_bias), | ||
array_index, | ||
); | ||
sum += sample_shadow_map_hardware( | ||
light_local + sample_offset2, | ||
depth + dot(sample_offset2, receiver_plane_depth_bias), | ||
array_index, | ||
); | ||
sum += sample_shadow_map_hardware( | ||
light_local + sample_offset3, | ||
depth + dot(sample_offset3, receiver_plane_depth_bias), | ||
array_index, | ||
); | ||
sum += sample_shadow_map_hardware( | ||
light_local + sample_offset4, | ||
depth + dot(sample_offset4, receiver_plane_depth_bias), | ||
array_index, | ||
); | ||
sum += sample_shadow_map_hardware( | ||
light_local + sample_offset5, | ||
depth + dot(sample_offset5, receiver_plane_depth_bias), | ||
array_index, | ||
); | ||
sum += sample_shadow_map_hardware( | ||
light_local + sample_offset6, | ||
depth + dot(sample_offset6, receiver_plane_depth_bias), | ||
array_index, | ||
); | ||
sum += sample_shadow_map_hardware( | ||
light_local + sample_offset7, | ||
depth + dot(sample_offset7, receiver_plane_depth_bias), | ||
array_index, | ||
); | ||
sum += sample_shadow_map_hardware( | ||
light_local + sample_offset8, | ||
depth + dot(sample_offset8, receiver_plane_depth_bias), | ||
array_index, | ||
); | ||
return sum / 8.0; | ||
} | ||
|
||
// Receiver Plane Depth Bias | ||
// Isidoro06 - Slides 36-40 https://web.archive.org/web/20230309054654/http://developer.amd.com/wordpress/media/2012/10/Isidoro-ShadowMapping.pdf | ||
// This implementation is from https://github.com/TheRealMJP/Shadows/blob/1a6d90c92ea58ccddb0dcd32b035c58b8f7784f4/Shadows/Mesh.hlsl#L102 | ||
fn compute_receiver_plane_depth_bias(tex_coord_dx: vec3<f32>, tex_coord_dy: vec3<f32>) -> vec2<f32> { | ||
var bias_uv: vec2<f32> = vec2<f32>( | ||
tex_coord_dy.y * tex_coord_dx.z - tex_coord_dx.y * tex_coord_dy.z, | ||
tex_coord_dx.x * tex_coord_dy.z - tex_coord_dy.x * tex_coord_dx.z | ||
); | ||
bias_uv = bias_uv * 1.0 / ((tex_coord_dx.x * tex_coord_dy.y) - (tex_coord_dx.y * tex_coord_dy.x)); | ||
return bias_uv; | ||
} | ||
|
||
fn sample_shadow_map(light_local: vec2<f32>, depth: f32, array_index: i32, texel_size: f32) -> f32 { | ||
#ifndef SHADOW_FILTER_METHOD_HARDWARE_2X2 | ||
let shadow_pos = vec3(light_local, depth); | ||
let receiver_plane_depth_bias = compute_receiver_plane_depth_bias( | ||
dpdx(shadow_pos), | ||
dpdy(shadow_pos), | ||
); | ||
#endif | ||
|
||
#ifdef SHADOW_FILTER_METHOD_CASTANO_13 | ||
return sample_shadow_map_castano_thirteen(light_local, depth, array_index); | ||
return sample_shadow_map_castano_thirteen( | ||
light_local, | ||
depth, | ||
receiver_plane_depth_bias, | ||
array_index, | ||
); | ||
#else ifdef SHADOW_FILTER_METHOD_JIMENEZ_14 | ||
return sample_shadow_map_jimenez_fourteen(light_local, depth, array_index, texel_size); | ||
return sample_shadow_map_jimenez_fourteen( | ||
light_local, | ||
depth, | ||
receiver_plane_depth_bias, | ||
array_index, | ||
texel_size, | ||
); | ||
#else ifdef SHADOW_FILTER_METHOD_HARDWARE_2X2 | ||
return sample_shadow_map_hardware(light_local, depth, array_index); | ||
#else | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use a
sample_shadow_map_offset(uv, offset, depth, bias, index)
function?