I tried showing off my VFX Design scene to a coworker and realized that the SDFs no longer drew correctly. It was because of the changes I made to calculating the mesh center and box size. Turns out I did need the m_Mesh object from the MeshToSDFBaker class after all. I modified the package again and reverted the code to fix the SDF rendering in that scene.

I wanted to test the FPS of these metaballs in a moving scene, since the algorithm only actually runs when the positions/scales of the balls change. So, I added my simple player controller script to one of the balls and gave it a shot. Suffice to say, speeds were quite laggy at the lowest acceptable resolution for the metaballs. I could lower the resolution even more, but then my balls would look like rocks.

Which reminds me…I redid the flat white material for their mesh so that it includes transparency. That way, I could set the particles to the same position as the mesh and view both overlayed together. Matching the scale of the metaball mesh took some adjustments in my VFX graph—I used a VFX property binder to parent get the scale of the container and then multiply it by the size of the SDF to accurately match the size.

It ends up looking pretty solid. As you can see, I added a semi-transparent square to denote the size of the metaball container in place mode. Since I’m using an orthographic camera, a quad works fine for this. I would’ve grabbed a screen recording of the scene in action but Gyazo seems to have shit the bed on me and I don’t know why…

I’m so excited for these metaballs to actually be ready, but serious optimization is needed and I’m not yet sure how to achieve that. Common sense tells me that the CPU side of the marching cubes algorithm is what’s slowing stuff down, but I ought to learn how to profile each side of this. *But…*I’m getting the impression that work at my actual job might pick up again soon and am really hoping to get these metaballs figured out asap. Perhaps I can circumvent the entire mesh rendering part of the algorithm and pass the metaballs vertex array directly to the compute shader in the SDF Bake Tool. On top of that, if I could pass that array from a vertex shader, then I completly take my CPU from the equation. Sounds like a long shot, but honestly, I didn’t even expect to have working metaballs in my scene, and look at it now!


Tags: gamedev unity vfx metaballs sdf optimization shaders