which is the most optimal and correct way to drawing many different dynamic 3D models (they are animated and change every frame)

StackOverflow https://stackoverflow.com/questions/19717804

  •  02-07-2022
  •  | 
  •  

Question

I need to know how I can render many different 3D models, which change their geometry to each frame (are animated models), don't repeat models and textures.

I carry all models and for each created an "object" model class.

What is the most optimal way to render them?

  1. To use 1 VBO for each 3D model
  2. To use a single VBO for all models (to be all different, I do not see this option possible)

I work with OpenGL 3.x or higher, C++ on Windows.

Was it helpful?

Solution

TL; DR - there's no silver bullet when it comes to rendering performance

Why is that? That depends on the complicated process that gets your data, converts it, pushes it to GPU and then makes pixels on the screen flicker. So, instead of "one best way", a few of guideliness appeared that might usually improve the performance.

  • Keep all the necessary data on the GPU (because the closer to the screen, the shorter way electrons have to go :))
  • Send as little data to GPU between frames as possible
  • Don't sync needlessly between CPU and GPU (that's like trying to run two high speed trains on parallel tracks, but insisting on slowing them down to the point where you can pass something through the window every once in a while),

Now, it's obvious that if you want to have a model that will change, you can't have the cake and eat it. You have to made tradeoffs. Simply put, dynamic objects will never render as fast as static ones. So, what should you do?

  • Hint GPU about the data usage (GL_STREAM_DRAW or GL_DYNAMIC_DRAW) - that should guarantee optimal memory arrangement.
  • Don't use interleaved buffers to mix static vertex attributes with dynamic ones - if you divide the memory, you can batch-update the geometry leaving texture coordinates intact, for example.
  • Try to do as much as you can purely on the GPU - with compute shaders and transform feedback, it might well be possible to store whole animation data as a buffer itself and calculate it on GPU, avoiding expensive syncs.

And last but not least, always carefully measure the impact of your change on performance. Going blindly won't help. Measure accurately and thoroughly (even stuff like shader compilation time might matter sometimes!). Then, even if you go by trial-and-error, there's a hope you'll get somewhere.


And to address one of your points in particular; whether it's one large VBO and a few smaller ones doesn't really matter, but a huge one might have problems in fitting in memory. You can still update parts of it, and what matters most is the memory arrangement inside of it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top