本文整理汇总了C++中Spectrum::maxComponentValue方法的典型用法代码示例。如果您正苦于以下问题:C++ Spectrum::maxComponentValue方法的具体用法?C++ Spectrum::maxComponentValue怎么用?C++ Spectrum::maxComponentValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Spectrum
的用法示例。
在下文中一共展示了Spectrum::maxComponentValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: computeLi
Spectrum Path::computeLi( const vec2f &pFilm, const SceneData &i_scene, const Camera &i_camera, const Sampler &i_sampler, int i_depth )
{
Camera::CameraSample cameraSample;
cameraSample.pixelSample = pFilm + i_sampler.sample2D();
cameraSample.lensSample = i_sampler.sample2D();
Ray ray;
float weight = i_camera.generateRay( cameraSample, &ray );
// Radiance
Spectrum L = Spectrum( 0.0f );
// Importance
Spectrum beta = Spectrum( 1.0 );
for ( int bounces = 0;; bounces++ ) {
RayIntersection intersection;
bool foundIntersection = i_scene.intersect( ray, intersection );
float maxDepth = 5;
if ( !foundIntersection || bounces >= maxDepth ) {
break;
}
Spectrum Le = intersection.Le();
if ( Le.isBlack() )
{
// Direct illumination sampling
Spectrum Ld = beta * uniformSampleOneLight( intersection, i_sampler, i_scene );
L += Ld;
// BSDF Sampling
const shading::BSDF &bsdf = intersection.getBSDF();
const vec3f &surfacePosition = intersection.getSurfacePoint().pos;
vec3f woLocal = -intersection.worldToSurface( -intersection.dir );
vec3f wiLocal;
float pdf = 1.0;
const vec2f &bsdfSample = i_sampler.sample2D();
Spectrum f = bsdf.sampleF( woLocal, &wiLocal, bsdfSample, &pdf );
// No point of continuing if no color
if ( f.isBlack() || pdf == 0.0 ) {
break;
}
// Transform to world space
vec3f wiWorld = intersection.surfaceToWorld( wiLocal );
// Generate new ray
ray = Ray( surfacePosition, wiWorld );
beta *= ( f * absDot( wiWorld, intersection.getSurfacePoint().normal ) ) / pdf;
// Russian Roulette
if ( beta.y() < 1.0f && bounces > 3 ) {
float q = std::max( .05f, 1 - beta.maxComponentValue() );
if ( i_sampler.sample1D() > q ) {
beta /= ( 1.0 - q );
}
else {
break;
}
}
}
else {
L += beta * intersection.Le() / 50.0;
break;
}
}
return weight * L;
}