Skip to content

Commit

Permalink
refactor(shader-ast-stdlib): update vec const handling
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Aug 12, 2021
1 parent 2748f0b commit 3b31e72
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 13 deletions.
3 changes: 2 additions & 1 deletion packages/shader-ast-stdlib/src/color/rgbe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
sub,
ternary,
vec3,
VEC3_0,
} from "@thi.ng/shader-ast";

/**
Expand All @@ -30,7 +31,7 @@ export const decodeRGBE = defn("vec3", "decodeRGBE", ["ivec4"], (col) => {
ternary(
gt($w(col), INT0),
mul(vec3($xyz(col)), exp2(float(sub($w(col), 136)))),
vec3()
VEC3_0
)
),
];
Expand Down
3 changes: 2 additions & 1 deletion packages/shader-ast-stdlib/src/matrix/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import {
mat4,
ret,
vec3,
VEC3_0,
vec4,
} from "@thi.ng/shader-ast";

export const m22ToM33 = defn("mat3", "m22ToM33", ["mat2"], (m) => {
return [
ret(mat3(vec3(indexMat(m, 0), 0), vec3(indexMat(m, 1), 0), vec3())),
ret(mat3(vec3(indexMat(m, 0), 0), vec3(indexMat(m, 1), 0), VEC3_0)),
];
});

Expand Down
3 changes: 2 additions & 1 deletion packages/shader-ast-stdlib/src/noise/simplex2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
Vec2Sym,
vec3,
Vec3Sym,
VEC3_0,
vec4,
Vec4Sym,
} from "@thi.ng/shader-ast";
Expand Down Expand Up @@ -78,7 +79,7 @@ export const snoise2 = defn("float", "snoise2", ["vec2"], (v) => {
FLOAT05,
vec3(magSq2(x0), magSq2($xy(x12)), magSq2($(x12, "zw")))
),
vec3()
VEC3_0
)
)),
assign(m, mul(m, m)),
Expand Down
3 changes: 2 additions & 1 deletion packages/shader-ast-stdlib/src/screen/uv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
vec2,
Vec2Sym,
Vec2Term,
VEC2_1,
Vec4Term,
_any,
} from "@thi.ng/shader-ast";
Expand Down Expand Up @@ -70,7 +71,7 @@ export const borderMask = defn(
_any(
bvec4(
lessThan(uv, vec2(width)),
greaterThan(add(uv, width), vec2(1))
greaterThan(add(uv, width), VEC2_1)
)
)
),
Expand Down
12 changes: 6 additions & 6 deletions packages/shader-ast-stdlib/src/sdf/box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import {
ret,
sub,
sym,
vec2,
Vec2Sym,
vec3,
VEC2_0,
Vec3Sym,
VEC3_0,
} from "@thi.ng/shader-ast";
import { maxComp2, maxComp3 } from "../math/maxcomp";

Expand All @@ -22,11 +22,11 @@ import { maxComp2, maxComp3 } from "../math/maxcomp";
* @param p - vec2
* @param size - vec2
*/
export const sdfBox2 = defn("float", "sdRect", ["vec2", "vec2"], (p, size) => {
export const sdfBox2 = defn("float", "sdfBox2", ["vec2", "vec2"], (p, size) => {
let d: Vec2Sym;
return [
(d = sym(sub(abs(p), size))),
ret(add(min(maxComp2(d), FLOAT0), length(max(d, vec2())))),
ret(add(min(maxComp2(d), FLOAT0), length(max(d, VEC2_0)))),
];
});

Expand All @@ -36,10 +36,10 @@ export const sdfBox2 = defn("float", "sdRect", ["vec2", "vec2"], (p, size) => {
* @param p - vec3
* @param size - vec3
*/
export const sdfBox3 = defn("float", "sdAABB", ["vec3", "vec3"], (p, size) => {
export const sdfBox3 = defn("float", "sdfBox3", ["vec3", "vec3"], (p, size) => {
let d: Vec3Sym;
return [
(d = sym(sub(abs(p), size))),
ret(add(min(maxComp3(d), FLOAT0), length(max(d, vec3())))),
ret(add(min(maxComp3(d), FLOAT0), length(max(d, VEC3_0)))),
];
});
3 changes: 2 additions & 1 deletion packages/shader-ast-stdlib/src/sdf/cylinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
sym,
vec2,
Vec2Sym,
VEC2_0,
} from "@thi.ng/shader-ast";
import { maxComp2 } from "../math/maxcomp";

Expand All @@ -32,7 +33,7 @@ export const sdfCylinder = defn(
let d: Vec2Sym;
return [
(d = sym(sub(abs(vec2(length($(p, "xz")), $y(p))), vec2(h, r)))),
ret(add(min(maxComp2(d), FLOAT0), length(max(d, vec2())))),
ret(add(min(maxComp2(d), FLOAT0), length(max(d, VEC2_0)))),
];
}
);
4 changes: 2 additions & 2 deletions packages/shader-ast-stdlib/src/sdf/plane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { add, defn, dot, ret } from "@thi.ng/shader-ast";
*/
export const sdfPlane2 = defn(
"float",
"sdPlane",
"sdPlane2",
["vec2", "vec2", "float"],
(p, n, w) => [ret(add(dot(p, n), w))]
);
Expand All @@ -23,7 +23,7 @@ export const sdfPlane2 = defn(
*/
export const sdfPlane3 = defn(
"float",
"sdPlane",
"sdPlane3",
["vec3", "vec3", "float"],
(p, n, w) => [ret(add(dot(p, n), w))]
);

0 comments on commit 3b31e72

Please sign in to comment.