From cb8db6a0b6466a934f637441d64a6bfc6b3227a6 Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Sat, 2 Jan 2016 11:17:52 -0800 Subject: [PATCH] Added command-line control of sample count, and more interesting default scene. --- src/main.rs | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/main.rs b/src/main.rs index c1ca8aa..006ecf0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,18 +31,22 @@ const USAGE: &'static str = r#" Psychopath Usage: - psychopath + psychopath [options] psychopath (-h | --help) psychopath --version Options: - -h --help Show this screen. - --version Show version. + -i Input .psy file + -s , --spp Number of samples per pixel [default: 16]. + -h, --help Show this screen. + --version Show version. "#; #[derive(Debug, RustcDecodable)] struct Args { arg_imgpath: String, + flag_input_file: Option, + flag_spp: Option, flag_version: bool, } @@ -73,25 +77,30 @@ fn main() { return; } + let samples_per_pixel = args.flag_spp.unwrap_or_else(|| 16); + println!("Sample count: {}", samples_per_pixel); + println!("Ray size: {} bytes", mem::size_of::()); // Generate a scene of triangles let mut triangles = { let mut triangles = Vec::new(); - let xres = 16; - let yres = 16; + let xres = 32; + let yres = 32; let xinc = 512.0 / (xres as f32); let yinc = 512.0 / (yres as f32); for x in 0..xres { for y in 0..yres { - let cx = x as f32 * xinc; - let cy = y as f32 * yinc; - triangles.push((Point::new(cx, cy, 1.0), - Point::new(cx + xinc, cy, 1.1), - Point::new(cx, cy + yinc, 1.2))); - triangles.push((Point::new(cx + xinc, cy + yinc, 1.0), - Point::new(cx, cy + yinc, 1.1), - Point::new(cx + xinc, cy, 1.2))); + let i = y * xres + x; + let cx = halton::sample(0, i) * 512.0; + let cy = halton::sample(1, i) * 512.0; + let cz = halton::sample(2, i) * 512.0; + triangles.push((Point::new(cx, cy, cz + 1.0), + Point::new(cx + xinc, cy, cz + 1.1), + Point::new(cx, cy + yinc, cz + 1.2))); + triangles.push((Point::new(cx + xinc, cy + yinc, cz + 1.0), + Point::new(cx, cy + yinc, cz + 1.1), + Point::new(cx + xinc, cy, cz + 1.2))); } } triangles @@ -114,17 +123,16 @@ fn main() { for y in 0..img.height() { for x in 0..img.width() { let offset = hash_u32(((x as u32) << 16) ^ (y as u32), 0); - const SAMPLES: usize = 16; // Generate rays rays.clear(); isects.clear(); - for si in 0..SAMPLES { - let mut ray = Ray::new(Point::new(x as f32 + + for si in 0..samples_per_pixel { + let mut ray = Ray::new(Point::new(0.5 + x as f32 + fast_logit(halton::sample(0, offset + si as u32), 1.5), - y as f32 + + 0.5 + y as f32 + fast_logit(halton::sample(3, offset + si as u32), 1.5), @@ -162,9 +170,9 @@ fn main() { b += 0.1; } } - r *= 255.0 / SAMPLES as f32; - g *= 255.0 / SAMPLES as f32; - b *= 255.0 / SAMPLES as f32; + r *= 255.0 / samples_per_pixel as f32; + g *= 255.0 / samples_per_pixel as f32; + b *= 255.0 / samples_per_pixel as f32; // Set pixel color img.set(x, y, (r as u8, g as u8, b as u8));