November is here! And with that flip of the calendar page, I awoke this morning with a simple confidence, an inner knowing that if I attempted to recreate the bug from yesterday’s trials in a simpler scene, I’d gain insight into the issue. Well, reader, that’s what I did!
I opened my metaballs fork of the marching cubes project, added the Visual Effects Graph package, and created a new scene where I combined my logic for baking SDFs into the VFX graph with my logic for creating metaballs. Suffice to say, I already got it working!
Now, as I gradually rebuild this successful script in my energy ball project, I’ll do it in a modular way, so that I’ll be able to trace the exact cause of the issue. That, my dear reader, is debugging.
I tried taking the shortest path to success and just copying the working script to my energy ball project. After that failed (and I tried adjusting some VFX graph params to no avail), I went back to my tester project and began by increasing the scale of the metaball grid to match the one in my energy ball project. That’s where I noticed the SDF output wasn’t matching the mesh renderer output. In the footage below, I adjust the target value of the metaballs and the difference between the outputs becomes more noticeable as the value increases.
Seeing that the outputs became more synchronous at higher metaball radii sizes made me realize I needed to increase the “maxRes” parameter that I pass into the MeshToSDFBaker class. Doubling it from 32 to 64 fixed the issue in the tester scene.
Even with the resolution fixed, there are still problems, and they seem to be related to the position of the transform containing the VFX graph. Moving the graph caused the mesh to displace and/or get cut off.
My initial thought was that this issue is related to the “center” param I’m passing into the MeshToSDFBaker class, but according to the docs, that controls the center of the baking box, which I’m pretty sure has nothing to do with the SDF’s position in world space. Next step, more testing!
By binding the SDF node’s field transform’s center to another transform in my scene, I was able to move the particles around without breaking their shape. This way, I keep the VFX graph’s transform untouched.