From ab349b1d7e9901d833d7a96e2af7390f31f7b6ef Mon Sep 17 00:00:00 2001 From: "max.nuding" Date: Thu, 14 Jul 2022 12:00:28 +0200 Subject: [PATCH] Fix triangle issue --- src/main.rs | 26 ++++++++++++++++---------- src/obj.rs | 8 +++----- src/triangle.rs | 2 +- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6f2cc81..c707dd4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,7 +47,7 @@ mod triangle; // Image const DEFAULT_ASPECT_RATIO: f64 = 3.0 / 2.0; -const IMAGE_WIDTH: usize = 600; +const IMAGE_WIDTH: usize = 300; const SAMPLES_PER_PIXEL: i32 = 100; const MAX_DEPTH: i32 = 50; @@ -74,17 +74,23 @@ fn obj(path: &str) -> Scene { 5.0, difflight.clone() )), - Arc::new(Rect2D::new( - Plane::XY, - -2.0, - 2.0, - -2.0, - 2.0, - 5.0, - difflight + Arc::new(Sphere::new( + Point3::new(-5.0, 5.0, 0.0), + 1.0, + Arc::new(Material::white_light(4.0)) + )), + Arc::new(Sphere::new( + Point3::new(4.0, 3.5, 1.0), + 1.0, + Arc::new(Material::Metal(Metal::new(Color::new(1.0, 0.0, 0.0), 0.2))) + )), + Arc::new(Sphere::new( + Point3::new(0.0, 300.0, 0.0), + 300.0, + Arc::new(Material::Lambertian(Lambertian::textured(Arc::new(NoiseTexture { noise: Perlin::new(), scale: 20.0 })))) ))]; - let look_from = Point3::new(10.0, 10.0, 10.0); + let look_from = Point3::new(10.0, 6.0, 10.0); let look_at = Point3::new(0.0, 1.0, 0.0); let focus_dist = 2.0; diff --git a/src/obj.rs b/src/obj.rs index c817cad..626230f 100644 --- a/src/obj.rs +++ b/src/obj.rs @@ -1,7 +1,7 @@ use std::path::Path; use std::sync::Arc; use tobj::LoadOptions; -use crate::{BVH, Color, HittableList, HittableObject, Lambertian, Material, Point3, Vec3}; +use crate::{BVH, Color, Dielectric, HittableList, HittableObject, Lambertian, Material, Point3, Vec3}; use crate::hittable::Hittable; use crate::triangle::Triangle; @@ -12,10 +12,8 @@ pub fn obj_to_hitable(path: &Path) -> HittableObject { .unwrap(); let default_mat: Arc = Arc::new( - Material::Lambertian( - Lambertian::from( - Color::new(0.6, 0.6, 0.6) - ) + Material::Dielectric( + Dielectric::new(1.5) ) ); let mut triangles: HittableList = Vec::with_capacity(models.len()); diff --git a/src/triangle.rs b/src/triangle.rs index 6f22cad..9b40f42 100644 --- a/src/triangle.rs +++ b/src/triangle.rs @@ -45,7 +45,7 @@ impl Hittable for Triangle { match ac.dot(&qvec) * inv_det { t if t < t_min || t > t_max => None, - _ => { + t => { let mut rec = HitRecord { point: ray.at(t), normal: self.normal,