本文整理汇总了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;
}
示例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();
}