DirectX 中顶点法线的计算

发布于 2024-07-29 08:19:50 字数 143 浏览 3 评论 0原文

作为学习经验,我正在编写一个立即模式管理的 DirectX 9 应用程序。

我手动计算场景中所有三角形的顶点法线,以实现平滑的 Gouraud 着色。

这按预期工作,但我猜这不是最有效的方法。 是否可以让 GPU 帮我做这件事?

As a learning experience, I'm writing an Immediate mode managed DirectX 9 application.

I'm manually calculating Vertex normals across all triangles in a scene to allow smooth Gouraud shading.

This works as expected, but I'm guessing this is not the most efficient approach. Is it possible to get the GPU to do this for me?

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

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

发布评论

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

评论(1

仙气飘飘 2024-08-05 08:19:50

理论上,您可以在顶点着色器内生成顶点法线。 不过,每次使用该着色器渲染网格时都需要进行计算,所以为什么不提前生成它们呢。

如果你的意思是你想在渲染之前生成它们,但使用 GPU 而不是 CPU,我会说,不值得为你只要做一次的事情而费心加速。 此外,我不确定 DX9 是否有办法从着色器获取计算出的顶点信息(DX10 有)。

总而言之,在大多数情况下最好的做法是传统的:在保存包含网格的数据文件的程序中计算顶点法线 - 将其作为预计算步骤进行。 通常,如果网格来自 Max 或 Maya 等 3D 包,则您会拥有它们,因为法线中存在艺术信息,除非您知道整个网格应该完全平滑(或有面),否则在一般情况下它是不可计算的。

You could in theory generate the vertex normals inside the vertex shader. That involves computation every single time you render a mesh using that shader though, so why not generate them in advance.

If you mean you want to generate them in advance of rendering, but use the GPU instead of the CPU, I would say that it's not worth the bother of speeding up something you are only going to do once. Besides, I'm not sure if DX9 has a way to get computed vertex information back from a shader (DX10 does).

All in all, the best thing to do in most cases is the traditional: compute vertex normals in the program that saves the data files that contain the meshes - do it as a pre-computation step. Usually you have them if the mesh came from a 3d package like Max or Maya, because there is artistic information in the normals, unless you know the whole mesh is supposed to be perfectly smooth (or faceted), it's not computable in the general case.

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