00001 /*************************************************************************** 00002 * Copyright (C) 1998-2008 by authors (see AUTHORS.txt ) * 00003 * * 00004 * This file is part of LuxRender. * 00005 * * 00006 * Lux Renderer is free software; you can redistribute it and/or modify * 00007 * it under the terms of the GNU General Public License as published by * 00008 * the Free Software Foundation; either version 3 of the License, or * 00009 * (at your option) any later version. * 00010 * * 00011 * Lux Renderer is distributed in the hope that it will be useful, * 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00014 * GNU General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU General Public License * 00017 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 00018 * * 00019 * This project is based on PBRT ; see http://www.pbrt.org * 00020 * Lux Renderer website : http://www.luxrender.net * 00021 ***************************************************************************/ 00022 00023 // fresnel.cpp* 00024 #include "fresnel.h" 00025 #include "color.h" 00026 #include "spectrum.h" 00027 #include "mc.h" 00028 #include "sampling.h" 00029 #include <stdarg.h> 00030 00031 using namespace lux; 00032 00033 Fresnel::~Fresnel() { } 00034 00035 namespace lux 00036 { 00037 00038 // Utility Functions 00039 SWCSpectrum FrDiel(float cosi, float cost, 00040 const SWCSpectrum &etai, 00041 const SWCSpectrum &etat) { 00042 SWCSpectrum Rparl = ((etat * cosi) - (etai * cost)) / 00043 ((etat * cosi) + (etai * cost)); 00044 SWCSpectrum Rperp = ((etai * cosi) - (etat * cost)) / 00045 ((etai * cosi) + (etat * cost)); 00046 return (Rparl*Rparl + Rperp*Rperp) / 2.f; 00047 } 00048 SWCSpectrum FrCond(float cosi, 00049 const SWCSpectrum &eta, 00050 const SWCSpectrum &k) { 00051 SWCSpectrum tmp = (eta*eta + k*k) * cosi*cosi; 00052 SWCSpectrum Rparl2 = (tmp - (2.f * eta * cosi) + 1) / 00053 (tmp + (2.f * eta * cosi) + 1); 00054 SWCSpectrum tmp_f = eta*eta + k*k; 00055 SWCSpectrum Rperp2 = 00056 (tmp_f - (2.f * eta * cosi) + cosi*cosi) / 00057 (tmp_f + (2.f * eta * cosi) + cosi*cosi); 00058 return (Rparl2 + Rperp2) / 2.f; 00059 } 00060 SWCSpectrum FresnelApproxEta(const SWCSpectrum &Fr) { 00061 SWCSpectrum reflectance = Fr.Clamp(0.f, .999f); 00062 return (SWCSpectrum(1.) + reflectance.Sqrt()) / 00063 (SWCSpectrum(1.) - reflectance.Sqrt()); 00064 } 00065 SWCSpectrum FresnelApproxK(const SWCSpectrum &Fr) { 00066 SWCSpectrum reflectance = Fr.Clamp(0.f, .999f); 00067 return 2.f * (reflectance / 00068 (SWCSpectrum(1.) - reflectance)).Sqrt(); 00069 } 00070 00071 }//namespace lux 00072