Usage of osg::BufferObjects

10 views
Skip to first unread message

Werner Modenbach

unread,
May 26, 2021, 10:15:15 AMMay 26
to OpenSceneGraph Users
Hi users,

I'm currently experimenting with the usage of meshlets in OSG.
Robert already implemented the corresponding draw methods. Thanks Robert!
The main thing necessary to make it work is the indexed access to almost every data given by the CPU,
which is very limited in the traditional shader pipeline. I.e. a vertex shader can only access 1 Vertex at a time.
Mesh shaders can fetch any vertex by index and any number of vertices.

A typical use/definition of the shader structures may be:
//-------------------------------------
// transform_ub: Uniform buffer for transformations
//
layout (std140, binding = 0) uniform uniforms_t { 
  mat4 ViewProjectionMatrix;
  mat4 ModelMatrix;
} transform_ub;
 
//-------------------------------------
// vb: storage buffer for vertices.
//
struct s_vertex {
	vec4 position;
	vec4 color;
};
 
layout (std430, binding = 1) buffer _vertices {
	s_vertex vertices[];
} vb;
 
 
//-------------------------------------
// mbuf: storage buffer for meshlets.
//
struct s_meshlet {
	uint vertices[64];
	uint indices[378]; // up to 126 triangles
	uint vertex_count;
	uint index_count;
};
 
layout (std430, binding = 2) buffer _meshlets {
	s_meshlet meshlets[];
} mbuf;


So all data is given via BufferObjects.

Meshlet shaders are kind of compute shaders with output to the rasterizer and thus a fragment shader.
The indexed access is like:

  uint mi = gl_WorkGroupID.x;
  uint thread_id = gl_LocalInvocationID.x;
 
  uint vertex_count = mbuf.meshlets[mi].vertex_count;
  for (uint i = 0; i < vertex_count; ++i) {
    uint vi = mbuf.meshlets[mi].vertices[i];
 
Precondition for the indexed access is having the data given via BufferObjects.
In OSG we have only predefined types (Indices, Vertices and Images) for BufferObjects.

Has anybody any experience deriving a more general class for putting arbitrary structs in BufferObjects (i.e. struct s_meshlet)?
I think that shouldn't be such a big deal or am I overseeing something.

@Robert: Or can you provide any hints to me for creating such a derived class?

If I manage getting this working I'll provide it to the community because mesh shaders are really great for many applications!

Many thanks in advance

- Werner -
Reply all
Reply to author
Forward
0 new messages