'How to round the corners of an sdf, without changing it's size in glsl

I have an sdf function for a polygon, and I want to be able to round the corners, without changing the size of the resulting shape.

I know that I can round the corners of an sdf by simply subtracting the radius from the result, but this also makes the resulting shape bigger, while I want it to stay the same size.

Here's an example of the sdf with sharp corners

And this is the sdf with rounded corners, but now much larger

Here is a demonstration of what I have currently on Shadertoy: https://www.shadertoy.com/view/NlBcDt



Solution 1:[1]

As far as I know there is no generic code that works with any given sdf.

You need to modify the dimension or the formula of the primitive accordingly.

For a box, that's quite simple, you just need to subtract the rounding radius to both dimensions. For the generic polygon you have, it will be a bit trickier.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Emanuele Spatola