TITLE: Blend multiple shapes.
QUESTION [5 upvotes]: Using circle and square equations I was able to draw this. Any way to blend these two shapes(equations) like this and this. I want to achieve metaballs like effect.


I'm using unity engine to render the above, I want a 2D version of it. I basically colored all pixels which are inside a circle.
Eg: using unit circle at origin equation $x^2 + y^2 = 1$ I'm coloring all pixels if $p_x^2 + p_y^2 <= 1$, where $p_x$ and $p_y$ are position of pixel.So I want a equation(or method) which blends the shapes and determines if a pixel is inside the overall shape.

REPLY [3 votes]: Finally got working pseudocode:
//distance between point p and circle with radius r
float sdCircle( vec2 p, float r )
{
    return length(p) - r;
}

//function to blend
float smin( float a, float b, float k )
{
    float res = exp2( -k*a ) + exp2( -k*b );
    return -log2( res )/k;
}

float circle1_Dis = sdCircle(...);
float circle2_Dis = sdCircle(...);
float k = 0.5; // how much to blend

if(smin(circle1_Dis ,circle2_Dis ,k) < 0)
{
    //draw
}

reference:

https://iquilezles.org/articles/distfunctions2d/
https://iquilezles.org/articles/smin/
https://youtu.be/Cp5WWtMoeKg