OBJ 格式以及平面着色与平滑着色

发布于 2024-11-06 04:21:01 字数 392 浏览 1 评论 0原文

我正在使用 OpenGL ES 1.1 并致力于将 Blender 导出的 OBJ 转换为一些包含顶点数据的二进制文件。实际上我已经有了一个可用的工具,但我正在努力改变一些东西并遇到了一个问题。

即使使用平滑着色,似乎通过正确的法线(垂直于面部平面),它也能实现面部的平坦外观。启用平滑着色和正确的法线(只需在 Blender 中标记为锐利的边缘并应用边缘分割修改器),我可以获得平滑部分和锐利边缘的效果。

我要说的这个问题带来了两个问题。

  1. 从平滑着色和使用法线的角度来看,OBJ 文件中表示平滑或平坦着色的“s 1”或“s off”线是否完全没有必要?

  2. 当在 OpenGL 中实际设置为平面着色时,法线是否完全被忽略(或只是假设全部垂直于面)?

I'm using OpenGL ES 1.1 and working on converting an OBJ export from Blender into some binary files containing vertex data. I actually already have a working tool, but I'm working on changing some things and came across a question.

Even with Smooth shading, it seems that with correct normals (perpendicular to the face plane) it achieves a flat appearance for faces. With Smooth shading enabled and the proper normals (simply via edges marked as sharp in Blender and an edge-split modifier applied), I can get the affect of smooth parts and sharp edges.

Where I'm going with this brings 2 questions.

  1. Are the "s 1" or "s off" lines where smooth or flat shading is denoted in the OBJ file completely unnecessary from a smooth shading and use of normals standpoint?

  2. When actually set to Flat shading in OpenGL, are normals completely ignored (or just assumed to all be perpendicular to the faces)?

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

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

发布评论

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

评论(2

淡淡の花香 2024-11-13 04:21:01

为了使顶点看起来平滑,其法线必须是相邻面法线的平均值(或类似的东西),但不垂直于面平面(除非您指的是所有相邻面的平均平面)。

GL_FLAT 意味着,面的颜色不是在三角形上插值,而是从单个三角形角获取(不知道是第一个还是最后一个)。该颜色来自顶点颜色或顶点光照,因此实际上您可以获得每个面的法线,但这不一定是面方向,而是角顶点的法线。

如果您在 OBJ 文件中获得了每个顶点法线,则不需要 s 部分。但您可以使用它们来计算顶点法线。 s 部分是平滑组,将被解释为 32 位位域。因此,实际上有 32 个不同的平滑组,并且每个面都可以属于多个面。因此,“s 5”线之后的所有面都是平滑组 1 和 3(第一和第三位集)的一部分。当两个相邻面属于同一平滑组时,它们之间的边缘是平滑的(顶点共享法线)。这样您就可以重建必要的每顶点法线。

For a vertex to look smooth, its normal has to be the average of the adjacent face normals (or something the like), but not perpendicular to the face plane (except if you meaned the average plane of all its adjacent faces).

GL_FLAT means, the color of a face is not interpolated over the triangle, but taken from a single triangle corner (don't know which, first or last). This color comes either from vertex colors or vertex lighting, so in fact you get per-face normals, but this is not neccessarily the faces direction, but the normal of a corner vertex.

If you got per vertex normals in the OBJ file you do not need the s parts. But you can use these to compute vertex normals. The s parts are the smoothing groups and are to be interpreted as 32bit bitfields. So there are actually 32 different smoothing groups and every face can be part of more than one. So all faces after an "s 5" line are part of smoothing groups 1 and 3 (first and third bits set). When two neighbouring faces are part of the same smoothing group, the edge between them is smooth (vertices share normals). This way you can reconstruct the neccessary per-vertex normals.

¢蛋碎的人ぎ生 2024-11-13 04:21:01

当我使用每个顶点法线时,更改 gl_flat 和 gl_smooth 之间的模式似乎不会影响我的渲染。据我所知,你的问题是每张脸只有一个法线。为了实现平滑着色,每个面应具有三个法线,每个顶点一个法线,并且它们都应该不同。例如,圆柱体的法线,如果投影到圆柱体内部,则应全部相交于圆柱体的轴。如果您的模型具有平滑法线,则 OBJ 导出应导出每个顶点法线。听起来您可能正在分配每个面的法线。就 OpenGL-ES 中的渲染而言,不使用平滑组,仅使用法线。

Changing the mode between gl_flat and gl_smooth doesn't seem to affect my rendering when I'm using per vertex normals. Your problem from what I can tell is that each face only has one normal. For smooth shading, each face should have three normals, one for each vertex, and they should all be different. For example, the normals of a cylinder, if projected inside of the cylinder, should all intersect at the axis of the cylinder. If your model has smooth normals, then an OBJ export should export per vertex normals. It sounds like you are probably assigning per face normals. As far as rendering in OpenGL-ES, the smoothing groups aren't used, only normals.

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