1/* 2smooth_union .5 ( 3 smooth_union .5 ( 4 box.exact(1,5,5), 5 box.exact(5,1,5), 6 ), 7 box.exact(5,5,1) 8) 9*/ 10smooth_min(a,b,k) = 11( 12 var h := clamp( 0.5+0.5*(b-a)/k, 0, 1 ); 13 lerp( b, a, h ) - k*h*(1.0-h) 14), 15Goal: generalize this to an associate N-ary operator. 16Simplification: fix k at 1, then reintroduce it later by scaling the result. 17 18smooth_min(a,b) = 19( 20 var h := clamp( 0.5+0.5*(b-a), 0, 1 ); 21 lerp( b, a, h ) - h*(1-h) 22), 23 24h is in range [0..1]. 25The function has 3 "bands": 26* the 'a' band, where it is equal to a. h==1 27* the 'b' band, where it is equal to b. h==0 28* the rounded band, a narrow diagonal going through the origin 29 where it is shaped like a quarter circle. h>0 && h<1. 30 31round_min2(k,a,b) = max(k, min(a,b)) - mag(max([k-a,k-b], 0)); 32