I’ve finally gotten some compute shader 101 schooling. I now have a basic understanding of thread count and dispatch group sizes (see my ChatGPT conversation) and the use cases for compute shaders. Basically, they’re the way to go for any program whose tasks can run concurrently but also must read or write data from/to the CPU. My understanding tells me I’ll be calculating the boundaries of my metaballs on the GPU and writing that data back to the CPU to create my custom metaballs meshFilter.

I’ve found some great resources to help me approach this problem. This repo covers a ton of useful compute shader examples, but I’m specifically interested in the 06_1_ComputeVertex example. The 06_5_VFXGraphMeshDeform example might be fun to play with later on to add some additional noise to the spherical meshes. I’ve also rediscovered this repo—I didn’t realize that it uses a compute shader for its marching cubes algorithm! I can reuse that algorithm for myself but replace its vertex shader functionality with something that writes to the mesh filter rather than the material renderer. Perhaps I’ll even optimize the metaballs algorithm with a function from this post.

Research before play, otherwise play becomes research.


Tags: unity shaders metaballs gamedev gpu mesh vfx