Builtin Library
- ..
- .metadata17 B
- README.md2.2 KB
- module.wgsl5.5 KB
README.md
fx_sdf
Signed distance fields for effect shaders — the primitives an effect is shaped out of, the boolean and smooth-boolean operators that combine them, and the domain operators that repeat, round and hollow them.
#include "@builtin::deprecated.deprecatedParticles.fx.fx_sdf"
Pure math — no bindings. A Surface-domain shader and a .computeShader see
different generated frameworks and can share a function only when it touches
neither, so a shield's material and the compute pass that fills its volume
measure one distance.
Every primitive is centred on the origin and takes the sample point in its own
space, so a caller places one by transforming p rather than by passing a
centre. Every one returns the signed distance to the surface: negative inside,
positive outside, zero on it.
Primitives
| Function | Surface |
|---|---|
fx_sd_sphere(p, r) | radius r about the origin |
fx_sd_box(p, b) | half-extents b |
fx_sd_round_box(p, b, r) | half-extents b with edges rounded by r; the solid still reaches b |
fx_sd_torus(p, major, minor) | ring of radius major in XZ, tube radius minor |
fx_sd_plane(p, n, h) | plane through -h * n with normal n |
fx_sd_capsule(p, a, b, r) | radius r around the segment a→b |
fx_sd_cylinder(p, h, r) | radius r, half-height h, axis Y |
Operators
fx_op_union is min, fx_op_intersect is max, and fx_op_subtract(a, b)
carves b out of a.
fx_op_smooth_union, fx_op_smooth_intersect and fx_op_smooth_subtract take
a fillet width k and weld the surfaces over it. A smooth union is never
greater than min(a, b) and never less than min(a, b) - k / 4, so it reaches
its hard counterpart as k approaches zero.
fx_op_round grows the field outwards, fx_op_onion hollows it into a shell,
and fx_op_blend morphs one field into another.
Domain operators
These transform the point rather than the distance, so a primitive evaluated at
the result is the one that repeats or stretches: fx_op_elongate stretches
along each axis, fx_op_repeat folds the point into one cell of an infinite
grid, fx_op_mirror folds it into the positive octant.