00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef LUX_PHOTONMAP_H
00024 #define LUX_PHOTONMAP_H
00025
00026
00027
00028 #include "lux.h"
00029 #include "kdtree.h"
00030 #include "transport.h"
00031 #include "scene.h"
00032 #include "mc.h"
00033 #include "sampling.h"
00034
00035 namespace lux
00036 {
00037
00038
00039 struct Photon;
00040 struct ClosePhoton;
00041 struct PhotonProcess;
00042
00043
00044
00045 class PhotonIntegrator : public SurfaceIntegrator {
00046 public:
00047
00048 PhotonIntegrator(int ncaus, int ndir, int nindir, int nLookup, int mdepth,
00049 float maxdist, bool finalGather, int gatherSamples,
00050 bool directWithPhotons);
00051 ~PhotonIntegrator();
00052 Spectrum Li(const Scene *scene, const RayDifferential &ray,
00053 const Sample *sample, float *alpha) const;
00054 void RequestSamples(Sample *sample, const Scene *scene);
00055 void Preprocess(const Scene *);
00056 virtual PhotonIntegrator* clone() const;
00057 IntegrationSampler* HasIntegrationSampler(IntegrationSampler *is) { return NULL; };
00058 static SurfaceIntegrator *CreateSurfaceIntegrator(const ParamSet ¶ms);
00059 private:
00060
00061 static inline bool unsuccessful(int needed, int found, int shot) {
00062 return (found < needed &&
00063 (found == 0 || found < shot / 1024));
00064 }
00065 static Spectrum LPhoton(KdTree<Photon, PhotonProcess> *map,
00066 int nPaths, int nLookup, BSDF *bsdf, const Intersection &isect,
00067 const Vector &w, float maxDistSquared);
00068
00069 u_int nCausticPhotons, nIndirectPhotons, nDirectPhotons;
00070 u_int nLookup;
00071 mutable int specularDepth;
00072 int maxSpecularDepth;
00073 float maxDistSquared;
00074 bool directWithPhotons, finalGather;
00075 int gatherSamples;
00076
00077 int *lightSampleOffset, lightNumOffset;
00078 int *bsdfSampleOffset, *bsdfComponentOffset;
00079 int gatherSampleOffset, gatherComponentOffset;
00080 int nCausticPaths, nDirectPaths, nIndirectPaths;
00081 mutable KdTree<Photon, PhotonProcess> *causticMap;
00082 mutable KdTree<Photon, PhotonProcess> *directMap;
00083 mutable KdTree<Photon, PhotonProcess> *indirectMap;
00084 };
00085 struct Photon {
00086
00087 Photon(const Point &pp, const Spectrum &wt, const Vector &w)
00088 : p(pp), alpha(wt), wi(w) {
00089 }
00090 Photon() { }
00091 Point p;
00092 Spectrum alpha;
00093 Vector wi;
00094 };
00095 struct PhotonProcess {
00096
00097 PhotonProcess(u_int mp, const Point &p);
00098 void operator()(const Photon &photon, float dist2, float &maxDistSquared) const;
00099 const Point &p;
00100 ClosePhoton *photons;
00101 u_int nLookup;
00102 mutable u_int foundPhotons;
00103 };
00104 struct ClosePhoton {
00105 ClosePhoton(const Photon *p = NULL,
00106 float md2 = INFINITY) {
00107 photon = p;
00108 distanceSquared = md2;
00109 }
00110 bool operator<(const ClosePhoton &p2) const {
00111 return distanceSquared == p2.distanceSquared ? (photon < p2.photon) :
00112 distanceSquared < p2.distanceSquared;
00113 }
00114 const Photon *photon;
00115 float distanceSquared;
00116 };
00117
00118 }
00119
00120 #endif