library: render: scene: cleanup refracted calculation

This commit is contained in:
Bruno BELANYI 2020-03-21 01:45:43 +01:00
parent 16066a3c7d
commit 6af36d814f

View file

@ -311,8 +311,8 @@ fn refracted(incident: Vector, normal: Vector, n_1: f32, n_2: f32) -> Option<(Ve
return None; return None;
} }
let cos1 = cos1.abs(); let cos1 = cos1.abs();
let refracted = eta * incident + (eta * cos1 - f32::sqrt(k)) * normal; let cos2 = k.sqrt();
let cos2 = -refracted.dot(&normal); // Take the negation because we're on the other side let refracted = eta * incident + (eta * cos1 - cos2) * normal;
let f_r = (n_2 * cos1 - n_1 * cos2) / (n_2 * cos1 + n_1 * cos2); let f_r = (n_2 * cos1 - n_1 * cos2) / (n_2 * cos1 + n_1 * cos2);
let f_t = (n_1 * cos2 - n_2 * cos1) / (n_1 * cos2 + n_2 * cos1); let f_t = (n_1 * cos2 - n_2 * cos1) / (n_1 * cos2 + n_2 * cos1);
let refl_t = (f_r * f_r + f_t * f_t) / 2.; let refl_t = (f_r * f_r + f_t * f_t) / 2.;