Bevy-Rust-GPU / rust-gpu-sdf

Signed distance field library usable on both CPU and GPU.
Apache License 2.0
12 stars 1 forks source link

Comprehensive shape / modifier decomposition #4

Open Shfty opened 1 year ago

Shfty commented 1 year ago

Need to finish implementing the various shapes from Inigo Quilez' SDF reference.

Favor decomposing each shape into its constituent primitives and operators. Explicit implementations should only be created in cases where the compositional equivalent would result in a bound instead of a field, and those should be analyzed further to determine whether the algorithm used to achieve that end can itself be generalized.

Shfty commented 1 year ago

Making progress; all modifiers are implemented, and the explicit Torus shape has been generalized into Sweep<Circle, Circle>.

Shfty commented 1 year ago

Remaining 3D shapes of note:

Box Frame Appears to be a set of boolean operations, but manages to avoid bounding somehow

Capped Torus Appears to convert a line from cartesian to polar before rounding it into a capsule

Cone Evaluates a 2D circle SDF, then somehow sweeps it along an axis while increasing radius and applying a sign

Round Cone Appears to be a swept sphere with increasing radius

Cut Hollow Sphere / Death Star Both seem arbitrary, but may contain a generalizable technique to avoid bound issues with booleans

Ellipsoid Appears similar to Cone etc in practical terms, but using different mathematical properties to scale along an axis

Octahedron Uses abs(p) for an 8-way mirror, but manages to avoid bounding somehow

Triangle / Quad Are these 3D generalizations w/built in extrude?

2D shapes are all still of note; probably some interesting n-gon implementations there that may be generalizable into 3d prisms.

On prisms and reflection: Field approach likely predicated on finding angles containing a bound edge, then rounding them out with a point evaluation versus the nearest shape vertex.

Shfty commented 1 year ago

Finished analysing 2D N-gon implementations.

Composition strategy:

Optimization strategy:

Notes: This can be broken down into the following sub-operations:

It should be possible to build compositional machinery for these. Much of it already exists, but 1D distance functions and adapters to lift them into 2D functions will need to be implemented, as well as adapters for picking between SDFs based on some conditional.

Shfty commented 1 year ago

Finished generalizing N-gon implementation; shapes up to decagon are now encoded as compositional type aliases.