我正在尝试将凹凸贴图功能添加到我的应用程序中,但我得到了非常多方面的模型:
之所以发生这种情况,是因为我在计算每个面的切线、副法线和法线,而完全忽略了从模型文件中获得的法线。
该计算目前使用三角形的两条边和纹理空间向量来获得切线和副法线,然后使用它们通过叉积来计算法线。一旦加载模型,所有这些都在CPU上完成,然后将值作为模型几何图形的一部分存储。
vector1 = vertex2.coords - vertex1.coords;
vector2 = vertex3.coords - vertex1.coords;
tuVector = vertex2.texcoords - vertex1.texcoords;
tvVector = vertex3.texcoords - vertex1.texcoords;
float den = 1.0f / (tuVector.x * tvVector.y - tuVector.y * tvVector.x);
tangent.x = (tvVector.y * vector1.x - tvVector.x * vector2.x) * den;
tangent.y = (tvVector.y * vector1.y - tvVector.x * vector2.y) * den;
tangent.z = (tvVector.y * vector1.z - tvVector.x * vector2.z) * den;
binormal.x = (tuVector.x * vector2.x - tuVector.y * vector1.x) * den;
binormal.y = (tuVector.x * vector2.y - tuVector.y * vector1.y) * den;
binormal.z = (tuVector.x * vector2.z - tuVector.y * vector1.z) * den;
D3DXVec3Normalize(&tangent, &tangent);
D3DXVec3Normalize(&binormal, &binormal);
D3DXVec3Cross(&normal, &tangent, &binormal);
D3DXVec3Normalize(&normal, &normal);
有没有一种方法可以在每个顶点的基础上计算这些值,也许是使用模型提供的法线,或者以某种方式平滑它们,使模型不会出现多面?