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


C++ Ray::getRefractiveIndex方法代码示例

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


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

示例1: indirectRadiance

// Light that bounces multiple times before reaching the eye
Rgb Dielectric::indirectRadiance(Intersection *intersection, Ray ray, Scene *scene, int depth)
{
	/*
	 *	IDEA: Set index of refraction to be the same as the airs. In this event, should go straight through
	 *		  and the towardsViewer and refracted vector should differ in sign value (ie, they will be pointing 
	 *		  in opposite directions, but parallel)
	 */


	//TODO: Might as well store the surface normal with the intersection
	Vector3 towardsViewer = -ray.getDirection().normalized();
	Vector3 normal = intersection->getSurface()->computeSurfaceNormal(intersection->getIntersectionPoint()).normalized();

	Ray reflectedRay(intersection->getIntersectionPoint(),
					 -towardsViewer.reflect(normal),
					 ray.getRefractiveIndex(),
					 ray.getMaxDepth());

	// Add refracted ray
	bool isReflected = false;
	Vector3 refractedDirection = towardsViewer.refract(normal, ray.getRefractiveIndex(), refractiveIndex, isReflected);

	Ray refractedRay(intersection->getIntersectionPoint(),
					 refractedDirection,
					 refractiveIndex,
					 ray.getMaxDepth());

	// Compute fresnel
	double fresnel = computeFresnel(towardsViewer, normal, ray.getRefractiveIndex(),  refractiveIndex);

	Rgb radiance;
	if (fresnel >= 1.0 || isReflected == true)
	{
		radiance = scene->trace(reflectedRay, EPSILON, depth + 1).getPixelColor();
	}
	else
	{
		Rgb refractedColor = scene->trace(refractedRay, EPSILON, depth + 1).getPixelColor();
		Rgb reflectedColor = scene->trace(reflectedRay, EPSILON, depth + 1).getPixelColor();

		radiance.u.a[0] = (1.0 - fresnel) * refractedColor.u.a[0] + (fresnel) * reflectedColor.u.a[0];
		radiance.u.a[1] = (1.0 - fresnel) * refractedColor.u.a[1] + (fresnel) * reflectedColor.u.a[1];
		radiance.u.a[2] = (1.0 - fresnel) * refractedColor.u.a[2] + (fresnel) * reflectedColor.u.a[2];
	}
	return kAbsorption * radiance;
}
开发者ID:jadmr,项目名称:CS548_BasicRayTracer,代码行数:47,代码来源:dielectric.cpp

示例2: indirectRadiance

// Light that bounces multiple times before reaching the eye
Rgb Reflector::indirectRadiance(Intersection *intersection, Ray ray, Scene *scene, int depth)
{
	Vector3 towardsViewer = ray.getDirection().normalized();
	Vector3 normal = intersection->getSurface()->computeSurfaceNormal(intersection->getIntersectionPoint()).normalized();

	Ray reflectedRay(intersection->getIntersectionPoint(),
					 towardsViewer.reflect(normal),
					 ray.getRefractiveIndex(),
					 ray.getMaxDepth());
	
	return kReflectivity * scene->trace(reflectedRay, EPSILON, depth + 1).getPixelColor();
}
开发者ID:jadmr,项目名称:CS548_BasicRayTracer,代码行数:13,代码来源:reflector.cpp


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