rtiow: break project into multiple workspaces.
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2019-11-09 11:56:33 -08:00
parent 2541b76ae6
commit d9d183b1e5
62 changed files with 941 additions and 957 deletions

View File

@@ -0,0 +1,78 @@
use log::trace;
use rand;
use rand::Rng;
use crate::bvh::BVH;
use crate::camera::Camera;
use crate::hitable::Hit;
use crate::hitable_list::HitableList;
use crate::kdtree::KDTree;
use crate::material::Lambertian;
use crate::renderer::Opt;
use crate::renderer::Scene;
use crate::sphere::Sphere;
use crate::texture::ConstantTexture;
use crate::vec3::Vec3;
pub fn new(opt: &Opt) -> Scene {
let lookfrom = Vec3::new(20., 20., 20.);
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<dyn Hit>> = Vec::new();
let len = 1000;
for x in 0..len {
for z in 0..len {
let r = rng.gen_range(0., 1.);
let g = rng.gen_range(0., 1.);
let b = rng.gen_range(0., 1.);
let x_pos = (x - len / 2) as f32 + rng.gen_range(-0.1, 0.1);
let z_pos = (z - len / 2) as f32 + rng.gen_range(-0.1, 0.1);
grid.push(Box::new(Sphere::new(
Vec3::new(x_pos, 0., z_pos),
0.5,
Lambertian::new(ConstantTexture::new(Vec3::new(r, g, b))),
)));
}
}
let world: Box<dyn Hit>;
if opt.use_accel {
let use_kd = true;
if use_kd {
let kdtree = KDTree::new(grid, time_min, time_max);
trace!("k-d tree world {}", kdtree);
world = Box::new(kdtree);
} else {
let bvh = BVH::new(grid, time_min, time_max);
trace!("BVH world {}", bvh);
world = Box::new(bvh);
}
} else {
world = Box::new(HitableList::new(grid));
}
Scene {
camera,
world,
subsamples: opt.subsamples,
num_threads: opt.num_threads,
width: opt.width,
height: opt.height,
..Default::default()
}
}

View File

