00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "iphotontracer.h"
00024 #include "common/math/real.h"
00025 #include "ilight.h"
00026 #include "photonmap.h"
00027 #include "scene.h"
00028
00029 #include <cassert>
00030
00031 using namespace sheep;
00032 using namespace toxic;
00033
00034 void IPhotonTracer::BuildPhotonMap(const Context &context,
00035 PhotonMap *photonmap,
00036 const Scene *scene,
00037 int photon_count,
00038 ProgressMonitor *progmon ) const
00039 {
00040 assert(photonmap);
00041 assert(scene);
00042 assert(photon_count > 0);
00043
00044 const Real inv_photon_count = 1.0 / photon_count;
00045 const int light_count = scene->GetLightCount();
00046
00047 if(light_count > 0) {
00048 photon_count /= light_count;
00049
00050 const Real inv_light_count = 1.0 / light_count;
00051
00052 for(int i = 0; i < light_count; ++i) {
00053 if(progmon)
00054 progmon->StartJob(0.0, photon_count, inv_light_count);
00055
00056 emit_photons(
00057 context,
00058 photonmap,
00059 scene,
00060 scene->GetLight(i),
00061 photon_count,
00062 progmon
00063 );
00064
00065 if(progmon)
00066 progmon->EndJob();
00067
00068
00069 photonmap->ScalePhotonPower(inv_photon_count);
00070 }
00071 }
00072
00073 if(progmon)
00074 progmon->Done();
00075 }
00076
00077 void IPhotonTracer::emit_photons(const Context &context,
00078 PhotonMap *photonmap,
00079 const Scene *scene,
00080 const ILight *light,
00081 int photon_count,
00082 ProgressMonitor *progmon ) const
00083 {
00084 assert(photonmap);
00085 assert(scene);
00086 assert(light);
00087 assert(photon_count > 0);
00088
00089 for(int i = 0; i < photon_count; ++i) {
00090 if(progmon)
00091 progmon->SetJobProgress(i);
00092
00093 trace_photon(
00094 context,
00095 photonmap,
00096 scene,
00097 light->GeneratePhotonRay(context),
00098 light->GetPower()
00099 );
00100 }
00101 }