-
|
Hello! I have recently been using meshoptimizer at my day job, and have been very impressed by its results. Now I wish to use it in my side project, specifically for optimizing the vertex cache hit rate of my voxel models. To maximize the vertex processing performance of my voxel models, I have reduced them to a mere 3 bytes each, just an 8-bit unsigned integer 3D position. The normal and texture projection data is then stored per triangle instead, which I then read in the fragment shader using gl_PrimitiveID. Unfortunately, this kind of per-triangle seems to be somewhat incompatible with meshopt_optimizeVertexCache(), as the triangles end up being reordered, but my per-triangle data remains the same as before. While I could in theory build my own remapping by matching triangles in the original and reordered index buffers, this would be a bit slow. Is there any functionality in meshoptimizer that I've missed that would allow me to reorder the per-triangle data together with the triangles in the index buffer? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
|
There isn't a way to do this out of the box. Probably remapping the triangle data with a hash map after the function completes is the best option here; optimizeVertexCache keeps the order of indices in the triangle consistent I believe, so you can just key the hash map by the index triple. Not directly related, but beware: using gl_PrimitiveID in fragment shader on all NVidia hardware (and early AMD GPUs, but that's less of a concern because they aren't as common) is not great for performance. It switches the pipeline to some sort of alternate mode of operation that is a little similar to their FastGS feature, and results in a reduced rate of geometry processing. Of course you may not necessarily have a good alternative option, and if your terrain is voxel based a-la Minecraft (each quad is using separate normals/triangles), then the penalty is not as high as it is in the general case, although in that case vertex cache optimization is also less important. For smooth shading / isosurface meshing it can be a problem. |
Beta Was this translation helpful? Give feedback.
There isn't a way to do this out of the box. Probably remapping the triangle data with a hash map after the function completes is the best option here; optimizeVertexCache keeps the order of indices in the triangle consistent I believe, so you can just key the hash map by the index triple.
Not directly related, but beware: using gl_PrimitiveID in fragment shader on all NVidia hardware (and early AMD GPUs, but that's less of a concern because they aren't as common) is not great for performance. It switches the pipeline to some sort of alternate mode of operation that is a little similar to their FastGS feature, and results in a reduced rate of geometry processing. Of course you may not nec…