@@ -0,0 +1,144 @@
use rand;
use rand::Rng;
use crate::camera::Camera;
use crate::hitable::Hit;
use crate::hitable_list::HitableList;
use crate::kdtree::KDTree;
use crate::material::Dielectric;
use crate::material::Lambertian;
use crate::material::Material;
use crate::material::Metal;
use crate::renderer::Opt;
use crate::renderer::Scene;
use crate::sphere::Sphere;
use crate::texture::CheckerTexture;
use crate::texture::ConstantTexture;
use crate::texture::EnvMap;
use crate::vec3::Vec3;
pub fn new(opt: &Opt) -> Scene {
let lookfrom = Vec3::new(13., 2., 3.);
let lookat = Vec3::new(0., 0., 0.);
let dist_to_focus = 10.;
let aperture = 0.1;
let time_min = 0.;
let time_max = 1.;
let camera = Camera::new(
lookfrom,
lookat,
Vec3::new(0., 1., 0.),
20.,
opt.width as f32 / opt.height as f32,
aperture,
dist_to_focus,
time_min,
time_max,
);
let ground_color = if opt.use_accel {
[1.0, 0.4, 0.4]
} else {
[0.4, 1.0, 0.4]
};
let world: Box<dyn Hit> = if opt.use_accel {
Box::new(KDTree::new(random_scene(ground_color), time_min, time_max))
} else {
Box::new(HitableList::new(random_scene(ground_color)))
};
let skybox_bytes = include_bytes!("../../images/envmap.jpg");
let skybox = image::load_from_memory(skybox_bytes).unwrap().to_rgb();
Scene {
camera,
world,
subsamples: opt.subsamples,
adaptive_subsampling: Some(0.5),
num_threads: opt.num_threads,
width: opt.width,
height: opt.height,
global_illumination: true,
env_map: Some(EnvMap::new(skybox)),
..Default::default()
}
}
fn random_scene<V>(ground_color: V) -> Vec<Box<dyn Hit>>
where
V: Into<Vec3>,
{
let mut rng = rand::thread_rng();
let checker = true;
let ground_material: Box<dyn Material> = if checker {
Box::new(Lambertian::new(CheckerTexture::new(
ConstantTexture::new([0., 0., 0.]),
ConstantTexture::new(ground_color),
)))
} else {
Box::new(Lambertian::new(ConstantTexture::new(ground_color)))
};
let mut objects: Vec<Box<dyn Hit>> = vec![Box::new(Sphere::new(
[0., -1000., 0.],
1000.,
ground_material,
))];
let mut random = || rng.gen_range(0., 1.);
for a in -11..11 {
for b in -11..11 {
let choose_mat = random();
let center = Vec3::new(a as f32 + 0.9 * random(), 0.2, b as f32 + 0.9 * random());
if (center - Vec3::new(4., 0.2, 0.)).length() > 0.9 {
let sphere: Box<dyn Hit> = if choose_mat < 0.8 {
// diffuse
Box::new(Sphere::new(
center,
0.2,
Lambertian::new(ConstantTexture::new([
random() * random(),
random() * random(),
random() * random(),
])),
))
} else if choose_mat < 0.95 {
// metal
Box::new(Sphere::new(
center,
0.2,
Metal::new(
Vec3::new(
0.5 * (1. + random()),
0.5 * (1. + random()),
0.5 * (1. + random()),
),
0.5 * random(),
),
))
} else {
// glass
Box::new(Sphere::new(center, 0.2, Dielectric::new(1.5)))
};
objects.push(sphere);
};
}
}
let more: Vec<Box<dyn Hit>> = vec![
Box::new(Sphere::new(
Vec3::new(0., 1., 0.),
1.0,
Dielectric::new(1.5),
)),
Box::new(Sphere::new(
Vec3::new(-4., 1., 0.),
1.0,
Lambertian::new(ConstantTexture::new(Vec3::new(0.4, 0.2, 0.1))),
)),
Box::new(Sphere::new(
Vec3::new(4., 1., 0.),
1.0,
Metal::new(Vec3::new(0.7, 0.6, 0.5), 0.0),
)),
];
objects.extend(more);
objects
}

View File

@@ -0,0 +1,73 @@
use log::trace;
use crate::bvh::BVH;
use crate::camera::Camera;
use crate::hitable::Hit;
use crate::material::Lambertian;
use crate::material::Metal;
use crate::moving_sphere::MovingSphere;
use crate::renderer::Opt;
use crate::renderer::Scene;
use crate::sphere::Sphere;
use crate::texture::ConstantTexture;
use crate::vec3::Vec3;
pub fn new(opt: &Opt) -> Scene {
let lookfrom = Vec3::new(3., 3., 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 = 1.;
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 b = BVH::new(
vec![
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., -100.5, -1.),
100.,
Lambertian::new(ConstantTexture::new(Vec3::new(0.8, 0.8, 0.8))),
)),
Box::new(Sphere::new(
Vec3::new(1., 0., -1.),
0.5,
Metal::new(Vec3::new(0.6, 0.6, 0.6), 0.2),
)),
Box::new(MovingSphere::new(
Vec3::new(-1., 0., -1.25),
Vec3::new(-1., 0., -0.75),
0.5,
time_min,
time_max,
Lambertian::new(ConstantTexture::new(Vec3::new(0.2, 0.8, 0.2))),
)),
],
time_min,
time_max,
);
trace!(target: "bvh", "World {}", b);
let world: Box<dyn Hit> = Box::new(b);
Scene {
camera,
world,
subsamples: opt.subsamples,
num_threads: opt.num_threads,
width: opt.width,
height: opt.height,
..Default::default()
}
}

View File

