Minor rearrangement of ray generation sampling code.

This commit is contained in:
Nathan Vegdahl 2022-07-17 21:16:00 -07:00
parent 89429ed9f0
commit 86814dbf8f

View File

@ -240,15 +240,16 @@ impl<'a> Renderer<'a> {
for x in bucket.x..(bucket.x + bucket.w) {
for si in 0..self.spp {
// Raw sample numbers.
let (d0, d1, d2, d3) =
let d0 = golden_ratio_sample(si as u32, (x, y), self.seed, self.spp as u32);
let (d1, d2, d3, d4) =
get_sample_4d(si as u32, 0, (x, y), self.seed, self.spp as u32);
let (d4, _, _, _) =
let (d5, _, _, _) =
get_sample_4d(si as u32, 1, (x, y), self.seed, self.spp as u32);
// Calculate image plane x and y coordinates
let (img_x, img_y) = {
let filter_x = probit(d3, 2.0 / 6.0) + 0.5;
let filter_y = probit(d4, 2.0 / 6.0) + 0.5;
let filter_x = probit(d4, 2.0 / 6.0) + 0.5;
let filter_y = probit(d5, 2.0 / 6.0) + 0.5;
let samp_x = (filter_x + x as f32) * cmpx;
let samp_y = (filter_y + y as f32) * cmpy;
((samp_x - 0.5) * x_extent, (0.5 - samp_y) * y_extent)
@ -260,14 +261,9 @@ impl<'a> Renderer<'a> {
self.seed,
(x, y),
(img_x, img_y),
(d1, d2),
d0,
map_0_1_to_wavelength(golden_ratio_sample(
si as u32,
self.seed,
(x, y),
self.spp as u32,
)),
(d2, d3),
d1,
map_0_1_to_wavelength(d0),
si as u32,
self.spp as u32,
);
@ -746,7 +742,7 @@ fn get_sample_4d(
// due to the nature of hero wavelength sampling this ends up
// being crazily more efficient than pretty much any other sampler,
// and reduces variance by a huge amount.
fn golden_ratio_sample(i: u32, seed: u32, pixel_co: (u32, u32), max_samples: u32) -> f32 {
fn golden_ratio_sample(i: u32, pixel_co: (u32, u32), seed: u32, max_samples: u32) -> f32 {
use sobol_burley::parts::{owen_scramble_rev, u32_to_f32_norm};
// Turns out the screen-space blue-noise diffusion trick mentioned