Added command-line control of sample count, and more interesting default scene.
This commit is contained in:
parent
eaeec4c207
commit
cb8db6a0b6
46
src/main.rs
46
src/main.rs
|
@ -31,18 +31,22 @@ const USAGE: &'static str = r#"
|
|||
Psychopath <VERSION>
|
||||
|
||||
Usage:
|
||||
psychopath <imgpath>
|
||||
psychopath [options] <imgpath>
|
||||
psychopath (-h | --help)
|
||||
psychopath --version
|
||||
|
||||
Options:
|
||||
-h --help Show this screen.
|
||||
-i <input_file> Input .psy file
|
||||
-s <n>, --spp <n> 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<String>,
|
||||
flag_spp: Option<u32>,
|
||||
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::<Ray>());
|
||||
|
||||
// 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));
|
||||
|
|
Loading…
Reference in New Issue
Block a user