@@ -0,0 +1,139 @@
use std::sync::Arc;
use crate::camera::Camera;
use crate::cuboid::Cuboid;
use crate::flip_normals::FlipNormals;
use crate::hitable::Hit;
use crate::hitable_list::HitableList;
use crate::kdtree::KDTree;
use crate::material::DiffuseLight;
use crate::material::Lambertian;
use crate::rect::XYRect;
use crate::rect::XZRect;
use crate::rect::YZRect;
use crate::renderer::Opt;
use crate::renderer::Scene;
use crate::rotate::RotateY;
use crate::texture::ConstantTexture;
use crate::translate::Translate;
use crate::vec3::Vec3;
pub fn new(opt: &Opt) -> Scene {
let lookfrom = Vec3::new(278., 278., -800.);
let lookat = Vec3::new(278., 278., 0.);
let dist_to_focus = 10.0;
let aperture = 0.0;
let time_min = 0.;
let time_max = 1.;
let camera = Camera::new(
lookfrom,
lookat,
Vec3::new(0., 1., 0.),
40.,
opt.width as f32 / opt.height as f32,
aperture,
dist_to_focus,
time_min,
time_max,
);
let objects: Vec<Box<dyn Hit>> = vec![
// Box1
Box::new(Translate::new(
RotateY::new(
Cuboid::new(
Vec3::new(0., 0., 0.),
Vec3::new(165., 165., 165.),
Arc::new(Lambertian::new(ConstantTexture::new(Vec3::new(
0.73, 0.73, 0.73,
)))),
),
-18.,
),
Vec3::new(100., 0., 0.),
)),
// Box2
Box::new(Translate::new(
RotateY::new(
Cuboid::new(
Vec3::new(0., 0., 0.),
Vec3::new(165., 330., 165.),
Arc::new(Lambertian::new(ConstantTexture::new(Vec3::new(
0.73, 0.73, 0.73,
)))),
),
15.,
),
Vec3::new(265., 0., 295.),
)),
// Green wall left
Box::new(FlipNormals::new(YZRect::new(
0.,
555.,
0.,
555.,
555.,
Lambertian::new(ConstantTexture::new(Vec3::new(0.12, 0.45, 0.15))),
))),
// Red floor right
Box::new(YZRect::new(
0.,
555.,
0.,
555.,
0.,
Lambertian::new(ConstantTexture::new(Vec3::new(0.65, 0.05, 0.05))),
)),
// Light in ceiling
Box::new(XZRect::new(
213.,
343.,
227.,
332.,
554.,
DiffuseLight::new(ConstantTexture::new(Vec3::new(15., 15., 15.))),
)),
// Grey ceiling
Box::new(FlipNormals::new(XZRect::new(
0.,
555.,
0.,
555.,
555.,
Lambertian::new(ConstantTexture::new(Vec3::new(0.73, 0.73, 0.73))),
))),
// Grey floor
Box::new(XZRect::new(
0.,
555.,
0.,
555.,
0.,
Lambertian::new(ConstantTexture::new(Vec3::new(0.73, 0.73, 0.73))),
)),
// Grey back wall
Box::new(FlipNormals::new(XYRect::new(
0.,
555.,
0.,
555.,
555.,
Lambertian::new(ConstantTexture::new(Vec3::new(0.73, 0.73, 0.73))),
))),
];
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,
num_threads: opt.num_threads,
width: opt.width,
height: opt.height,
global_illumination: false,
..Default::default()
}
}

View File

