Skip to content

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

bevy_solari ReSTIR DI #19790

wants to merge 7 commits into from

Conversation

JMS55
Copy link
Contributor

@JMS55 JMS55 commented Jun 24, 2025

Objective

  • Add temporal and spatial resampling to bevy_solari.

Showcase

ReSTIR:
image

Previous RIS:
455750793-b70b968d-9c73-4983-9b6b-b60cace9b47a

@JMS55 JMS55 added the A-Rendering Drawing game state to the screen label Jun 24, 2025
@JMS55 JMS55 added this to the 0.17 milestone Jun 24, 2025
let tangent_plane_distance = abs(dot(normal, other_world_position - world_position));
let view_z = -depth_ndc_to_view_z(depth);

return tangent_plane_distance / view_z > 0.003 || dot(normal, other_normal) < 0.906;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe write as cos(radians(25.0))?

Comment on lines 67 to 71
size: Extent3d {
width: view_size.x,
height: view_size.y,
depth_or_array_layers: 1,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like logic that would be used in a lot of places in bevy, perhaps extracting a function is in order

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What logic?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UVec2 -> Extent3d. its used 4 times in this file alone, probably more in bevy

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably better for a different pr

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +198 to +207
fn depth_ndc_to_view_z(ndc_depth: f32) -> f32 {
#ifdef VIEW_PROJECTION_PERSPECTIVE
return -view.clip_from_view[3][2]() / ndc_depth;
#else ifdef VIEW_PROJECTION_ORTHOGRAPHIC
return -(view.clip_from_view[3][2] - ndc_depth) / view.clip_from_view[2][2];
#else
let view_pos = view.view_from_clip * vec4(0.0, 0.0, ndc_depth, 1.0);
return view_pos.z / view_pos.w;
#endif
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its really unfortunate that the one exported from view transformations cant be used because it references a different binding. I believe the wpgu 25 upgrade will force them to coincide again, so deduplicating this in the future should be kept in mind


var phi: f32;
var r: f32;
if (a * a > b * b) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (a * a > b * b) {
if (abs(a) > abs(b)) {

Comment on lines +27 to +33
if (a * a > b * b) {
r = disk_radius * a;
phi = (PI / 4.0) * (b / a);
} else {
r = disk_radius * b;
phi = (PI / 2.0) - (PI / 4.0) * (a / b);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this whole thing could probably be rewritten to collapse the branches using min/max

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe extract a safe_invert function?

@JMS55 JMS55 marked this pull request as ready for review June 24, 2025 18:44
@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible S-Needs-Review Needs reviewer attention (from anyone!) to move forward M-Needs-Release-Note Work that should be called out in the blog due to impact labels Jun 24, 2025
return world_pos.xyz / world_pos.w;
}

// Reject if tangent plane difference difference more than 0.3% or angle between normals more than 25 degrees
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How were these numbers chosen?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

25 degrees is what's suggested in the original ReSTIR paper, and 0.3% was what was suggested when I asked what thresholds people use in discord.

@JMS55 JMS55 requested a review from tychedelia June 26, 2025 21:41
@@ -1092,7 +1093,8 @@ pub fn prepare_prepass_textures(
dimension: TextureDimension::D2,
format: DEFERRED_PREPASS_FORMAT,
usage: TextureUsages::RENDER_ATTACHMENT
| TextureUsages::TEXTURE_BINDING,
| TextureUsages::TEXTURE_BINDING
| TextureUsages::COPY_SRC, // TODO: Remove COPY_SRC, double buffer instead (for bevy_solari)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you want to double buffer, but we should also just make these more easily configurable in general to avoid this kind of thing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. The problem is that it's configured per-render target, and not per camera, but all our components live on cameras. For now I don't have any better idea :/

@@ -5,6 +5,9 @@
struct PreviousViewUniforms {
view_from_world: mat4x4<f32>,
clip_from_world: mat4x4<f32>,
clip_from_view: mat4x4<f32>,
Copy link
Member

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.

Copy link
Contributor Author

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.

@tychedelia tychedelia added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jun 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Feature A new feature, making something new possible M-Needs-Release-Note Work that should be called out in the blog due to impact S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

4 participants