渲染具有多个索引的网格 [英] Rendering meshes with multiple indices

查看:110
本文介绍了渲染具有多个索引的网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些顶点数据.位置,法线,纹理坐标.我可能是从.obj文件或其他某种格式加载的.也许我在画一个立方体.但是每个顶点数据都有其自己的索引.我可以使用OpenGL/Direct3D渲染此网格数据吗?

解决方案

从最一般的意义上讲,不是. OpenGL和Direct3D每个顶点只允许一个索引;每个顶点只允许一个索引.索引从每个顶点数据流中获取.因此,每个组件的唯一组合都必须具有自己的单独索引.

因此,如果您有一个立方体,每个面都有自己的法线,则需要大量复制位置和法线数据.即使多维数据集只有8个 unique 位置和6个唯一法线,您仍需要24个位置和24个法线.

您最好的选择是简单地接受您的数据将更大.大量的模型格式将使用多个索引.您需要先修正此顶点数据,然后才能使用它进行渲染.许多网格物体加载工具(例如Open Asset Importer)将为您执行此修复程序.

还应注意,大多数网格都不是立方体.大多数网格在绝大多数顶点上都是平滑的,只是偶尔具有不同的法线/纹理坐标/等.因此,尽管通常是针对简单的几何形状,但实际模型很少具有大量的顶点重复.

GL 3.x和D3D10

对于D3D10/OpenGL 3.x类硬件,可以避免执行修复并直接使用多个索引属性.但是,请注意,这可能会降低渲染性能.

以下讨论将使用OpenGL术语,但是Direct3D v10及更高版本具有等效的功能.

这个想法是从顶点着色器手动访问不同的顶点属性.除了直接发送顶点属性外,传递的属性实际上是该特定顶点的索引.然后,顶点着色器使用索引通过一个或多个缓冲区纹理来访问实际属性.. /p>

属性可以存储在多个缓冲区纹理中或全部存储在一个缓冲区中.如果使用后者,则着色器将需要向每个索引添加偏移量,以便在缓冲区中找到相应属性的起始索引.

可以以多种方式压缩常规顶点属性.缓冲区纹理具有较少的压缩方式,仅允许相对数量有限的顶点格式(通过图像格式)使用数量有限的顶点他们支持).

请再次注意,这些技术中的任何一种都可能会降低整体顶点处理性能.因此,只有在用尽所有其他压缩或优化选项之后,才应在内存限制最大的情况下使用它.

OpenGL ES 3.0也提供了缓冲区纹理.较高的OpenGL版本允许您通过 SSBO 更直接地读取缓冲区对象,而不是缓冲区纹理,可能具有更好的性能特征.

I have some vertex data. Positions, normals, texture coordinates. I probably loaded it from a .obj file or some other format. Maybe I'm drawing a cube. But each piece of vertex data has its own index. Can I render this mesh data using OpenGL/Direct3D?

解决方案

In the most general sense, no. OpenGL and Direct3D only allow one index per vertex; the index fetches from each stream of vertex data. Therefore, every unique combination of components must have its own separate index.

So if you have a cube, where each face has its own normal, you will need to replicate the position and normal data a lot. You will need 24 positions and 24 normals, even though the cube will only have 8 unique positions and 6 unique normals.

Your best bet is to simply accept that your data will be larger. A great many model formats will use multiple indices; you will need to fixup this vertex data before you can render with it. Many mesh loading tools, such as Open Asset Importer, will perform this fixup for you.

It should also be noted that most meshes are not cubes. Most meshes are smooth across the vast majority of vertices, only occasionally having different normals/texture coordinates/etc. So while this often comes up for simple geometric shapes, real models rarely have substantial amounts of vertex duplication.

GL 3.x and D3D10

For D3D10/OpenGL 3.x-class hardware, it is possible to avoid performing fixup and use multiple indexed attributes directly. However, be advised that this will likely decrease rendering performance.

The following discussion will use the OpenGL terminology, but Direct3D v10 and above has equivalent functionality.

The idea is to manually access the different vertex attributes from the vertex shader. Instead of sending the vertex attributes directly, the attributes that are passed are actually the indices for that particular vertex. The vertex shader then uses the indices to access the actual attribute through one or more buffer textures.

Attributes can be stored in multiple buffer textures or all within one. If the latter is used, then the shader will need an offset to add to each index in order to find the corresponding attribute's start index in the buffer.

Regular vertex attributes can be compressed in many ways. Buffer textures have fewer means of compression, allowing only a relatively limited number of vertex formats (via the image formats they support).

Please note again that any of these techniques may decrease overall vertex processing performance. Therefore, it should only be used in the most memory-limited of circumstances, after all other options for compression or optimization have been exhausted.

OpenGL ES 3.0 provides buffer textures as well. Higher OpenGL versions allow you to read buffer objects more directly via SSBOs rather than buffer textures, which might have better performance characteristics.

这篇关于渲染具有多个索引的网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