ft (wip): 10: dielectrics
This commit is contained in:
22
src/vec3.rs
22
src/vec3.rs
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user