当前位置: 首页>>代码示例>>C++>>正文


C++ SurfaceInteraction::CreateBSDF方法代码示例

本文整理汇总了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;
}
开发者ID:SRaimondi,项目名称:Rose,代码行数:73,代码来源:path_integrator.cpp


注:本文中的SurfaceInteraction::CreateBSDF方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。