Skip to content

Commit

Permalink
Expose pairwise MIS in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Sep 7, 2024
1 parent 3981d63 commit 022811c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
1 change: 1 addition & 0 deletions blade-helpers/src/hud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ impl ExposeHud for blade_render::RayConfig {
.text("T min")
.logarithmic(true),
);
ui.checkbox(&mut self.pairwise_mis, "Pairwise MIS");
}
}

Expand Down
14 changes: 5 additions & 9 deletions blade-render/code/ray-trace.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<u32>,
temporal_accumulation_weight: f32,
grid_scale: vec2<u32>,
}

var<uniform> camera: CameraParams;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -485,14 +483,12 @@ fn finalize_resampling(
base: ResampleBase, mis_canonical: f32, rng: ptr<function, RandomState>,
) -> 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);

Expand Down
11 changes: 7 additions & 4 deletions blade-render/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion examples/scene/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,15 @@ 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,
spatial_confidence: 5.0,
spatial_min_distance: 4,
group_mixer: 10,
t_start: 0.1,
pairwise_mis: true,
},
denoiser_config: blade_render::DenoiserConfig {
enabled: true,
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,14 +483,15 @@ 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,
spatial_confidence: 5.0,
spatial_min_distance: 4,
group_mixer: 10,
t_start: 0.01,
pairwise_mis: true,
},
denoiser_config: blade_render::DenoiserConfig {
enabled: true,
Expand Down

0 comments on commit 022811c

Please sign in to comment.