rtiow: new debugging of spheramid scene.
This commit is contained in:
parent
2541b76ae6
commit
ea40835125
@ -6,17 +6,53 @@ use crate::material::Dielectric;
|
|||||||
use crate::material::Lambertian;
|
use crate::material::Lambertian;
|
||||||
use crate::material::Metal;
|
use crate::material::Metal;
|
||||||
use crate::moving_sphere::MovingSphere;
|
use crate::moving_sphere::MovingSphere;
|
||||||
|
use crate::rect::XYRect;
|
||||||
|
use crate::rect::XZRect;
|
||||||
use crate::renderer::Opt;
|
use crate::renderer::Opt;
|
||||||
use crate::renderer::Scene;
|
use crate::renderer::Scene;
|
||||||
use crate::sphere::Sphere;
|
use crate::sphere::Sphere;
|
||||||
use crate::texture::CheckerTexture;
|
use crate::texture::CheckerTexture;
|
||||||
use crate::texture::ConstantTexture;
|
use crate::texture::ConstantTexture;
|
||||||
|
use crate::texture::EnvMap;
|
||||||
use crate::texture::Texture;
|
use crate::texture::Texture;
|
||||||
use crate::vec3::Vec3;
|
use crate::vec3::Vec3;
|
||||||
|
|
||||||
|
// Draws many spheres along each positive axis.
|
||||||
|
// Blue X-positive
|
||||||
|
// Green Y-positive
|
||||||
|
// Red Z-positive
|
||||||
|
fn draw_axises() -> Vec<Box<dyn Hit>> {
|
||||||
|
let half_diameter = 0.1;
|
||||||
|
let x = (0..100).map(|i| -> Box<dyn Hit> {
|
||||||
|
// X-axis
|
||||||
|
Box::new(Sphere::new(
|
||||||
|
Vec3::new(i as f32 * 2. * half_diameter, 0., 0.),
|
||||||
|
half_diameter,
|
||||||
|
Lambertian::new(ConstantTexture::new([0., 0., 1.])),
|
||||||
|
))
|
||||||
|
});
|
||||||
|
let y = (0..100).map(|i| -> Box<dyn Hit> {
|
||||||
|
// Y-axis
|
||||||
|
Box::new(Sphere::new(
|
||||||
|
Vec3::new(0., i as f32 * 2. * half_diameter, 0.),
|
||||||
|
half_diameter,
|
||||||
|
Lambertian::new(ConstantTexture::new([0., 1., 0.])),
|
||||||
|
))
|
||||||
|
});
|
||||||
|
let z = (0..100).map(|i| -> Box<dyn Hit> {
|
||||||
|
// Z-axis
|
||||||
|
Box::new(Sphere::new(
|
||||||
|
Vec3::new(0., 0., i as f32 * 2. * half_diameter),
|
||||||
|
half_diameter,
|
||||||
|
Lambertian::new(ConstantTexture::new([1., 0., 0.])),
|
||||||
|
))
|
||||||
|
});
|
||||||
|
x.chain(y.chain(z)).collect()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn new(opt: &Opt) -> Scene {
|
pub fn new(opt: &Opt) -> Scene {
|
||||||
let lookfrom = Vec3::new(3., 4., 2.);
|
let lookfrom = Vec3::new(10., 10., 20.);
|
||||||
let lookat = Vec3::new(0., 0., -1.);
|
let lookat = Vec3::new(0., 0., 0.);
|
||||||
let dist_to_focus = (lookfrom - lookat).length();
|
let dist_to_focus = (lookfrom - lookat).length();
|
||||||
let aperture = 0.1;
|
let aperture = 0.1;
|
||||||
let time_min = 0.;
|
let time_min = 0.;
|
||||||
@ -24,7 +60,7 @@ pub fn new(opt: &Opt) -> Scene {
|
|||||||
let camera = Camera::new(
|
let camera = Camera::new(
|
||||||
lookfrom,
|
lookfrom,
|
||||||
lookat,
|
lookat,
|
||||||
Vec3::new(0., 1., 0.),
|
Vec3::new(0., 0., 1.),
|
||||||
45.,
|
45.,
|
||||||
opt.width as f32 / opt.height as f32,
|
opt.width as f32 / opt.height as f32,
|
||||||
aperture,
|
aperture,
|
||||||
@ -32,28 +68,26 @@ pub fn new(opt: &Opt) -> Scene {
|
|||||||
time_min,
|
time_min,
|
||||||
time_max,
|
time_max,
|
||||||
);
|
);
|
||||||
let ground_color: Box<dyn Texture> = if opt.use_accel {
|
let ground_color = CheckerTexture::new(
|
||||||
Box::new(CheckerTexture::new(
|
ConstantTexture::new([0., 0., 0.]),
|
||||||
ConstantTexture::new([0., 0., 0.]),
|
ConstantTexture::new([1.0, 1.0, 1.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 mut objects: Vec<Box<dyn Hit>> = vec![
|
||||||
//let world: Box<Hit> = Box::new(HitableList::new(vec![
|
Box::new(XYRect::new(
|
||||||
|
-10.,
|
||||||
|
10.,
|
||||||
|
-10.,
|
||||||
|
10.,
|
||||||
|
0.,
|
||||||
|
Lambertian::new(ground_color),
|
||||||
|
)),
|
||||||
Box::new(Sphere::new([1., 0.5, 1.], 0.5, Dielectric::new(1.5))),
|
Box::new(Sphere::new([1., 0.5, 1.], 0.5, Dielectric::new(1.5))),
|
||||||
Box::new(Sphere::new(
|
Box::new(Sphere::new(
|
||||||
Vec3::new(0., 0., -1.),
|
Vec3::new(0., 0., 0.5),
|
||||||
0.5,
|
0.5,
|
||||||
Lambertian::new(ConstantTexture::new(Vec3::new(0.1, 0.2, 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(
|
Box::new(Sphere::new(
|
||||||
Vec3::new(1., 0., -1.),
|
Vec3::new(1., 0., -1.),
|
||||||
0.5,
|
0.5,
|
||||||
@ -68,11 +102,11 @@ pub fn new(opt: &Opt) -> Scene {
|
|||||||
Lambertian::new(ConstantTexture::new(Vec3::new(0.2, 0.8, 0.2))),
|
Lambertian::new(ConstantTexture::new(Vec3::new(0.2, 0.8, 0.2))),
|
||||||
)),
|
)),
|
||||||
];
|
];
|
||||||
let world: Box<dyn Hit> = if opt.use_accel {
|
objects.extend(draw_axises());
|
||||||
Box::new(KDTree::new(objects, time_min, time_max))
|
//let world = Box::new(KDTree::new(objects, time_min, time_max));
|
||||||
} else {
|
let world = Box::new(HitableList::new(objects));
|
||||||
Box::new(HitableList::new(objects))
|
let skybox_bytes = include_bytes!("../../images/envmap.jpg");
|
||||||
};
|
let skybox = image::load_from_memory(skybox_bytes).unwrap().to_rgb();
|
||||||
Scene {
|
Scene {
|
||||||
camera,
|
camera,
|
||||||
world,
|
world,
|
||||||
@ -83,6 +117,7 @@ pub fn new(opt: &Opt) -> Scene {
|
|||||||
width: opt.width,
|
width: opt.width,
|
||||||
height: opt.height,
|
height: opt.height,
|
||||||
global_illumination: true,
|
global_illumination: true,
|
||||||
|
env_map: Some(EnvMap::new(skybox)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user