Search code examples
javavectorraytracing

How to find refraction vector from incoming vector and surface normal?


I'm writing a ray tracer in java and I'm trying to implement refraction, but I'm getting confused by the information I'm finding on the subject. If I have a 3D vector for the incoming ray of light, the surface normal given as a 3D Vector and the refractive indexes of the two mediums what operations do I need to apply in order to get the vector of the transmitted ray?


Solution

  • Let V_incedence be the normalized incoming vector. Let n1 and n2 be the refracting indices of the two surfaces. You want to calculate V_refraction. Let n be the normalized normal vector.

    V_refraction = r*V_incedence + (rc - sqrt(1-Math.pow(r,2)(1-Math.pow(c,2))))n
    where r = n1/n2 and c = -n dot V_incedence.