Function glm::builtin::refract [] [src]

pub fn refract<S: BaseFloat, T: GenFloatVec<S>>(I: T, N: T, eta: S) -> T

For the incident vector I and surface normal N, and the ratio of indices of refraction eta, return the refraction vector.

The result is computed by,

This example is not tested
k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I))
if (k < 0.0)
    return genType(0.0) // or genDType(0.0)
else
    return eta * I - (eta * dot(N, I) + sqrt(k)) * N

The input parameters for the incident vector I and the surface normal N must already be normalized to get the desired results.