@@ -0,0 +1,124 @@
use std::sync::Arc;
use crate::camera::Camera;
use crate::constant_medium::ConstantMedium;
use crate::cuboid::Cuboid;
use crate::flip_normals::FlipNormals;
use crate::hitable::Hit;
use crate::hitable_list::HitableList;
use crate::kdtree::KDTree;
use crate::material::DiffuseLight;
use crate::material::Lambertian;
use crate::material::Material;
use crate::rect::XYRect;
use crate::rect::XZRect;
use crate::rect::YZRect;
use crate::renderer::Opt;
use crate::renderer::Scene;
use crate::rotate::RotateY;
use crate::texture::ConstantTexture;
use crate::translate::Translate;
use crate::vec3::Vec3;
pub fn new(opt: &Opt) -> Scene {
let lookfrom = Vec3::new(278., 278., -800.);
let lookat = Vec3::new(278., 278., 0.);
let dist_to_focus = 10.0;
let aperture = 0.0;
let time_min = 0.;
let time_max = 1.;
let camera = Camera::new(
lookfrom,
lookat,
Vec3::new(0., 1., 0.),
40.,
opt.width as f32 / opt.height as f32,
aperture,
dist_to_focus,
time_min,
time_max,
);
let red = Lambertian::new(ConstantTexture::new([0.65, 0.05, 0.05]));
let white: Arc<dyn Material> =
Arc::new(Lambertian::new(ConstantTexture::new([0.73, 0.73, 0.73])));
let green = Lambertian::new(ConstantTexture::new([0.12, 0.45, 0.15]));
let light = DiffuseLight::new(ConstantTexture::new([7., 7., 7.]));
let objects: Vec<Box<dyn Hit>> = vec![
// White smoke box on the right
Box::new(ConstantMedium::new(
Translate::new(
RotateY::new(
Cuboid::new(
Vec3::new(0., 0., 0.),
Vec3::new(165., 165., 165.),
Arc::clone(&white),
),
-18.,
),
Vec3::new(130., 0., 65.),
),
0.01,
ConstantTexture::new([1., 1., 1.]),
)),
// Black smoke box on the left
Box::new(ConstantMedium::new(
Translate::new(
RotateY::new(
Cuboid::new(
Vec3::new(0., 0., 0.),
Vec3::new(165., 330., 165.),
Arc::clone(&white),
),
15.,
),
Vec3::new(265., 0., 295.),
),
0.01,
ConstantTexture::new([0., 0., 0.]),
)),
// Green wall left
Box::new(FlipNormals::new(YZRect::new(
0., 555., 0., 555., 555., green,
))),
// Red floor right
Box::new(YZRect::new(0., 555., 0., 555., 0., red)),
// Light in ceiling
Box::new(XZRect::new(113., 443., 127., 432., 554., light)),
// Grey ceiling
Box::new(FlipNormals::new(XZRect::new(
0.,
555.,
0.,
555.,
555.,
Arc::clone(&white),
))),
// Grey floor
Box::new(XZRect::new(0., 555., 0., 555., 0., Arc::clone(&white))),
// Grey back wall
Box::new(FlipNormals::new(XYRect::new(
0.,
555.,
0.,
555.,
555.,
Arc::clone(&white),
))),
];
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,
num_threads: opt.num_threads,
width: opt.width,
height: opt.height,
..Default::default()
}
}

View File

