Skip to content

Commit

Permalink
refactor(shader-ast-stdlib): update imports
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Sep 13, 2021
1 parent 69414ec commit b22054e
Show file tree
Hide file tree
Showing 68 changed files with 387 additions and 753 deletions.
3 changes: 2 additions & 1 deletion packages/shader-ast-stdlib/src/color/aces-film.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { add, defn, div, mul, ret } from "@thi.ng/shader-ast";
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
import { add, div, mul } from "@thi.ng/shader-ast/ast/ops";
import { clamp01 } from "../math/clamp";

/**
Expand Down
33 changes: 13 additions & 20 deletions packages/shader-ast-stdlib/src/color/levels.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
import type {
FloatTerm,
Mat3Term,
Vec2Term,
Vec3Term,
} from "@thi.ng/shader-ast";
import { ternary } from "@thi.ng/shader-ast/ast/controlflow";
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
import { indexMat } from "@thi.ng/shader-ast/ast/indexed";
import {
$x,
$y,
$z,
defn,
float,
FLOAT0,
FLOAT05,
FLOAT1,
FloatTerm,
indexMat,
lt,
madd,
Mat3Term,
max,
min,
mul,
pow,
reciprocal,
ret,
sub,
ternary,
Vec2Term,
vec3,
Vec3Term,
VEC3_0,
VEC3_1,
} from "@thi.ng/shader-ast";
} from "@thi.ng/shader-ast/ast/lit";
import { lt, madd, mul, reciprocal, sub } from "@thi.ng/shader-ast/ast/ops";
import { $x, $y, $z } from "@thi.ng/shader-ast/ast/swizzle";
import { max, min, pow } from "@thi.ng/shader-ast/builtin/math";
import { fit01, fitClamped } from "../math/fit";

/**
Expand Down
13 changes: 3 additions & 10 deletions packages/shader-ast-stdlib/src/color/linear-srgb.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import {
float,
FloatTerm,
pow,
Prim,
Term,
vec2,
vec3,
vec4,
} from "@thi.ng/shader-ast";
import type { FloatTerm, Prim, Term } from "@thi.ng/shader-ast";
import { float, vec2, vec3, vec4 } from "@thi.ng/shader-ast/ast/lit";
import { pow } from "@thi.ng/shader-ast/builtin/math";

const GAMMA = float(2.2);
const INV_GAMMA = float(1 / 2.2);
Expand Down
4 changes: 3 additions & 1 deletion packages/shader-ast-stdlib/src/color/luminance.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { dot, vec3, Vec3Term } from "@thi.ng/shader-ast";
import type { Vec3Term } from "@thi.ng/shader-ast";
import { vec3 } from "@thi.ng/shader-ast/ast/lit";
import { dot } from "@thi.ng/shader-ast/builtin/math";

/**
* Inline function. Computes luminance of given RGB color
Expand Down
18 changes: 5 additions & 13 deletions packages/shader-ast-stdlib/src/color/porter-duff.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import type { Fn2 } from "@thi.ng/api";
import {
$w,
add,
defn,
FLOAT0,
FLOAT1,
FloatTerm,
mul,
ret,
sub,
vec4,
Vec4Sym,
} from "@thi.ng/shader-ast";
import type { FloatTerm, Vec4Sym } from "@thi.ng/shader-ast";
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
import { FLOAT0, FLOAT1, vec4 } from "@thi.ng/shader-ast/ast/lit";
import { add, mul, sub } from "@thi.ng/shader-ast/ast/ops";
import { $w } from "@thi.ng/shader-ast/ast/swizzle";
import { clamp01 } from "../math/clamp";

const coeff = (
Expand Down
21 changes: 6 additions & 15 deletions packages/shader-ast-stdlib/src/color/rgbe.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
import {
$w,
$xyz,
defn,
exp2,
float,
gt,
INT0,
mul,
ret,
sub,
ternary,
vec3,
VEC3_0,
} from "@thi.ng/shader-ast";
import { ternary } from "@thi.ng/shader-ast/ast/controlflow";
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
import { float, INT0, vec3, VEC3_0 } from "@thi.ng/shader-ast/ast/lit";
import { gt, mul, sub } from "@thi.ng/shader-ast/ast/ops";
import { $w, $xyz } from "@thi.ng/shader-ast/ast/swizzle";
import { exp2 } from "@thi.ng/shader-ast/builtin/math";

/**
* RGBE (Radiance HDR) to linear float RGB conversion. The input vec is supposed
Expand Down
5 changes: 4 additions & 1 deletion packages/shader-ast-stdlib/src/fog/exp.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { defn, exp, FLOAT1, mul, neg, ret, sub } from "@thi.ng/shader-ast";
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
import { FLOAT1 } from "@thi.ng/shader-ast/ast/lit";
import { mul, neg, sub } from "@thi.ng/shader-ast/ast/ops";
import { exp } from "@thi.ng/shader-ast/builtin/math";
import { clamp01 } from "../math/clamp";

/**
Expand Down
6 changes: 5 additions & 1 deletion packages/shader-ast-stdlib/src/fog/exp2.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { assign, defn, exp2, FLOAT1, mul, ret, sub } from "@thi.ng/shader-ast";
import { assign } from "@thi.ng/shader-ast/ast/assign";
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
import { FLOAT1 } from "@thi.ng/shader-ast/ast/lit";
import { mul, sub } from "@thi.ng/shader-ast/ast/ops";
import { exp2 } from "@thi.ng/shader-ast/builtin/math";
import { clamp01 } from "../math/clamp";

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/shader-ast-stdlib/src/fog/linear.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defn, ret } from "@thi.ng/shader-ast";
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
import { clamp01 } from "../math/clamp";
import { fitNorm1 } from "../math/fit";

Expand Down
13 changes: 4 additions & 9 deletions packages/shader-ast-stdlib/src/light/lambert.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import {
dot,
FLOAT0,
FloatTerm,
madd,
max,
mul,
Vec3Term,
} from "@thi.ng/shader-ast";
import type { FloatTerm, Vec3Term } from "@thi.ng/shader-ast";
import { FLOAT0 } from "@thi.ng/shader-ast/ast/lit";
import { madd, mul } from "@thi.ng/shader-ast/ast/ops";
import { dot, max } from "@thi.ng/shader-ast/builtin/math";
import { fit1101 } from "../math/fit";

/**
Expand Down
21 changes: 6 additions & 15 deletions packages/shader-ast-stdlib/src/light/trilight.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
import {
abs,
add,
defn,
dot,
FLOAT0,
FLOAT1,
FloatSym,
max,
mul,
neg,
ret,
sub,
sym,
} from "@thi.ng/shader-ast";
import type { FloatSym } from "@thi.ng/shader-ast";
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
import { FLOAT0, FLOAT1 } from "@thi.ng/shader-ast/ast/lit";
import { add, mul, neg, sub } from "@thi.ng/shader-ast/ast/ops";
import { sym } from "@thi.ng/shader-ast/ast/sym";
import { abs, dot, max } from "@thi.ng/shader-ast/builtin/math";

/**
* Tom Forsyth's Trilight lighting model.
Expand Down
27 changes: 8 additions & 19 deletions packages/shader-ast-stdlib/src/math/additive.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
import type { Fn } from "@thi.ng/api";
import {
add,
assign,
defn,
float,
FLOAT0,
FLOAT05,
FloatSym,
FloatTerm,
forLoop,
inc,
lt,
mul,
Prim,
ret,
sym,
Term,
} from "@thi.ng/shader-ast";
import type { FloatSym, FloatTerm, Prim, Term } from "@thi.ng/shader-ast";
import { assign } from "@thi.ng/shader-ast/ast/assign";
import { forLoop } from "@thi.ng/shader-ast/ast/controlflow";
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
import { float, FLOAT0, FLOAT05 } from "@thi.ng/shader-ast/ast/lit";
import { add, inc, lt, mul } from "@thi.ng/shader-ast/ast/ops";
import { sym } from "@thi.ng/shader-ast/ast/sym";

/**
* Higher order function. Takes an AST type ID, a single-arg scalar
Expand Down Expand Up @@ -50,7 +39,7 @@ export const additive = <T extends Prim>(
(n = sym(FLOAT0)),
(amp = sym(FLOAT05)),
forLoop(
sym(float(0)),
sym(FLOAT0),
(i) => lt(i, float(oct)),
inc,
(i) => [
Expand Down
19 changes: 6 additions & 13 deletions packages/shader-ast-stdlib/src/math/cartesian.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import {
$x,
$y,
$z,
defn,
FloatSym,
mul,
ret,
sym,
Vec2Sym,
Vec2Term,
vec3,
} from "@thi.ng/shader-ast";
import type { FloatSym, Vec2Sym, Vec2Term } from "@thi.ng/shader-ast";
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
import { vec3 } from "@thi.ng/shader-ast/ast/lit";
import { mul } from "@thi.ng/shader-ast/ast/ops";
import { $x, $y, $z } from "@thi.ng/shader-ast/ast/swizzle";
import { sym } from "@thi.ng/shader-ast/ast/sym";
import { cossin } from "./sincos";

/**
Expand Down
29 changes: 13 additions & 16 deletions packages/shader-ast-stdlib/src/math/clamp.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
import {
clamp,
float,
import type {
FloatTerm,
PrimTerm,
Term,
TermType,
vec2,
Vec2Term,
vec3,
Vec3Term,
vec4,
Vec4Term,
} from "@thi.ng/shader-ast";
import { float, vec2, vec3, vec4 } from "@thi.ng/shader-ast/ast/lit";
import { clamp } from "@thi.ng/shader-ast/builtin/math";

const __clamp = (min: number, max: number) => <T extends PrimTerm>(
x: T
): Term<TermType<T>> =>
x.type === "float"
? clamp(<FloatTerm>x, float(min), float(max))
: x.type === "vec2"
? clamp(<Vec2Term>x, vec2(min), vec2(max))
: x.type === "vec3"
? clamp(<Vec3Term>x, vec3(min), vec3(max))
: clamp(<Vec4Term>x, vec4(min), vec4(max));
const __clamp =
(min: number, max: number) =>
<T extends PrimTerm>(x: T): Term<TermType<T>> =>
x.type === "float"
? clamp(<FloatTerm>x, float(min), float(max))
: x.type === "vec2"
? clamp(<Vec2Term>x, vec2(min), vec2(max))
: x.type === "vec3"
? clamp(<Vec3Term>x, vec3(min), vec3(max))
: clamp(<Vec4Term>x, vec4(min), vec4(max));
/**
* Inline function, expands to equivalent of `clamp(x, 0, 1)`.
*
Expand Down
4 changes: 3 additions & 1 deletion packages/shader-ast-stdlib/src/math/cross2.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { $x, $y, FloatTerm, mul, sub, Vec2Term } from "@thi.ng/shader-ast";
import type { FloatTerm, Vec2Term } from "@thi.ng/shader-ast";
import { mul, sub } from "@thi.ng/shader-ast/ast/ops";
import { $x, $y } from "@thi.ng/shader-ast/ast/swizzle";

/**
* Inline function. Computes 2D "cross product" of given vectors. See
Expand Down
16 changes: 4 additions & 12 deletions packages/shader-ast-stdlib/src/math/dist-chebyshev.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import {
$,
$x,
$y,
$z,
abs,
max,
sub,
Vec2Term,
Vec3Term,
Vec4Term,
} from "@thi.ng/shader-ast";
import type { Vec2Term, Vec3Term, Vec4Term } from "@thi.ng/shader-ast";
import { sub } from "@thi.ng/shader-ast/ast/ops";
import { $, $x, $y, $z } from "@thi.ng/shader-ast/ast/swizzle";
import { abs, max } from "@thi.ng/shader-ast/builtin/math";

export const distChebyshev2 = (
a: Vec2Term | Vec3Term | Vec4Term,
Expand Down
16 changes: 4 additions & 12 deletions packages/shader-ast-stdlib/src/math/dist-manhattan.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import {
$,
$x,
$y,
$z,
abs,
add,
sub,
Vec2Term,
Vec3Term,
Vec4Term,
} from "@thi.ng/shader-ast";
import type { Vec2Term, Vec3Term, Vec4Term } from "@thi.ng/shader-ast";
import { add, sub } from "@thi.ng/shader-ast/ast/ops";
import { $, $x, $y, $z } from "@thi.ng/shader-ast/ast/swizzle";
import { abs } from "@thi.ng/shader-ast/builtin/math";

export const distManhattan2 = (
a: Vec2Term | Vec3Term | Vec4Term,
Expand Down
24 changes: 6 additions & 18 deletions packages/shader-ast-stdlib/src/math/fit.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
import {
add,
defn,
div,
FLOAT0,
FLOAT05,
FLOAT1,
FLOAT2,
mix,
mul,
neq,
PrimTerm,
ret,
sub,
Term,
TermType,
ternary,
} from "@thi.ng/shader-ast";
import type { PrimTerm, Term, TermType } from "@thi.ng/shader-ast";
import { ternary } from "@thi.ng/shader-ast/ast/controlflow";
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
import { FLOAT0, FLOAT05, FLOAT1, FLOAT2 } from "@thi.ng/shader-ast/ast/lit";
import { add, div, mul, neq, sub } from "@thi.ng/shader-ast/ast/ops";
import { mix } from "@thi.ng/shader-ast/builtin/math";
import { clamp01 } from "./clamp";

/**
Expand Down
4 changes: 3 additions & 1 deletion packages/shader-ast-stdlib/src/math/magsq.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { defn, dot, ret, TaggedFn1 } from "@thi.ng/shader-ast";
import type { TaggedFn1 } from "@thi.ng/shader-ast";
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
import { dot } from "@thi.ng/shader-ast/builtin/math";

const $ = (n: 2 | 3 | 4) =>
defn("float", `magSq${n}`, [<any>`vec${n}`], (v) => [ret(dot(v, v))]);
Expand Down
13 changes: 3 additions & 10 deletions packages/shader-ast-stdlib/src/math/maxcomp.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import {
$w,
$x,
$y,
$z,
max,
Vec2Sym,
Vec3Sym,
Vec4Sym,
} from "@thi.ng/shader-ast";
import type { Vec2Sym, Vec3Sym, Vec4Sym } from "@thi.ng/shader-ast";
import { $w, $x, $y, $z } from "@thi.ng/shader-ast/ast/swizzle";
import { max } from "@thi.ng/shader-ast/builtin/math";

/**
* Inline function. Returns max(v.x, v.y)
Expand Down
Loading

0 comments on commit b22054e

Please sign in to comment.