1 #pragma once
2 
3 #ifndef Y_PHOTONINTEGR_H
4 #define Y_PHOTONINTEGR_H
5 
6 #include <yafray_constants.h>
7 
8 #include <yafraycore/timer.h>
9 #include <yafraycore/photon.h>
10 #include <yafraycore/spectrum.h>
11 #include <yafraycore/scr_halton.h>
12 #include <yafraycore/monitor.h>
13 
14 #include <core_api/mcintegrator.h>
15 #include <core_api/environment.h>
16 #include <core_api/material.h>
17 #include <core_api/background.h>
18 #include <core_api/light.h>
19 #include <core_api/imagefilm.h>
20 #include <core_api/camera.h>
21 
22 #include <utilities/mcqmc.h>
23 #include <utilities/sample_utils.h>
24 
25 #include <sstream>
26 #include <iomanip>
27 
28 __BEGIN_YAFRAY
29 
30 struct preGatherData_t
31 {
preGatherData_tpreGatherData_t32 	preGatherData_t(photonMap_t *dm): diffuseMap(dm), fetched(0) {}
33 	photonMap_t *diffuseMap;
34 
35 	std::vector<radData_t> rad_points;
36 	std::vector<photon_t> radianceVec;
37 	progressBar_t *pbar;
38 	volatile int fetched;
39 	std::mutex mutx;
40 };
41 
42 class YAFRAYPLUGIN_EXPORT photonIntegrator_t: public mcIntegrator_t
43 {
44 	public:
45 		photonIntegrator_t(unsigned int dPhotons, unsigned int cPhotons, bool transpShad=false, int shadowDepth = 4, float dsRad = 0.1f, float cRad = 0.01f);
46 		~photonIntegrator_t();
47 		virtual bool preprocess();
48 		virtual colorA_t integrate(renderState_t &state, diffRay_t &ray, colorPasses_t &colorPasses, int additionalDepth = 0) const;
49 		static integrator_t* factory(paraMap_t &params, renderEnvironment_t &render);
50 		virtual void preGatherWorker(preGatherData_t * gdata, float dsRad, int nSearch);
51 		virtual void causticWorker(photonMap_t * causticMap, int threadID, const scene_t *scene, unsigned int nCausPhotons, const pdf1D_t *lightPowerD, int numCLights, const std::string &integratorName, const std::vector<light_t *> &tmplights, int causDepth, progressBar_t *pb, int pbStep, unsigned int &totalPhotonsShot, int maxBounces);
52 		virtual void diffuseWorker(photonMap_t * diffuseMap, int threadID, const scene_t *scene, unsigned int nDiffusePhotons, const pdf1D_t *lightPowerD, int numDLights, const std::string &integratorName, const std::vector<light_t *> &tmplights, progressBar_t *pb, int pbStep, unsigned int &totalPhotonsShot, int maxBounces, bool finalGather, preGatherData_t &pgdat);
53 		virtual void photonMapKdTreeWorker(photonMap_t * photonMap);
54 
55 	protected:
56 		color_t finalGathering(renderState_t &state, const surfacePoint_t &sp, const vector3d_t &wo, colorPasses_t &colorPasses) const;
57 
enableCaustics(const bool caustics)58 		void enableCaustics(const bool caustics) { usePhotonCaustics = caustics; }
enableDiffuse(const bool diffuse)59 		void enableDiffuse(const bool diffuse) { usePhotonDiffuse = diffuse; }
60 
61 		bool usePhotonDiffuse; //!< enable/disable diffuse photon processing
62 		bool finalGather, showMap;
63 		bool prepass;
64 		unsigned int nDiffusePhotons;
65 		int nDiffuseSearch;
66 		int gatherBounces;
67 		float dsRadius; //!< diffuse search radius
68 		float lookupRad; //!< square radius to lookup radiance photons, as infinity is no such good idea ;)
69 		float gatherDist; //!< minimum distance to terminate path tracing (unless gatherBounces is reached)
70 		friend class prepassWorker_t;
71 };
72 
73 __END_YAFRAY
74 
75 #endif // Y_PHOTONINTEGR_H
76