2

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

1 Answer 1

2

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.

2
  • Hmm, that's good to know. In the end, I used a completely different solution, using the sdf of multiple Bézier curves (one at each corner) and combining them to get the sdf of the rounded polygon. That made it easy to change the roundness by simply changing the input points of the Bézier curves. This is the bezier sdf I used. Commented Apr 28, 2022 at 14:11
  • That's great! Can you share the code? I'm very curious to see the result :) Commented May 6, 2022 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.