fx: sphere hit calculation sometimes picking wrong isct point
This commit is contained in:
@@ -24,7 +24,7 @@ impl Material for Dielectric {
|
|||||||
self.refraction_index
|
self.refraction_index
|
||||||
};
|
};
|
||||||
let unit = ray.dir().get_unit();
|
let unit = ray.dir().get_unit();
|
||||||
let refr = unit.refract(hit.n(), ri);
|
let refr = unit.refract(&hit.n().get_unit(), ri);
|
||||||
Some((Ray::new(*hit.p(), refr), Colour::new(1., 1., 1.)))
|
Some((Ray::new(*hit.p(), refr), Colour::new(1., 1., 1.)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,9 @@ impl Hittable for Sphere {
|
|||||||
if d < 0. {
|
if d < 0. {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
let t = (h - sqrt(d)) / a;
|
let tl = (h - sqrt(d)) / a;
|
||||||
|
let tr = (h + sqrt(d)) / a;
|
||||||
|
let t = if tl > 0.001 { tl } else { tr };
|
||||||
let p = r.at(t);
|
let p = r.at(t);
|
||||||
let out_n = (p - self.center) / self.radius;
|
let out_n = (p - self.center) / self.radius;
|
||||||
Some(Hit::new(
|
Some(Hit::new(
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ impl Vec3 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn reflect(&self, n: &Self) -> Self {
|
pub fn reflect(&self, n: &Self) -> Self {
|
||||||
*self - 2. * self.dot(n) * n
|
*self - 2. * (self.dot(n) * n)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn refract(&self, n: &Self, etai_over_etat: f32) -> Self {
|
pub fn refract(&self, n: &Self, etai_over_etat: f32) -> Self {
|
||||||
|
|||||||
Reference in New Issue
Block a user