我希望有经验的光线追踪者能够帮我解决一些程序问题,但由于这个程序是学校作业,我不能发布太多代码。我只是想知道是否可以得到一些提示,以帮助我朝着正确的方向前进。提前感谢!
第一)正如您所见,我的光线追踪图像中存在大量噪点。场景由一个悬浮在平面上的单个三角形和一个单独的点光源组成。
第二)当我计算阴影射线时,噪声不会出现,但它会计算错误的阴影颜色。
我的光线追踪算法:
我知道这是一种算法的非常笼统的描述。但如果需要,我可以提供更多信息。
第一)正如您所见,我的光线追踪图像中存在大量噪点。场景由一个悬浮在平面上的单个三角形和一个单独的点光源组成。
第二)当我计算阴影射线时,噪声不会出现,但它会计算错误的阴影颜色。
我的光线追踪算法:
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
我知道这是一种算法的非常笼统的描述。但如果需要,我可以提供更多信息。
![不好的光线追踪](https://istack.dev59.com/RZZ2U.webp)