Hey!
I am pretty new in Unity. I use Unity for doing some modeling and research purposes. In my project, I have a heavy calculation where ~50,000 pair vectors per 5 frames that I would like to calculate the angle between each pair and sort them in an array and return to Unity.
I am not good in CUDA and OpenCL so, I though that maybe I can run it on GPU using a shader and return it back to the unity. So here are my questions:
is it possible to do this calculation on a shader, if so, does it accelerate the process?
how can I return the calculated values (like an array of double)?
How can I pass my vector list to the shader?
is there any sample out there that can be useful for me?
1 - The angle calculations are perfectly suited to parallelization on the GPU the sorting however will be a problem. Its not something GPU’s are good at and although its not impossible it maybe be better to sort on the CPU.
2/3 - Passing and retrieving values from the GPU is best done with Compute buffers in Unity, which means using Direct Compute. Without using buffers its rather difficult to pass/retrieve floating point values. You will need to encode the values into 8bit textures. Its not very practical. Its easier to use the get and set data functions of a buffer.
I know a bit about CUDA and programming on GPU but I don’t understand how can I split the job between different threads.
In my problem, I have two list of vectors (let’s call them Pivots and Points). For each vector of Pivots list, I have a position of a plane that should rotate clockwise around Y axis and I want to calculate the incidence angle between each point of Points list and my plane, and it should do it for all 360 degree and Pivot points. My original idea was to design a shader to do it for each pivot in a separated thread and for for each angle we have a thread to calculate the angle. In CUDA, we can easily handle it by an if condition and define segment to figure out which thread should run witch part and the rest of them should do different things. I am a bit confused how can I have access to this process? for example how can I enumerate angles? Could you give me some idea?