src/rcrt/materials/WoodMaterial.cpp

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

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