void computeRectangleBounds( float in_offset, float in_radius, float in_maxRadius, vec2 size, out vec2 minP, out vec2 maxP, out float out_radius ) { out_radius = min( in_radius, in_maxRadius ); float borderSize = out_radius + in_offset; minP = vec2( borderSize, borderSize ); maxP = size - vec2( borderSize, borderSize ); } float roundedRectangleDistance( vec2 minP, vec2 maxP, vec2 pos) { vec2 leftTop = minP - pos; vec2 bottomRight = pos - maxP; vec2 maximum = max( leftTop, bottomRight ); maximum = max( maximum, vec2(0,0) ); return length( maximum ); } float roundedRectangle( vec2 minP, vec2 maxP, vec2 point, float borderSize, float sharp ) { float rectangleDistance = roundedRectangleDistance( minP, maxP, point ); rectangleDistance -= borderSize; rectangleDistance *= sharp; rectangleDistance = clamp( rectangleDistance, 0.0, 1.0 ); return 1.0 - rectangleDistance; }