Skip to content

Commit 84936ca

Browse files
authored
Fix visibility (re)use in Solari DI (#20113)
# Objective Fixes the re(use) of visibility in Solari's ReSTIR DI. The paper I based things off of didn't (seem) to use visibility in their resampling https://yusuketokuyoshi.com/papers/2024/Efficient_Visibility_Reuse_for_Real-time_ReSTIR_(Supplementary_Document).pdf, only shading, but factoring it into the resampling improves things a lot. --- ## Showcase Before: <img width="2564" height="1500" alt="image" src="https://github.com/user-attachments/assets/15fa7941-ab68-47bc-9bbc-42ca55359046" /> After: <img width="2564" height="1500" alt="image" src="https://github.com/user-attachments/assets/6fe52ed0-7832-41c1-b1cd-e8c8d9825e51" />
1 parent 7ae8b53 commit 84936ca

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

crates/bevy_solari/src/realtime/restir_di.wgsl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ fn generate_initial_reservoir(world_position: vec3<f32>, world_normal: vec3<f32>
112112
reservoir.unbiased_contribution_weight = reservoir.weight_sum * inverse_target_function;
113113

114114
reservoir.visibility = trace_light_visibility(reservoir.sample, world_position);
115-
reservoir.unbiased_contribution_weight *= reservoir.visibility;
116115
}
117116

118117
reservoir.confidence_weight = 1.0;
@@ -175,8 +174,8 @@ fn load_spatial_reservoir(pixel_id: vec2<u32>, depth: f32, world_position: vec3<
175174
}
176175

177176
fn get_neighbor_pixel_id(center_pixel_id: vec2<u32>, rng: ptr<function, u32>) -> vec2<u32> {
178-
var spatial_id = vec2<i32>(center_pixel_id) + vec2<i32>(sample_disk(SPATIAL_REUSE_RADIUS_PIXELS, rng));
179-
spatial_id = clamp(spatial_id, vec2(0i), vec2<i32>(view.viewport.zw) - 1i);
177+
var spatial_id = vec2<f32>(center_pixel_id) + sample_disk(SPATIAL_REUSE_RADIUS_PIXELS, rng);
178+
spatial_id = clamp(spatial_id, vec2(0.0), view.viewport.zw - 1.0);
180179
return vec2<u32>(spatial_id);
181180
}
182181

@@ -288,7 +287,7 @@ fn merge_reservoirs(
288287

289288
fn reservoir_target_function(reservoir: Reservoir, world_position: vec3<f32>, world_normal: vec3<f32>, diffuse_brdf: vec3<f32>) -> vec4<f32> {
290289
if !reservoir_valid(reservoir) { return vec4(0.0); }
291-
let light_contribution = calculate_light_contribution(reservoir.sample, world_position, world_normal).radiance;
290+
let light_contribution = calculate_light_contribution(reservoir.sample, world_position, world_normal).radiance * reservoir.visibility;
292291
let target_function = luminance(light_contribution * diffuse_brdf);
293292
return vec4(light_contribution, target_function);
294293
}

crates/bevy_solari/src/realtime/restir_gi.wgsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ fn load_spatial_reservoir(pixel_id: vec2<u32>, depth: f32, world_position: vec3<
172172
}
173173

174174
fn get_neighbor_pixel_id(center_pixel_id: vec2<u32>, rng: ptr<function, u32>) -> vec2<u32> {
175-
var spatial_id = vec2<i32>(center_pixel_id) + vec2<i32>(sample_disk(SPATIAL_REUSE_RADIUS_PIXELS, rng));
176-
spatial_id = clamp(spatial_id, vec2(0i), vec2<i32>(view.viewport.zw) - 1i);
175+
var spatial_id = vec2<f32>(center_pixel_id) + sample_disk(SPATIAL_REUSE_RADIUS_PIXELS, rng);
176+
spatial_id = clamp(spatial_id, vec2(0.0), view.viewport.zw - 1.0);
177177
return vec2<u32>(spatial_id);
178178
}
179179

release-content/release-notes/bevy_solari.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Initial raytraced lighting progress (bevy_solari)
33
authors: ["@JMS55"]
4-
pull_requests: [19058, 19620, 19790, 20020]
4+
pull_requests: [19058, 19620, 19790, 20020, 20113]
55
---
66

77
(TODO: Embed solari example screenshot here)

0 commit comments

Comments
 (0)