rtiow: tweak scenes and cleanup lint

This commit is contained in:
Bill Thiede 2023-02-12 13:01:54 -08:00
parent a2f9166b5a
commit f51d3396f4
4 changed files with 23 additions and 36 deletions

View File

@ -52,7 +52,7 @@ impl Material for Box<dyn Material> {
} }
} }
#[derive(Debug)] #[derive(Clone, Debug)]
pub struct Isotropic<T> pub struct Isotropic<T>
where where
T: Texture, T: Texture,
@ -83,7 +83,7 @@ where
} }
} }
#[derive(Debug)] #[derive(Clone, Debug)]
pub struct Lambertian<T> pub struct Lambertian<T>
where where
T: Texture, T: Texture,
@ -115,7 +115,7 @@ where
} }
} }
#[derive(Debug)] #[derive(Clone, Debug)]
pub struct Metal { pub struct Metal {
albedo: Vec3, albedo: Vec3,
fuzzy: f32, fuzzy: f32,
@ -170,7 +170,7 @@ fn schlick(cosine: f32, ref_idx: f32) -> f32 {
r0 + (1. - r0) * (1. - cosine).powf(5.) r0 + (1. - r0) * (1. - cosine).powf(5.)
} }
#[derive(Debug)] #[derive(Clone, Debug)]
pub struct Dielectric { pub struct Dielectric {
ref_idx: f32, ref_idx: f32,
} }

View File

@ -1,14 +1,10 @@
use std::{ use std::io::{BufReader, Cursor};
io::{BufReader, Cursor},
sync::Arc,
};
use stl::STL; use stl::STL;
use crate::{ use crate::{
bvh_triangles::BVHTriangles, bvh_triangles::BVHTriangles,
camera::Camera, camera::Camera,
cuboid::Cuboid,
hitable::Hit, hitable::Hit,
hitable_list::HitableList, hitable_list::HitableList,
kdtree::KDTree, kdtree::KDTree,
@ -17,6 +13,7 @@ use crate::{
scale::Scale, scale::Scale,
sphere::Sphere, sphere::Sphere,
texture::{ConstantTexture, EnvMap}, texture::{ConstantTexture, EnvMap},
translate::Translate,
vec3::Vec3, vec3::Vec3,
}; };
@ -46,8 +43,7 @@ pub fn new(opt: &Opt) -> Scene {
let stl_cube = STL::parse( let stl_cube = STL::parse(
BufReader::new(Cursor::new(include_bytes!( BufReader::new(Cursor::new(include_bytes!(
"../../stls/cube.stl" "../../stls/stanford_dragon-lowres.stl" //"../../stls/stanford_dragon.stl"
//"../../stls/stanford_dragon-lowres.stl" //"../../stls/stanford_dragon.stl"
))), ))),
false, false,
) )
@ -81,20 +77,9 @@ pub fn new(opt: &Opt) -> Scene {
Lambertian::new(ConstantTexture::new(Vec3::new(1.0, 0.2, 0.2))), Lambertian::new(ConstantTexture::new(Vec3::new(1.0, 0.2, 0.2))),
)), )),
// STL Mesh // STL Mesh
Box::new(Scale::new( Box::new(Translate::new(
BVHTriangles::new( Scale::new(BVHTriangles::new(&stl_cube, Dielectric::new(1.5)), 250.),
&stl_cube, [0., -10., 0.],
Dielectric::new(1.5),
//Metal::new(Vec3::new(0.8, 0.8, 0.8), 0.2),
//Lambertian::new(ConstantTexture::new(Vec3::new(1.0, 0.2, 0.2))),
),
1.,
//250.,
)),
Box::new(Cuboid::new(
[-20., 0., 0.].into(),
[0., 20., 20.].into(),
Arc::new(Dielectric::new(1.5)),
)), )),
]; ];
let world: Box<dyn Hit> = if opt.use_accel { let world: Box<dyn Hit> = if opt.use_accel {

View File

@ -12,7 +12,7 @@ use crate::{
hitable::Hit, hitable::Hit,
hitable_list::HitableList, hitable_list::HitableList,
kdtree::KDTree, kdtree::KDTree,
material::{Dielectric, Lambertian}, material::{Dielectric, Lambertian, Metal},
renderer::{Opt, Scene}, renderer::{Opt, Scene},
sphere::Sphere, sphere::Sphere,
texture::{ConstantTexture, EnvMap}, texture::{ConstantTexture, EnvMap},
@ -43,13 +43,20 @@ pub fn new(opt: &Opt) -> Scene {
ConstantTexture::new(Vec3::new(0.4, 0.4, 0.4)) ConstantTexture::new(Vec3::new(0.4, 0.4, 0.4))
}; };
let glass = Dielectric::new(1.5);
let metal = Metal::new(Vec3::new(0.8, 0.8, 0.8), 0.2);
let red = Lambertian::new(ConstantTexture::new(Vec3::new(1.0, 0.2, 0.2)));
let box_material = glass;
let _ = glass;
let _ = metal;
let _ = red;
let stl_cube = STL::parse( let stl_cube = STL::parse(
BufReader::new(Cursor::new(include_bytes!("../../stls/cube.stl"))), BufReader::new(Cursor::new(include_bytes!("../../stls/cube.stl"))),
false, false,
) )
.expect("failed to parse cube"); .expect("failed to parse cube");
let _light_size = 50.;
let _light_height = 200.;
let objects: Vec<Box<dyn Hit>> = vec![ let objects: Vec<Box<dyn Hit>> = vec![
// Light from above - white // Light from above - white
// Earth sized sphere // Earth sized sphere
@ -77,16 +84,11 @@ pub fn new(opt: &Opt) -> Scene {
Lambertian::new(ConstantTexture::new(Vec3::new(1.0, 0.2, 0.2))), Lambertian::new(ConstantTexture::new(Vec3::new(1.0, 0.2, 0.2))),
)), )),
// STL Mesh // STL Mesh
Box::new(BVHTriangles::new( Box::new(BVHTriangles::new(&stl_cube, box_material.clone())),
&stl_cube,
Dielectric::new(1.5),
//Metal::new(Vec3::new(0.8, 0.8, 0.8), 0.2),
//Lambertian::new(ConstantTexture::new(Vec3::new(1.0, 0.2, 0.2))),
)),
Box::new(Cuboid::new( Box::new(Cuboid::new(
[-20., 0., 0.].into(), [-20., 0., 0.].into(),
[0., 20., 20.].into(), [0., 20., 20.].into(),
Arc::new(Dielectric::new(1.5)), Arc::new(box_material),
)), )),
]; ];
let world: Box<dyn Hit> = if opt.use_accel { let world: Box<dyn Hit> = if opt.use_accel {

View File

@ -1,6 +1,6 @@
use crate::{texture::Texture, vec3::Vec3}; use crate::{texture::Texture, vec3::Vec3};
#[derive(Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub struct ConstantTexture { pub struct ConstantTexture {
color: Vec3, color: Vec3,
} }