00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "stdafx.h"
00027 #include "lights/diffuse.h"
00028 #include "paramset.h"
00029 #include "montecarlo.h"
00030
00031
00032 DiffuseAreaLight::~DiffuseAreaLight() {
00033 delete shapeSet;
00034 }
00035
00036
00037 DiffuseAreaLight::DiffuseAreaLight(const Transform &light2world,
00038 const Spectrum &le, int ns, const Reference<Shape> &s)
00039 : AreaLight(light2world, ns) {
00040 Lemit = le;
00041 shapeSet = new ShapeSet(s);
00042 area = shapeSet->Area();
00043 }
00044
00045
00046 Spectrum DiffuseAreaLight::Power(const Scene *) const {
00047 return Lemit * area * M_PI;
00048 }
00049
00050
00051 AreaLight *CreateDiffuseAreaLight(const Transform &light2world, const ParamSet ¶mSet,
00052 const Reference<Shape> &shape) {
00053 Spectrum L = paramSet.FindOneSpectrum("L", Spectrum(1.0));
00054 Spectrum sc = paramSet.FindOneSpectrum("scale", Spectrum(1.0));
00055 int nSamples = paramSet.FindOneInt("nsamples", 1);
00056 if (PbrtOptions.quickRender) nSamples = max(1, nSamples / 4);
00057 return new DiffuseAreaLight(light2world, L * sc, nSamples, shape);
00058 }
00059
00060
00061 Spectrum DiffuseAreaLight::Sample_L(const Point &p, float pEpsilon,
00062 const LightSample &ls, float time, Vector *wi, float *pdf,
00063 VisibilityTester *visibility) const {
00064 PBRT_AREA_LIGHT_STARTED_SAMPLE();
00065 Normal ns;
00066 Point ps = shapeSet->Sample(p, ls, &ns);
00067 *wi = Normalize(ps - p);
00068 *pdf = shapeSet->Pdf(p, *wi);
00069 visibility->SetSegment(p, pEpsilon, ps, 1e-3f, time);
00070 Spectrum Ls = L(ps, ns, -*wi);
00071 PBRT_AREA_LIGHT_FINISHED_SAMPLE();
00072 return Ls;
00073 }
00074
00075
00076 float DiffuseAreaLight::Pdf(const Point &p, const Vector &wi) const {
00077 return shapeSet->Pdf(p, wi);
00078 }
00079
00080
00081 Spectrum DiffuseAreaLight::Sample_L(const Scene *scene,
00082 const LightSample &ls, float u1, float u2, float time,
00083 Ray *ray, Normal *Ns, float *pdf) const {
00084 PBRT_AREA_LIGHT_STARTED_SAMPLE();
00085 Point org = shapeSet->Sample(ls, Ns);
00086 Vector dir = UniformSampleSphere(u1, u2);
00087 if (Dot(dir, *Ns) < 0.) dir *= -1.f;
00088 *ray = Ray(org, dir, 1e-3f, INFINITY, time);
00089 *pdf = shapeSet->Pdf(org) * INV_TWOPI;
00090 Spectrum Ls = L(org, *Ns, dir);
00091 PBRT_AREA_LIGHT_FINISHED_SAMPLE();
00092 return Ls;
00093 }
00094
00095