diff --git a/packages/shader-ast-stdlib/src/index.ts b/packages/shader-ast-stdlib/src/index.ts index 50033ea896..fa80cda419 100644 --- a/packages/shader-ast-stdlib/src/index.ts +++ b/packages/shader-ast-stdlib/src/index.ts @@ -62,6 +62,7 @@ export * from "./sdf/smooth-isec"; export * from "./sdf/smooth-sub"; export * from "./sdf/smooth-union"; export * from "./sdf/sphere"; +export * from "./sdf/sub"; export * from "./sdf/torus"; export * from "./sdf/tri"; export * from "./sdf/union"; diff --git a/packages/shader-ast-stdlib/src/sdf/union.ts b/packages/shader-ast-stdlib/src/sdf/union.ts index ebc2d29cc6..f7cebdd0ea 100644 --- a/packages/shader-ast-stdlib/src/sdf/union.ts +++ b/packages/shader-ast-stdlib/src/sdf/union.ts @@ -1,4 +1,4 @@ -import { FloatTerm, min } from "@thi.ng/shader-ast"; +import { $x, defn, FloatTerm, lt, min, ret, ternary } from "@thi.ng/shader-ast"; /** * Inline function. SDF shape union (a || b). @@ -7,3 +7,14 @@ import { FloatTerm, min } from "@thi.ng/shader-ast"; * @param b - float */ export const sdfUnion = (a: FloatTerm, b: FloatTerm) => min(a, b); + +/** + * SDF shape union for vec2 terms, i.e. the common form where the X coord + * defines distance and Y an object or material ID. + * + * @param a - + * @param b - + */ +export const sdfUnion2 = defn("vec2", "sdfUnion2", ["vec2", "vec2"], (a, b) => [ + ret(ternary(lt($x(a), $x(b)), a, b)), +]);