Change box with shader and mesh

Hello friends
I was able to change the shape of a box with Vertex in the shader
And with changes in the mesh, I was able to change the shape of the box
What is the difference between changing the box by changing the mesh and changing the vertex in the shader?

Hi @MaDBoY,

That’s a very good question:

  1. Changing the mesh in JavaScript using the Mesh API involves using the CPU to update the vertex buffer and reupload it to the GPU.

  2. Changing the mesh in a vertex shader involves updating its position and other properties (e.g. UV coordinates, normals etc) per vertex in the shader.

The 1st scenario is taxing the CPU, the 2nd one the GPU. The GPU usually is way faster in this kind of operation but it comes down to what you are trying to do.

Are you updating the mesh once or at least a few times and you are also using it as a trimesh collider? You can only go with the 1st scenario, since physics need access to the mesh (it needs to live in RAM in addition, not only in the GPU memory).

Are you updating the mesh per frame e.g. doing a nice vertex animation? Definitely do it in the GPU (2nd case), it’s much faster and performance will not suffer (unless you are animating A LOT of vertices per frame).

Hope that helps as a starting point.