Add boolean for drawing book cover.
This commit is contained in:
parent
f2c5cf48ad
commit
823e75da88
@ -13,6 +13,8 @@ use rtiow::ray::Ray;
|
|||||||
use rtiow::sphere::Sphere;
|
use rtiow::sphere::Sphere;
|
||||||
use rtiow::vec3::Vec3;
|
use rtiow::vec3::Vec3;
|
||||||
|
|
||||||
|
const BOOK_COVER: bool = true;
|
||||||
|
|
||||||
fn color(r: Ray, world: &Hit, depth: usize) -> Vec3 {
|
fn color(r: Ray, world: &Hit, depth: usize) -> Vec3 {
|
||||||
if let Some(rec) = world.hit(r, 0.001, std::f32::MAX) {
|
if let Some(rec) = world.hit(r, 0.001, std::f32::MAX) {
|
||||||
let scatter_response = rec.material.scatter(&r, &rec);
|
let scatter_response = rec.material.scatter(&r, &rec);
|
||||||
@ -103,47 +105,65 @@ fn main() -> Result<(), std::io::Error> {
|
|||||||
let nx = 200;
|
let nx = 200;
|
||||||
let ny = 100;
|
let ny = 100;
|
||||||
let ns = 100;
|
let ns = 100;
|
||||||
let lookfrom = Vec3::new(3., 3., 2.);
|
let (cam, world) = if BOOK_COVER {
|
||||||
let lookat = Vec3::new(0., 0., -1.);
|
let lookfrom = Vec3::new(13., 2., 3.);
|
||||||
let dist_to_focus = (lookfrom - lookat).length();
|
let lookat = Vec3::new(0., 0., 0.);
|
||||||
let aperture = 2.;
|
let dist_to_focus = 10.;
|
||||||
let cam = Camera::new(
|
let aperture = 0.1;
|
||||||
lookfrom,
|
let cam = Camera::new(
|
||||||
lookat,
|
lookfrom,
|
||||||
Vec3::new(0., 1., 0.),
|
lookat,
|
||||||
20.,
|
Vec3::new(0., 1., 0.),
|
||||||
nx as f32 / ny as f32,
|
20.,
|
||||||
aperture,
|
nx as f32 / ny as f32,
|
||||||
dist_to_focus,
|
aperture,
|
||||||
);
|
dist_to_focus,
|
||||||
let world = HitableList::new(vec![
|
);
|
||||||
Box::new(Sphere::new(
|
let world = HitableList::new(random_scene());
|
||||||
Vec3::new(0., 0., -1.),
|
(cam, world)
|
||||||
0.5,
|
} else {
|
||||||
Box::new(Lambertian::new(Vec3::new(0.1, 0.2, 0.5))),
|
let lookfrom = Vec3::new(3., 3., 2.);
|
||||||
)),
|
let lookat = Vec3::new(0., 0., -1.);
|
||||||
Box::new(Sphere::new(
|
let dist_to_focus = (lookfrom - lookat).length();
|
||||||
Vec3::new(0., -100.5, -1.),
|
let aperture = 2.;
|
||||||
100.,
|
let cam = Camera::new(
|
||||||
Box::new(Lambertian::new(Vec3::new(0.8, 0.8, 0.))),
|
lookfrom,
|
||||||
)),
|
lookat,
|
||||||
Box::new(Sphere::new(
|
Vec3::new(0., 1., 0.),
|
||||||
Vec3::new(1., 0., -1.),
|
20.,
|
||||||
0.5,
|
nx as f32 / ny as f32,
|
||||||
Box::new(Metal::new(Vec3::new(0.8, 0.6, 0.2), 0.2)),
|
aperture,
|
||||||
)),
|
dist_to_focus,
|
||||||
Box::new(Sphere::new(
|
);
|
||||||
Vec3::new(-1., 0., -1.),
|
let world = HitableList::new(vec![
|
||||||
0.5,
|
Box::new(Sphere::new(
|
||||||
Box::new(Dielectric::new(1.5)),
|
Vec3::new(0., 0., -1.),
|
||||||
)),
|
0.5,
|
||||||
Box::new(Sphere::new(
|
Box::new(Lambertian::new(Vec3::new(0.1, 0.2, 0.5))),
|
||||||
Vec3::new(-1., 0., -1.),
|
)),
|
||||||
-0.45,
|
Box::new(Sphere::new(
|
||||||
Box::new(Dielectric::new(1.5)),
|
Vec3::new(0., -100.5, -1.),
|
||||||
)),
|
100.,
|
||||||
]);
|
Box::new(Lambertian::new(Vec3::new(0.8, 0.8, 0.))),
|
||||||
//let world = HitableList::new(random_scene());
|
)),
|
||||||
|
Box::new(Sphere::new(
|
||||||
|
Vec3::new(1., 0., -1.),
|
||||||
|
0.5,
|
||||||
|
Box::new(Metal::new(Vec3::new(0.8, 0.6, 0.2), 0.2)),
|
||||||
|
)),
|
||||||
|
Box::new(Sphere::new(
|
||||||
|
Vec3::new(-1., 0., -1.),
|
||||||
|
0.5,
|
||||||
|
Box::new(Dielectric::new(1.5)),
|
||||||
|
)),
|
||||||
|
Box::new(Sphere::new(
|
||||||
|
Vec3::new(-1., 0., -1.),
|
||||||
|
-0.45,
|
||||||
|
Box::new(Dielectric::new(1.5)),
|
||||||
|
)),
|
||||||
|
]);
|
||||||
|
(cam, world)
|
||||||
|
};
|
||||||
println!("P3\n{} {}\n255", nx, ny);
|
println!("P3\n{} {}\n255", nx, ny);
|
||||||
for j in (0..ny).rev() {
|
for j in (0..ny).rev() {
|
||||||
for i in 0..nx {
|
for i in 0..nx {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user