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


C++ BSDF::pdf方法代码示例

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


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

示例1: sampleScattering

bool BidirPathTracing::sampleScattering(BSDF& bsdf , 
	const Vector3& hitPos , BidirPathState& pathState)
{
	Real bsdfDirPdf , cosWo;
	int sampledBSDFType;
	Color3 bsdfFactor = bsdf.sample(scene , rng.randVector3() ,
		pathState.dir , bsdfDirPdf , cosWo , &sampledBSDFType);

	if (bsdfFactor.isBlack())
		return 0;

	Real bsdfRevPdf = bsdfDirPdf;
	if ((sampledBSDFType & BSDF_SPECULAR) == 0)
		bsdfRevPdf = bsdf.pdf(scene , pathState.dir , 1);

	Real contProb = bsdf.continueProb;
	if (rng.randFloat() > contProb)
		return 0;

	bsdfDirPdf *= contProb;
	bsdfRevPdf *= contProb;

	// Partial sub-path MIS quantities
	// the evaluation is completed when the actual hit point is known!
	// i.e. after tracing the ray, out of the procedure
	if (sampledBSDFType & BSDF_SPECULAR)
	{
		pathState.specularVertexNum++;

		pathState.dVCM = 0.f;
		pathState.dVC *= mis(cosWo);
	}
	else
	{
		pathState.specularPath &= 0;

		pathState.dVC = mis(1.f / bsdfDirPdf) * (pathState.dVCM +
			pathState.dVC * mis(bsdfRevPdf));
		pathState.dVCM = mis(1.f / bsdfDirPdf);
	}

	pathState.origin = hitPos;
	pathState.throughput = (pathState.throughput | bsdfFactor) *
		(cosWo / bsdfDirPdf);

	return 1;
}
开发者ID:winmad,项目名称:Winmad-s-raytracer-v1.0,代码行数:47,代码来源:bidirPathTracing.cpp

示例2: extend

    bool extend(BDPTPathVertex& next,
                const Scene& scene,
                uint32_t pathCount,
                bool sampleAdjoint, // Number of paths sampled with the strategies s/t = m_nDepth + 1, t/s = *
                RandomGenerator&& rng,
                MisFunctor&& mis) {
        if(!m_Intersection) {
            return false; // Can't sample from infinity
        }

        Sample3f woSample;
        float cosThetaOutDir;
        uint32_t sampledEvent;
        auto fs = m_BSDF.sample(Vec3f(getFloat(rng), getFloat2(rng)), woSample, cosThetaOutDir, &sampledEvent, sampleAdjoint);

        if(woSample.pdf == 0.f || fs == zero<Vec3f>()) {
            return false;
        }

        float reversePdf = m_BSDF.pdf(woSample.value, true);

        auto nextI = scene.intersect(Ray(m_Intersection, woSample.value));

        if(!nextI) {
            next.m_Intersection = nextI;
            next.m_BSDF.init(-woSample.value, scene);
            next.m_fPdfWrtArea = woSample.pdf;
            next.m_fPathPdf = m_fPathPdf * woSample.pdf;
            next.m_Power = m_Power * abs(cosThetaOutDir) * fs / woSample.pdf;
            next.m_nDepth = m_nDepth + 1;

            auto previousPointToIncidentDirectionJacobian = abs(cosThetaOutDir); // No division by squared distance since the point is at infinity
            if((sampledEvent & ScatteringEvent::Specular) && m_BSDF.isDelta()) {
                next.m_fdVC = mis(previousPointToIncidentDirectionJacobian) * m_fdVC;
                next.m_fdVCM = 0.f;
            } else {
                // We set dVC first in case next == *this, so that the dVCM is unchanged until next line
                next.m_fdVC = mis(previousPointToIncidentDirectionJacobian / next.m_fPdfWrtArea) * (m_fdVCM + mis(reversePdf) * m_fdVC);
                next.m_fdVCM = mis(pathCount / next.m_fPdfWrtArea);
            }
        } else {
            auto incidentDirection = -woSample.value;
            auto sqrLength = sqr(nextI.distance);
            if(sqrLength == 0.f) {
                return false;
            }

            auto pdfWrtArea = woSample.pdf * abs(dot(nextI.Ns, incidentDirection)) / sqrLength;

            if(pdfWrtArea == 0.f) {
                return false;
            }

            next.m_Intersection = nextI;
            next.m_BSDF.init(incidentDirection, nextI, scene);
            next.m_fPdfWrtArea = pdfWrtArea;
            next.m_fPathPdf = m_fPathPdf * pdfWrtArea;
            next.m_Power = m_Power * abs(cosThetaOutDir) * fs / woSample.pdf;

            next.m_nDepth = m_nDepth + 1;

            auto previousPointToIncidentDirectionJacobian = abs(cosThetaOutDir) / sqrLength;
            if((sampledEvent & ScatteringEvent::Specular) && m_BSDF.isDelta()) {
                next.m_fdVC = mis(previousPointToIncidentDirectionJacobian) * m_fdVC;
                next.m_fdVCM = 0.f;
            } else {
                // We set dVC first in case next == *this, so that the dVCM is unchanged until next line
                next.m_fdVC = mis(previousPointToIncidentDirectionJacobian / next.m_fPdfWrtArea) * (m_fdVCM + mis(reversePdf) * m_fdVC);
                next.m_fdVCM = mis(pathCount / next.m_fPdfWrtArea);
            }
        }

        return true;
    }
开发者ID:Celeborn2BeAlive,项目名称:pg2015-code,代码行数:74,代码来源:recursive_mis_bdpt.hpp


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