src/rcrt/materials/ImageMaterial.cpp

Go to the documentation of this file.
00001 #include "ImageMaterial.h"
00002 
00003 namespace rcrt
00004 {
00005 
00006 ImageMaterial::ImageMaterial(ImageTexture* i, float iorR, float iorI) : Material(iorR,iorI), imageTex(i)
00007 {
00008 }
00009 
00010 ImageMaterial::ImageMaterial(ImageTexture* i, const std::complex<float>& IOR) : Material(IOR), imageTex(i)
00011 {
00012 }
00013 
00014 ImageMaterial::~ImageMaterial()
00015 {
00016 }
00017 
00018 RGBColor ImageMaterial::sample(const Vec3D& wOut, const Vec3D& wInc, Intersection& is)
00019 {
00020         return imageTex->getColor(is.getUV()).getRGB();
00021 }
00022 
00023 RGBColor ImageMaterial::sampleDiffuse(const Vec3D& wOut, const Vec3D& wInc, Intersection& is)
00024 {
00025         return imageTex->getColor(is.getUV()).getRGB();
00026 }
00027 
00028 RGBColor ImageMaterial::sampleSpecular(const Vec3D& wOut, const Vec3D& wInc, Intersection& is)
00029 {
00030         return imageTex->getColor(is.getUV()).getRGB();
00031 }
00032 
00033 RGBColor ImageMaterial::getEmitted(const Vec3D& wOut, Intersection& is)
00034 {
00035         return RGBColor::BLACK;
00036 }
00037 
00038 ScatterEvent ImageMaterial::scatterPhoton(Intersection& is, Photon* photon)
00039 {
00040         Vec3D normal(getShadingNormal(is));
00041         const RGBColor Kd(imageTex->getColor(is.getUV()).getRGB());
00042         //const RGBColor& P = photon->getPower();
00043         const float Pd = Kd.max();
00044         const float xi = float(rand()) / float(RAND_MAX); 
00045         if(xi <= Pd){
00046                 photon->setPos(is.getPosition());
00047                 //diffuse reflection
00048                 photon->scalePower(Kd/Pd);
00049                 //cout << " scaling " << Kd/Pd << endl;
00050                 //get a random direction in the upper hemisphere
00051                 float xi1 = float(rand()) / float(RAND_MAX);
00052                 float xi2 = float(rand()) / float(RAND_MAX);
00053                 float z2 = xi2 * 2.0f * M_PI;
00054                 Vec3D u;
00055                 Vec3D v;
00056                 normal.getCS(u, v);
00057                 Vec3D outDir(u * cos(z2) + v * sin(z2) * sqrt(1-xi1) + normal * sqrt(xi1));
00058                 outDir.normalize();
00059                 photon->setDir(outDir);
00060                 return DIFFUSE;
00061         } else
00062                 return STORE;
00063 }
00064 
00065 
00066 
00067 
00068 bool ImageMaterial::hasDiffuse() const
00069 {
00070         return true;
00071 }
00072 
00073 bool ImageMaterial::hasSpecular() const
00074 {
00075         return true;
00076 }
00077 
00078 bool ImageMaterial::hasTransmissive() const
00079 {
00080         return false;
00081 }
00082 
00083 }

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