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


C++ PathSampleGenerator::uniformGenerator方法代码示例

本文整理汇总了C++中PathSampleGenerator::uniformGenerator方法的典型用法代码示例。如果您正苦于以下问题:C++ PathSampleGenerator::uniformGenerator方法的具体用法?C++ PathSampleGenerator::uniformGenerator怎么用?C++ PathSampleGenerator::uniformGenerator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PathSampleGenerator的用法示例。


在下文中一共展示了PathSampleGenerator::uniformGenerator方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: transmittance

Vec3f VdbGrid::transmittance(PathSampleGenerator &sampler, Vec3f p, Vec3f w, float t0, float t1, Vec3f sigmaT) const
{
    auto accessor = _grid->getConstAccessor();

    if (_integrationMethod == IntegrationMethod::ExactNearest) {
        VdbRaymarcher<openvdb::FloatGrid::TreeType, 3> dda;

        float integral = 0.0f;
        dda.march(DdaRay(p + 0.5f, w), t0, t1, accessor, [&](openvdb::Coord voxel, float ta, float tb) {
            integral += accessor.getValue(voxel)*(tb - ta);
            return false;
        });
        return std::exp(-integral*sigmaT);
    } else if (_integrationMethod == IntegrationMethod::ExactLinear) {
        VdbRaymarcher<openvdb::FloatGrid::TreeType, 3> dda;

        float integral = 0.0f;
        float fa = gridAt(accessor, p + w*t0);
        dda.march(DdaRay(p, w), t0, t1, accessor, [&](openvdb::Coord /*voxel*/, float ta, float tb) {
            float fb = gridAt(accessor, p + w*tb);
            integral += (fa + fb)*0.5f*(tb - ta);
            fa = fb;
            return false;
        });
        return std::exp(-integral*sigmaT);
    } else if (_integrationMethod == IntegrationMethod::ResidualRatio) {
        VdbRaymarcher<Vec2fGrid::TreeType, 3> dda;

        float scale = _supergridSubsample;
        float invScale = 1.0f/scale;
        sigmaT *= scale;

        float sigmaTc = sigmaT.max();

        auto superAccessor =  _superGrid->getConstAccessor();

        UniformSampler &generator = sampler.uniformGenerator();

        float controlIntegral = 0.0f;
        Vec3f Tr(1.0f);
        dda.march(DdaRay(p*invScale + 0.5f, w), t0*invScale, t1*invScale, superAccessor, [&](openvdb::Coord voxel, float ta, float tb) {
            openvdb::Vec2s v = superAccessor.getValue(voxel);
            float muC = v.x();
            float muR = v.y();
            muR *= sigmaTc;

            controlIntegral += muC*(tb - ta);

            while (true) {
                ta -= BitManip::normalizedLog(generator.nextI())/muR;
                if (ta >= tb)
                    break;
                Tr *= 1.0f - sigmaT*((gridAt(accessor, p + w*ta*scale) - muC)/muR);
            }

            return false;
        });
        return std::exp(-controlIntegral*sigmaT)*Tr;
    } else {
        float ta = t0;
        float fa = gridAt(accessor, p + w*t0);
        float integral = 0.0f;
        float dT = sampler.next1D()*_stepSize;
        do {
            float tb = min(ta + dT, t1);
            float fb = gridAt(accessor, p + w*tb);
            integral += (fa + fb)*0.5f*(tb - ta);
            ta = tb;
            fa = fb;
            dT = _stepSize;
        } while (ta < t1);
        return std::exp(-integral*sigmaT);
    }
}
开发者ID:CounterPillow,项目名称:tungsten,代码行数:74,代码来源:VdbGrid.cpp


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