Implementing instanced meshes with compute shaders
In the previous recipe, we learned the fundamentals of instanced rendering. While that approach covers various aspects of rendering geometry instances, such as handling model matrices and materials, it’s not yet a practical implementation. Let’s build on that example and show how to render instanced meshes loaded from a .gltf
file.
To make this recipe more interesting, we’ll enhance the example by precalculating per-instance model matrices using a compute shader.
Getting ready
Make sure you read the previous recipe, Rendering instanced geometry. The source code for this recipe can be found in Chapter05/04_InstancedMeshes
.
How to do it…
Let’s skim the C++ code to understand the big picture
- First, we generate random positions and initial rotation angles for our meshes. We use 32,000 meshes because our GPU cannot handle 1 million meshes with this naïve brute-force...