Skip to content

Commit

Permalink
feat(shader-ast-stdlib): add sdfUnion2(), add missing exports
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Aug 9, 2021
1 parent b3f93d2 commit 9d52838
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/shader-ast-stdlib/src/index.ts
Expand Up @@ -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";
Expand Down
13 changes: 12 additions & 1 deletion 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).
Expand All @@ -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)),
]);

0 comments on commit 9d52838

Please sign in to comment.