Tested the metaballs compute shader in my code and noticed a significant dropoff in FPS vs inside my fork of the Keijiro demo project. There were two possible causes: either my Unity version needed to be upgraded to Unity 6, or the HDRP needed to be downgraded to the SRP. I tried updating the Unity version first; when that didn’t help, I downgraded to the SRP, and that made the difference. Manually moving a metaball in the scene drops the FPS to around 45 FPS with occasional stutters on this beaten and bruised laptop. Theoretically, that’ll do, but I needed to test this by actually tying these metaballs into the player controller.

To do that, I created some public methods inside the MetaballsVisualizer class to set the position and radius of a given metaball. I call those methods inside the FixedUpdate loop in my scene controller. Since the metaballs render inside a box at the origin, I had to move the Z-position of the game object that the script is attached to in order to match the depth the dummy players render at. I then offset the Z-position for the metaballs by that same depth in order to place them correctly.

It’s really hard to tell if my computer is lagging or the scene is running slow…

As I suspected, I’m gonna need to tone the scaling way back. Dampening the scaling value by 0.15 brings the sizes to something that looks pretty accurate to me.

That being said, I use a lot of math for relatively little scaling now, so maybe what I should do instead is try to drastically simplify the scaling algorithm to create a similar, yet cheaper effect. For now, I added a simple catch that ignores the scaling algorithm altogether if the damper value is 0. _Note: I should stop using the terms “scaler” and “damper” interchangeably…_

This is all well and good, but for some annoying reason, the SDF is not baking correctly. It just shows up as a sphere in the middle of the screen.

I’ve spent over an hour trying to fix this bug to no avail. It’s time for me to step away, go trick-or-treating, and enjoy Halloween!


Tags: unity metaballs shaders vfx optimization debugging sdf