本文整理汇总了C++中SurfaceInteraction::CreateBSDF方法的典型用法代码示例。如果您正苦于以下问题:C++ SurfaceInteraction::CreateBSDF方法的具体用法?C++ SurfaceInteraction::CreateBSDF怎么用?C++ SurfaceInteraction::CreateBSDF使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SurfaceInteraction
的用法示例。
在下文中一共展示了SurfaceInteraction::CreateBSDF方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: L
rose::Spectrum rose::PathTracerIntegrator::IncomingRadiance(const rose::Ray &ray,
const rose::RayInterval &interval,
const rose::Scene &scene,
uint32_t) const {
// Final incoming radiance and accumulation value
Spectrum L(0.f), beta(1.f);
Ray current_ray(ray);
RayInterval current_interval(interval);
bool specular_bounce = false;
uint32_t bounces;
// Keep track of specular bounce
for (bounces = 0;; ++bounces) {
SurfaceInteraction interaction;
bool found_interaction = scene.Intersect(current_ray, current_interval, &interaction);
// Possibly add emission
if (bounces == 0 || specular_bounce) {
// Add emitted light
if (found_interaction) {
L += beta * interaction.Le(Normalize(-current_ray.Direction()));
} else {
for (const auto &light : scene.Lights()) {
L += beta * light->Le(current_ray);
}
}
}
// Terminate path if ray escaped or max depth reached
if (!found_interaction || bounces >= max_depth) { break; }
// Compute scattering function
std::unique_ptr<BSDF> bsdf = interaction.CreateBSDF(true);
// Get shading variables
const Vector3f n = interaction.sh_frame.N();
const Vector3f wo = Normalize(-current_ray.Direction());
// Loop over all lights and add direct contribution
for (const auto &light : scene.Lights()) {
// Sample light
LightSample light_sample;
OcclusionTester occlusion_tester;
Spectrum Li = light->SampleLi(interaction, sampler->Next2D(), &light_sample, &occlusion_tester);
// Check light return
if (Li.IsBlack() || light_sample.pdf == 0.f) { continue; }
// Evaluate BSDF
Spectrum f = bsdf->F(wo, light_sample.wi);
if (!f.IsBlack() && occlusion_tester.Unoccluded(scene)) {
L += beta * f * Li * AbsDotProduct(n, light_sample.wi) / light_sample.pdf;
}
}
// Sample BSDF to get new path
BXDFSample bsdf_sample;
Spectrum f = bsdf->SampleF(wo, sampler->Next2D(), &bsdf_sample);
if (f.IsBlack() || bsdf_sample.pdf == 0.f) { break; }
// Update beta
beta *= f * AbsDotProduct(bsdf_sample.wi, n) / bsdf_sample.pdf;
// Check if bounce is specular
specular_bounce = (bsdf_sample.sampled_type & SPECULAR) != 0;
// Compute new ray
current_ray = interaction.SpawnRay(bsdf_sample.wi);
// Possibly terminate path with Russian roulette
if (bounces > 3) {
float q = std::max(0.05f, 1.f - beta.Norm());
if (sampler->Next1D() < q) { break; }
beta /= 1.f - q;
}
}
return L;
}