DX10 地形法线
我使用柏林噪声生成地形,然后使用以下方法计算法线:
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);
但是,这会导致网格线出现在网格方块之间。 有什么想法吗?
例子:
I'm generating terrain using perlin noise and then computing normals using:
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);
However this is causing grid lines to appear between grid squares.
Any ideas what the problem is?
Example:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对 DX10 不太了解,但我最近在 OpenGL 中做了这个,看起来你是在每个三角形的基础上做你的法线,这会给你平坦的阴影,所以你看到的可能是正确的。
如果您想计算每个顶点的法线,请使用以下内容:
((x+1) - (X-1)) X ((Y+1) - (Y-1))
其中 X 是 X 方向上的顶点Y 方向上的网格和 Y。
I don't know much about DX10 but I recently did this in OpenGL, it looks like you're doing your normals on a per triangle basis which will give you flat shading, so what you see is probably correct.
If you wish to calculate your normals per vertex use something like:
((x+1) - (X-1)) X ((Y+1) - (Y-1))
where X is the vertex in the X direction on the grid and Y in the Y direction.