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:
parent
ad6e1c1b4a
commit
dcee4fb716
|
|
@ -91,8 +91,8 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
Rc::new(PhongMaterial {
|
Rc::new(PhongMaterial {
|
||||||
colour: ColourRgbF::from_named(NamedColour::Red),
|
colour: ColourRgbF::from_named(NamedColour::Red),
|
||||||
diffuse_strength: 0.05,
|
diffuse_strength: 0.05,
|
||||||
smoothness: 20.0,
|
smoothness: 100.0,
|
||||||
specular_strength: 250.0,
|
specular_strength: 1.0,
|
||||||
}),
|
}),
|
||||||
)),
|
)),
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ impl<T: RealField> Intersect<T> for Sphere<T> {
|
||||||
} else {
|
} else {
|
||||||
let location = ray.point_at(distance);
|
let location = ray.point_at(distance);
|
||||||
let normal = (location - self.centre).normalize();
|
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 cotangent = normal.cross(&tangent);
|
||||||
let retro = -ray.direction;
|
let retro = -ray.direction;
|
||||||
Some(IntersectionInfo {
|
Some(IntersectionInfo {
|
||||||
|
|
@ -169,7 +169,7 @@ impl<T: RealField> Plane<T> {
|
||||||
normal.normalize();
|
normal.normalize();
|
||||||
let mut axis_closest_to_tangent = Vector3::zeros();
|
let mut axis_closest_to_tangent = Vector3::zeros();
|
||||||
axis_closest_to_tangent[normal.iamin()] = T::one();
|
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);
|
let tangent = normal.cross(&cotangent);
|
||||||
Plane {
|
Plane {
|
||||||
normal,
|
normal,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue