Really as simple as the title, willing to explore all options:
Is it possible to compile a Compute Shader at runtime?
In my own search the closest thing I can come up with is references to the deprecated Material.ctor() that took a string and was able to compile fixed function shaders.
It doesn’t even have to be a compute shader explicitly, if it means I have to write a c++ plugin that compiles a OpenCL kernel that’s fine too, I’m just not sure how I can share resources between Unity and it. Would love to know anyone else’s experience on this one. I’m actually using Unity Free, I’m not sure if c++ native plugins are even available.
No, I’m afraid Unity itself won’t let you compile shaders at runtime. Native plugin is probably your only option.
You can’t use resources created in native plugin in Unity but you can share resources the other way. You can access Unity textures, meshes, buffers etc. in native plugin. See GetNative…Ptr() functions. For example, Texture.GetNativeTexturePtr(). Just send the ptr to your plugin and use it as a native resource object - GLuint, ID3D11Texture2D, etc
So, you would have to send Unity resources to your plugin (or create your own resources in plugin). Create/compile your shader in your plugin and dispatch it in IssuePluginEvent callback. Look at the native plugin example for more information.