diff --git a/blade-helpers/src/hud.rs b/blade-helpers/src/hud.rs index efcba8c6..4d0579a0 100644 --- a/blade-helpers/src/hud.rs +++ b/blade-helpers/src/hud.rs @@ -33,6 +33,7 @@ impl ExposeHud for blade_render::RayConfig { .text("T min") .logarithmic(true), ); + ui.checkbox(&mut self.pairwise_mis, "Pairwise MIS"); } } diff --git a/blade-render/code/ray-trace.wgsl b/blade-render/code/ray-trace.wgsl index 7271c89f..9e0726e6 100644 --- a/blade-render/code/ray-trace.wgsl +++ b/blade-render/code/ray-trace.wgsl @@ -12,9 +12,6 @@ const PI: f32 = 3.1415926; const MAX_RESAMPLE: u32 = 4u; -// See "9.1 pairwise mis for robust reservoir reuse" -// "Correlations and Reuse for Fast and Accurate Physically Based Light Transport" -const PAIRWISE_MIS: bool = true; // See "DECOUPLING SHADING AND REUSE" in // "Rearchitecting Spatiotemporal Resampling for Production" const DECOUPLED_SHADING: bool = false; @@ -36,9 +33,10 @@ struct MainParams { spatial_tap_confidence: f32, spatial_min_distance: i32, t_start: f32, + use_pairwise_mis: u32, use_motion_vectors: u32, - grid_scale: vec2, temporal_accumulation_weight: f32, + grid_scale: vec2, } var camera: CameraParams; @@ -414,7 +412,7 @@ fn resample( var src: LiveReservoir; let neighbor = other.reservoir; var rr = ResampleResult(); - if (PAIRWISE_MIS) { + if (parameters.use_pairwise_mis != 0u) { let canonical = base.canonical; let neighbor_history = min(neighbor.confidence, max_confidence); { // scoping this to hint the register allocation @@ -485,14 +483,12 @@ fn finalize_resampling( base: ResampleBase, mis_canonical: f32, rng: ptr, ) -> ResampleOutput { var canonical = base.canonical; - var effective_history = canonical.history; - if (PAIRWISE_MIS) - { + if (parameters.use_pairwise_mis != 0u) { canonical.weight_sum *= mis_canonical / canonical.history; - effective_history = 1.0 + base.accepted_count; } merge_reservoir(reservoir, canonical, random_gen(rng)); + let effective_history = select((*reservoir).history, 1.0 + base.accepted_count, parameters.use_pairwise_mis != 0u); var ro = ResampleOutput(); ro.reservoir = pack_reservoir_detail(*reservoir, effective_history); diff --git a/blade-render/src/render/mod.rs b/blade-render/src/render/mod.rs index 9e692e17..4b18eecd 100644 --- a/blade-render/src/render/mod.rs +++ b/blade-render/src/render/mod.rs @@ -105,6 +105,9 @@ pub struct RayConfig { /// outside of the original workgroup pixel bounds. pub group_mixer: u32, pub t_start: f32, + /// See "9.1 pairwise mis for robust reservoir reuse" + /// "Correlations and Reuse for Fast and Accurate Physically Based Light Transport" + pub pairwise_mis: bool, } #[derive(Clone, Copy, Debug, PartialEq, PartialOrd)] @@ -370,10 +373,10 @@ struct MainParams { spatial_confidence: f32, spatial_min_distance: u32, t_start: f32, + use_pairwise_mis: u32, use_motion_vectors: u32, - grid_scale: [u32; 2], temporal_accumulation_weight: f32, - pad: f32, + grid_scale: [u32; 2], } #[derive(blade_macros::ShaderData)] @@ -1094,14 +1097,14 @@ impl Renderer { spatial_confidence: ray_config.spatial_confidence, spatial_min_distance: ray_config.spatial_min_distance, t_start: ray_config.t_start, + use_pairwise_mis: ray_config.pairwise_mis as u32, use_motion_vectors: (self.frame_scene_built == self.frame_index) as u32, - grid_scale, temporal_accumulation_weight: if denoiser_config.enabled { denoiser_config.temporal_weight } else { 1.0 }, - pad: 0.0, + grid_scale, }, acc_struct: self.acceleration_structure, prev_acc_struct: if self.frame_scene_built < self.frame_index diff --git a/examples/scene/main.rs b/examples/scene/main.rs index 10320e18..a6be3e9d 100644 --- a/examples/scene/main.rs +++ b/examples/scene/main.rs @@ -258,7 +258,7 @@ impl Example { render_times: VecDeque::with_capacity(FRAME_TIME_HISTORY), ray_config: blade_render::RayConfig { num_environment_samples: 1, - environment_importance_sampling: false, + environment_importance_sampling: true, temporal_tap: true, temporal_confidence: 10.0, spatial_taps: 1, @@ -266,6 +266,7 @@ impl Example { spatial_min_distance: 4, group_mixer: 10, t_start: 0.1, + pairwise_mis: true, }, denoiser_config: blade_render::DenoiserConfig { enabled: true, diff --git a/src/lib.rs b/src/lib.rs index 7a2c7a54..a91c33b2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -483,7 +483,7 @@ impl Engine { }, ray_config: blade_render::RayConfig { num_environment_samples: 1, - environment_importance_sampling: false, + environment_importance_sampling: true, temporal_tap: true, temporal_confidence: 10.0, spatial_taps: 1, @@ -491,6 +491,7 @@ impl Engine { spatial_min_distance: 4, group_mixer: 10, t_start: 0.01, + pairwise_mis: true, }, denoiser_config: blade_render::DenoiserConfig { enabled: true,