This page is created automatically. Click here to view this shader on Shadertoy.

I was hoping that 'folding' the input domain of the distance function would lead to some elegant math. Unfortunately, the math isn't that elegant at all, and also it isn't stable for large folding-angles (hence the 'clipping hack' at lines 90 to 99).

Source code

You can find (the full source of) Folding on Shadertoy.