In this material im addign 3 sphere masks.
I need to add more spheres at runtime depending on the situation. It might go up to 30.
Now I could in theory add them 20 all in the material before runtime with a parameter the turns them on or off, even if they are not being used. But they would be sitting there consuming performance without being used, which is not good.
So is there some technique that i dont know that could add in more? Just adding, removing is not necessary? Maybe something like a for loop in the material, then i have a parameter for how many spheres i need to add?
Or there is no way to do that?
You could use the Custom node:
SphereMask = saturate((distance(A, B) - Radius) / (1 - Hardness));
My Products
4 Likes
wow thats awesome. I diddnt know that was possible.
Though in my particular situation. Each sphere will have its own radius and position. So maybe i will need a lot of inputs. As you can see they differ a bit:
So i guess my custom node will look more like something like this:
It will get weird and more complex. But i think i will get there.
So many inputs and per instance custom data. I wonder if there is a simpler more performant way of doing this.
Try this:
float Mask = 0.0;
for(int i=0; i < Num; i++) {
if (i==0) Mask+=saturate(distance(A, B1)-Radius1);
}
return Mask;
Update: You deleted your last question, but I’ll leave this here.
1 Like
Sorry i deleted it because i figured it out, and was about to make a proper answer, this was a mess.
Its working now:
How awesome is that
Thanks so much.
Actually this is not working. What am i doing wrong?
for(int i=0; i < Num; i++) {
if(i==0) Mask += saturate(distance(A, B1)-Radius1);
if(i==1) Mask += saturate(distance(A, B2)-Radius2);
}
return Mask;
Apparently the second sphere if iterated through will make both not work.
It seems there should be 2
1 Like
with 2 both are disabled. Could it be that 2 sphere floats getting together then dont work as expected?
But your other solution worked and had many spheres.
Edit:
Its multiply thats necessary. So *= instead of + for the opacity.