-
-
Notifications
You must be signed in to change notification settings - Fork 4k
bevy_solari ReSTIR DI #19790
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
Merged
Merged
bevy_solari ReSTIR DI #19790
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2ad21d3
Merge from experiment branch
JMS55 82b75df
Use rust constants for missing lights/textures
JMS55 7df0224
Update comment
JMS55 2a927f6
Update release notes
JMS55 6aba44d
Merge commit '30800401b4515e9b9c6e87ef6caae73bfb697dc4' into solari6-…
JMS55 9e40fd1
Use new to_extents()
JMS55 c03a349
Fix typo
JMS55 0527f10
Use to_extents() more
JMS55 77fd784
Fix instructions
JMS55 2074f71
Remove unused import
JMS55 76ab6af
Merge branch 'main' into solari6-restir
JMS55 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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
|
@@ -2,7 +2,9 @@ | |
|
||
#define_import_path bevy_solari::reservoir | ||
|
||
#import bevy_solari::sampling::LightSample | ||
#import bevy_core_pipeline::tonemapping::tonemapping_luminance as luminance | ||
#import bevy_pbr::utils::rand_f | ||
#import bevy_solari::sampling::{LightSample, calculate_light_contribution} | ||
|
||
const NULL_RESERVOIR_SAMPLE = 0xFFFFFFFFu; | ||
|
||
|
@@ -12,7 +14,7 @@ struct Reservoir { | |
weight_sum: f32, | ||
confidence_weight: f32, | ||
unbiased_contribution_weight: f32, | ||
_padding: f32, | ||
visibility: f32, | ||
} | ||
|
||
fn empty_reservoir() -> Reservoir { | ||
|
@@ -28,3 +30,59 @@ fn empty_reservoir() -> Reservoir { | |
fn reservoir_valid(reservoir: Reservoir) -> bool { | ||
return reservoir.sample.light_id.x != NULL_RESERVOIR_SAMPLE; | ||
} | ||
|
||
struct ReservoirMergeResult { | ||
merged_reservoir: Reservoir, | ||
selected_sample_radiance: vec3<f32>, | ||
} | ||
|
||
fn merge_reservoirs( | ||
canonical_reservoir: Reservoir, | ||
other_reservoir: Reservoir, | ||
world_position: vec3<f32>, | ||
world_normal: vec3<f32>, | ||
diffuse_brdf: vec3<f32>, | ||
rng: ptr<function, u32>, | ||
) -> ReservoirMergeResult { | ||
// TODO: Balance heuristic MIS weights | ||
let mis_weight_denominator = 1.0 / (canonical_reservoir.confidence_weight + other_reservoir.confidence_weight); | ||
|
||
let canonical_mis_weight = canonical_reservoir.confidence_weight * mis_weight_denominator; | ||
let canonical_target_function = reservoir_target_function(canonical_reservoir, world_position, world_normal, diffuse_brdf); | ||
let canonical_resampling_weight = canonical_mis_weight * (canonical_target_function.a * canonical_reservoir.unbiased_contribution_weight); | ||
|
||
let other_mis_weight = other_reservoir.confidence_weight * mis_weight_denominator; | ||
let other_target_function = reservoir_target_function(other_reservoir, world_position, world_normal, diffuse_brdf); | ||
let other_resampling_weight = other_mis_weight * (other_target_function.a * other_reservoir.unbiased_contribution_weight); | ||
|
||
var combined_reservoir = empty_reservoir(); | ||
combined_reservoir.weight_sum = canonical_resampling_weight + other_resampling_weight; | ||
combined_reservoir.confidence_weight = canonical_reservoir.confidence_weight + other_reservoir.confidence_weight; | ||
|
||
// https://yusuketokuyoshi.com/papers/2024/Efficient_Visibility_Reuse_for_Real-time_ReSTIR_(Supplementary_Document).pdf | ||
combined_reservoir.visibility = max(0.0, (canonical_reservoir.visibility * canonical_resampling_weight | ||
+ other_reservoir.visibility * other_resampling_weight) / combined_reservoir.weight_sum); | ||
|
||
if rand_f(rng) < other_resampling_weight / combined_reservoir.weight_sum { | ||
combined_reservoir.sample = other_reservoir.sample; | ||
|
||
let inverse_target_function = select(0.0, 1.0 / other_target_function.a, other_target_function.a > 0.0); | ||
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. maybe extract a safe_invert function? |
||
combined_reservoir.unbiased_contribution_weight = combined_reservoir.weight_sum * inverse_target_function; | ||
|
||
return ReservoirMergeResult(combined_reservoir, other_target_function.rgb); | ||
} else { | ||
combined_reservoir.sample = canonical_reservoir.sample; | ||
|
||
let inverse_target_function = select(0.0, 1.0 / canonical_target_function.a, canonical_target_function.a > 0.0); | ||
combined_reservoir.unbiased_contribution_weight = combined_reservoir.weight_sum * inverse_target_function; | ||
|
||
return ReservoirMergeResult(combined_reservoir, canonical_target_function.rgb); | ||
} | ||
} | ||
|
||
fn reservoir_target_function(reservoir: Reservoir, world_position: vec3<f32>, world_normal: vec3<f32>, diffuse_brdf: vec3<f32>) -> vec4<f32> { | ||
if !reservoir_valid(reservoir) { return vec4(0.0); } | ||
let light_contribution = calculate_light_contribution(reservoir.sample, world_position, world_normal).radiance; | ||
let target_function = luminance(light_contribution * diffuse_brdf); | ||
return vec4(light_contribution, target_function); | ||
} |
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.
Was this just missed? Not sure why it's here.
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.
Yeah it was missed in a previous PR.