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/ambientocclusion.h"
00028 #include "paramset.h"
00029 #include "montecarlo.h"
00030 #include "scene.h"
00031 #include "intersection.h"
00032
00033
00034 Spectrum AmbientOcclusionIntegrator::Li(const Scene *scene, const Renderer *renderer,
00035 const RayDifferential &ray, const Intersection &isect,
00036 const Sample *sample, RNG &rng, MemoryArena &arena) const {
00037
00038 BSDF *bsdf = isect.GetBSDF(ray, arena);
00039 const Point &p = bsdf->dgShading.p;
00040 Normal n = Faceforward(isect.dg.nn, -ray.d);
00041
00042 uint32_t scramble[2] = { rng.RandomUInt(), rng.RandomUInt() };
00043 float u[2];
00044 int nClear = 0;
00045 for (int i = 0; i < nSamples; ++i) {
00046 Sample02(i, scramble, u);
00047 Vector w = UniformSampleSphere(u[0], u[1]);
00048 if (Dot(w, n) < 0.) w = -w;
00049 Ray r(p, w, .01f, maxDist);
00050 if (!scene->IntersectP(r)) ++nClear;
00051 }
00052 return Spectrum(float(nClear) / float(nSamples));
00053 }
00054
00055
00056 AmbientOcclusionIntegrator *CreateAmbientOcclusionIntegrator(const ParamSet ¶ms) {
00057 int nSamples = params.FindOneInt("nsamples", 2048);
00058 float maxDist = params.FindOneFloat("maxdist", INFINITY);
00059 if (PbrtOptions.quickRender) { nSamples = max(1, nSamples / 4); }
00060 return new AmbientOcclusionIntegrator(nSamples, maxDist);
00061 }
00062
00063