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 "integrators/whitted.h"
00028 #include "intersection.h"
00029 #include "paramset.h"
00030
00031
00032 Spectrum WhittedIntegrator::Li(const Scene *scene,
00033 const Renderer *renderer, const RayDifferential &ray,
00034 const Intersection &isect, const Sample *sample, RNG &rng,
00035 MemoryArena &arena) const {
00036 Spectrum L(0.);
00037
00038
00039
00040 BSDF *bsdf = isect.GetBSDF(ray, arena);
00041
00042
00043 const Point &p = bsdf->dgShading.p;
00044 const Normal &n = bsdf->dgShading.nn;
00045 Vector wo = -ray.d;
00046
00047
00048 L += isect.Le(wo);
00049
00050
00051 for (uint32_t i = 0; i < scene->lights.size(); ++i) {
00052 Vector wi;
00053 float pdf;
00054 VisibilityTester visibility;
00055 Spectrum Li = scene->lights[i]->Sample_L(p, isect.rayEpsilon,
00056 LightSample(rng), ray.time, &wi, &pdf, &visibility);
00057 if (Li.IsBlack() || pdf == 0.f) continue;
00058 Spectrum f = bsdf->f(wo, wi);
00059 if (!f.IsBlack() && visibility.Unoccluded(scene))
00060 L += f * Li * AbsDot(wi, n) *
00061 visibility.Transmittance(scene, renderer,
00062 sample, rng, arena) / pdf;
00063 }
00064 if (ray.depth + 1 < maxDepth) {
00065
00066 L += SpecularReflect(ray, bsdf, rng, isect, renderer, scene, sample,
00067 arena);
00068 L += SpecularTransmit(ray, bsdf, rng, isect, renderer, scene, sample,
00069 arena);
00070 }
00071 return L;
00072 }
00073
00074
00075 WhittedIntegrator *CreateWhittedSurfaceIntegrator(const ParamSet ¶ms)
00076 {
00077 int maxDepth = params.FindOneInt("maxdepth", 5);
00078 return new WhittedIntegrator(maxDepth);
00079 }
00080
00081