Form primitive based on vertexID

Hi All, beginner here to check if his idea isn’t madness :wink:

I’ve recorded the displacement of a 3d model into a texture. The width of the texture represents the pointnumbers(or vertexnumbers) and the height the duration of the displacement animation. So every pixel in every row represents the position of that vertex (based on float rgb values, would be a vec3).

I’ve also recorded a texture regarding the primitives. Width would be the primitivenumber, height the duration of the animation. The rgb value of every pixel represents the 3 vertexnumbers (also vec3) which are used to form the primitive.

I would like to rebuild my geometry based on these two textures. I’ve got through the vertexshader stage, but now for the geometry shader:

I would like to tell the shader that the formation of every primitive needs to be looked up in the texture I’ve mentioned before. So primitive 1 would look at pixel one, extracts the rgb data, now has the 3 vertexID numbers that needs to be used to form itself, the next step would be to extract the positions of these vertices from the other texture.

My gut feeling tells me that I somehow need to put in a textelfetch() function.

Would be great of someone can push me in the right direction!

Best!

There are two ways to go about this:

  1. The mode parameter to glDrawArrays is GL_POINTS, the vertex shader is empty, the geometry shader uses gl_PrimitiveIDIn as the horizontal index to the topology texture to obtain the three vertex indices which are used as the horizontal index to the positions texture.

  2. The mode parameter to glDrawArrays is GL_TRIANGLES, the vertex shader uses gl_VertexID/3 as the horizontal index to the topology texture to obtain the three vertex indices, one of which (depending upon gl_VertexID%3 is stored in an output variable. The geometry shader uses this as the horizontal index to the positions texture.

Having said that, it’s uncommon to animate topology. Normally you just animate positions; removing a section of geometry is achieved by making it into a point (i.e. giving all vertices the same positions).

1 Like

good content!
you can see all my content !

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.