-
Hello all, I am quite confused about how to use the output from the library in a GLSL mesh shader. |
Beta Was this translation helpful? Give feedback.
-
Let me know if you have ideas for how to improve documentation for meshopt_Meshlet structure (https://github.com/zeux/meshoptimizer/blob/master/src/meshoptimizer.h#L473-L489) or mesh shading section (https://github.com/zeux/meshoptimizer/blob/master/README.md#mesh-shading) except for adding a GLSL example - which I will do. The vertices offset refers to the offset in the vertex indirection buffer (meshlet_vertices) and is just there so that from a mesh shader you can quickly locate the relevant section. Here's an example from https://github.com/zeux/niagara (reworked a little to simplify, untested but you can refer to the actual shader here https://github.com/zeux/niagara/blob/master/src/shaders/meshlet.mesh.glsl although be warned that it's more complex as it repacks the data a little for efficiency and uses large shared buffers for all meshes in a scene): layout(binding = 0) readonly buffer MeshletVertices
{
uint meshletVertices[];
};
layout(binding = 1) readonly buffer MeshletIndices
{
uint8_t meshletIndices[];
};
...
uint vertexCount = uint(meshlets[mi].vertexCount);
uint triangleCount = uint(meshlets[mi].triangleCount);
SetMeshOutputsEXT(vertexCount, triangleCount);
uint vertexOffset = uint(meshlets[mi].vertexOffset);
uint indexOffset = uint(meshlets[mi].indexOffset);
for (uint i = gl_LocalInvocationIndex; i < vertexCount; i += gl_WorkGroupSize.x)
{
uint vi = meshletVertices[vertexOffset + i];
vec3 position = vec3(vertices[vi].vx, vertices[vi].vy, vertices[vi].vz);
gl_MeshVerticesEXT[i].gl_Position = globals.worldViewProjection * vec4(position, 1);
}
for (uint i = gl_LocalInvocationIndex; i < triangleCount; i += gl_WorkGroupSize.x)
{
uint offset = indexOffset + i * 3;
uint a = uint(meshletIndices[offset]), b = uint(meshletIndices[offset + 1]), c = uint(meshletIndices[offset + 2]);
gl_PrimitiveTriangleIndicesEXT[i] = uvec3(a, b, c);
} |
Beta Was this translation helpful? Give feedback.
-
Many thanks zeux for the reply. Again, it helped a lot and I can optimize now mesh with interleaved vertex/normal array. |
Beta Was this translation helpful? Give feedback.
Let me know if you have ideas for how to improve documentation for meshopt_Meshlet structure (https://github.com/zeux/meshoptimizer/blob/master/src/meshoptimizer.h#L473-L489) or mesh shading section (https://github.com/zeux/meshoptimizer/blob/master/README.md#mesh-shading) except for adding a GLSL example - which I will do.
The vertices offset refers to the offset in the vertex indirection buffer (meshlet_vertices) and is just there so that from a mesh shader you can quickly locate the relevant section. Here's an example from https://github.com/zeux/niagara (reworked a little to simplify, untested but you can refer to the actual shader here https://github.com/zeux/niagara/blob/master/src/…