0

I have a list of 3D vertices which I can easily render as a pointcloud by passing the whole list to my vertex shader, setting gl_Position = pos, then setting FragColor = vec4(1.0, 1.0, 1.0, 1.0)and use GL_POINTS in the drawing function.

I would now like to render an actual cube at that vertex position, with the vertex being the center of the cube and some given width. How can I achieve this in the most easy and performant way? Looping through all vertices, loading a cube into a buffer and then passing the vertex position to the vertex shader to draw each cube individually does not seem to be feasible to me, or is that the way to go?

Ke Vin
  • 2,004
  • 1
  • 18
  • 28
  • 3
    "the most easy and performant way" Hmm, those two things are very often excluding each other. Could you pick the one which is more important to you? – Yunnosch Dec 19 '19 at 09:29
  • Please explain "does not seem to be feasible". What makes you think so? – Yunnosch Dec 19 '19 at 09:30
  • Take a look at geometry shaders. You could let the GPU generate the needed vertices. If this is easy or fast or both or neither depends on some factors (as always). – Lukas-T Dec 19 '19 at 09:35
  • @Yunnosch It does not seem to leverage the GPUs parallel character when I have to call a drawing function iteratively in the CPU again and again. – Ke Vin Dec 19 '19 at 09:36
  • Thanks for answering my second question. How about the first one now? – Yunnosch Dec 19 '19 at 09:44
  • 2
    An option is to use a [Geometry Shader](https://www.khronos.org/opengl/wiki/Geometry_Shader) to generate the cube. Another option would be to use [Instanced Rendering](https://www.khronos.org/opengl/wiki/Vertex_Rendering#Instancing). Draw the cube multiple times. The individual positions for the instances can be stored in a [Shader Storage Buffer Object](https://www.khronos.org/opengl/wiki/Shader_Storage_Buffer_Object) – Rabbid76 Dec 19 '19 at 09:44
  • @Yunnosch Performance – Ke Vin Dec 19 '19 at 09:46
  • @Rabbid76 thank you, I will look into these! – Ke Vin Dec 19 '19 at 09:47
  • 1
    Instanced rendering will be simpler and more performant than a geometry shader here, I recommend that approach. – Andrea Dec 20 '19 at 13:54
  • Yep geometry shaders are slow and not very reliable on non nVidia cars :( at least last time I used them actively ... which was few years back so the situation might changed ... – Spektre Dec 21 '19 at 11:46

0 Answers0