Earlier quoted context omitted.
There's a bit to unpack here. There are two things one might care about when computing an SDF .. the isosurface, or the SDF itself. If you only care about the isosurface (ie. where the function is 0), you can do any ridiculous operations you can think of, and it'll work just fine. Add, sub, multiply, exp .. whatever you want. Voxel engines do this trick a lot. Then it becomes more of a density field, as apposed to a…
I did some simple experiments and fairly swiftly discovered where I went wrong. I'm still not totally convinced that there isn't something clever that can be done for more operations. My next thought is maybe you can do some interesting shenanigans by jumping to the nearest point on one surface then calculating a modulation that adjusts the distance by an amount. I can certainly see how difficult it would become if y…
2D Signed Distance Functions
11–19 of 19 posts
Re: 2D Signed Distance Functions
#12I 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. It's a priceless resource nevertheless.
I was just about to say the same thing. This is bad code/documentation. Single letter variable names is almost always wrong if it isn't i for an index or such (and even then, would typing 'idx' kill you?). And as parameters, so much worse. Don't make me guess how to call your function please.
Re: 2D Signed Distance Functions
#13Earlier quoted context omitted.
I did some simple experiments and fairly swiftly discovered where I went wrong. I'm still not totally convinced that there isn't something clever that can be done for more operations. My next thought is maybe you can do some interesting shenanigans by jumping to the nearest point on one surface then calculating a modulation that adjusts the distance by an amount. I can certainly see how difficult it would become if y…
I think you might be describing smoothmin? https://iquilezles.org/articles/smin/
It's multi sample but selective rather than weighted.
Re: 2D Signed Distance Functions
#14Re: 2D Signed Distance Functions
#15Can 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 u…
There's a bit to unpack here. There are two things one might care about when computing an SDF .. the isosurface, or the SDF itself. If you only care about the isosurface (ie. where the function is 0), you can do any ridiculous operations you can think of, and it'll work just fine. Add, sub, multiply, exp .. whatever you want. Voxel engines do this trick a lot. Then it becomes more of a density field, as apposed to a…
This is good enough for rendering via sphere tracing, where you want the sphere radius to never intersect the geometry, and converge to zero at the boundary.
A particular class of fields that have this property is fields with gradient not greater than one.
For example, linear blends of SDFs. So given SDFs f and g you can actually do (f(pos)+g(pos))/2 and get something you can render out the other side. Not sure what it will look like, or if it has some geometrical interpretation though.
Note that speed of convergence suffers if you do too many shenanigans.
Re: 2D Signed Distance Functions
#16Can 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 u…
Bauble https://bauble.studio/
MiniSDF https://siebencorgie.rs/article/minisdf/article.html
Re: 2D Signed Distance Functions
#17I 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.
Re: 2D Signed Distance Functions
#18I 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. https://www.youtube.com/c/InigoQuilez
His articles on his website are very much worth a deep read too!
Re: 2D Signed Distance Functions
#19Earlier quoted context omitted.
There's a bit to unpack here. There are two things one might care about when computing an SDF .. the isosurface, or the SDF itself. If you only care about the isosurface (ie. where the function is 0), you can do any ridiculous operations you can think of, and it'll work just fine. Add, sub, multiply, exp .. whatever you want. Voxel engines do this trick a lot. Then it becomes more of a density field, as apposed to a…
To add some more detail, the max of two SDFs is a correct SDF of the intersection of the two volumes represented by the two SDFs, but only on the inside and at the boundary. On the outside it's actually a lower bound. This is good enough for rendering via sphere tracing, where you want the sphere radius to never intersect the geometry, and converge to zero at the boundary. A particular class of fields that have this…