Is it possible to send ComputeShader GPU data directly to mesh without retrieving it back to CPU?

Hey,

Currently, I am using ComputeShader to retrieve displaced vertices data from the GPU to the CPU. UI then use this data to transform a mesh and obtain its exact world position via the ComputeBuffer.GetData method.

However, as the GetData method doesnt scale very well, I am exploring alternative options to transform the mesh and seperate the required calculations from the mesh transformation process. The calculations for the mesh and the retrieved data are the same, i just dont need them for every mesh.

My plan is to retrieve the data back to the CPU only when necessary and transform the mesh directly on the GPU. I am wondering if there is a way to send the ComputeShader GPU data directly to the mesh, rather than retrieving it back to the CPU to displace the vertices. Is this possible?

PS: The mesh transformation is only visual, so the actual vertices displacement doesn’t need to happen as long as the result would be visual the same.

Thanks for reading :slight_smile:

Displace vertices in compute shader and write results to structured buffer (you have already done this step). Make sure you have direct correspondance between vertex index of source mesh and result data in output buffer. Make a vertex shader modification that reads vertex position from structured buffer indexed by SV_VertexID. By this step you will get modified vertex position corresponding to every mesh vertex. Bind structured buffer made in “ComputeShader” step into material with new shader that used for mesh rendering. That’s it.

3 Likes

Thanks thats exactly what i needed! :slight_smile: