Skip to content

Commit

Permalink
feat(shader-ast-stdlib): add variadic SDF ops
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Aug 13, 2021
1 parent 61c74d1 commit 8d6390c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/shader-ast-stdlib/src/sdf/smooth-isec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
div,
FLOAT1,
FloatSym,
FloatTerm,
mix,
mul,
ret,
Expand All @@ -16,6 +17,7 @@ import { fit1101 } from "../math/fit";
/**
* @param d1 - float
* @param d2 - float
* @param k - float
*/
export const sdfSmoothIntersect = defn(
"float",
Expand All @@ -29,3 +31,13 @@ export const sdfSmoothIntersect = defn(
];
}
);

/**
* Variadic compiletime macro for {@link sdfSmoothIntersect}. Takes smooth factor
* `k`, followed by any number (at least 1 required) of SDF terms.
*
* @param k
* @param terms
*/
export const sdfSmoothIntersectAll = (k: FloatTerm, ...terms: FloatTerm[]) =>
terms.reduce((acc, x) => sdfSmoothIntersect(acc, x, k));
12 changes: 12 additions & 0 deletions packages/shader-ast-stdlib/src/sdf/smooth-sub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
div,
FLOAT1,
FloatSym,
FloatTerm,
mix,
mul,
neg,
Expand All @@ -17,6 +18,7 @@ import { fit1101 } from "../math/fit";
/**
* @param d1 - float
* @param d2 - float
* @param k - float
*/
export const sdfSmoothSubtract = defn(
"float",
Expand All @@ -30,3 +32,13 @@ export const sdfSmoothSubtract = defn(
];
}
);

/**
* Variadic compiletime macro for {@link sdfSmoothSubtract}. Takes smooth factor
* `k`, followed by any number (at least 1 required) of SDF terms.
*
* @param k
* @param terms
*/
export const sdfSmoothSubtractAll = (k: FloatTerm, ...terms: FloatTerm[]) =>
terms.reduce((acc, x) => sdfSmoothSubtract(acc, x, k));
12 changes: 12 additions & 0 deletions packages/shader-ast-stdlib/src/sdf/smooth-union.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
div,
FLOAT1,
FloatSym,
FloatTerm,
mix,
mul,
ret,
Expand All @@ -15,6 +16,7 @@ import { fit1101 } from "../math/fit";
/**
* @param d1 - float
* @param d2 - float
* @param k - float
*/
export const sdfSmoothUnion = defn(
"float",
Expand All @@ -28,3 +30,13 @@ export const sdfSmoothUnion = defn(
];
}
);

/**
* Variadic compiletime macro for {@link sdfSmoothUnion}. Takes smooth factor
* `k`, followed by any number (at least 1 required) of SDF terms.
*
* @param k
* @param terms
*/
export const sdfSmoothUnionAll = (k: FloatTerm, ...terms: FloatTerm[]) =>
terms.reduce((acc, x) => sdfSmoothUnion(acc, x, k));

0 comments on commit 8d6390c

Please sign in to comment.