ft (wip): 10: dielectrics

This commit is contained in:
2026-04-16 15:38:01 +02:00
parent b756cc394a
commit 1920376e34
6 changed files with 71 additions and 7 deletions

View File

@@ -4,6 +4,7 @@ use std::sync::Arc;
use crate::objects::hit::Hit;
use crate::objects::materials::traits::Material;
use crate::objects::traits::Hittable;
use crate::ray::Ray;
use crate::Vec3;
pub struct Sphere {
@@ -31,7 +32,7 @@ impl Sphere {
}
impl Hittable for Sphere {
fn hit(&self, r: &crate::ray::Ray) -> Option<Hit> {
fn hit(&self, r: &Ray) -> Option<Hit> {
let oc = self.center - r.origin();
let a = r.dir().length_squared();
let h = r.dir().dot(&oc);
@@ -43,7 +44,14 @@ impl Hittable for Sphere {
} else {
let t = (h - sqrt(d)) / a;
let p = r.at(t);
Some(Hit::new(t, p, self.normal_at(&p), self.material.clone()))
let out_n = (p - self.center) / self.radius;
Some(Hit::new(
t,
p,
self.normal_at(&p),
self.material.clone(),
out_n.dot(r.dir()) < 0.,
))
}
}