Skip to content
Chung Leong edited this page Jan 10, 2022 · 3 revisions

refract - Calculate refraction vector

float[] refract(float[] $I, float[] $N, float[] $eta)

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

k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I))
if (k < 0.0)
  return genType(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.

Version

1.0 and above.

(Language taken from OpenGL® ES 3.0 specification)

Clone this wiki locally