From dcee4fb7169ccf872ed46d71c144a43d0d995c61 Mon Sep 17 00:00:00 2001 From: Matthew Gordon Date: Fri, 29 Nov 2019 22:25:50 -0500 Subject: [PATCH] Add missing normalization of tangent vectors This was required to get reflection working but also fixes issues with the PhongMaterial parameters. --- src/main.rs | 4 ++-- src/raycasting.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index eebc51d..f58a1eb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -91,8 +91,8 @@ pub fn main() -> Result<(), Box> { Rc::new(PhongMaterial { colour: ColourRgbF::from_named(NamedColour::Red), diffuse_strength: 0.05, - smoothness: 20.0, - specular_strength: 250.0, + smoothness: 100.0, + specular_strength: 1.0, }), )), ], diff --git a/src/raycasting.rs b/src/raycasting.rs index b53c7ac..daad86f 100644 --- a/src/raycasting.rs +++ b/src/raycasting.rs @@ -135,7 +135,7 @@ impl Intersect for Sphere { } else { let location = ray.point_at(distance); let normal = (location - self.centre).normalize(); - let tangent = normal.cross(&Vector3::z_axis()); + let tangent = normal.cross(&Vector3::z_axis()).normalize(); let cotangent = normal.cross(&tangent); let retro = -ray.direction; Some(IntersectionInfo { @@ -169,7 +169,7 @@ impl Plane { normal.normalize(); let mut axis_closest_to_tangent = Vector3::zeros(); axis_closest_to_tangent[normal.iamin()] = T::one(); - let cotangent = normal.cross(&axis_closest_to_tangent); + let cotangent = normal.cross(&axis_closest_to_tangent).normalize(); let tangent = normal.cross(&cotangent); Plane { normal,