ft (wip): 10: dielectrics

This commit is contained in:
2026-04-16 15:38:01 +02:00
parent b756cc394a
commit 1920376e34
6 changed files with 71 additions and 7 deletions

View File

@@ -101,8 +101,18 @@ impl Vec3 {
&& default().is_close(self.b, 0.)
}
pub fn reflect(&self, o: &Vec3) -> Vec3 {
*self - 2. * self.dot(o) * o
pub fn reflect(&self, n: &Self) -> Self {
*self - 2. * self.dot(n) * n
}
pub fn refract(&self, n: &Self, etai_over_etat: f32) -> Self {
let mut cos_theta = -self.dot(n);
cos_theta = if cos_theta > 1.0 { 1.0 } else { cos_theta };
let r_out_perp = etai_over_etat * (*self + cos_theta * n);
let r_out_parr = -sqrt((1. - r_out_perp.length_squared()).abs()) * n;
return r_out_perp + r_out_parr;
}
pub fn output(self) -> image::Rgb<u8> {
@@ -139,6 +149,14 @@ impl Vec3 {
}
}
impl Neg for &Vec3 {
type Output = Vec3;
fn neg(self) -> Self::Output {
-*self
}
}
impl Neg for Vec3 {
type Output = Self;