9
$\begingroup$

As of now, when rendering my scene and while iterating through the scene graph, for each node its model matrix is calculated from the parent's model matrix and the scene node's pose. This is quite simple and already reduces the number of matrix multiplications to one multiplication per node and frame.

But all these matrix multiplications have to be done on the CPU and in every frame to be able to perform (multiple consecutive) movements of scene nodes very fast. The GPU, however, is probably much better suited to perform lots of matrix multiplications, so I'm thinking about sending multiple partial model matrices to the vertex shader instead of computing everything on the CPU.

Sending every single part (so the pose of every node) to the GPU probably does not make much sense, as in this case all the computations are done for every vertex instead of every node, which would actually decrease performance. But maybe scene nodes with lots of children or only non-moving children (relative to its parent) could be a place to split the model matrix and shift the multiplications to the shader.

So, when is it better to send partial model matrices to the shader and move the multiplication to the GPU? Or is it simply a bad idea to to this?

$\endgroup$

2 Answers 2

9
$\begingroup$

Doing math with uniforms is a shader won't usually get you any performance over doing it on the CPU. A CPU isn't slower than a GPU at doing matrix math, it just isn't structured so as to do large amounts of math in parallel. But you have to actually do that large amount of math to get a win. Sending extra data to the GPU just to have the GPU multiply two matrices together will rarely net you anything.

Now, say you have a buffer of skinning matrices. It might start to matter whether you transform them all into world space on the CPU or just pass an extra model-to-world-space matrix to the GPU. But even then it depends on your ratio of vertices to bones.

$\endgroup$
1
  • $\begingroup$ I depends on the amount of calculations.GPU is really fast about math operations.So it is a matter of try and benchmarking. $\endgroup$
    – Michael IV
    Commented Sep 3, 2015 at 9:30
5
$\begingroup$

Rarely, if ever. You half-answered it in your own question: a vertex shader runs once per-vertex, a fragment shader once per-fragment. If you're not doing something that's unique to that vertex or fragment, then you're doing literally the exact same thing every time you invoke a shader. That doesn't sound more efficient to me.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.