/// Calculates the fresnel (reflectivity) given the index of refraction and the cos_angle
/// This uses Schlick's approximation. cos_angle is normal_dot_incoming
/// http://graphics.stanford.edu/courses/cs148-10-summer/docs/2006--degreve--reflection_refraction.pdf
Calculates the fresnel (reflectivity) given the index of refraction and the cos_angle
This uses Schlick's approximation.
Calculates the fresnel ( reflectivity ) given the index of refraction and the cos_angle This uses Schlick ' s approximation .
fn fresnel_reflect(ior: f64, i: &Vec3, n: &Vec3, inside: bool) -> f64 {
        let (n1, n2) = if inside { (ior, 1.0) } else { (1.0, ior) };
        let actual_n = if inside { -*n } else { *n };
        let r0_sqrt = (n1 - n2) / (n1 + n2);
        let r0 = r0_sqrt * r0_sqrt;
        let cos_angle = if n1 <= n2 {
            i.dot(&actual_n)
        } else {
            let t = match Vec3::refract(i, &-actual_n, ior, inside) {
                Some(x) => x,
                None => return 1.0 // n1 > n2 && TIR
            };
            -actual_n.dot(&t) // n1 > n2 && !TIR
        };
        let cos_term = 1.0 - cos_angle;
        (r0 + ((1.0 - r0) * cos_term * cos_term * cos_term * cos_term * cos_term)).max(0.0).min(1.0)
    }
fn fresnel_reflect ( ior : f64 , i : & Vec3 , n : & Vec3 , inside : bool ) -> f64 { let ( n1 , n2 ) = if inside { ( ior , 1.0 ) } else { ( 1.0 , ior ) } ; let actual_n = if inside { - * n } else { * n } ; let r0_sqrt = ( n1 - n2 ) / ( n1 + n2 ) ; let r0 = r0_sqrt * r0_sqrt ; let cos_angle = if n1 <= n2 { i . dot ( & actual_n ) } else { let t = match Vec3 :: refract ( i , & - actual_n , ior , inside ) { Some ( x ) => x , None => return 1.0 // n1 > n2 && TIR } ; - actual_n . dot ( & t ) // n1 > n2 && !TIR } ; let cos_term = 1.0 - cos_angle ; ( r0 + ( ( 1.0 - r0 ) * cos_term * cos_term * cos_term * cos_term * cos_term ) ) . max ( 0.0 ) . min ( 1.0 ) }
Calculates the fresnel (reflectivity) given the index of refraction and the cos_angle
This uses Schlick's approximation.
Calculates the fresnel ( reflectivity ) given the index of refraction and the cos_angle This uses Schlick ' s approximation .
ior
f64
i
&Vec3
n
&Vec3
inside
bool