本文整理汇总了C++中VisibilityTester::Tr方法的典型用法代码示例。如果您正苦于以下问题:C++ VisibilityTester::Tr方法的具体用法?C++ VisibilityTester::Tr怎么用?C++ VisibilityTester::Tr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VisibilityTester
的用法示例。
在下文中一共展示了VisibilityTester::Tr方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: EstimateDirect
Spectrum EstimateDirect(const Interaction &it, const Point2f &uScattering,
const Light &light, const Point2f &uLight,
const Scene &scene, Sampler &sampler,
MemoryArena &arena, bool handleMedia, bool specular) {
BxDFType bsdfFlags =
specular ? BSDF_ALL : BxDFType(BSDF_ALL & ~BSDF_SPECULAR);
Spectrum Ld(0.f);
// Sample light source with multiple importance sampling
Vector3f wi;
Float lightPdf = 0, scatteringPdf = 0;
VisibilityTester visibility;
Spectrum Li = light.Sample_Li(it, uLight, &wi, &lightPdf, &visibility);
if (lightPdf > 0 && !Li.IsBlack()) {
// Compute BSDF or phase function's value for light sample
Spectrum f;
if (it.IsSurfaceInteraction()) {
// Evaluate BSDF for light sampling strategy
const SurfaceInteraction &isect = (const SurfaceInteraction &)it;
f = isect.bsdf->f(isect.wo, wi, bsdfFlags) *
AbsDot(wi, isect.shading.n);
scatteringPdf = isect.bsdf->Pdf(isect.wo, wi, bsdfFlags);
} else {
// Evaluate phase function for light sampling strategy
const MediumInteraction &mi = (const MediumInteraction &)it;
Float p = mi.phase->p(mi.wo, wi);
f = Spectrum(p);
scatteringPdf = p;
}
if (!f.IsBlack()) {
// Compute effect of visibility for light source sample
if (handleMedia)
Li *= visibility.Tr(scene, sampler);
else if (!visibility.Unoccluded(scene))
Li = Spectrum(0.f);
// Add light's contribution to reflected radiance
if (!Li.IsBlack()) {
if (IsDeltaLight(light.flags))
Ld += f * Li / lightPdf;
else {
Float weight =
PowerHeuristic(1, lightPdf, 1, scatteringPdf);
Ld += f * Li * weight / lightPdf;
}
}
}
}
// Sample BSDF with multiple importance sampling
if (!IsDeltaLight(light.flags)) {
Spectrum f;
bool sampledSpecular = false;
if (it.IsSurfaceInteraction()) {
// Sample scattered direction for surface interactions
BxDFType sampledType;
const SurfaceInteraction &isect = (const SurfaceInteraction &)it;
f = isect.bsdf->Sample_f(isect.wo, &wi, uScattering, &scatteringPdf,
bsdfFlags, &sampledType);
f *= AbsDot(wi, isect.shading.n);
sampledSpecular = sampledType & BSDF_SPECULAR;
} else {
// Sample scattered direction for medium interactions
const MediumInteraction &mi = (const MediumInteraction &)it;
Float p = mi.phase->Sample_p(mi.wo, &wi, uScattering);
f = Spectrum(p);
scatteringPdf = p;
}
if (!f.IsBlack() && scatteringPdf > 0) {
// Account for light contributions along sampled direction _wi_
Float weight = 1;
if (!sampledSpecular) {
lightPdf = light.Pdf_Li(it, wi);
if (lightPdf == 0) return Ld;
weight = PowerHeuristic(1, scatteringPdf, 1, lightPdf);
}
// Find intersection and compute transmittance
SurfaceInteraction lightIsect;
Ray ray = it.SpawnRay(wi);
Spectrum Tr(1.f);
bool foundSurfaceInteraction =
handleMedia ? scene.IntersectTr(ray, sampler, &lightIsect, &Tr)
: scene.Intersect(ray, &lightIsect);
// Add light contribution from material sampling
Spectrum Li(0.f);
if (foundSurfaceInteraction) {
if (lightIsect.primitive->GetAreaLight() == &light)
Li = lightIsect.Le(-wi);
} else
Li = light.Le(ray);
if (!Li.IsBlack()) Ld += f * Li * Tr * weight / scatteringPdf;
}
}
return Ld;
}
示例2: ConnectBDPT
Spectrum ConnectBDPT(
const Scene &scene, Vertex *lightVertices, Vertex *cameraVertices, int s,
int t, const Distribution1D &lightDistr,
const std::unordered_map<const Light *, size_t> &lightToIndex,
const Camera &camera, Sampler &sampler, Point2f *pRaster,
Float *misWeightPtr) {
Spectrum L(0.f);
// Ignore invalid connections related to infinite area lights
if (t > 1 && s != 0 && cameraVertices[t - 1].type == VertexType::Light)
return Spectrum(0.f);
// Perform connection and write contribution to _L_
Vertex sampled;
if (s == 0) {
// Interpret the camera subpath as a complete path
const Vertex &pt = cameraVertices[t - 1];
if (pt.IsLight()) L = pt.Le(scene, cameraVertices[t - 2]) * pt.beta;
DCHECK(!L.HasNaNs());
} else if (t == 1) {
// Sample a point on the camera and connect it to the light subpath
const Vertex &qs = lightVertices[s - 1];
if (qs.IsConnectible()) {
VisibilityTester vis;
Vector3f wi;
Float pdf;
Spectrum Wi = camera.Sample_Wi(qs.GetInteraction(), sampler.Get2D(),
&wi, &pdf, pRaster, &vis);
if (pdf > 0 && !Wi.IsBlack()) {
// Initialize dynamically sampled vertex and _L_ for $t=1$ case
sampled = Vertex::CreateCamera(&camera, vis.P1(), Wi / pdf);
L = qs.beta * qs.f(sampled, TransportMode::Importance) * sampled.beta;
if (qs.IsOnSurface()) L *= AbsDot(wi, qs.ns());
DCHECK(!L.HasNaNs());
// Only check visibility after we know that the path would
// make a non-zero contribution.
if (!L.IsBlack()) L *= vis.Tr(scene, sampler);
}
}
} else if (s == 1) {
// Sample a point on a light and connect it to the camera subpath
const Vertex &pt = cameraVertices[t - 1];
if (pt.IsConnectible()) {
Float lightPdf;
VisibilityTester vis;
Vector3f wi;
Float pdf;
int lightNum =
lightDistr.SampleDiscrete(sampler.Get1D(), &lightPdf);
const std::shared_ptr<Light> &light = scene.lights[lightNum];
Spectrum lightWeight = light->Sample_Li(
pt.GetInteraction(), sampler.Get2D(), &wi, &pdf, &vis);
if (pdf > 0 && !lightWeight.IsBlack()) {
EndpointInteraction ei(vis.P1(), light.get());
sampled =
Vertex::CreateLight(ei, lightWeight / (pdf * lightPdf), 0);
sampled.pdfFwd =
sampled.PdfLightOrigin(scene, pt, lightDistr, lightToIndex);
L = pt.beta * pt.f(sampled, TransportMode::Radiance) * sampled.beta;
if (pt.IsOnSurface()) L *= AbsDot(wi, pt.ns());
// Only check visibility if the path would carry radiance.
if (!L.IsBlack()) L *= vis.Tr(scene, sampler);
}
}
} else {
// Handle all other bidirectional connection cases
const Vertex &qs = lightVertices[s - 1], &pt = cameraVertices[t - 1];
if (qs.IsConnectible() && pt.IsConnectible()) {
L = qs.beta * qs.f(pt, TransportMode::Importance) * pt.f(qs, TransportMode::Radiance) * pt.beta;
VLOG(2) << "General connect s: " << s << ", t: " << t <<
" qs: " << qs << ", pt: " << pt << ", qs.f(pt): " << qs.f(pt, TransportMode::Importance) <<
", pt.f(qs): " << pt.f(qs, TransportMode::Radiance) << ", G: " << G(scene, sampler, qs, pt) <<
", dist^2: " << DistanceSquared(qs.p(), pt.p());
if (!L.IsBlack()) L *= G(scene, sampler, qs, pt);
}
}
++totalPaths;
if (L.IsBlack()) ++zeroRadiancePaths;
ReportValue(pathLength, s + t - 2);
// Compute MIS weight for connection strategy
Float misWeight =
L.IsBlack() ? 0.f : MISWeight(scene, lightVertices, cameraVertices,
sampled, s, t, lightDistr, lightToIndex);
VLOG(2) << "MIS weight for (s,t) = (" << s << ", " << t << ") connection: "
<< misWeight;
DCHECK(!std::isnan(misWeight));
L *= misWeight;
if (misWeightPtr) *misWeightPtr = misWeight;
return L;
}
示例3: ConnectBDPT
Spectrum ConnectBDPT(const Scene &scene, Vertex *lightVertices,
Vertex *cameraVertices, int s, int t,
const Distribution1D &lightDistr, const Camera &camera,
Sampler &sampler, Point2f *pRaster, Float *misWeightPtr) {
Spectrum L(0.f);
// Ignore invalid connections related to infinite area lights
if (t > 1 && s != 0 && cameraVertices[t - 1].type == VertexType::Light)
return Spectrum(0.f);
// Perform connection and write contribution to _L_
Vertex sampled;
if (s == 0) {
// Interpret the camera subpath as a complete path
const Vertex &pt = cameraVertices[t - 1];
if (pt.IsLight()) L = pt.Le(scene, cameraVertices[t - 2]) * pt.beta;
} else if (t == 1) {
// Sample a point on the camera and connect it to the light subpath
const Vertex &qs = lightVertices[s - 1];
if (qs.IsConnectible()) {
VisibilityTester vis;
Vector3f wi;
Float pdf;
Spectrum Wi = camera.Sample_Wi(qs.GetInteraction(), sampler.Get2D(),
&wi, &pdf, pRaster, &vis);
if (pdf > 0 && !Wi.IsBlack()) {
// Initialize dynamically sampled vertex and _L_ for $t=1$ case
sampled = Vertex::CreateCamera(&camera, vis.P1(), Wi / pdf);
L = qs.beta * qs.f(sampled) * vis.Tr(scene, sampler) *
sampled.beta;
if (qs.IsOnSurface()) L *= AbsDot(wi, qs.ns());
}
}
} else if (s == 1) {
// Sample a point on a light and connect it to the camera subpath
const Vertex &pt = cameraVertices[t - 1];
if (pt.IsConnectible()) {
Float lightPdf;
VisibilityTester vis;
Vector3f wi;
Float pdf;
int lightNum =
lightDistr.SampleDiscrete(sampler.Get1D(), &lightPdf);
const std::shared_ptr<Light> &light = scene.lights[lightNum];
Spectrum lightWeight = light->Sample_Li(
pt.GetInteraction(), sampler.Get2D(), &wi, &pdf, &vis);
if (pdf > 0 && !lightWeight.IsBlack()) {
EndpointInteraction ei(vis.P1(), light.get());
sampled =
Vertex::CreateLight(ei, lightWeight / (pdf * lightPdf), 0);
sampled.pdfFwd = sampled.PdfLightOrigin(scene, pt, lightDistr);
L = pt.beta * pt.f(sampled) * vis.Tr(scene, sampler) *
sampled.beta;
if (pt.IsOnSurface()) L *= AbsDot(wi, pt.ns());
}
}
} else {
// Handle all other bidirectional connection cases
const Vertex &qs = lightVertices[s - 1], &pt = cameraVertices[t - 1];
if (qs.IsConnectible() && pt.IsConnectible()) {
L = qs.beta * qs.f(pt) * pt.f(qs) * pt.beta;
if (!L.IsBlack()) L *= G(scene, sampler, qs, pt);
}
}
// Compute MIS weight for connection strategy
Float misWeight =
L.IsBlack() ? 0.f : MISWeight(scene, lightVertices, cameraVertices,
sampled, s, t, lightDistr);
L *= misWeight;
if (misWeightPtr) *misWeightPtr = misWeight;
return L;
}