00001 #include "WallMaterial.h"
00002
00003 namespace rcrt
00004 {
00005
00006 WallMaterial::WallMaterial(BSDF b, const float& dens) : Material(),mat(b),density(dens)
00007 {
00008 }
00009
00010 WallMaterial::~WallMaterial()
00011 {
00012 }
00013
00014 RGBColor WallMaterial::sample(const Vec3D& wOut, const Vec3D& wInc, Intersection& is)
00015 {
00016 Intersection distIS = is;
00017 distortNormal(distIS);
00018
00019
00020 float noise = PerlinNoise::noise(is.getPosition() * density);
00021 return mat.sampleDiffuse(wOut,wInc,distIS) * (1 - 0.07 * noise);
00022 }
00023
00024 RGBColor WallMaterial::sampleDiffuse(const Vec3D& wOut, const Vec3D& wInc, Intersection& is)
00025 {
00026 Intersection distIS = is;
00027 distortNormal(distIS);
00028
00029
00030 return mat.sampleDiffuse(wOut,wInc,distIS);
00031 }
00032
00033 RGBColor WallMaterial::sampleSpecular(const Vec3D& wOut, const Vec3D& wInc, Intersection& is)
00034 {
00035 Intersection distIS = is;
00036 distortNormal(distIS);
00037
00038 return mat.sampleSpecular(wOut,wInc,distIS);
00039 }
00040
00041 RGBColor WallMaterial::getEmitted(const Vec3D& wOut, Intersection& is)
00042 {
00043 return 0;
00044 }
00045
00046 ScatterEvent WallMaterial::scatterPhoton(Intersection& is, Photon* photon)
00047 {
00048 return mat.scatterPhoton(is, photon);
00049 }
00050
00051 bool WallMaterial::refracts() const
00052 {
00053 return false;
00054 }
00055
00056 bool WallMaterial::hasDiffuse() const
00057 {
00058 return mat.hasDiffuse();
00059 }
00060
00061 bool WallMaterial::hasSpecular() const
00062 {
00063 return mat.hasSpecular();
00064 }
00065 bool WallMaterial::hasTransmissive() const
00066 {
00067 return mat.hasTransmissive();
00068 }
00069
00070 void WallMaterial::distortNormal(Intersection& is) const
00071 {
00072 is.setSNormalW(calcDistNormal(is));
00073 }
00074
00075 Vec3D WallMaterial::calcDistNormal(Intersection& is) const
00076 {
00077 const Point3D& p = is.getPosition();
00078 const Vec3D& n = is.getSNormalW();
00079
00080 float factor = 0.001;
00081
00082 float density = 12;
00083
00084 float distX = (0.5 - PerlinNoise::noise(p * density)) * factor;
00085 float distY = (0.5 - PerlinNoise::noise(Point3D(p.y()+7.687,-p.z(),p.x()-3.65) * density)) * factor;
00086 float distZ = (0.5 - PerlinNoise::noise(Point3D(p.z()+2.456,p.x()-4.6587,-p.y()) * density)) * factor;
00087
00088 return Vec3D(n.x() + distX, n.z() + distY, n.z() + distZ).normalize();
00089 }
00090
00091 Vec3D WallMaterial::getShadingNormal(Intersection& is) const
00092 {
00093 return is.getSNormalW();
00094
00095 }
00096
00097 }