src/rcrt/materials/DielectricMaterial.cpp

Go to the documentation of this file.
00001 #include "DielectricMaterial.h"
00002 #include "../bxdf/fresnel.hpp"
00003 
00004 namespace rcrt
00005 {
00006 
00007 DielectricMaterial::DielectricMaterial(const float& realIOR, const RGBColor& absorb):Material(realIOR, 0, absorb)
00008 {
00009 }
00010 
00011 DielectricMaterial::~DielectricMaterial()
00012 {
00013 }
00014 
00015 RGBColor DielectricMaterial::sample(const Vec3D& wOut, const Vec3D& wInc,
00016                                 Intersection& is)
00017 {       
00018         return 0;
00019 }
00020 
00021 bool DielectricMaterial::hasDiffuse() const
00022 {
00023         return false;
00024 }
00025 
00026 bool DielectricMaterial::hasSpecular() const
00027 {
00028         return false;
00029 }
00030 
00031 bool DielectricMaterial::hasTransmissive() const
00032 {
00033         return true;
00034 }
00035 
00036 bool DielectricMaterial::refracts() const
00037 {
00038         return true;
00039 }
00040 
00041 RGBColor DielectricMaterial::getEmitted(const Vec3D& wOut, Intersection& is)
00042 {
00043         return 0;
00044 }
00045 
00046 RGBColor DielectricMaterial::sampleDiffuse(const Vec3D& wOut, const Vec3D& wInc, Intersection& is)
00047 {
00048         //const Vec3D no(getShadingNormal(is));
00049         //return frRDielectric(wInc * no, wOut * no, 1.0,ior.real());
00050         return 0;
00051 }
00052 
00053 RGBColor DielectricMaterial::sampleSpecular(const Vec3D& wOut, const Vec3D& wInc, Intersection& is)
00054 {
00055         //const Vec3D no(getShadingNormal(is));
00056         //return frRDielectric(wInc * no, wOut * no, 1.0,ior.real());
00057         return 0;
00058 }
00059 
00060 ScatterEvent DielectricMaterial::scatterPhoton(Intersection& is, Photon* photon)
00061 {
00062         float etaI = is.getLastIOR().real();
00063         float etaT = 1.0;
00064         Vec3D normal = getShadingNormal(is);
00065         if(!is.backSide())//we are entering this material
00066                 etaT = ior.real();
00067         else {//we are leaving this material, we always assume to "air"
00068                 etaI = ior.real();
00069         }
00070         
00071         float eta = etaI / etaT;
00072         Vec3D wInc(photon->getDir());
00073         Vec3D wOut(snell(wInc, normal, eta));
00074         float cosT = wOut * normal;
00075         ScatterEvent evnt = REFRACTED;
00076         if(cosT > 0.0f){//total internal reflection, we do not handle this currently
00077                 //std::cout << "hurz "<< is.getPosition() << std::endl;
00078                 return INVALID;
00079         }
00080         photon->setDir(wOut);
00081         photon->setPos(is.getPosition());
00082         RGBColor absorb(RGBColor::WHITE);
00083         float dist = is.getDistance();
00084         if(is.backSide()){
00085                 //absorb = RGBColor(exp(-dist * absorbance.r()),
00086                 //              exp(-dist * absorbance.g()),
00087                 //              exp(-dist * absorbance.b()));
00088         }
00089         photon->scalePower(absorb * frTDielectric(wInc * normal, cosT, etaI, etaT));
00090         return evnt;
00091 }
00092 
00093 }

Generated on Thu Jan 31 19:26:19 2008 for RenderingCompetitionRayTracer by  doxygen 1.5.3