Fix triangle issue

master
max.nuding 2022-07-14 12:00:28 +02:00
parent cee009f5a8
commit ab349b1d7e
Failed to extract signature
3 changed files with 20 additions and 16 deletions

View File

@ -47,7 +47,7 @@ mod triangle;
// Image // Image
const DEFAULT_ASPECT_RATIO: f64 = 3.0 / 2.0; 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 SAMPLES_PER_PIXEL: i32 = 100;
const MAX_DEPTH: i32 = 50; const MAX_DEPTH: i32 = 50;
@ -74,17 +74,23 @@ fn obj(path: &str) -> Scene {
5.0, 5.0,
difflight.clone() difflight.clone()
)), )),
Arc::new(Rect2D::new( Arc::new(Sphere::new(
Plane::XY, Point3::new(-5.0, 5.0, 0.0),
-2.0, 1.0,
2.0, Arc::new(Material::white_light(4.0))
-2.0, )),
2.0, Arc::new(Sphere::new(
5.0, Point3::new(4.0, 3.5, 1.0),
difflight 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 look_at = Point3::new(0.0, 1.0, 0.0);
let focus_dist = 2.0; let focus_dist = 2.0;

View File

@ -1,7 +1,7 @@
use std::path::Path; use std::path::Path;
use std::sync::Arc; use std::sync::Arc;
use tobj::LoadOptions; 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::hittable::Hittable;
use crate::triangle::Triangle; use crate::triangle::Triangle;
@ -12,10 +12,8 @@ pub fn obj_to_hitable(path: &Path) -> HittableObject {
.unwrap(); .unwrap();
let default_mat: Arc<Material> = Arc::new( let default_mat: Arc<Material> = Arc::new(
Material::Lambertian( Material::Dielectric(
Lambertian::from( Dielectric::new(1.5)
Color::new(0.6, 0.6, 0.6)
)
) )
); );
let mut triangles: HittableList = Vec::with_capacity(models.len()); let mut triangles: HittableList = Vec::with_capacity(models.len());

View File

@ -45,7 +45,7 @@ impl Hittable for Triangle {
match ac.dot(&qvec) * inv_det { match ac.dot(&qvec) * inv_det {
t if t < t_min || t > t_max => None, t if t < t_min || t > t_max => None,
_ => { t => {
let mut rec = HitRecord { let mut rec = HitRecord {
point: ray.at(t), point: ray.at(t),
normal: self.normal, normal: self.normal,