@@ -0,0 +1,177 @@
use std::sync::Arc;
use image;
use rand;
use rand::Rng;
use crate::camera::Camera;
use crate::constant_medium::ConstantMedium;
use crate::cuboid::Cuboid;
use crate::hitable::Hit;
use crate::hitable_list::HitableList;
use crate::kdtree::KDTree;
use crate::material::Dielectric;
use crate::material::DiffuseLight;
use crate::material::Lambertian;
use crate::material::Material;
use crate::material::Metal;
use crate::moving_sphere::MovingSphere;
use crate::noise::perlin::Perlin;
use crate::noise::NoiseType;
use crate::rect::XZRect;
use crate::renderer::Opt;
use crate::renderer::Scene;
use crate::rotate::RotateY;
use crate::sphere::Sphere;
use crate::texture::ConstantTexture;
use crate::texture::ImageTexture;
use crate::texture::NoiseTexture;
use crate::translate::Translate;
use crate::vec3::Vec3;
pub fn new(opt: &Opt) -> Scene {
let lookfrom = Vec3::new(478., 278., -600.);
let lookat = Vec3::new(278., 278., 0.);
let dist_to_focus = 10.;
let aperture = 0.0;
let t_min = 0.;
let t_max = 1.;
let camera = Camera::new(
lookfrom,
lookat,
Vec3::new(0., 1., 0.),
40.,
opt.width as f32 / opt.height as f32,
aperture,
dist_to_focus,
t_min,
t_max,
);
let nb = 20;
let rng = &mut rand::thread_rng();
let mut boxlist: Vec<Box<dyn Hit>> = Vec::with_capacity(10000);
let mut list: Vec<Box<dyn Hit>> = Vec::new();
let white: Arc<dyn Material> =
Arc::new(Lambertian::new(ConstantTexture::new([0.73, 0.73, 0.73])));
let ground: Arc<dyn Material> =
Arc::new(Lambertian::new(ConstantTexture::new([0.48, 0.83, 0.53])));
for i in 0..nb {
for j in 0..nb {
let w = 100.;
let x0 = -1000. + i as f32 * w;
let z0 = -1000. + j as f32 * w;
let y0 = 0.;
let x1 = x0 + w;
let y1 = 100. * (rng.gen_range(0., 1.) + 0.01);
let z1 = z0 + w;
boxlist.push(Box::new(Cuboid::new(
Vec3::new(x0, y0, z0),
Vec3::new(x1, y1, z1),
Arc::clone(&ground),
)));
}
}
list.push(Box::new(KDTree::new(boxlist, t_min, t_max)));
let light = DiffuseLight::new(ConstantTexture::new([7., 7., 7.]));
// Light in ceiling
list.push(Box::new(XZRect::new(123., 423., 147., 412., 554., light)));
let center = Vec3::new(400., 400., 200.);
// Moving brownish ball
list.push(Box::new(MovingSphere::new(
center,
center + Vec3::new(30., 0., 0.),
50.,
t_min,
t_max,
Lambertian::new(ConstantTexture::new([0.7, 0.3, 0.1])),
)));
// Glass ball, lower-left corner
list.push(Box::new(Sphere::new(
[260., 150., 45.],
50.,
Dielectric::new(1.5),
)));
// Metal ball lower-right corner
list.push(Box::new(Sphere::new(
[0., 150., 145.],
50.,
Metal::new([0.8, 0.8, 0.9], 10.0),
)));
// Blue smokey glass ball lower-left
let boundary: Arc<dyn Hit> =
Arc::new(Sphere::new([360., 150., 145.], 70., Dielectric::new(1.5)));
list.push(Box::new(Arc::clone(&boundary)));
list.push(Box::new(ConstantMedium::new(
Arc::clone(&boundary),
0.2,
ConstantTexture::new([0.2, 0.4, 0.9]),
)));
// General white mist over whole scene
let boundary: Arc<dyn Hit> = Arc::new(Sphere::new([0., 0., 0.], 5000., Dielectric::new(1.5)));
list.push(Box::new(Arc::clone(&boundary)));
list.push(Box::new(ConstantMedium::new(
Arc::clone(&boundary),
0.0001,
ConstantTexture::new([1.0, 1.0, 1.0]),
)));
// Earth sphere
let world_image_bytes = include_bytes!("../../images/world.jpg");
let world = ImageTexture::new(image::load_from_memory(world_image_bytes).unwrap().to_rgb());
list.push(Box::new(Sphere::new(
Vec3::new(400., 200., 400.),
100.,
Lambertian::new(world),
)));
// Perlin noise sphere
let noise_source = Perlin::new(rng);
let noise_type = NoiseType::Marble {
period: Vec3::new(0., 1., 0.),
power: 4.,
size: 32,
scale: 0.5,
};
let pertext = NoiseTexture::new(noise_source, noise_type);
list.push(Box::new(Sphere::new(
[220., 280., 300.],
80.,
Lambertian::new(pertext),
)));
// White 'cube' made of 1000 spheres
let ns = 1000;
let mut boxlist: Vec<Box<dyn Hit>> = Vec::with_capacity(1000);
for _ in 0..ns {
boxlist.push(Box::new(Sphere::new(
[
165. * rng.gen_range(0., 1.),
165. * rng.gen_range(0., 1.),
165. * rng.gen_range(0., 1.),
],
10.,
Arc::clone(&white),
)));
}
list.push(Box::new(Translate::new(
RotateY::new(KDTree::new(boxlist, t_min, t_max), 15.),
[-100., 270., 395.],
)));
Scene {
camera,
world: Box::new(HitableList::new(list)),
subsamples: opt.subsamples,
num_threads: opt.num_threads,
width: opt.width,
height: opt.height,
..Default::default()
}
}

