Add missing normalization of tangent vectors

This was required to get reflection working but also fixes
issues with the PhongMaterial parameters.
This commit is contained in:
Matthew Gordon 2019-11-29 22:25:50 -05:00
parent ad6e1c1b4a
commit dcee4fb716
2 changed files with 4 additions and 4 deletions

View File

@ -91,8 +91,8 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
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,
}),
)),
],

View File

@ -135,7 +135,7 @@ impl<T: RealField> Intersect<T> for Sphere<T> {
} 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<T: RealField> Plane<T> {
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,