Skip to content

Commit

Permalink
feat(shader-ast-stdlib): add borderMask()
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Aug 8, 2020
1 parent ae593e4 commit bea00bf
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions packages/shader-ast-stdlib/src/screen/uv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@ import {
$x,
$xy,
$y,
add,
assign,
bvec4,
defn,
div,
greaterThan,
lessThan,
mul,
ret,
sym,
vec2,
Vec2Sym,
Vec2Term,
Vec4Term,
_any,
} from "@thi.ng/shader-ast";
import { fit0111 } from "../math/fit";

Expand Down Expand Up @@ -44,3 +50,29 @@ export const aspectCorrectedUV = defn(
];
}
);

/**
* Returns true if at least one coordinate of the given point is within the
* `width` internal border region of UV rect ([0,0] .. [1,1]).
*
* ```c
* borderMask(vec2(0.91, 0.5), 0.1) // true
* borderMask(vec2(0.2, 0.01), 0.1) // true
* borderMask(vec2(0.2, 0.2), 0.1) // false
* ```
*/
export const borderMask = defn(
"bool",
"borderMask",
["vec2", "float"],
(uv, width) => [
ret(
_any(
bvec4(
lessThan(uv, vec2(width)),
greaterThan(add(uv, width), vec2(1))
)
)
),
]
);

0 comments on commit bea00bf

Please sign in to comment.