Add benchmark scene and change default flags to run under cargo-profile.
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
extern crate cpuprofiler;
|
||||
extern crate rand;
|
||||
extern crate rtiow;
|
||||
extern crate stderrlog;
|
||||
extern crate structopt;
|
||||
|
||||
use std::fs;
|
||||
use std::time::Instant;
|
||||
|
||||
use cpuprofiler::PROFILER;
|
||||
use structopt::StructOpt;
|
||||
|
||||
use rtiow::renderer::render;
|
||||
@@ -24,12 +27,22 @@ fn main() -> Result<(), std::io::Error> {
|
||||
let opt = Opt::from_args();
|
||||
let scene = match opt.model {
|
||||
Model::Book => scenes::book::new(false, &opt),
|
||||
Model::Bench => scenes::bench::new(&opt),
|
||||
Model::BookBVH => scenes::book::new(true, &opt),
|
||||
Model::Cube => scenes::cube::new(&opt),
|
||||
Model::Tutorial => scenes::tutorial::new(&opt),
|
||||
Model::BVH => scenes::bvh::new(&opt),
|
||||
};
|
||||
fs::create_dir_all(&opt.output)?;
|
||||
let pprof_path = "pprof.profile";
|
||||
if opt.pprof {
|
||||
PROFILER.lock().unwrap().start(pprof_path).unwrap();
|
||||
}
|
||||
let res = render(scene, &opt.output);
|
||||
if opt.pprof {
|
||||
info!("Saving pprof to {}", pprof_path);
|
||||
PROFILER.lock().unwrap().stop().unwrap();
|
||||
}
|
||||
let runtime = start.elapsed();
|
||||
info!(
|
||||
"Render time {}.{} seconds",
|
||||
|
||||
@@ -20,6 +20,7 @@ use vec3::Vec3;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Model {
|
||||
Bench,
|
||||
Book,
|
||||
BookBVH,
|
||||
Tutorial,
|
||||
@@ -40,6 +41,7 @@ impl str::FromStr for Model {
|
||||
type Err = ModelParseError;
|
||||
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
|
||||
match s {
|
||||
"bench" => Ok(Model::Bench),
|
||||
"book" => Ok(Model::Book),
|
||||
"book_bvh" => Ok(Model::BookBVH),
|
||||
"tutorial" => Ok(Model::Tutorial),
|
||||
@@ -54,19 +56,21 @@ impl str::FromStr for Model {
|
||||
#[structopt(name = "tracer", about = "An experimental ray tracer.")]
|
||||
pub struct Opt {
|
||||
/// Image width
|
||||
#[structopt(short = "w", long = "width", default_value = "1280")]
|
||||
#[structopt(short = "w", long = "width", default_value = "128")]
|
||||
pub width: usize,
|
||||
/// Image height
|
||||
#[structopt(short = "h", long = "height", default_value = "720")]
|
||||
#[structopt(short = "h", long = "height", default_value = "128")]
|
||||
pub height: usize,
|
||||
/// Sub-samples per pixel
|
||||
#[structopt(short = "s", long = "subsample", default_value = "10")]
|
||||
#[structopt(short = "s", long = "subsample", default_value = "1")]
|
||||
pub subsamples: usize,
|
||||
#[structopt(long = "model")]
|
||||
#[structopt(long = "model", default_value = "bench")]
|
||||
pub model: Model,
|
||||
#[structopt(long = "pprof")]
|
||||
pub pprof: bool,
|
||||
|
||||
/// Output directory
|
||||
#[structopt(parse(from_os_str))]
|
||||
#[structopt(parse(from_os_str), default_value = "/tmp/tracer")]
|
||||
pub output: PathBuf,
|
||||
}
|
||||
|
||||
|
||||
64
rtiow/src/scenes/bench.rs
Normal file
64
rtiow/src/scenes/bench.rs
Normal file
@@ -0,0 +1,64 @@
|
||||
use rand;
|
||||
use rand::Rng;
|
||||
|
||||
use bvh::BVH;
|
||||
use camera::Camera;
|
||||
use hitable::Hit;
|
||||
use hitable_list::HitableList;
|
||||
use material::Lambertian;
|
||||
use renderer::Opt;
|
||||
use renderer::Scene;
|
||||
use sphere::Sphere;
|
||||
use vec3::Vec3;
|
||||
|
||||
pub fn new(opt: &Opt) -> Scene {
|
||||
let lookfrom = Vec3::new(0.01, 20., 0.);
|
||||
let lookat = Vec3::new(0., 0., 0.);
|
||||
let dist_to_focus = (lookfrom - lookat).length();
|
||||
let aperture = 0.1;
|
||||
let time_min = 0.;
|
||||
let time_max = 1.;
|
||||
let camera = Camera::new(
|
||||
lookfrom,
|
||||
lookat,
|
||||
Vec3::new(0., 1., 0.),
|
||||
70.,
|
||||
opt.width as f32 / opt.height as f32,
|
||||
aperture,
|
||||
dist_to_focus,
|
||||
time_min,
|
||||
time_max,
|
||||
);
|
||||
let mut rng = rand::thread_rng();
|
||||
let mut grid: Vec<Box<Hit>> = Vec::new();
|
||||
let len = 30;
|
||||
for x in 0..len {
|
||||
for z in 0..len {
|
||||
let r = rng.gen_range::<f32>(0., 1.);
|
||||
let g = rng.gen_range::<f32>(0., 1.);
|
||||
let b = rng.gen_range::<f32>(0., 1.);
|
||||
|
||||
grid.push(Box::new(Sphere::new(
|
||||
Vec3::new((x - len / 2) as f32, 0., (z - len / 2) as f32),
|
||||
0.5,
|
||||
Box::new(Lambertian::new(Vec3::new(r, g, b))),
|
||||
)));
|
||||
}
|
||||
}
|
||||
let use_bvh = false;
|
||||
let world: Box<Hit>;
|
||||
if use_bvh {
|
||||
let bvh = BVH::new(grid, time_min, time_max);
|
||||
trace!(target: "bvh", "World {}", bvh);
|
||||
world = Box::new(bvh);
|
||||
} else {
|
||||
world = Box::new(HitableList::new(grid));
|
||||
}
|
||||
Scene {
|
||||
camera,
|
||||
world,
|
||||
subsamples: opt.subsamples,
|
||||
width: opt.width,
|
||||
height: opt.height,
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod bench;
|
||||
pub mod book;
|
||||
pub mod bvh;
|
||||
pub mod cube;
|
||||
|
||||
Reference in New Issue
Block a user