DX10 地形法线

发布于 2024-10-17 01:45:45 字数 1233 浏览 4 评论 0原文

我使用柏林噪声生成地形,然后使用以下方法计算法线:

    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:
Example

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遮了一弯 2024-10-24 01:45:45

我对 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文