00001 #include <yafray_config.h>
00002 #include <core_api/environment.h>
00003 #include <core_api/material.h>
00004 #include <core_api/integrator.h>
00005 #include <core_api/background.h>
00006 #include <core_api/light.h>
00007 #include <integrators/integr_utils.h>
00008 #include <yafraycore/photon.h>
00009 #include <utilities/mcqmc.h>
00010 #include <yafraycore/scr_halton.h>
00011 #include <vector>
00012 #include <cmath>
00013
00014 __BEGIN_YAFRAY
00015
00016 class YAFRAYPLUGIN_EXPORT EmissionIntegrator : public volumeIntegrator_t {
00017 public:
00018 EmissionIntegrator() {}
00019
00020
00021 virtual colorA_t transmittance(renderState_t &state, ray_t &ray) const {
00022 colorA_t result(1.f);
00023
00024
00025
00026 std::vector<VolumeRegion*> listVR = scene->getVolumes();
00027
00028
00029
00030 for (unsigned int i = 0; i < listVR.size(); i++) {
00031
00032
00033
00034
00035
00036
00037
00038 result *= listVR.at(i)->tau(ray, 0, 0);
00039 }
00040
00041
00042
00043 result = colorA_t(fExp(-result.getR()), fExp(-result.getG()), fExp(-result.getB()));
00044
00045 return result;
00046 }
00047
00048
00049 virtual colorA_t integrate(renderState_t &state, ray_t &ray) const {
00050
00051 float t0, t1;
00052 int N = 10;
00053
00054 colorA_t result(0.f);
00055
00056
00057 bool hit = ray.tmax > 0.f;
00058
00059 std::vector<VolumeRegion*> listVR = scene->getVolumes();
00060
00061 for (unsigned int i = 0; i < listVR.size(); i++) {
00062
00063 VolumeRegion* vr = listVR.at(i);
00064
00065 if (!vr->intersect(ray, t0, t1)) continue;
00066
00067 if (hit && ray.tmax < t0) continue;
00068
00069 if (hit && ray.tmax < t1) {
00070
00071 t1 = ray.tmax;
00072 }
00073
00074
00075
00076
00077
00078
00079 float step = (t1 - t0) / (float)N;
00080 --N;
00081 float pos = t0 + 0.5 * step;
00082 point3d_t p(ray.from);
00083 color_t Tr(1.f);
00084
00085 for (int i = 0; i < N; ++i) {
00086 ray_t stepRay(ray.from + (ray.dir * pos), ray.dir, 0, step, 0);
00087 color_t stepTau = vr->tau(stepRay, 0, 0);
00088 Tr *= colorA_t(fExp(-stepTau.getR()), fExp(-stepTau.getG()), fExp(-stepTau.getB()));
00089 result += Tr * vr->emission(stepRay.from, stepRay.dir);
00090 pos += step;
00091 }
00092
00093 result *= step;
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 }
00104
00105 return result;
00106 }
00107
00108 static integrator_t* factory(paraMap_t ¶ms, renderEnvironment_t &render)
00109 {
00110 EmissionIntegrator* inte = new EmissionIntegrator();
00111 return inte;
00112 }
00113
00114 };
00115
00116 extern "C"
00117 {
00118
00119 YAFRAYPLUGIN_EXPORT void registerPlugin(renderEnvironment_t &render) {
00120 render.registerFactory("EmissionIntegrator", EmissionIntegrator::factory);
00121 }
00122
00123 }
00124
00125 __END_YAFRAY