射线追踪噪音

Fat*_*ler 1 graphics raytracing

我想知道有光线追踪经验的人是否可以帮助我找出我的程序中的一些问题,但是我不能发布很多代码,因为这个程序是学校作业.我只是想知道我是否能得到一些有助于引导我朝正确方向前进的技巧.所以提前谢谢!

首先)如您所见,我的光线追踪图像中有大量噪音.场景由悬停在平面上的单个三角形组成.还存在单个点光源.

第二)当我计算阴影射线时不会发生噪声,但它会为阴影计算错误的颜色.

我的光线追踪算法:

for each pixel,
    color c;
    for each shape in the scene
        send a ray through each pixel and see if it collides with a shape
        if it does
            color = calculate color of ray
        else, color = background color
    return color

To calculate color of ray...
    color c = 0,0,0 // rgb
    for each light source in the scene
        make a new ray (shad_ray) that starts at where the original ray hit the shape...
        ... and ends at the light source
        see if the shadow ray hits a shape on its way to the light
        if it does, 
            calculate ambient color using ambient color of shape material and...
            ... ambient light intensity 
        if not,
            calculate shading with sum of ambient/diffuse/specular components 
Run Code Online (Sandbox Code Playgroud)

我知道这是一个非常宽松的算法描述.但如果需要,我可以提供更多信息.

坏光线追踪</ 3

rha*_*oto 8

这看起来很熟悉,被称为"表面痤疮".光线跟踪阴影的常见错误是阴影光线与阴影光线发出的对象相交.由于有限的浮点精度,交点并不总是精确地在表面上 - 它最终略高于或低于.投射阴影射线时,可以再次与该曲面相交.它看起来很吵,因为有些地方会自相交,有些则没有

处理此问题的典型方法是将阴影射线的原点稍微向后移动到眼点,或忽略在很短距离内发生的阴影交叉点,或忽略与该表面的所有交点(如果表面是平面或凸面的) ).

至于阴影区域的颜色,您可能需要发布实际代码,但看起来您正在使用阴影光线相交的对象材质而不是主光线.