Search code examples
performance3dvertex-buffer

Drawing Meshes with Transformation


Say there are many different meshes with transformations that changes more or less each frame, what would in general be the faster of these drawing methods:

  1. For each frame fill a big vertex buffer with the transformed vertices of the mesh (transformation is done on CPU and vertices copied to the buffer each frame).
  2. For each object creation insert the non-transformed vertices of the mesh, then when drawing send the transformation of each mesh as a uniform parameter (transformation done on GPU, vertices are copied at mesh creation).

We can assume that all meshes are drawn each frame so not copying vertices for case 1) would not matter.


Solution

  • Option #2 will almost always be faster. If you have N vertices and M transformations, it's the difference between doing ~N arithmetic ops on a CPU followed by a ~N bus transfer, versus doing a ~M bus transfer (faster) followed by ~N arithmetic ops on a GPU (also faster).

    The only times this would be a lose is if your CPU were way faster than your GPU in terms of total throughput for vertex manipulation (very unlikely), or if M is the same order of magnitude as N.