我使用perlin噪声生成地形,然后使用以下方法计算法线:
D3DXVECTOR3 v0 = aoVertices[auiIndices[i]].Position;
D3DXVECTOR3 v1 = aoVertices[auiIndices[i + 1]].Position;
D3DXVECTOR3 v2 = aoVertices[auiIndices[i + 2]].Position;
D3DXVECTOR3 v3 = aoVertices[auiIndices[i + 3]].Position;
D3DXVECTOR3 v4 = aoVertices[auiIndices[i + 4]].Position;
D3DXVECTOR3 v5 = aoVertices[auiIndices[i + 5]].Position;
D3DXVECTOR3 vNormal;
D3DXVECTOR3 vCross;
D3DXVec3Cross(&vCross, &D3DXVECTOR3(v2 - v0), &D3DXVECTOR3(v1 - v0));
D3DXVec3Normalize(&vNormal, &vCross);
aoVertices[auiIndices[i]].Normal = D3DXVECTOR3(vNormal);
aoVertices[auiIndices[i + 1]].Normal = D3DXVECTOR3(vNormal);
aoVertices[auiIndices[i + 2]].Normal = D3DXVECTOR3(vNormal);
D3DXVec3Cross(&vCross, &D3DXVECTOR3(v5 - v3), &D3DXVECTOR3(v4 - v3));
D3DXVec3Normalize(&vNormal, &vCross);
aoVertices[auiIndices[i + 3]].Normal = D3DXVECTOR3(vNormal);
aoVertices[auiIndices[i + 4]].Normal = D3DXVECTOR3(vNormal);
aoVertices[auiIndices[i + 5]].Normal = D3DXVECTOR3(vNormal);
然而,这会导致网格线出现在网格方块之间。 任何想法是什么问题?
实施例:
答案 0 :(得分:0)
我对DX10了解不多,但我最近在OpenGL中做了这个,看起来你在每个三角形的基础上做法线会给你平面阴影,所以你看到的可能是正确的。
如果您希望计算每个顶点的法线,请使用以下内容:
((x + 1) - (X-1))X((Y + 1) - (Y-1))
其中X是网格上X方向的顶点,Y方向上的Y.