View File

@@ -0,0 +1,157 @@
use rand;
use crate::camera::Camera;
use crate::hitable::Hit;
use crate::hitable_list::HitableList;
use crate::kdtree::KDTree;
use crate::material::DiffuseLight;
use crate::material::Lambertian;
use crate::noise::perlin::Perlin;
use crate::noise::NoiseType;
use crate::rect::XYRect;
use crate::rect::XZRect;
use crate::rect::YZRect;
use crate::renderer::Opt;
use crate::renderer::Scene;
use crate::sphere::Sphere;
use crate::texture::ConstantTexture;
use crate::texture::ImageTexture;
use crate::texture::Mandelbrot;
use crate::texture::NoiseTexture;
use crate::vec3::Vec3;
pub fn new(opt: &Opt) -> Scene {
let lookfrom = Vec3::new(20., 20., 20.);
let lookat = Vec3::new(0., 1., 0.);
let dist_to_focus = 10.0;
let aperture = 0.0;
let time_min = 0.;
let time_max = 1.;
let camera = Camera::new(
lookfrom,
lookat,
Vec3::new(0., 1., 0.),
20.,
opt.width as f32 / opt.height as f32,
aperture,
dist_to_focus,
time_min,
time_max,
);
let rng = &mut rand::thread_rng();
let _ground_color = if opt.use_accel {
Box::new(ConstantTexture::new(Vec3::new(1.0, 0.4, 0.4)))
} else {
Box::new(ConstantTexture::new(Vec3::new(0.4, 1.0, 0.4)))
};
let world_image_bytes = include_bytes!("../../images/world.jpg");
let it = ImageTexture::new(image::load_from_memory(world_image_bytes).unwrap().to_rgb());
let noise_source = Perlin::new(rng);
let noise_type = NoiseType::Scale(10.);
let objects: Vec<Box<dyn Hit>> = vec![
// Textured globe
// Box::new(Sphere::new(Vec3::new(0., 2., 0.), 2.0, Lambertian::new(it))),
Box::new(Sphere::new(
Vec3::new(0., 2., 0.),
2.0,
DiffuseLight::new(it),
)),
// Ground
Box::new(XZRect::new(
-100.,
100.,
-100.,
1000.,
-60.,
DiffuseLight::new(Mandelbrot::default()),
)),
Box::new(XZRect::new(
-100.,
100.,
-100.,
200.,
60.,
DiffuseLight::new(ConstantTexture::new(Vec3::new(1., 1., 1.))),
)),
Box::new(YZRect::new(
1.,
3.,
-1.,
1.,
4.,
DiffuseLight::new(ConstantTexture::new(Vec3::new(4., 0., 4.))),
)),
Box::new(YZRect::new(
1.,
3.,
-1.,
1.,
-4.,
DiffuseLight::new(ConstantTexture::new(Vec3::new(0., 4., 0.))),
)),
Box::new(XZRect::new(
-1.,
1.,
-1.,
1.,
6.,
DiffuseLight::new(ConstantTexture::new(Vec3::new(4., 4., 0.))),
)),
Box::new(XYRect::new(
-1.,
1.,
1.,
3.,
-4.,
DiffuseLight::new(ConstantTexture::new(Vec3::new(0., 0., 4.))),
)),
Box::new(XYRect::new(
-1.75,
1.75,
1.,
3.,
4.,
Lambertian::new(NoiseTexture::new(noise_source, noise_type)),
)),
/*
Box::new(Sphere::new(
Vec3::new(0., 0., 0.),
0.5,
Box::new(Lambertian::new(ConstantTexture::new(Vec3::new(
0.1, 0.2, 0.5,
)))),
)),
// Shiny sphere
Box::new(Sphere::new(
Vec3::new(1., 0., 0.),
0.5,
Metal::new(Vec3::new(0.8, 0.8, 0.8), 0.2),
)),
Box::new(MovingSphere::new(
Vec3::new(-1., 0., -0.25),
Vec3::new(-1., 0., 0.25),
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,
num_threads: opt.num_threads,
width: opt.width,
height: opt.height,
..Default::default()
}
}

View File

@@ -0,0 +1,11 @@
pub mod bench;
pub mod book;
pub mod bvh;
pub mod cornell_box;
pub mod cornell_smoke;
pub mod final_scene;
pub mod mandelbrot;
pub mod perlin_debug;
pub mod spheramid;
pub mod test;
pub mod tutorial;

View File

@@ -0,0 +1,74 @@
use std::sync::Arc;
use rand;
use crate::camera::Camera;
use crate::hitable::Hit;
use crate::hitable_list::HitableList;
use crate::kdtree::KDTree;
use crate::material::Lambertian;
use crate::noise::perlin::Perlin;
use crate::noise::NoiseType;
use crate::renderer::Opt;
use crate::renderer::Scene;
use crate::sphere::Sphere;
use crate::texture::NoiseTexture;
use crate::texture::Texture;
use crate::vec3::Vec3;
pub fn new(opt: &Opt) -> Scene {
let lookfrom = Vec3::new(13., 2., 3.);
let lookat = Vec3::new(0., 0., 0.);
let dist_to_focus = 10.0;
let aperture = 0.0;
let time_min = 0.;
let time_max = 1.;
let camera = Camera::new(
lookfrom,
lookat,
Vec3::new(0., 1., 0.),
20.,
opt.width as f32 / opt.height as f32,
aperture,
dist_to_focus,
time_min,
time_max,
);
let rng = &mut rand::thread_rng();
let noise_source = Perlin::new(rng);
let noise_type = NoiseType::Marble {
period: Vec3::new(0., 1., 0.),
power: 4.,
size: 32,
scale: 0.05,
};
let pertext: Arc<dyn Texture> = Arc::new(NoiseTexture::new(noise_source, noise_type));
let objects: Vec<Box<dyn Hit>> = vec![
Box::new(Sphere::new(
Vec3::new(0., -1000., 0.),
1000.,
Lambertian::new(Arc::clone(&pertext)),
)),
Box::new(Sphere::new(
Vec3::new(0., 2., 0.),
2.0,
Lambertian::new(Arc::clone(&pertext)),
)),
];
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,
num_threads: opt.num_threads,
width: opt.width,
height: opt.height,
global_illumination: true,
..Default::default()
}
}

View File

@@ -0,0 +1,88 @@
use crate::camera::Camera;
use crate::hitable::Hit;
use crate::hitable_list::HitableList;
use crate::kdtree::KDTree;
use crate::material::Dielectric;
use crate::material::Lambertian;
use crate::material::Metal;
use crate::moving_sphere::MovingSphere;
use crate::renderer::Opt;
use crate::renderer::Scene;
use crate::sphere::Sphere;
use crate::texture::CheckerTexture;
use crate::texture::ConstantTexture;
use crate::texture::Texture;
use crate::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()
}
}

View File

@@ -0,0 +1,150 @@
use image;
use rand;
use crate::camera::Camera;
use crate::hitable::Hit;
use crate::hitable_list::HitableList;
use crate::kdtree::KDTree;
use crate::material::DiffuseLight;
use crate::material::Lambertian;
use crate::noise::perlin::Perlin;
use crate::noise::NoiseType;
use crate::rect::XYRect;
use crate::rect::XZRect;
use crate::rect::YZRect;
use crate::renderer::Opt;
use crate::renderer::Scene;
use crate::sphere::Sphere;
use crate::texture::ConstantTexture;
use crate::texture::ImageTexture;
use crate::texture::NoiseTexture;
use crate::vec3::Vec3;
pub fn new(opt: &Opt) -> Scene {
let lookfrom = Vec3::new(20., 20., 20.);
let lookat = Vec3::new(0., 1., 0.);
let dist_to_focus = 10.0;
let aperture = 0.0;
let time_min = 0.;
let time_max = 1.;
let camera = Camera::new(
lookfrom,
lookat,
Vec3::new(0., 1., 0.),
20.,
opt.width as f32 / opt.height as f32,
aperture,
dist_to_focus,
time_min,
time_max,
);
let rng = &mut rand::thread_rng();
let _ground_color = if opt.use_accel {
Box::new(ConstantTexture::new(Vec3::new(1.0, 0.4, 0.4)))
} else {
Box::new(ConstantTexture::new(Vec3::new(0.4, 1.0, 0.4)))
};
let world_image_bytes = include_bytes!("../../images/world.jpg");
let it = ImageTexture::new(image::load_from_memory(world_image_bytes).unwrap().to_rgb());
let noise_source = Perlin::new(rng);
let noise_type = NoiseType::Scale(10.);
let objects: Vec<Box<dyn Hit>> = vec![
// Big sphere
Box::new(Sphere::new(Vec3::new(0., 2., 0.), 2.0, Lambertian::new(it))),
// Earth sized sphere
Box::new(Sphere::new(
Vec3::new(0., -1000., 0.),
1000.,
// Box::new(Lambertian::new(ground_color)),
Lambertian::new(NoiseTexture::new(noise_source, noise_type)),
)),
Box::new(XZRect::new(
-100.,
100.,
-100.,
1000.,
60.,
DiffuseLight::new(ConstantTexture::new(Vec3::new(1., 1., 1.))),
)),
Box::new(YZRect::new(
1.,
3.,
-1.,
1.,
4.,
DiffuseLight::new(ConstantTexture::new(Vec3::new(4., 0., 4.))),
)),
Box::new(YZRect::new(
1.,
3.,
-1.,
1.,
-4.,
DiffuseLight::new(ConstantTexture::new(Vec3::new(0., 4., 0.))),
)),
Box::new(XZRect::new(
-1.,
1.,
-1.,
1.,
6.,
DiffuseLight::new(ConstantTexture::new(Vec3::new(4., 4., 0.))),
)),
Box::new(XYRect::new(
-1.,
1.,
1.,
3.,
-4.,
DiffuseLight::new(ConstantTexture::new(Vec3::new(0., 0., 4.))),
)),
Box::new(XYRect::new(
-1.,
1.,
1.,
3.,
4.,
DiffuseLight::new(ConstantTexture::new(Vec3::new(0., 4., 4.))),
)),
/*
Box::new(Sphere::new(
Vec3::new(0., 0., 0.),
0.5,
Box::new(Lambertian::new(ConstantTexture::new(Vec3::new(
0.1, 0.2, 0.5,
)))),
)),
// Shiny sphere
Box::new(Sphere::new(
Vec3::new(1., 0., 0.),
0.5,
Metal::new(Vec3::new(0.8, 0.8, 0.8), 0.2),
)),
Box::new(MovingSphere::new(
Vec3::new(-1., 0., -0.25),
Vec3::new(-1., 0., 0.25),
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,
num_threads: opt.num_threads,
width: opt.width,
height: opt.height,
..Default::default()
}
}

View File

@@ -0,0 +1,88 @@
use crate::camera::Camera;
use crate::hitable::Hit;
use crate::hitable_list::HitableList;
use crate::kdtree::KDTree;
use crate::material::Dielectric;
use crate::material::Lambertian;
use crate::material::Metal;
use crate::moving_sphere::MovingSphere;
use crate::renderer::Opt;
use crate::renderer::Scene;
use crate::sphere::Sphere;
use crate::texture::CheckerTexture;
use crate::texture::ConstantTexture;
use crate::texture::Texture;
use crate::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()
}
}