2
\$\begingroup\$

In a Unity game I have an object whose mesh is made of around 10k vertices and I have to make changes to these vertices (position, color, etc) almost every frame.

Considering that such object is always visible to the main camera, I was wondering if there is a way for me to keep the whole mesh in the GPU and do the changes to its vertices there with a Compute Shader.

I know how to use Compute Shaders. What I can't find out is how should I, in Unity, keep a mesh entirely in the GPU. I could use 3 StructuredBuffers, 1 for the vertices, 1 for the vertex-colors and 1 for the UVs of the mesh. However, that is not enough to properly form the mesh in the GPU (it means, with only those I would be displaying just the vertices on scree as in a point-mesh, not exactly the triangles of the mesh).

Is there a way I could achieve such a thing? If so, I would highly appreciate a short example in pseudo-code to point me in the right direction.

\$\endgroup\$
  • \$\begingroup\$ skeletal animation is not an option? \$\endgroup\$ – ratchet freak Jun 17 '16 at 13:18
  • \$\begingroup\$ @ratchetfreak Unfortunately not. I don't see how that would benefit the situation. I need to render the mesh entirely from the GPU (without the calls from the CPU), getting vertices, vertex-color and UV from a Structured Buffer calculated in a Command Shader \$\endgroup\$ – AndraSol Jun 17 '16 at 19:10
  • \$\begingroup\$ Are there chunks of the object moving together (like an arm or leg)? If you then you can define "bones" for each of those groups and assign an ID to the vertices and pass an array of matrices that describes how that group moves relative to the center. \$\endgroup\$ – ratchet freak Jun 17 '16 at 19:51
  • \$\begingroup\$ @ratchetfreak No, there aren't. It's (fortunately) simpler: it's a one-mesh object. And not very complex. I might even be able to treat like a mere sphere for the sake of example \$\endgroup\$ – AndraSol Jun 18 '16 at 0:33
  • \$\begingroup\$ @AndraSol Did you ever coming up with a solution for this? \$\endgroup\$ – Jacksonkr Dec 30 '18 at 20:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.