added hemispherical scattering, switched to ppm version 6

This commit is contained in:
2023-01-30 13:50:32 +01:00
parent b27c90195a
commit 899e8b7228
6 changed files with 87 additions and 539 deletions

View File

@@ -1,4 +1,4 @@
use std::{ops::{Add, Sub, AddAssign, SubAssign, Mul, Div, MulAssign, DivAssign}};
use std::ops::{Add, Sub, AddAssign, SubAssign, Mul, Div, MulAssign, DivAssign, Neg};
use crate::rtweekend::{random_f64, random_range_f64};
@@ -89,6 +89,20 @@ impl Sub for Vec3 {
}
}
impl Neg for Vec3 {
type Output = Self;
fn neg(self) -> Self::Output {
Self {
elements: [
-self.x(),
-self.y(),
-self.z()
]
}
}
}
impl Mul<f64> for Vec3 {
type Output = Self;
@@ -185,4 +199,17 @@ pub fn random_in_unit_sphere() -> Vec3 {
}
return p;
}
}
pub fn random_unit_vector() -> Vec3 {
random_in_unit_sphere().unit_vector()
}
pub fn random_in_hemisphere(normal: &Vec3) -> Vec3 {
let in_unit_sphere = random_in_unit_sphere();
if in_unit_sphere.dot(&normal) > 0.0 {
return in_unit_sphere;
} else {
return -in_unit_sphere;
}
}