opengl - Rendering meshes with multiple indices -
i have vertex data. positions, normals, texture coordinates. loaded .obj file or other format. each piece of vertex data has own index. can render mesh data using opengl/direct3d?
in general sense, no. opengl , direct3d allow 1 index per vertex; index fetches each stream of vertex data. therefore, every unique combination of components must have own separate index.
so if have cube, each face has own normal, need replicate position , normal data lot. need 24 positions , 24 normals, though cube have 8 unique positions , 6 unique normals.
your best bet accept data larger. great many model formats use multiple indices; need fixup vertex data before can render it. many mesh loading tools, such open asset importer, perform fixup you.
gl 3.x , d3d10
for d3d10/opengl 3.x-class hardware, possible avoid performing fixup , use multiple indexed attributes directly. however, advised decrease rendering performance.
the following discussion use opengl terminology, direct3d v10 , above has equivalent functionality.
the idea manually access different vertex attributes vertex shader. instead of sending vertex attributes directly, attributes passed indices particular vertex. vertex shader uses indices access actual attribute through 1 or more buffer textures.
attributes can stored in multiple buffer textures or within one. if latter used, shader need offset add each index in order find corresponding attribute's start index in buffer.
regular vertex attributes can compressed in many ways. buffer textures have fewer means of compression, allowing relatively limited number of vertex formats (via image formats support).
please note again of these techniques may decrease overall vertex processing performance. therefore, should used in memory-limited of circumstances, after other options compression or optimization have been exhausted.
opengl es 3.0 provides buffer textures well.
Comments
Post a Comment