1
我嘗試添加凹凸貼圖功能,我的應用程序,但我已經非常多面模型:如何實現平滑切線空間法線?
它發生的原因是因爲我計算每對切線,副法線和正常並且完全忽略了我從模型文件中獲得的法線。
該計算當前使用三角形的兩個邊和紋理空間矢量來得到正切和副法線,然後用於通過叉積來計算法線。一旦模型加載完成,所有這些都在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);
有沒有辦法,要麼計算每頂點基礎上這些值可能使用與模型或將它們以某種方式理順因此模型不會出現刻面提供的正常?
我們展示着色器。 – Drop