Sending to the shader doesn’t seem to be as much of a problem, but it’s getting the data back from the shader that I’m having issues with.
What I want to do is sent a couple float arrays to a compute buffer, have a compute shader do some math on them, and then send back an array of floats to Unity. I tried using a struct, but when you nest an array of floats inside a struct, it is no longer blittable. I need to send the arrays individually.
The problem comes when trying to send data back to the C# script. Since I can’t use a struct, I have to send an individual array. My problem is that I can’t set the RWStructuredBuffer to accept a type of float array.
If I type RWStructuredBuffer<float[ ]> buffer; then it says that there are brackets where there shouldn’t be. If I type RWStructuredBuffer buffer[ ]; then it’s attempting to create an array of structured buffers, each containing a single float.
How can I send an array of floats from the shader to the C# script? I’ve been searching for hours and can’t even seem to find others who have this problem.
public struct vars
{
public float var1;
public float var2;
}
and then send array of vars to compute shader and read it back. If lengths of your float arrays are different, you can pad the short arrays to the longest array’s length, and don’t do any calculations for padded indexes.