Is it possible to get Vertex data back from a Vertex Shader?

If a vertex shader does transformations on vertex coordinates, is it somehow possible to return this data to Unity - for instance on the mesh?

Or is it possible to get data from any non-compute shaders somehow?

If not, is it possible to run a compute shader in the rendering thread alongside vertex shaders and perform the GetData() operation within the rendering thread? (I’ve started looking at Low Level Native Plugins, but running a Unity-compiled shader in native C++ is probably impossible)

To your first question: No. Vertex shaders can only send data to the fragment shader (or geometry shader, but that too can only really send data to the fragment shader).

You can write data to a texture using a fragment shader using data from the vertex shader and read that back. Have the vertex shader feed into a geometry shader that builds a 1 pixel quad in the position of the first pixel of a render texture for each vertex and then read the render texture! Done! Oh, and you still have to render the object again with a version of the shader with out the geometry shader and not to the render texture. Also reading render textures back to the CPU side every frame is super duper slow.

So, yes, but not it isn’t practical.

I think the “real” path is to use a computer shader to do all of the vertex manipulations and then either render that pre-deformed mesh using DrawProcedural or just do the deformation again in the vertex shader.

1 Like