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


C++ HitInfo::getInterpolatedNormal方法代码示例

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


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

示例1: sampleRay

const Vector3 RectangleLight::sampleLight(const unsigned int threadID, const Vector3 &from, const Vector3 &normal, const float time, const Scene &scene, const Vector3 &rVec, float &outSpec, bool isSecondary) const
{
	Ray sampleRay(threadID);
	HitInfo sampleHit;
	Vector3 randDir = 0, tmpResult = 0;
	float e1, e2, tmpSpec = 0;
	bool cutOff = false;
	int samplesDone = 0;
	float samplesDoneRecip = 1.0f;
	ALIGN_SSE float falloff = 1.0f;

	do
	{
		// Get a random vector into the light
		e1 = Scene::getRand(threadID);
		e2 = Scene::getRand(threadID);
		e2 = (e2 > 0.99) ? 0.99 : e2;
		randDir = ((m_v1 + e1*(m_v2-m_v1) + e2*(m_v3-m_v1)) - from);

		float nDotL = dot(normal, randDir);
		Vector3 E   = 0;
		float attenuate = 1.0f;

		if (nDotL > epsilon)															// Only do work if light can be hit
		{
			// the inverse-squared falloff
			falloff = randDir.length2();
			ALIGN_SSE float distanceRecip, distance;
#ifndef NO_SSE
			fastrsqrtss(setSSE(falloff), distanceRecip);
			recipss(setSSE(falloff), falloff);
			recipss(setSSE(distanceRecip), distance);
#else
			distance      = sqrtf(falloff);
			distanceRecip = 1.0f / distance;
			falloff       = 1.0f / falloff;
#endif
			randDir *= distanceRecip;
			nDotL   *= distanceRecip;

			if (m_castShadows)
			{
				sampleHit.t = distance - epsilon;									// We need this to account for the fact that we CAN hit geometry, to avoid false positives.
				if (m_fastShadows)
				{
					sampleRay.set(threadID, from, randDir, time, 1.001f, 0, 0, IS_SHADOW_RAY);		// Create shadow ray
					if (scene.trace(threadID, sampleHit, sampleRay, epsilon))					// Quick method, returns any hit
					{
						attenuate = 0.0f;
					}
				}
				else																// Full method, accounts for transparency effects
				{
					float distanceTraversed = 0.0f;
					sampleRay.set(threadID, from, randDir, time, 1.001f, 0, 0, IS_PRIMARY_RAY);		// Create primary ray
					while (distanceTraversed < distance && attenuate > epsilon)
					{
						if (scene.trace(threadID, sampleHit, sampleRay, epsilon))				
						{
							Vector3 hitN; sampleHit.getInterpolatedNormal(hitN);
							float nDL = dot(hitN, -randDir);
							if (nDL > 0.0)											// Only attenuate on incoming direction
							{
								attenuate *= sampleHit.obj->m_material->refractAmt();
							}
							Vector3 newP = Vector3(sampleRay.o[0], sampleRay.o[1], sampleRay.o[2]) + sampleHit.t * randDir;
							sampleRay.set(threadID, newP, randDir, time, 1.001f, 0, 0, IS_PRIMARY_RAY);
							distanceTraversed += sampleHit.t;
						}
						else
						{
							distanceTraversed = distance;
						}
					}
				}
			}
		}
		else
		{
			attenuate = 0.0f;														
		}

		E = m_power * falloff * _1_4PI;										// Light irradiance for this sample
		samplesDone++;
		samplesDoneRecip = 1.0f / (float)samplesDone;

		cutOff = (E * samplesDoneRecip).average() < m_noiseThreshold;		// Stop sampling if contribution is below the noise threshold

		tmpResult += E * attenuate;
		tmpSpec   += max(0.f, dot(rVec, randDir)) * attenuate;

	}  while (samplesDone < m_numSamples && !cutOff);

	outSpec = tmpSpec * samplesDoneRecip;
	return tmpResult * samplesDoneRecip;
}
开发者ID:curonian,项目名称:rendering-algorithms-raytracer,代码行数:96,代码来源:RectangleLight.cpp


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