本文整理汇总了C++中Distribution1D类的典型用法代码示例。如果您正苦于以下问题:C++ Distribution1D类的具体用法?C++ Distribution1D怎么用?C++ Distribution1D使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Distribution1D类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GenerateLightSubpath
int GenerateLightSubpath(
const Scene &scene, Sampler &sampler, MemoryArena &arena, int maxDepth,
Float time, const Distribution1D &lightDistr,
const std::unordered_map<const Light *, size_t> &lightToIndex,
Vertex *path) {
if (maxDepth == 0) return 0;
// Sample initial ray for light subpath
Float lightPdf;
int lightNum = lightDistr.SampleDiscrete(sampler.Get1D(), &lightPdf);
const std::shared_ptr<Light> &light = scene.lights[lightNum];
RayDifferential ray;
Normal3f nLight;
Float pdfPos, pdfDir;
Spectrum Le = light->Sample_Le(sampler.Get2D(), sampler.Get2D(), time, &ray,
&nLight, &pdfPos, &pdfDir);
if (pdfPos == 0 || pdfDir == 0 || Le.IsBlack()) return 0;
// Generate first vertex on light subpath and start random walk
path[0] =
Vertex::CreateLight(light.get(), ray, nLight, Le, pdfPos * lightPdf);
Spectrum beta = Le * AbsDot(nLight, ray.d) / (lightPdf * pdfPos * pdfDir);
VLOG(2) << "Starting light subpath. Ray: " << ray << ", Le " << Le <<
", beta " << beta << ", pdfPos " << pdfPos << ", pdfDir " << pdfDir;
int nVertices =
RandomWalk(scene, ray, sampler, arena, beta, pdfDir, maxDepth - 1,
TransportMode::Importance, path + 1);
// Correct subpath sampling densities for infinite area lights
if (path[0].IsInfiniteLight()) {
// Set spatial density of _path[1]_ for infinite area light
if (nVertices > 0) {
path[1].pdfFwd = pdfPos;
if (path[1].IsOnSurface())
path[1].pdfFwd *= AbsDot(ray.d, path[1].ng());
}
// Set spatial density of _path[0]_ for infinite area light
path[0].pdfFwd =
InfiniteLightDensity(scene, lightDistr, lightToIndex, ray.d);
}
return nVertices + 1;
}
示例2: GenerateLightSubpath
int GenerateLightSubpath(const Scene &scene, Sampler &sampler,
MemoryArena &arena, int maxdepth, Float time,
const Distribution1D &lightDistr, Vertex *path) {
if (maxdepth == 0) return 0;
// Sample initial ray for light subpath
Float lightPdf;
int lightNum = lightDistr.SampleDiscrete(sampler.Get1D(), &lightPdf);
const std::shared_ptr<Light> &light = scene.lights[lightNum];
RayDifferential ray;
Normal3f Nl;
Float pdfPos, pdfDir;
Spectrum Le = light->Sample_L(sampler.Get2D(), sampler.Get2D(), time, &ray,
&Nl, &pdfPos, &pdfDir);
if (pdfPos == 0.f || pdfDir == 0.f || Le.IsBlack()) return 0;
// Generate first vertex on light subpath and start random walk
Spectrum weight = Le * AbsDot(Nl, ray.d) / (lightPdf * pdfPos * pdfDir);
path[0] = Vertex(VertexType::Light,
EndpointInteraction(light.get(), ray, Nl), Le);
path[0].pdfFwd = pdfPos * lightPdf;
int nvertices =
RandomWalk(scene, ray, sampler, arena, weight, pdfDir, maxdepth - 1,
TransportMode::Importance, path + 1);
// Correct sampling densities for infinite area lights
if (path[0].IsInfiniteLight()) {
// Set positional density of _path[1]_
if (nvertices > 0) {
path[1].pdfFwd = pdfPos;
if (path[1].IsOnSurface())
path[1].pdfFwd *= AbsDot(ray.d, path[1].GetGeoNormal());
}
// Set positional density of _path[0]_
path[0].pdfFwd = InfiniteLightDensity(scene, lightDistr, ray.d);
}
return nvertices + 1;
}
示例3: lightNum
void IGIIntegrator::Preprocess(const Scene *scene, const Camera *camera,
const Renderer *renderer) {
if (scene->lights.size() == 0) return;
MemoryArena arena;
RNG rng;
// Compute samples for emitted rays from lights
vector<float> lightNum(nLightPaths * nLightSets);
vector<float> lightSampPos(2 * nLightPaths * nLightSets, 0.f);
vector<float> lightSampComp(nLightPaths * nLightSets, 0.f);
vector<float> lightSampDir(2 * nLightPaths * nLightSets, 0.f);
LDShuffleScrambled1D(nLightPaths, nLightSets, &lightNum[0], rng);
LDShuffleScrambled2D(nLightPaths, nLightSets, &lightSampPos[0], rng);
LDShuffleScrambled1D(nLightPaths, nLightSets, &lightSampComp[0], rng);
LDShuffleScrambled2D(nLightPaths, nLightSets, &lightSampDir[0], rng);
// Precompute information for light sampling densities
Distribution1D *lightDistribution = ComputeLightSamplingCDF(scene);
for (uint32_t s = 0; s < nLightSets; ++s) {
for (uint32_t i = 0; i < nLightPaths; ++i) {
// Follow path _i_ from light to create virtual lights
int sampOffset = s*nLightPaths + i;
// Choose light source to trace virtual light path from
float lightPdf;
int ln = lightDistribution->SampleDiscrete(lightNum[sampOffset],
&lightPdf);
Light *light = scene->lights[ln];
// Sample ray leaving light source for virtual light path
RayDifferential ray;
float pdf;
LightSample ls(lightSampPos[2*sampOffset], lightSampPos[2*sampOffset+1],
lightSampComp[sampOffset]);
Normal Nl;
Spectrum alpha = light->Sample_L(scene, ls, lightSampDir[2*sampOffset],
lightSampDir[2*sampOffset+1],
camera->shutterOpen, &ray, &Nl, &pdf);
if (pdf == 0.f || alpha.IsBlack()) continue;
alpha /= pdf * lightPdf;
Intersection isect;
while (scene->Intersect(ray, &isect) && !alpha.IsBlack()) {
// Create virtual light and sample new ray for path
alpha *= renderer->Transmittance(scene, RayDifferential(ray), NULL,
rng, arena);
Vector wo = -ray.d;
BSDF *bsdf = isect.GetBSDF(ray, arena);
// Create virtual light at ray intersection point
Spectrum contrib = alpha * bsdf->rho(wo, rng) / M_PI;
virtualLights[s].push_back(VirtualLight(isect.dg.p, isect.dg.nn, contrib,
isect.rayEpsilon));
// Sample new ray direction and update weight for virtual light path
Vector wi;
float pdf;
BSDFSample bsdfSample(rng);
Spectrum fr = bsdf->Sample_f(wo, &wi, bsdfSample, &pdf);
if (fr.IsBlack() || pdf == 0.f)
break;
Spectrum contribScale = fr * AbsDot(wi, bsdf->dgShading.nn) / pdf;
// Possibly terminate virtual light path with Russian roulette
float rrProb = min(1.f, contribScale.y());
if (rng.RandomFloat() > rrProb)
break;
alpha *= contribScale / rrProb;
ray = RayDifferential(isect.dg.p, wi, ray, isect.rayEpsilon);
}
arena.FreeAll();
}
}
delete lightDistribution;
}
示例4: 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;
}
示例5: 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;
}
示例6: ConnectBDPT
Spectrum ConnectBDPT(const Scene &scene, Vertex *lightSubpath,
Vertex *cameraSubpath, int s, int t,
const Distribution1D &lightDistr, const Camera &camera,
Sampler &sampler, Point2f *rasterPos, Float *misWeight) {
Spectrum weight(0.f);
// Ignore invalid connections related to infinite area lights
if (t > 1 && s != 0 && cameraSubpath[t - 1].type == VertexType::Light)
return Spectrum(0.f);
// Perform connection and write contribution to _weight_
Vertex sampled;
if (s == 0) {
// Interpret the camera subpath as a complete path
const Vertex &pt = cameraSubpath[t - 1];
if (pt.IsLight()) {
const Vertex &ptMinus = cameraSubpath[t - 2];
weight = pt.Le(scene, ptMinus) * pt.weight;
}
} else if (t == 1) {
// Sample a point on the camera and connect it to the light subpath
const Vertex &qs = lightSubpath[s - 1];
if (qs.IsConnectible()) {
VisibilityTester vis;
Vector3f wi;
Float pdf;
Spectrum cameraWeight =
camera.Sample_We(qs.GetInteraction(), sampler.Get2D(), &wi,
&pdf, rasterPos, &vis);
if (pdf > 0 && !cameraWeight.IsBlack()) {
// Initialize dynamically sampled vertex and _weight_
sampled = Vertex(VertexType::Camera,
EndpointInteraction(vis.P1(), &camera),
cameraWeight);
weight = qs.weight * qs.f(sampled) * vis.T(scene, sampler) *
sampled.weight;
if (qs.IsOnSurface())
weight *= AbsDot(wi, qs.GetShadingNormal());
}
}
} else if (s == 1) {
// Sample a point on a light and connect it to the camera subpath
const Vertex &pt = cameraSubpath[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_L(
pt.GetInteraction(), sampler.Get2D(), &wi, &pdf, &vis);
if (pdf > 0 && !lightWeight.IsBlack()) {
sampled = Vertex(VertexType::Light,
EndpointInteraction(vis.P1(), light.get()),
lightWeight / (pdf * lightPdf));
sampled.pdfFwd = sampled.PdfLightOrigin(scene, pt, lightDistr);
weight = pt.weight * pt.f(sampled) * vis.T(scene, sampler) *
sampled.weight;
if (pt.IsOnSurface())
weight *= AbsDot(wi, pt.GetShadingNormal());
}
}
} else {
// Handle all other cases
const Vertex &qs = lightSubpath[s - 1], &pt = cameraSubpath[t - 1];
if (qs.IsConnectible() && pt.IsConnectible()) {
weight = qs.weight * qs.f(pt) *
GeometryTerm(scene, sampler, qs, pt) * pt.f(qs) *
pt.weight;
}
}
// Compute MIS weight for connection strategy
*misWeight =
weight.IsBlack() ? 0.f : MISWeight(scene, lightSubpath, cameraSubpath,
sampled, s, t, lightDistr);
return weight;
}
示例7: Sample_L
Spectrum InfiniteAreaLightIS::Sample_L(const Point &p, float u1,
float u2, Vector *wi, float *pdf,
VisibilityTester *visibility) const {
// Find floating-point $(u,v)$ sample coordinates
float pdfs[2];
float fu = uDistrib->Sample(u1, &pdfs[0]);
int u = Clamp(Float2Int(fu), 0, uDistrib->count-1);
float fv = vDistribs[u]->Sample(u2, &pdfs[1]);
if (pdfs[0] == 0.f || pdfs[1] == 0.f) {
*pdf = 0.f;
return Spectrum(0.f);
}
// Convert sample point to direction on the unit sphere
float theta = fv * vDistribs[u]->invCount * M_PI;
float phi = fu * uDistrib->invCount * 2.f * M_PI;
float costheta = cos(theta), sintheta = sin(theta);
if (sintheta == 0.f) return 0.f;
float sinphi = sin(phi), cosphi = cos(phi);
*wi = LightToWorld(Vector(sintheta * cosphi, sintheta * sinphi,
costheta));
// Compute PDF for sampled direction
*pdf = (pdfs[0] * pdfs[1]) / (2. * M_PI * M_PI * sintheta);
// Return radiance value for direction
visibility->SetRay(p, *wi);
return Lbase * radianceMap->Lookup(fu * uDistrib->invCount,
fv * vDistribs[u]->invCount);
}