I think it’s important to consider potential issues that may arise down the line when building something. Something I’ve mostly ignored so far is the weird vortexes of attraction that manifest when an SDF’s base mesh contains multiple pieces (see 7/27/24 log). I hope to eventually figure out this strange issue and get the particles to actually attract to the nearest body; nevertheless I have been considering another solution to completely eliminate the problem, which involves cropping the SDF box size to eliminate all non-relevant pieces of the mesh.

In the above example, the SDF box is only drawn around the ball closest to the spawn point. The obvious issue here is the amount of transformation math this involves. I do have the ball position and radius at all times, so the math is solvable. However, what happens when two balls merge? The logical thing to do is to crop around the entire combined mesh for those balls. After all, they’re one piece, not two. Some quick experiments with the SDF bake tool show that cutting off parts of a mesh can lead to some broken SDF results.

Getting the proper area of a mesh of combined metaballs would require some testing because I’ll need to know the rate at which the radius of each metaball increases as they begin to merge. First, I’d collect some data, and then use it to derive a formula to estimate a given metaball’s area at a particular distance from any number of other metaball. The natural scaling that goes on with metaballs definitely complicates things.

Before doing any of this though, I’ll proceed as intended, and not give myself any extra work until I get to a road block. There’s a chance, a chance, that the issues that plagued my SDFs before will be solved in a much simpler way. Pray for me, and pray for America!


Tags: gamedev vfx unity sdf metaballs particles optimization