Fresnel.h

Go to the documentation of this file.
00001 /**<!-------------------------------------------------------------------->
00002    @class  Fresnel
00003    @author Travis Fischer (fisch0920@gmail.com)
00004    @author Matthew Jacobs (jacobs.mh@gmail.com)
00005    @date   Fall 2008
00006    
00007    @brief
00008       Utility class encapsulating Fresnel's Law which computes the fraction of 
00009    incident power that is reflected when light travels across an interface 
00010    defined by the boundary between two media with different indices of 
00011    refraction.
00012    
00013    @note
00014       The index of refraction (aka refractive index) of a medium is a measure 
00015    for how much the speed of light (or other waves such as sound waves) is 
00016    reduced inside the medium (source: Wikipedia).
00017    <!-------------------------------------------------------------------->**/
00018 
00019 #ifndef FRESNEL_H_
00020 #define FRESNEL_H_
00021 
00022 #include <common/math/Vector.h>
00023 
00024 class Fresnel {
00025    public:
00026       ///@name Constructors
00027       //@{-----------------------------------------------------------------
00028       
00029       /**
00030        * @brief
00031        *    Uses Fresnel's Law to compute the fraction of incident power that 
00032        * is reflected from the given interface in the perfectly specular
00033        * reflected direction defined by incident vector wi and the interface's 
00034        * local normal, N.
00035        * 
00036        * @param wi is incident vector
00037        * @param N  is local surface normal
00038        * @param n1 is index of refraction of medium on incident side of surface
00039        * @param n2 is index of refraction of medium on opposite side of surface
00040        * 
00041        * @returns the reflection coefficient, Fr, of this interaction
00042        * @note  the transmission coefficient, Fs, is assumed to be (1 - Fr)
00043        */
00044       static inline real_t getFr(const Vector3 &wi, const Vector3 &N, 
00045                                  real_t n1, real_t n2)
00046       {
00047          real_t cosTheta = N.dot(wi);
00048          
00049          if (cosTheta < 0) // wi incident on front-side of surface
00050             return Fresnel::getFr(-cosTheta, n1, n2);
00051          else              // wi incident on back-side  of surface
00052             return Fresnel::getFr( cosTheta, n2, n1);
00053       }
00054       
00055       /**
00056        * @brief
00057        *    Uses Fresnel's Law to compute the fraction of incident power that 
00058        * is reflected from the given interface at incident angle theta_i with 
00059        * respect to the interface's local normal.
00060        * 
00061        * @param cos_theta_i is cosine of angle theta_i btwn reversed incident 
00062        *    vector and normal
00063        * @param n1 is index of refraction of medium on incident side of surface
00064        * @param n2 is index of refraction of medium on opposite side of surface
00065        * 
00066        * @returns the reflection coefficient, Fr, of this interaction
00067        * @note  the transmission coefficient, Fs, is assumed to be (1 - Fr)
00068        */
00069       static inline real_t getFr(real_t cos_theta_i, 
00070                                  real_t n1, real_t n2)
00071       {
00072          real_t snell   = (n1 / n2) * sin(acos(cos_theta_i));
00073          if (ABS(snell) >= 1)
00074             return 1; // total internal reflection
00075          
00076          const real_t cos_theta_t = cos(asin(snell));
00077          const real_t n1cosi = n1 * cos_theta_i, n1cost = n1 * cos_theta_t;
00078          const real_t n2cosi = n2 * cos_theta_i, n2cost = n2 * cos_theta_t;
00079          
00080          // s-polarized
00081          const real_t Rs = (n1cosi - n2cost) / (n1cosi + n2cost);
00082          
00083          // p-polarized
00084          const real_t Rp = (n1cost - n2cosi) / (n1cost + n2cosi);
00085          
00086          // assumes incident light is unpolarized (containing an equal mixture 
00087          // of s- and p-polarizations)
00088          return (Rs * Rs + Rp * Rp) / 2.0; // Fr
00089       }
00090       
00091       /**
00092        * @brief
00093        *    Uses Fresnel's Law to compute the fraction of incident power that 
00094        * is refracted from the given interface in the perfect refractive
00095        * direction defined by incident vector wi and the interface's local 
00096        * normal, N.
00097        * 
00098        * @param wi is incident vector
00099        * @param N  is local surface normal
00100        * @param n1 is index of refraction of medium on incident side of surface
00101        * @param n2 is index of refraction of medium on opposite side of surface
00102        * 
00103        * @returns the transmission coefficient, Fs, of this interaction
00104        * @note  the reflection coefficient, Fr, is assumed to be (1 - Fs)
00105        */
00106       static inline real_t getFs(const Vector3 &wi, const Vector3 &N, 
00107                                  real_t n1, real_t n2)
00108       {
00109          return (1 - Fresnel::getFr(wi, N, n1, n2));
00110       }
00111 
00112       //@}-----------------------------------------------------------------
00113 };
00114 
00115 #endif // FRESNEL_H_
00116 

Generated on 28 Feb 2009 for Milton by doxygen 1.5.6