2022-07-28 21:39:00 -07:00

86 lines
2.4 KiB
Rust

use crate::{
camera::Camera,
hitable::Hit,
hitable_list::HitableList,
kdtree::KDTree,
material::{Dielectric, Lambertian, Metal},
moving_sphere::MovingSphere,
renderer::{Opt, Scene},
sphere::Sphere,
texture::{CheckerTexture, ConstantTexture, Texture},
vec3::Vec3,
};
pub fn new(opt: &Opt) -> Scene {
let lookfrom = Vec3::new(3., 4., 2.);
let lookat = Vec3::new(0., 0., -1.);
let dist_to_focus = (lookfrom - lookat).length();
let aperture = 0.1;
let time_min = 0.;
let time_max = 0.;
let camera = Camera::new(
lookfrom,
lookat,
Vec3::new(0., 1., 0.),
45.,
opt.width as f32 / opt.height as f32,
aperture,
dist_to_focus,
time_min,
time_max,
);
let ground_color: Box<dyn Texture> = if opt.use_accel {
Box::new(CheckerTexture::new(
ConstantTexture::new([0., 0., 0.]),
ConstantTexture::new([1.0, 0.4, 0.4]),
))
} else {
Box::new(ConstantTexture::new(Vec3::new(0.4, 1.0, 0.4)))
};
let objects: Vec<Box<dyn Hit>> = vec![
//let world: Box<Hit> = Box::new(HitableList::new(vec![
Box::new(Sphere::new([1., 0.5, 1.], 0.5, Dielectric::new(1.5))),
Box::new(Sphere::new(
Vec3::new(0., 0., -1.),
0.5,
Lambertian::new(ConstantTexture::new(Vec3::new(0.1, 0.2, 0.5))),
)),
Box::new(Sphere::new(
Vec3::new(0., -1000.5, -1.),
1000.,
Lambertian::new(ground_color),
)),
Box::new(Sphere::new(
Vec3::new(1., 0., -1.),
0.5,
Metal::new(Vec3::new(0.8, 0.6, 0.2), 0.2),
)),
Box::new(MovingSphere::new(
Vec3::new(-1., 0., -1.25),
Vec3::new(-1., 0., -0.75),
0.5,
0.,
1.,
Lambertian::new(ConstantTexture::new(Vec3::new(0.2, 0.8, 0.2))),
)),
];
let world: Box<dyn Hit> = if opt.use_accel {
Box::new(KDTree::new(objects, time_min, time_max))
} else {
Box::new(HitableList::new(objects))
};
Scene {
camera,
world,
subsamples: opt.subsamples,
adaptive_subsampling: None,
// adaptive_subsampling: Some(0.5),
num_threads: opt.num_threads,
width: opt.width,
height: opt.height,
global_illumination: true,
..Default::default()
}
}