本文整理汇总了C++中Octree::Add方法的典型用法代码示例。如果您正苦于以下问题:C++ Octree::Add方法的具体用法?C++ Octree::Add怎么用?C++ Octree::Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Octree
的用法示例。
在下文中一共展示了Octree::Add方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: IndirectLo
Spectrum IrradianceCache::IndirectLo(const Point &p,
const Normal &n, const Vector &wo, BSDF *bsdf,
BxDFType flags, const Sample *sample,
const Scene *scene) const {
if (bsdf->NumComponents(flags) == 0)
return Spectrum(0.);
Spectrum E;
if (!InterpolateIrradiance(scene, p, n, &E)) {
// Compute irradiance at current point
u_int scramble[2] = { RandomUInt(), RandomUInt() };
float sumInvDists = 0.;
for (int i = 0; i < nSamples; ++i) {
// Trace ray to sample radiance for irradiance estimate
// Update irradiance statistics for rays traced
static StatsCounter nIrradiancePaths("Irradiance Cache",
"Paths followed for irradiance estimates");
++nIrradiancePaths;
float u[2];
Sample02(i, scramble, u);
Vector w = CosineSampleHemisphere(u[0], u[1]);
RayDifferential r(p, bsdf->LocalToWorld(w));
if (Dot(r.d, n) < 0) r.d = -r.d;
Spectrum L(0.);
// Do path tracing to compute radiance along ray for estimate
{
// Declare common path integration variables
Spectrum pathThroughput = 1.;
RayDifferential ray(r);
bool specularBounce = false;
for (int pathLength = 0; ; ++pathLength) {
// Find next vertex of path
Intersection isect;
if (!scene->Intersect(ray, &isect))
break;
if (pathLength == 0)
r.maxt = ray.maxt;
pathThroughput *= scene->Transmittance(ray);
// Possibly add emitted light at path vertex
if (specularBounce)
L += pathThroughput * isect.Le(-ray.d);
// Evaluate BSDF at hit point
BSDF *bsdf = isect.GetBSDF(ray);
// Sample illumination from lights to find path contribution
const Point &p = bsdf->dgShading.p;
const Normal &n = bsdf->dgShading.nn;
Vector wo = -ray.d;
L += pathThroughput *
UniformSampleOneLight(scene, p, n, wo, bsdf, sample);
if (pathLength+1 == maxIndirectDepth) break;
// Sample BSDF to get new path direction
// Get random numbers for sampling new direction, \mono{bs1}, \mono{bs2}, and \mono{bcs}
float bs1 = RandomFloat(), bs2 = RandomFloat(), bcs = RandomFloat();
Vector wi;
float pdf;
BxDFType flags;
Spectrum f = bsdf->Sample_f(wo, &wi, bs1, bs2, bcs,
&pdf, BSDF_ALL, &flags);
if (f.Black() || pdf == 0.)
break;
specularBounce = (flags & BSDF_SPECULAR) != 0;
pathThroughput *= f * AbsDot(wi, n) / pdf;
ray = RayDifferential(p, wi);
// Possibly terminate the path
if (pathLength > 3) {
float continueProbability = .5f;
if (RandomFloat() > continueProbability)
break;
pathThroughput /= continueProbability;
}
}
}
E += L;
float dist = r.maxt * r.d.Length();
sumInvDists += 1.f / dist;
}
E *= M_PI / float(nSamples);
// Add computed irradiance value to cache
// Update statistics for new irradiance sample
static StatsCounter nSamplesComputed("Irradiance Cache",
"Irradiance estimates computed");
++nSamplesComputed;
// Compute bounding box of irradiance sample's contribution region
static float minMaxDist =
.001f * powf(scene->WorldBound().Volume(), 1.f/3.f);
static float maxMaxDist =
.125f * powf(scene->WorldBound().Volume(), 1.f/3.f);
float maxDist = nSamples / sumInvDists;
if (minMaxDist > 0.f)
maxDist = Clamp(maxDist, minMaxDist, maxMaxDist);
maxDist *= maxError;
BBox sampleExtent(p);
sampleExtent.Expand(maxDist);
octree->Add(IrradianceSample(E, p, n, maxDist),
sampleExtent);
}
return .5f * bsdf->rho(wo, flags) * E;
}