I’m jotting down some shower thoughts from last night:

  • I’m fairly certain my bad SDF is a result of a bug in the SDF Baker. I’ll submit a bug report to the Unity Tea, including a demo scene with my saved metaball mesh asset linked to a VFX graph. I’ll provide instructions for recreating the broken SDF asset.
  • The memory leaks from the metaballs compute shader are very likely causing the program to overflow after extended periods of time. Part of successfully implementing metaballs involves patching up the memory leaks.
  • I’ll need to decouple the size of the metaballs bounding box from the radius of the metaballs themselves. Right now, when I scale up the game object, the metaballs inside inside also increase in scale. This is not due to the fact that the metaball game objects are inside the scaled parent, because their individual scale vectors do not control their perceived sizes. Somehow, the overall dimensions of the metaballs boundary are being divided by individual metaball radius to control the output of the mesh.
  • I’ll need to figure out how to make the metaballs bounding box as large as possible without losing FPS. The energy balls in my scene can grow to sizes of 10 x 10 x 10 units, and right now, my metaballs boundary can handle a size of 3 x 3 x 3. The fork I used includes a Smooth() function which uses interpolation to add extra vertices to the mesh. The function isn’t being used in the code, but it intuitively makes sense to add in vertexes after the marching cubes algorithm has already ran its course.

I updated my Unity 2022 install to the latest version, then went ahead and created a demo scene with the broken SDF asset so that I could submit a bug report to Unity. It’s a simple HDRP scene with two VFX graphs side by side. The graphs are duplicates of the same VFX graph asset with the single difference being the SDF texture assigned to each one’s “Conform to Signed Distance Field” block. I figured that I’d use the graph on the right to demonstrate what a working SDF texture output looked like, so I baked my first SDF from Unity’s default sphere’s mesh. Then, I went ahead and baked my second SDF using one of my captured metaball meshes from yesterday’s trial. Of course, as soon as I baked the SDF for my metaball mesh, there was no bug anymore. Updating Unity must have done the trick.

This is great news, of course, but there’s a small part of me that was wishing this bug would take Unity a month or two to fix (fuck that). Nay, it’s time to get right back to making metaballs!

I re-opened my main project with the newer Unity version and viola! Still buggy. I realized that it was VFX Graph, not Unity, that had needed to update. Since I’d modified my VFX Graph package (see post on 11/30/23), I had to remove my modified version, update to the new version, then modify the new version. Modifying the package broke something though, and now I can’t get any VFX graphs to display.

I’ll fix this tomorrow because it’s time for me to play some basketball.


Tags: gamedev unity vfx metaballs sdf debugging optimization