Fix iridescent material
This commit is contained in:
parent
543bf7e1bf
commit
b1351747b7
2 changed files with 45 additions and 20 deletions
|
|
@ -22,26 +22,24 @@ impl Iridescent {
|
|||
}
|
||||
}
|
||||
|
||||
fn fresnel_reflection(&self, theta1: f32, theta2: f32, s_polaized: bool) -> f32 {
|
||||
fn fresnel_reflection(n1: f32, n2: f32, theta1: f32, theta2: f32, s_polaized: bool) -> f32 {
|
||||
if s_polaized {
|
||||
(self.n1 * theta1.cos() - self.n2 * theta2.cos())
|
||||
/ (self.n1 * theta1.cos() + self.n2 * theta2.cos())
|
||||
(n1 * theta1.cos() - n2 * theta2.cos()) / (n1 * theta1.cos() + n2 * theta2.cos())
|
||||
} else {
|
||||
(self.n2 * theta1.cos() - self.n1 * theta2.cos())
|
||||
/ (self.n2 * theta1.cos() + self.n1 * theta2.cos())
|
||||
(n2 * theta1.cos() - n1 * theta2.cos()) / (n2 * theta1.cos() + n1 * theta2.cos())
|
||||
}
|
||||
}
|
||||
|
||||
fn abs_r_1_squared(&self, l: f32, theta1: f32, theta2: f32, s_polaized: bool) -> f32 {
|
||||
let r12 = self.fresnel_reflection(theta1, theta2, s_polaized);
|
||||
let r12 = Self::fresnel_reflection(self.n1, self.n2, theta1, theta2, s_polaized);
|
||||
|
||||
let phi = 2.0 * f32::consts::PI * self.n2 * self.d2 * theta2.cos() / l;
|
||||
|
||||
let num_real = r12 * (1.0 - f32::cos(-2.0 * phi));
|
||||
let num_imag = r12 * (1.0 - f32::sin(-2.0 * phi));
|
||||
let num_imag = r12 * (-1.0 * f32::sin(-2.0 * phi));
|
||||
|
||||
let denom_real = 1.0 - r12 * r12 * f32::cos(-2.0 * phi);
|
||||
let denom_imag = 1.0 - r12 * r12 * f32::sin(-2.0 * phi);
|
||||
let denom_imag = 0.0 - r12 * r12 * f32::sin(-2.0 * phi);
|
||||
|
||||
let real = (num_real * denom_real + num_imag * denom_imag)
|
||||
/ (denom_real * denom_real + denom_imag * denom_imag);
|
||||
|
|
@ -59,10 +57,10 @@ impl Iridescent {
|
|||
real * real + imag * imag
|
||||
}
|
||||
|
||||
fn abs_C_squared(&self, l: f32, theta1: f32, theta2: f32, s_polaized: bool) -> f32 {
|
||||
pub fn abs_C_squared(&self, l: f32, theta1: f32, theta2: f32, s_polaized: bool) -> f32 {
|
||||
let local_abs_r_1_squared = self.abs_r_1_squared(l, theta1, theta2, s_polaized);
|
||||
|
||||
local_abs_r_1_squared / (local_abs_r_1_squared + 1.0)
|
||||
local_abs_r_1_squared / (1.0 - local_abs_r_1_squared)
|
||||
}
|
||||
|
||||
fn cos_K_Delta(&self, l: f32, theta1: f32, theta2: f32, s_polaized: bool) -> f32 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue