00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef Y_INTEGR_UTILS_H
00022 #define Y_INTEGR_UTILS_H
00023
00024 #include <utilities/mcqmc.h>
00025 #include <yafraycore/scr_halton.h>
00026 #include <yafraycore/monitor.h>
00027
00028 __BEGIN_YAFRAY
00029
00030 class photonMap_t;
00031
00032
00033
00034 color_t estimateDirect_PH(renderState_t &state, const surfacePoint_t &sp, const std::vector<light_t *> &lights, scene_t *scene, const vector3d_t &wo, bool trShad, int sDepth);
00035 color_t estimatePhotons(renderState_t &state, const surfacePoint_t &sp, const photonMap_t &map, const vector3d_t &wo, int nSearch, PFLOAT radius);
00036
00037 bool createCausticMap(const scene_t &scene, const std::vector<light_t *> &lights, photonMap_t &cMap, int depth, int count, progressBar_t *pb = 0);
00038
00040 inline float kernel(PFLOAT r_photon2, PFLOAT ir_gather2)
00041 {
00042 float s = (1.f - r_photon2 * ir_gather2);
00043 return 3.f * ir_gather2 * M_1_PI * s * s;
00044 }
00045
00046 inline float ckernel(PFLOAT r_photon2, PFLOAT r_gather2)
00047 {
00048 float r_p=fSqrt(r_photon2), r_g=fSqrt(r_gather2);
00049 return 3.f * (1.f - r_p/r_g) / (r_gather2 * M_PI);
00050 }
00051
00052
00057 inline color_t estimateOneDirect(renderState_t &state, const scene_t *scene, const surfacePoint_t &sp, vector3d_t wo, const std::vector<light_t *> &lights,
00058 bool trShad, int sDepth, int d1, int n)
00059 {
00060 color_t lcol(0.0), scol, col(0.0);
00061 ray_t lightRay;
00062 float lightPdf;
00063 bool shadowed;
00064 const material_t *oneMat = sp.material;
00065 lightRay.from = sp.P;
00066 int nLightsI = lights.size();
00067 if(nLightsI == 0) return color_t(0.f);
00068 float nLights = float(nLightsI);
00069 float s1;
00070 if(d1 > 50) s1 = (*state.prng)() * nLights;
00071 else s1 = scrHalton(d1, n) * nLights;
00072 int lnum = (int)(s1);
00073 if(lnum > nLightsI-1) lnum = nLightsI-1;
00074 const light_t *light = lights[lnum];
00075 s1 = s1 - (float)lnum;
00076
00077
00078
00079 if( light->diracLight() )
00080 {
00081 if( light->illuminate(sp, lcol, lightRay) )
00082 {
00083
00084 lightRay.tmin = YAF_SHADOW_BIAS;
00085 shadowed = (trShad) ? scene->isShadowed(state, lightRay, sDepth, scol) : scene->isShadowed(state, lightRay);
00086 if(!shadowed)
00087 {
00088 if(trShad) lcol *= scol;
00089 color_t surfCol = oneMat->eval(state, sp, wo, lightRay.dir, BSDF_ALL);
00090 col = surfCol * lcol * std::fabs(sp.N*lightRay.dir);
00091 }
00092 }
00093 }
00094 else
00095 {
00096 lSample_t ls;
00097
00098 ls.s1 = s1;
00099 if(d1 > 49) ls.s2 = (*state.prng)();
00100 else ls.s2 = scrHalton(d1+1, n);
00101
00102 if( light->illumSample (sp, ls, lightRay) )
00103 {
00104
00105 lightPdf = 1.f/ls.pdf;
00106 lightRay.tmin = YAF_SHADOW_BIAS;
00107 shadowed = (trShad) ? scene->isShadowed(state, lightRay, sDepth, scol) : scene->isShadowed(state, lightRay);
00108 if(!shadowed)
00109 {
00110 if(trShad) ls.col *= scol;
00111 color_t surfCol = oneMat->eval(state, sp, wo, lightRay.dir, BSDF_ALL);
00112
00113 if(lightPdf > 1.f) lightPdf = 1.f;
00114 col = surfCol * ls.col * std::fabs(sp.N*lightRay.dir) * lightPdf;
00115 }
00116 }
00117 }
00118 return col*nLights;
00119 }
00120
00121 __END_YAFRAY
00122
00123 #endif // Y_INTEGR_UTILS_H