本文整理汇总了C++中PathSampleGenerator::nextDiscrete方法的典型用法代码示例。如果您正苦于以下问题:C++ PathSampleGenerator::nextDiscrete方法的具体用法?C++ PathSampleGenerator::nextDiscrete怎么用?C++ PathSampleGenerator::nextDiscrete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PathSampleGenerator
的用法示例。
在下文中一共展示了PathSampleGenerator::nextDiscrete方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sampleDistance
bool AtmosphericMedium::sampleDistance(PathSampleGenerator &sampler, const Ray &ray,
MediumState &state, MediumSample &sample) const
{
if (state.bounce > _maxBounce)
return false;
Vec3f p = (ray.pos() - _center);
float t0 = p.dot(ray.dir());
float h = (p - t0*ray.dir()).length();
float maxT = ray.farT() + t0;
if (_absorptionOnly) {
sample.t = ray.farT();
sample.weight = std::exp(-_sigmaT*densityIntegral(h, t0, maxT));
sample.pdf = 1.0f;
sample.exited = true;
} else {
int component = sampler.nextDiscrete(3);
float sigmaTc = _sigmaT[component];
float xi = 1.0f - sampler.next1D();
float t = inverseOpticalDepth(h, t0, sigmaTc, xi);
sample.t = min(t, maxT);
sample.weight = std::exp(-_sigmaT*densityIntegral(h, t0, sample.t));
sample.exited = (t >= maxT);
if (sample.exited) {
sample.pdf = sample.weight.avg();
} else {
float rho = density(h, sample.t);
sample.pdf = (rho*_sigmaT*sample.weight).avg();
sample.weight *= rho*_sigmaS;
}
sample.weight /= sample.pdf;
sample.t -= t0;
state.advance();
}
sample.p = ray.pos() + sample.t*ray.dir();
sample.phase = _phaseFunction.get();
return true;
}
示例2: sampleDistance
bool HomogeneousMedium::sampleDistance(PathSampleGenerator &sampler, const Ray &ray,
MediumState &state, MediumSample &sample) const
{
if (state.bounce > _maxBounce)
return false;
float maxT = ray.farT();
if (_absorptionOnly) {
if (maxT == Ray::infinity())
return false;
sample.t = maxT;
sample.weight = std::exp(-_sigmaT*maxT);
sample.pdf = 1.0f;
sample.exited = true;
} else {
int component = sampler.nextDiscrete(3);
float sigmaTc = _sigmaT[component];
float t = -std::log(1.0f - sampler.next1D())/sigmaTc;
sample.t = min(t, maxT);
sample.weight = std::exp(-sample.t*_sigmaT);
sample.exited = (t >= maxT);
if (sample.exited) {
sample.pdf = sample.weight.avg();
} else {
sample.pdf = (_sigmaT*sample.weight).avg();
sample.weight *= _sigmaS;
}
sample.weight /= sample.pdf;
state.advance();
}
sample.p = ray.pos() + sample.t*ray.dir();
sample.phase = _phaseFunction.get();
return true;
}