我可以在GPU中计算法线吗?
我有一个 opengl 应用程序,可以加载 dxf 并将其绘制在屏幕上, 每次我需要计算法线。有没有办法在 GPU 而不是 CPU 中计算法线?如果是这样怎么办?
I have an opengl application that loads a dxf and draws it on the screen,
each time i need to calculate normals. is there a way to calculate normals in GPU instead of CPU ? if so how ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以从几何着色器中计算“平面着色”(每个面一个法线)法线。每个三角形一个,“动态”,使用叉积。您无法以这种方式生成“平滑”法线,因为 GS 没有有关邻居的信息。
如果网格是参数化的(例如元球),则可以通过采样几个附近的函数值来计算法线。这也可以在 GPU 上完成。
如果网格基于高度图或类似的东西,您还可以在着色器中计算法线。
如果 GPU 支持 CUDA、OpenCL 或类似的东西,并且如果它可以处理任意数据数组,那么您也可以使用传统技术在 GPU 上计算法线。
另外,我认为 5 年前(大约)我看到了一篇名为“GPU 上的正常平滑”或“GPU 上的正常生成”之类的论文。它的第一页上有一个平底阴影的反光多边形心形。不幸的是,我找不到那篇论文,而且我不确定它是否存在(或者我在哪里看到它)。您也许可以在 GDC 论文、SIGGRAPH 论文、ATI SDK 或 NVidia SDK 中找到它(如果存在)。
You can calculate "flat-shaded" (one normal per face) normals from within geometry shader. One for each triangle, "on the fly", using cross-products. You cannot generate "smooth" normals that way, because GS doesn't have info about neighbors.
If mesh is parametric (say, metaballs), normal can be calculated by sampling few nearby function values. This can also be done on GPU.
You can also calculate normals in shader if mesh is based on heightmap or something similar.
IF GPU supports CUDA, OpenCL or something similar, AND if it can process arbitrary arrays of data, then you can probably also compute normals on the GPU, using traditional tehcniques.
Also, I think that 5 years ago (or so) I saw a paper titled something like "normal smoothing on GPU" or "normal generation on GPU". It had a flat-shaded reflective polygonal heart on the first page. Unfortunately, I cannot locate that paper, and I'm not exactly sure if it existed (or where I saw it). You may be able to find it(if it exists) in GDC papers, SIGGRAPH papers, ATI SDK or NVidia SDK.
您必须使用着色器。
您可以使用 GLSL 几何着色器。这是面部法线的 GLSL 版本。顶点法线需要更多工作,因为它们必须考虑相邻顶点。
You'll have to use shaders.
You can use a GLSL geometry shader. Here's the GLSL version for face normals. Vertices normals require more work since they have to take neighboring vertices into account.
是的,这是可能的。您将需要在 Cg 中了解着色器。
官方书籍。
Yes, it's possible. You will want to learn about Shaders in Cg.
Official book.
看看
glEnable(GL_AUTO_NORMAL)
。Have a look at
glEnable(GL_AUTO_NORMAL)
.