-
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(shader-ast-stdlib): add mixCubic()/mixQuadratic()
- Loading branch information
1 parent
64ba64c
commit 4dfc020
Showing
2 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { | ||
add, | ||
defn, | ||
FloatSym, | ||
mul, | ||
PrimTypeMap, | ||
ret, | ||
sub, | ||
sym, | ||
} from "@thi.ng/shader-ast"; | ||
|
||
const $ = <N extends 1 | 2 | 3 | 4, T extends PrimTypeMap[N]>(n: N, type: T) => | ||
defn( | ||
type, | ||
`mixCubic${n > 1 ? n : ""}`, | ||
[type, type, type, type, "float"], | ||
(a, b, c, d, t) => { | ||
let s: FloatSym; | ||
let s2: FloatSym; | ||
let t2: FloatSym; | ||
return [ | ||
(t2 = sym(mul(t, t))), | ||
(s = sym(sub(1, t))), | ||
(s2 = sym(mul(s, s))), | ||
ret( | ||
add( | ||
add( | ||
add( | ||
mul(<any>a, mul(s, s2)), | ||
mul(<any>b, mul(3, mul(s2, t))) | ||
), | ||
mul(<any>c, mul(3, mul(t2, s))) | ||
), | ||
mul(<any>d, mul(t, t2)) | ||
) | ||
), | ||
]; | ||
} | ||
); | ||
|
||
export const mixCubic = $(1, "float"); | ||
export const mixCubic2 = $(2, "vec2"); | ||
export const mixCubic3 = $(3, "vec3"); | ||
export const mixCubic4 = $(4, "vec4"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { | ||
add, | ||
defn, | ||
FloatSym, | ||
mul, | ||
PrimTypeMap, | ||
ret, | ||
sub, | ||
sym, | ||
} from "@thi.ng/shader-ast"; | ||
|
||
const $ = <N extends 1 | 2 | 3 | 4, T extends PrimTypeMap[N]>(n: N, type: T) => | ||
defn( | ||
type, | ||
`mixQuadratic${n > 1 ? n : ""}`, | ||
[type, type, type, "float"], | ||
(a, b, c, t) => { | ||
let s: FloatSym; | ||
return [ | ||
(s = sym(sub(1, t))), | ||
ret( | ||
add( | ||
add( | ||
mul(<any>a, mul(s, s)), | ||
mul(<any>b, mul(2, mul(s, t))) | ||
), | ||
mul(<any>c, mul(t, t)) | ||
) | ||
), | ||
]; | ||
} | ||
); | ||
|
||
export const mixQuadratic = $(1, "float"); | ||
export const mixQuadratic2 = $(2, "vec2"); | ||
export const mixQuadratic3 = $(3, "vec3"); | ||
export const mixQuadratic4 = $(4, "vec4"); |