本文整理汇总了C++中Sampler::Sample2D方法的典型用法代码示例。如果您正苦于以下问题:C++ Sampler::Sample2D方法的具体用法?C++ Sampler::Sample2D怎么用?C++ Sampler::Sample2D使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sampler
的用法示例。
在下文中一共展示了Sampler::Sample2D方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetDi
float3 DiTracer::GetDi(World const& world, Light const& light, Sampler const& lightsampler, Sampler const& bsdfsampler, float3 const& wo, ShapeBundle::Hit& hit) const
{
float3 radiance;
// TODO: fix that later with correct heuristic
assert(lightsampler.num_samples() == bsdfsampler.num_samples());
// Sample light source first to apply MIS later
{
// Direction from the shading point to the light
float3 lightdir;
// PDF for BSDF sample
float bsdfpdf = 0.f;
// PDF for light sample
float lightpdf = 0.f;
// Sample numsamples times
int numsamples = lightsampler.num_samples();
// Allocate samples
std::vector<float2> lightsamples(numsamples);
std::vector<float2> bsdfsamples(numsamples);
// Generate samples
for (int i = 0; i < numsamples; ++i)
{
lightsamples[i] = lightsampler.Sample2D();
bsdfsamples[i] = bsdfsampler.Sample2D();
}
// Cache singularity flag to avoid virtual call in the loop below
bool singularlight = light.Singular();
// Fetch the material
Material const& mat = *world.materials_[hit.m];
// Start sampling
for (int i=0; i<numsamples; ++i)
{
lightpdf = 0.f;
bsdfpdf = 0.f;
// This is needed to support normal mapping.
// Original intersection needs to be kept around since bsdf might alter the normal
ShapeBundle::Hit hitlocal = hit;
// Sample light source
float3 le = light.GetSample(hitlocal, lightsamples[i], lightdir, lightpdf);
// Continue if intensity > 0 and there is non-zero probability of sampling the point
if (lightpdf > MINPDF && le.sqnorm() > 0.f)
{
// Normalize direction to light
float3 wi = normalize(lightdir);
// Calculate distance for shadow testing
float dist = sqrtf(lightdir.sqnorm());
// Spawn shadow ray
ray shadowray;
// From an intersection point
shadowray.o = hitlocal.p;
// Into evaluated direction
shadowray.d = wi;
// TODO: move ray epsilon into some global options object
shadowray.t = float2(0.01f, dist - 0.01f);
// Check for an occlusion
float shadow = world.Intersect(shadowray) ? 0.f : 1.f;
// If we are not in shadow
if (shadow > 0.f)
{
// Evaluate BSDF
float3 bsdf = mat.Evaluate(hitlocal, wi, wo);
// We can't apply MIS for singular lights, so use simple estimator
if (singularlight)
{
// Estimate with Monte-Carlo L(wo) = int{ Ld(wi, wo) * fabs(dot(n, wi)) * dwi }
radiance += le * bsdf * fabs(dot(hitlocal.n, wi)) * (1.f / lightpdf);
assert(!has_nans(radiance));
}
else
{
// Apply MIS
bsdfpdf = mat.GetPdf(hitlocal, wi, wo);
// Evaluate weight
float weight = PowerHeuristic(1, lightpdf, 1, bsdfpdf);
// Estimate with Monte-Carlo L(wo) = int{ Ld(wi, wo) * fabs(dot(n, wi)) * dwi }
radiance += le * bsdf * fabs(dot(hitlocal.n, wi)) * weight * (1.f / lightpdf);
assert(!has_nans(radiance));
}
}
}
// Sample BSDF if the light is not singular
if (!singularlight)
{
int bsdftype = 0;
float3 wi;
// Sample material
float3 bsdf = mat.Sample(hitlocal, bsdfsamples[i], wo, wi, bsdfpdf, bsdftype);
//.........这里部分代码省略.........