pub fn refract(v: &Vec3, n: &Vec3, ni_over_nt: f32) -> Option<Vec3> {
    let uv = unit_vector(&v);
    let dt = dot(&uv, n);
    let discriminant = 1.0 - ni_over_nt.powi(2) * (1. - dt.powi(2));
    if discriminant > 0. {
        Some(ni_over_nt * (uv - *n * dt) - *n * discriminant.sqrt())
    } else {
        None
    }
}
/// Compute the refracted ray vector.
///
/// Input is the incoming vector `v` and the normal `n` at the point
/// where the ray hits the surface between two materials of different
/// refractive indices whose ratio is given by `ni_over_nt`.
///
/// Sometimes, refraction is not possible, if Snell's law has no solution
/// and in this case None is returned.
Compute the refracted ray vector.

Sometimes, refraction is not possible, if Snell's law has no solution
and in this case None is returned.
Compute the refracted ray vector . Sometimes refraction is not possible if Snell ' s law has no solution and in this case None is returned .
pub fn refract(v: &Vec3, n: &Vec3, ni_over_nt: f32) -> Option<Vec3> {
    let uv = unit_vector(&v);
    let dt = dot(&uv, n);
    let discriminant = 1.0 - ni_over_nt.powi(2) * (1. - dt.powi(2));
    if discriminant > 0. {
        Some(ni_over_nt * (uv - *n * dt) - *n * discriminant.sqrt())
    } else {
        None
    }
}
pub fn refract ( v : & Vec3 , n : & Vec3 , ni_over_nt : f32 ) -> Option < Vec3 > { let uv = unit_vector ( & v ) ; let dt = dot ( & uv , n ) ; let discriminant = 1.0 - ni_over_nt . powi ( 2 ) * ( 1. - dt . powi ( 2 ) ) ; if discriminant > 0. { Some ( ni_over_nt * ( uv - * n * dt ) - * n * discriminant . sqrt ( ) ) } else { None } }
Compute the refracted ray vector.
Compute the refracted ray vector .
v
&Vec3
n
&Vec3
ni_over_nt
f32