Smooth edges of a mask

Hi,

I would like to smooth the edges of a mask consisting of a number of different masks. For example like the 2 rectangles in the attached picture but I would like a solution that works for any number of different masks. Smoothing the edges of every single mask like in the second picture does obviously not what I want. The edge where the 2 rectangles intersect should just disappear and the smoothing should also not be dependent on how large the rectangle is.

I already searched the docs for quite some time but couldnt find anything helpful. I kinda need the opposite of the AntialiasedTextureMask. But due to my limited experience with materials I don’t know where to start. I would really appreciate if someone could give me a hint how to solve this.

102484-mask.png

102485-masksmoothed.png

Do tell us how exactly are you generating the mask. The answer to your question is there.

Ok here are the nodes I use to generate that mask. The second picture I generated by using divide instead of if nodes.

Well, you are doing everything fine. To achieve the effect you want, introduce a [smoothstep][1] function instead of IF in your nodes. Either use a custom node, or recreate functionality of smoothstep in a new material function.

Here is a material function, that generates smoothed box for you.

Then you just combine several of these to get the shape you want, as you did before, via max node.

Please note, that getting smoothed corners is a bit more invovled, but is also quite possible. You would need to clamp off the corners, and add a sphere mask for every corner of your box mask. Whatever you do, take into consideration the fact, that the more complex you mask is, the more expensive it gets. Please, don’t forget to mark the question as resolved, if that is the answer, that you were looking for.

Wow this looks exactly like what I wanted. I’ll try it out as soon as I can. Thank you very much. I wonder why I didn’t give the smooth_step function a try. I scrolled through the whole functions available in the material graph.

And yes I’m very well aware of the increasing cost per node in the material function since I want to use some more rectangles.

This looks cleary better than what I made so far. I don’t understand how you created your smooth_step function but I was able to create the same effect with 4 smoothstep functions from the library (that works only in 1 dimension).

Sadly the rectangles still need to overlap in the SmoothingRange to avoid an undesired effect. I was hoping for a solution that works also with adjacent rectangles but I guess there’s no cheap way for that.