射线示踪反射粒状 [英] Ray tracer reflections grainy

查看:153
本文介绍了射线示踪反射粒状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在光线跟踪器中实现了反射,下面是处理反射的代码,但是我已将所有代码上传到



然而,像1920x1080这样的较低分辨率更为明显:



解决方案

问题在于Ray反射本身。我没有重新编译代码来确认这一点。您可以尝试在反射光线的起始位置添加一些偏移量。

 向量偏移=合成反射* 0.001; 
Ray reflectionRay(intersectionRayPos + offset,resultingReflection);


I just implemented reflections in my ray tracer, here is the code that handles the reflections, however i have all my code uploaded to a github repository for better reading:

Color finalColor = closestObjectMaterial.GetColor() * AMBIENTLIGHT; // Add ambient light to the calculation

// Reflections
if(closestObjectMaterial.GetSpecular() > 0 && closestObjectMaterial.GetSpecular() <= 1)
{
    Vector scalar = closestObjectNormal * (closestObjectNormal.Dot(intersectingRayDir.Negative()));
    Vector resultantReflection = intersectingRayDir.Negative() + ((scalar + (intersectingRayDir)) * 2);
    Vector reflectionDirection = resultantReflection.Normalize();

    Ray reflectionRay(intersectionRayPos, resultantReflection);

    // determine what the ray intersects with first
    std::vector<FPType> reflectionIntersections;
    for(auto sceneObject : sceneObjects)
    {
        reflectionIntersections.push_back(sceneObject->GetIntersection(reflectionRay));
    }

    int closestObjectWithReflection = ClosestObjectIndex(reflectionIntersections);

    if(closestObjectWithReflection != -1)
    {
        // reflection ray missed everthing else
        if(reflectionIntersections[closestObjectWithReflection] > TOLERANCE)
        {
            // determine the position and direction at the point of intersection with the reflection ray
            // the ray only affects the color if it reflected off something
            Vector reflectionIntersectionPosition = intersectionRayPos + (resultantReflection * (reflectionIntersections[closestObjectWithReflection]));
            Vector reflectionIntersectionRayDirection = resultantReflection;
            Color reflectionIntersectionColor = GetColorAt(reflectionIntersectionPosition, reflectionIntersectionRayDirection, sceneObjects, closestObjectWithReflection, lightSources);
            finalColor += (reflectionIntersectionColor * closestObjectMaterial.GetReflection());
        }
    }
}

I'm getting these grainy artifacts on all reflections (this is a 16k resolution render zoomed in):

However it's even more obvious on lower resolutions like 1920x1080:

解决方案

I think the problem is that the reflection Ray hits itself. I didn't recompile the code to confirm this. You might try adding some offset to the start position of reflection ray.

Vector offset = resultantReflection * 0.001;
Ray reflectionRay(intersectionRayPos + offset, resultantReflection);

这篇关于射线示踪反射粒状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