00001 #include <cstdlib>
00002 #include <testsuite/simplemat.h>
00003 #include <core_api/scene.h>
00004 #include <utilities/sample_utils.h>
00005
00006 __BEGIN_YAFRAY
00007
00008 simplemat_t::simplemat_t(const color_t &col, float transp, float emit, texture_t *tex): texture(tex)
00009 {
00010 transparent = (transp > 0.0) ? true : false;
00011 trCol=col*transp;
00012 emitCol=col*emit;
00013
00014 color = (1.0-transp)*col;
00015
00016 CFLOAT lum = std::max(col.getR(), std::max(col.getG(), col.getB()));
00017 pScatter = std::min(1.f, lum);
00018 photonCol = col * (1.f/pScatter);
00019 bsdfFlags = BSDF_DIFFUSE;
00020 if(transparent)
00021 {
00022 bsdfFlags |= BSDF_SPECULAR;
00023 pDiffuse = 1.f-transp;
00024 }
00025 }
00026
00027 color_t simplemat_t::volumeTransmittance(const renderState_t &state, const surfacePoint_t &sp1, const surfacePoint_t &sp2) const
00028 {
00029 return color_t(1.,1.,1.);
00030 }
00031
00032 void simplemat_t::getSpecular(const renderState_t &state, const surfacePoint_t &sp, const vector3d_t &wo,
00033 bool &reflect, bool &refract, vector3d_t *const dir, color_t *const col)const
00034 {
00035 if(transparent)
00036 {
00037 refract=true;
00038 dir[1] = -wo;
00039 col[1] = trCol;
00040 }
00041 }
00042
00043 color_t simplemat_t::eval(const renderState_t &state, const surfacePoint_t &sp, const vector3d_t &wo, const vector3d_t &wl, unsigned int bsdfs)const
00044 {
00045
00046 if(texture) return texture->getColor( point3d_t(sp.U, sp.V, 0.f) );
00047 return color;
00048 }
00049
00050 color_t simplemat_t::sample(const renderState_t &state, const surfacePoint_t &sp, const vector3d_t &wo, vector3d_t &wi, sample_t &s)const
00051 {
00052 wi = SampleCosHemisphere(sp.N, sp.NU, sp.NV, s.s1, s.s2);
00053 return color;
00054 }
00055
00056 bool simplemat_t::scatterPhoton(const surfacePoint_t &sp, const vector3d_t &wi, vector3d_t &wo, float s1, float s2,
00057 BSDF_t bsdfs, BSDF_t &sampledBSDF, color_t &col) const
00058 {
00059 if(s1 > pScatter) return false;
00060 col = photonCol;
00061 if(transparent)
00062 {
00063 if(s2 > pDiffuse)
00064 {
00065 sampledBSDF = BSDF_NONE;
00066 wo = -wi;
00067 return true;
00068 }
00069 s2 /= pDiffuse;
00070 }
00071
00072 s1 /= pScatter;
00073 sampledBSDF = BSDF_DIFFUSE;
00074 if(s1>1.0 || s2>1.0 || s1<0.0 || s2<0){ std::cout << "wasted!\n"; exit(1); }
00075 wo = SampleCosHemisphere(sp.N, sp.NU, sp.NV, s1, s2);
00076 if(wo*sp.N < 0.0) std::cout << "wtf!?\n";
00077 return true;
00078 }
00079
00080 __END_YAFRAY