Added command-line control of sample count, and more interesting default scene.
This commit is contained in:
parent
eaeec4c207
commit
cb8db6a0b6
48
src/main.rs
48
src/main.rs
|
@ -31,18 +31,22 @@ const USAGE: &'static str = r#"
|
||||||
Psychopath <VERSION>
|
Psychopath <VERSION>
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
psychopath <imgpath>
|
psychopath [options] <imgpath>
|
||||||
psychopath (-h | --help)
|
psychopath (-h | --help)
|
||||||
psychopath --version
|
psychopath --version
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-h --help Show this screen.
|
-i <input_file> Input .psy file
|
||||||
--version Show version.
|
-s <n>, --spp <n> Number of samples per pixel [default: 16].
|
||||||
|
-h, --help Show this screen.
|
||||||
|
--version Show version.
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
#[derive(Debug, RustcDecodable)]
|
#[derive(Debug, RustcDecodable)]
|
||||||
struct Args {
|
struct Args {
|
||||||
arg_imgpath: String,
|
arg_imgpath: String,
|
||||||
|
flag_input_file: Option<String>,
|
||||||
|
flag_spp: Option<u32>,
|
||||||
flag_version: bool,
|
flag_version: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,25 +77,30 @@ fn main() {
|
||||||
return;
|
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::<Ray>());
|
println!("Ray size: {} bytes", mem::size_of::<Ray>());
|
||||||
|
|
||||||
// Generate a scene of triangles
|
// Generate a scene of triangles
|
||||||
let mut triangles = {
|
let mut triangles = {
|
||||||
let mut triangles = Vec::new();
|
let mut triangles = Vec::new();
|
||||||
let xres = 16;
|
let xres = 32;
|
||||||
let yres = 16;
|
let yres = 32;
|
||||||
let xinc = 512.0 / (xres as f32);
|
let xinc = 512.0 / (xres as f32);
|
||||||
let yinc = 512.0 / (yres as f32);
|
let yinc = 512.0 / (yres as f32);
|
||||||
for x in 0..xres {
|
for x in 0..xres {
|
||||||
for y in 0..yres {
|
for y in 0..yres {
|
||||||
let cx = x as f32 * xinc;
|
let i = y * xres + x;
|
||||||
let cy = y as f32 * yinc;
|
let cx = halton::sample(0, i) * 512.0;
|
||||||
triangles.push((Point::new(cx, cy, 1.0),
|
let cy = halton::sample(1, i) * 512.0;
|
||||||
Point::new(cx + xinc, cy, 1.1),
|
let cz = halton::sample(2, i) * 512.0;
|
||||||
Point::new(cx, cy + yinc, 1.2)));
|
triangles.push((Point::new(cx, cy, cz + 1.0),
|
||||||
triangles.push((Point::new(cx + xinc, cy + yinc, 1.0),
|
Point::new(cx + xinc, cy, cz + 1.1),
|
||||||
Point::new(cx, cy + yinc, 1.1),
|
Point::new(cx, cy + yinc, cz + 1.2)));
|
||||||
Point::new(cx + xinc, cy, 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
|
triangles
|
||||||
|
@ -114,17 +123,16 @@ fn main() {
|
||||||
for y in 0..img.height() {
|
for y in 0..img.height() {
|
||||||
for x in 0..img.width() {
|
for x in 0..img.width() {
|
||||||
let offset = hash_u32(((x as u32) << 16) ^ (y as u32), 0);
|
let offset = hash_u32(((x as u32) << 16) ^ (y as u32), 0);
|
||||||
const SAMPLES: usize = 16;
|
|
||||||
|
|
||||||
// Generate rays
|
// Generate rays
|
||||||
rays.clear();
|
rays.clear();
|
||||||
isects.clear();
|
isects.clear();
|
||||||
for si in 0..SAMPLES {
|
for si in 0..samples_per_pixel {
|
||||||
let mut ray = Ray::new(Point::new(x as f32 +
|
let mut ray = Ray::new(Point::new(0.5 + x as f32 +
|
||||||
fast_logit(halton::sample(0,
|
fast_logit(halton::sample(0,
|
||||||
offset + si as u32),
|
offset + si as u32),
|
||||||
1.5),
|
1.5),
|
||||||
y as f32 +
|
0.5 + y as f32 +
|
||||||
fast_logit(halton::sample(3,
|
fast_logit(halton::sample(3,
|
||||||
offset + si as u32),
|
offset + si as u32),
|
||||||
1.5),
|
1.5),
|
||||||
|
@ -162,9 +170,9 @@ fn main() {
|
||||||
b += 0.1;
|
b += 0.1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
r *= 255.0 / SAMPLES as f32;
|
r *= 255.0 / samples_per_pixel as f32;
|
||||||
g *= 255.0 / SAMPLES as f32;
|
g *= 255.0 / samples_per_pixel as f32;
|
||||||
b *= 255.0 / SAMPLES as f32;
|
b *= 255.0 / samples_per_pixel as f32;
|
||||||
|
|
||||||
// Set pixel color
|
// Set pixel color
|
||||||
img.set(x, y, (r as u8, g as u8, b as u8));
|
img.set(x, y, (r as u8, g as u8, b as u8));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user