【发布时间】:2013-04-09 17:23:07
【问题描述】:
所以我试图让 OBJ 加载在我的光线追踪器中工作。加载 OBJ 工作正常,但我在纹理映射工作时遇到了一些问题。
这是我的结果的图像。它应该是一个带有彩色“经纬度”线的黑色球体,中间有一个黑点。但似乎每隔一个三角形都是黑色的。你可以在这里看到结果:
我的教授说看起来法线是向后的,但我不认为是这种情况,因为形状仍在被击中 - “错误”三角形的颜色是背景颜色的颜色纹理(即在这种情况下为黑色)。
当我加载 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
有人知道会发生什么吗?如果您认为有帮助,我可以发布我的部分代码。
【问题讨论】:
标签: c++ debugging geometry texture-mapping raytracing