00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "light.h"
00025 #include "scene.h"
00026 #include "shape.h"
00027 #include "reflection/bxdf.h"
00028
00029 using namespace lux;
00030
00031
00032 Light::~Light() {
00033 }
00034 bool VisibilityTester::Unoccluded(const Scene *scene) const {
00035
00036
00037
00038 return !scene->IntersectP(r);
00039 }
00040
00041 bool VisibilityTester::TestOcclusion(const TsPack *tspack, const Scene *scene, SWCSpectrum *f, float *pdf, float *pdfR) const
00042 {
00043 RayDifferential ray(r);
00044 ray.time = tspack->time;
00045 Vector d(Normalize(ray.d));
00046 Intersection isect;
00047 const BxDFType flags(BxDFType(BSDF_SPECULAR | BSDF_TRANSMISSION));
00048
00049
00050 for (u_int i = 0; i < 10000; ++i) {
00051 if (!scene->Intersect(ray, &isect))
00052 return true;
00053 BSDF *bsdf = isect.GetBSDF(tspack, ray);
00054
00055 *f *= bsdf->f(tspack, -d, d, flags);
00056 if (f->Black())
00057 return false;
00058 *f *= AbsDot(bsdf->dgShading.nn, d);
00059 if (pdf)
00060 *pdf *= bsdf->Pdf(tspack, -d, d);
00061 if (pdfR)
00062 *pdfR *= bsdf->Pdf(tspack, d, -d);
00063
00064 ray.mint = ray.maxt + MachineEpsilon::E(ray.maxt);
00065 ray.maxt = r.maxt;
00066 }
00067 return false;
00068 }
00069
00070 void VisibilityTester::Transmittance(const TsPack *tspack, const Scene *scene,
00071 const Sample *sample, SWCSpectrum *const L) const {
00072 scene->Transmittance(tspack, r, sample, L);
00073 }
00074 SWCSpectrum Light::Le(const TsPack *tspack, const RayDifferential &) const {
00075 return SWCSpectrum(0.);
00076 }
00077 SWCSpectrum Light::Le(const TsPack *tspack, const Scene *scene, const Ray &r,
00078 const Normal &n, BSDF **bsdf, float *pdf, float *pdfDirect) const
00079 {
00080 return SWCSpectrum(0.f);
00081 }
00082
00083 void Light::AddPortalShape(boost::shared_ptr<Primitive> s) {
00084 if (s->CanIntersect() && s->CanSample()) {
00085 PortalArea += s->Area();
00086 PortalShapes.push_back(s);
00087 ++nrPortalShapes;
00088 } else {
00089
00090 vector<boost::shared_ptr<Primitive> > done;
00091 PrimitiveRefinementHints refineHints(true);
00092 s->Refine(done, refineHints, s);
00093 for (u_int i = 0; i < done.size(); ++i) {
00094 PortalArea += done[i]->Area();
00095 PortalShapes.push_back(done[i]);
00096 ++nrPortalShapes;
00097 }
00098 }
00099 havePortalShape = true;
00100 }