How do I use the GPU in Unity? I’m using some extensive algorithms and want to know how I can reduce the time it takes to compute.
Just to bump with some so-so info:
o The physics system, Phys-X(sp?) uses the graphics card already (it was written by NVidea to show off the non-graphical uses of their chips.) I’m thinking their could be some conflicts if we throw more on the GPU.
o I believe GPU-as-CPU tricks use render-to-texture as communication back from the GPU, and that only Unity Pro allows R-to-T.
o GPU shaders work just fine, even on free. The docs cover an alternate method of setting lots of switches, instead of writing a shader. Easiest way to write real shaders is click Create->NewShader in your Assets, and also to download their package of the built-in shaders for samples. And read their “surface shaders” section.
Some more info. I don’t think this requires Unity Pro either.
If you have an NVidia video card you can write your algorithms up using CUDA in a separate DLL and then call them from a Mono/Unity DLL (giving you access from scripts etc). Something like this (from the Mono/Unity DLL):
using System;
...
using System.Runtime.InteropServices;
namespace MyMonoDllPackage
{
public class MyCudaBehaviour : MonoBehaviour
{
[DllImport("MyCudaFunctions.dll")]
public static extern void DoSomethingInCuda(float[] aSomeData);
public void Update()
{
float[] tSomeData = { 0.0f, 0.1f, 0.2f, 0.4f };
DoSomethingInCuda(tSomeData);
}
}
}