diff options
author | Julian T <julian@jtle.dk> | 2021-08-01 22:55:07 +0200 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2021-08-01 22:55:07 +0200 |
commit | 86ad7845219e8db06fe47b62794180e1b40f90a5 (patch) | |
tree | 2fe1de5c4a854522536a397b7913d7c299b35c67 /src/world/shapes/sphere.rs | |
parent | ae460c3f34838e3baf0ffafe4ccbcf1fbfe03095 (diff) |
Implement dielectric material from RTIAW
Diffstat (limited to 'src/world/shapes/sphere.rs')
-rw-r--r-- | src/world/shapes/sphere.rs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/world/shapes/sphere.rs b/src/world/shapes/sphere.rs index 9ecedd6..1df9c35 100644 --- a/src/world/shapes/sphere.rs +++ b/src/world/shapes/sphere.rs @@ -1,7 +1,7 @@ //! Implements sphere //! //! Spheres are relatively easy to calculate intersections between -use crate::Float; +use crate::{Float, NEAR_ZERO}; use crate::core::{Ray, Vector3f, Bound3f}; use crate::world::{Hittable, Intersection}; @@ -37,10 +37,17 @@ impl Hittable for Sphere { if disc < 0.0 { None } else { - let distance = (-half_b - disc.sqrt()) / a; - if distance < 0.0 { - return None + let disc_sqrt = disc.sqrt(); + + let mut distance = -half_b - disc_sqrt; + if distance <= NEAR_ZERO { + distance = -half_b + disc_sqrt; + } + if distance <= NEAR_ZERO { + return None; } + + distance /= a; let w = ray.at(distance); Some(Intersection::new( self.norm_at(&w), |