How can I create a dynamic opacity mask with an unspecified amount of sphere masks?

I’m working on a project where objects of a certain material should only be visible where they are inside a sphere of a certain class. I have followed the “Location Based Opacity” tutorial and managed to get it working with two spheres using material parameters.

The way it works now is hardcoded, I have two spheres of the same class, each writes its position and radius to its own parameter in a material parameter collection, then in the material blueprint (manually repeated per sphere) I read those two parameters and create a sphere mask, which I add together and apply as opacity mask

The problem is that this solution is not scalable to an indeterminate number of spheres that might even be spawned at runtime. I thought about writing a custom shader, but the documentation on the subject is not all that clear about stuff like uniforms, shader language and where to actually place the shader.

I am willing to do this with blueprints if possible, but the functionality that is available in the material blueprints is severely limited for this purpose, and I dont believe I can add material parameters to a collection dynamically, or even do a for-each for every parameter in a collection at all and add those results in a single mask.

Any help would be appreciated.

I would also like to know about this. From what I’ve read, most people suggest making a parameter for every sphere but there’s gotta be another way to do it. One that allows you to dynamically create as many or few as you need.