|
|
|
|
|
by Lerc
179 days ago
|
|
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)
}
|
|
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 distance field.
If you care about having a correct SDF, for something like raymarching, then you have to be somewhat more careful. Adding two SDFs does not result in a valid SDF, but taking the min or max of two SDFs does. Additionally, computing an analytical derivative of an SDF breaks if you add them, but you can use the analytical derivative if you take a min or max. Same applies for smooth min/max.