ShaderMaterial does not update mesh vertex data

I’m using BABYLON.ShaderMaterial to manually modify the vertex coordinates of a mesh by using vertex and fragment shaders.

The mesh is visually rendered correctly on screen, but when I call the mesh.getVerticesData() method, the returned data is wrong and is not the vertex coordinates updated from the vertex shader. The data that I get is the same as from the original mesh shape. I think something is missing for the mesh to update properly.

Here is a demo with the code:

As seen in the demo, the bounding mesh does not obtain the same shape as the new mesh.

What have I missed here?

mesh.getVerticesData() only returns the vertices from the CPU side. Getting modified vertices back from the GPU can be done in WebGL2 using transform feedback buffers [source], but I have no idea how to use them.

1 Like

@Gijs is correct. As you update the mesh on GPU side, the CPU side is left unchanged.

You can still force the bounding box to update correctly by calling:

1 Like

Also…welcome to the Babylon Family @johan!