光线跟踪器纹理映射留下工件

时间:2013-04-09 17:23:07

标签: c++ debugging geometry texture-mapping raytracing

所以我试图让我的光线跟踪器中的OBJ加载工作。加载OBJ工作正常,但我在使纹理映射工作时遇到了一些麻烦。

这是我的结果的图像。它应该是一个带有彩色“经纬度”线条的黑色球体,中间有一个黑点。但似乎每个第二个三角形都是黑色的。你可以在这里看到结果:

enter image description here

我的教授说看起来法线是向后的,但我不认为是这种情况,因为形状仍然被击中 - 而“错误”三角形的颜色是背景颜色的颜色。纹理(即在这种情况下为黑色)。

当我加载OBJ时,每个顶点都有一个与之关联的UV坐标。当光线照射到形状时,我所做的是获得UV坐标,如下所示:

T: the triangle that was hit
hp: where on the triangle the ray hit
v1,v2,v3: the vertices of the triangle, each has a UV coord UV1, UV2, UV3

find the distance to each v[i] from hp (d1,d2,d3 respectively)
find the weight of each of these (w1 = d1/(d1+d2+d3), same for d2,d3)
find the weighted UV coord: UV1/w1 + UV2/w2 + UV3/w3

find the pixel color based on this weighted coord

有没有人有任何想法可能会发生什么?如果您认为这会有所帮助,我可以发布部分代码。

1 个答案:

答案 0 :(得分:1)

你的紫外线坐标计算中确实存在一个错误(无论你的法线是否有额外的错误)。

我说的原因是:例如,如果你的hp非常接近v1,你的最终权重w1非常接近零,当你计算UV1 / w1时,它会倾向于+无穷大而不是预期值UV1。

因此,您需要查看barycentric coordinates