diff options
author | Rosyid Haryadi <rosyid_haryadi@protonmail.com> | 2025-03-03 01:55:16 +0700 |
---|---|---|
committer | Rosyid Haryadi <rosyid_haryadi@protonmail.com> | 2025-03-03 01:55:16 +0700 |
commit | 988a418f8907fb5e3abb77222929d6ab7b60c1b6 (patch) | |
tree | b2adb4d4d08dca50a0d57b8a580c755b84ad9c04 /src/calculus.rs | |
parent | ab0b3f165788c5d79b2d159aeefda8c8947b68ae (diff) |
upd transparent material
Diffstat (limited to 'src/calculus.rs')
-rw-r--r-- | src/calculus.rs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/calculus.rs b/src/calculus.rs index 568eb60..2e8a1d5 100644 --- a/src/calculus.rs +++ b/src/calculus.rs @@ -119,6 +119,19 @@ pub mod calculus { ) ) } + + pub fn refract(&self, normal: &Self, etai_over_etat: f32) -> Self { + let cos_theta = f32::min( + 1.0, + self.scalar_mul(-1.0).dot_prod(&normal) + ); + let r_out_perp = self + .add(&normal.scalar_mul(cos_theta)) + .scalar_mul(etai_over_etat); + let f = (1.0 - r_out_perp.mag_sqr()).abs().sqrt(); + let r_out_parallel = normal.scalar_mul(-1.0 * f); + r_out_perp.add(&r_out_parallel) + } } pub struct Ray { @@ -133,7 +146,13 @@ pub mod calculus { } pub fn reflect(&self, normal: &Vec3) -> Vec3 { - self.direction.reflect(&normal) + // return unit direction vector + self.direction.reflect(&normal).unit() + } + + pub fn refract(&self, normal: &Vec3, etai_over_etat: f32) -> Vec3 { + // return unit direction vector + self.direction.unit().refract(&normal, etai_over_etat) } } |