extern crate png;
extern crate rustic_zen;
use std::env;
use std::fs::File;
use std::io::BufWriter;
use std::path::Path;
use std::sync::Arc;
use std::time;
use png::HasParameters;
use rustic_zen::material::hqz_legacy_default;
use rustic_zen::prelude::*;
fn main() {
let args: Vec<String> = env::args().collect();
let threads = usize::from_str_radix(args.get(1).unwrap_or(&"1".to_owned()), 10)
.expect("Usage <script> [threads]");
let now = time::Instant::now();
let width: f64 = 3440.0;
let height: f64 = 1440.0;
let time = 15000;
let o = Segment::line_from_points(
(width, height * 0.75),
(0.0, height * 0.75),
hqz_legacy_default(),
);
let l = Light::new(
(width / 2.0, height / 2.0),
1.0,
0.0,
0.0,
(360.0, 0.0),
Sampler::new_blackbody(4500.0),
);
let r = Scene::new(width as usize, height as usize)
.with_object(o)
.with_light(l);
let mut image = Arc::new(Image::new(width as usize, height as usize));
let setup = now.elapsed();
println!("Tracing rays for {}ms, with {} threads!\n", time, threads);
let now = time::Instant::now();
let rays = r.render(RenderConstraint::TimeMS(time), threads, &mut image);
let tracing = now.elapsed();
let now = time::Instant::now();
let data = image.to_rgba8(rays, 0.7, 1.2);
let downsampling = now.elapsed();
let filename = format!("dawn-{}t.png", threads);
let path = Path::new(&filename);
let file = File::create(path).unwrap();
let ref mut w = BufWriter::new(file);
let mut encoder = png::Encoder::new(w, width as u32, height as u32);
encoder.set(png::ColorType::RGBA).set(png::BitDepth::Eight);
let mut writer = encoder.write_header().unwrap();
writer.write_image_data(&data).unwrap();
println!("\nTiming Summary:");
println!(" Setup: {}ms", setup.as_millis());
println!(
" Tracing: {}ms ({}cpu ms)",
tracing.as_millis(),
tracing.as_millis() * threads as u128
);
println!(" Downsampling: {}ms\n", downsampling.as_millis());
println!(
"{} rays in {}ms: {}rays/s",
rays,
tracing.as_millis(),
rays as f32 / (tracing.as_millis() as f32 / 1000.0)
);
}