How to write vertex color data out to retrieve from c# script?

I’m interested in collecting the color of object vertices over time (the color after this object has been affected by the lights in the scene). To do this I want to save out the vertex colors to memory so I can retrieve from script. I have seen example of compute shaders writing to compute buffers and scripts accessing that data, and examples of reading data from compute buffers into other shaders but have not yet found an example of a non compute shader writing data to a buffer. Is this possible? Is there any example out there? Please advise, thanks!

Not possible, not directly at least. The closest you can get is rendering values from the vertex shader to an offscreen texture via a fragment shader and copying that back to the CPU, but that is very slow. Compute shaders were created to facilitate doing these kinds of on gpu operations, but even then copying back to the CPU is kind of slow. Generally if you can find a way to keep things on the GPU once it’s there it’s best to do so.

thanks bgolus, I’m not too worried about the latency since this purpose is for analysis, not a game playing experience…just looking for the right place to collect the data I need to support statistics regarding visibility of objects over time. Do you know a better way to collect that data?

Regarding your suggestion above, what is the proper way to copy that texture back to the cpu from the frag shader? Do you pack it in something like RWStructuredBuffer<2dTexture>?? Thanks for the guidance, cheers!