I come back every couple of months when I have a new project involving sdfs. And almost every time it's a bit of trial and error figuring out the parameters. It's workable, but a minor pet peeve that they're not described or named better.
Can you freely compose signed distance functions? Obviously people use them for + and - regularly. My intuition says you should be able to apply *, / and more as well.
and
sqrt( sdEquilateralTriangle(pos.xy, 10)**2 + sdCircle(pos.xz,10)**2 )
seems like there's scope for a nice little domain specific language to.
I think it would be interesting to have some composite operations that did probabilistic branching based upon a hashing RNG to conditionally combine shapes
something like
float thingy(pos,r) {
float more = infinity
float pseudoRandom = HashToUnit(pos)
if (pseudoRandom >0.5) {
float direction=randomAngleFromSeed(pseudoRandom+r)
more = thingy(pos+direction*r, r*0.75)
}
return min(circle(pos,r),more)
}
I owe iq so much; a living legend. Inigo, if you happen to ever read this, thanks so much for all the work you've published. Your Youtube videos (not to mention shadertoy) sparked an interest in graphics I never knew I had.
For anyone that's unfamiliar, his Youtube videos are extremely well put together, and well worth the handful of hours to watch.
I can definitely say I wouldn't know half of what I do and probably wouldn't have kept at it with writing GLSL and learning more about how GPUs really work without a lot of his freely shared knowledge over the years.
His articles on his website are very much worth a deep read too!
Someone at work recently copied the ellipse SDF from that page into production code without checking it, and shipped a crash to a ton of people. If you simply glance at it, you’ll see it divides by zero on circles. Then, if you try to check for that, you’ll immediately hit overflow cases for common values in shaders.
I replaced it with correctly designed, numerically robust code.
Don’t use these routines; they’re all similarly land mines of bad numerics. They’re pretty but not robust.
6 comments
[ 3.1 ms ] story [ 19.3 ms ] threadIt's a priceless resource nevertheless.
and sqrt( sdEquilateralTriangle(pos.xy, 10)**2 + sdCircle(pos.xz,10)**2 )
seems like there's scope for a nice little domain specific language to.
I think it would be interesting to have some composite operations that did probabilistic branching based upon a hashing RNG to conditionally combine shapes
something like
For anyone that's unfamiliar, his Youtube videos are extremely well put together, and well worth the handful of hours to watch.
https://www.youtube.com/c/InigoQuilez
His articles on his website are very much worth a deep read too!
I replaced it with correctly designed, numerically robust code.
Don’t use these routines; they’re all similarly land mines of bad numerics. They’re pretty but not robust.