@thi.ng/shader-ast-js 0.7.67 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -1
- package/README.md +10 -9
- package/api.d.ts +28 -2
- package/env/ivec2.js +24 -22
- package/env/ivec3.js +24 -22
- package/env/ivec4.js +24 -22
- package/env/mat2.js +20 -18
- package/env/uvec2.js +24 -22
- package/env/uvec3.js +24 -22
- package/env/uvec4.js +24 -22
- package/env/vec2.d.ts +2 -1
- package/env/vec2.js +52 -51
- package/env/vec3.d.ts +2 -1
- package/env/vec3.js +53 -52
- package/env/vec4.d.ts +2 -1
- package/env/vec4.js +52 -51
- package/env.js +51 -30
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +9 -6
- package/pool.d.ts +37 -0
- package/pool.js +68 -0
- package/runtime.d.ts +41 -28
- package/runtime.js +46 -40
- package/target.js +41 -13
package/env/vec3.d.ts
CHANGED
package/env/vec3.js
CHANGED
|
@@ -51,67 +51,68 @@ import { step3 } from "@thi.ng/vectors/step";
|
|
|
51
51
|
import { sub3 } from "@thi.ng/vectors/sub";
|
|
52
52
|
import { subN3 } from "@thi.ng/vectors/subn";
|
|
53
53
|
import { tan3 } from "@thi.ng/vectors/tan";
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
54
|
+
import { Pool } from "../pool.js";
|
|
55
|
+
export const VEC3 = ({ next, uniform }) => ({
|
|
56
|
+
abs: (a) => abs3(next(), a),
|
|
57
|
+
acos: (a) => acos3(next(), a),
|
|
58
|
+
add: (a, b) => add3(next(), a, b),
|
|
59
|
+
addnv: (a, b) => addN3(next(), b, a),
|
|
60
|
+
addvn: (a, b) => addN3(next(), a, b),
|
|
61
|
+
asin: (a) => asin3(next(), a),
|
|
62
|
+
atan: (a) => atan3(next(), a),
|
|
63
|
+
atannn: (a, b) => atan_23(next(), a, b),
|
|
64
|
+
ceil: (a) => ceil3(next(), a),
|
|
65
|
+
clamp: (x, a, b) => clamp3(next(), x, a, b),
|
|
66
|
+
cos: (a) => cos3(next(), a),
|
|
67
|
+
cross: (a, b) => cross3(next(), a, b),
|
|
68
|
+
dec: (a) => subN3(next(), a, 1),
|
|
69
|
+
degrees: (a) => degrees3(next(), a),
|
|
69
70
|
dFdx: () => ZERO3,
|
|
70
71
|
dFdy: () => ZERO3,
|
|
71
72
|
distance: dist,
|
|
72
|
-
div: (a, b) => div3(
|
|
73
|
-
divnv: (a, b) => div3(null,
|
|
74
|
-
divvn: (a, b) => divN3(
|
|
73
|
+
div: (a, b) => div3(next(), a, b),
|
|
74
|
+
divnv: (a, b) => div3(null, uniform(a), b),
|
|
75
|
+
divvn: (a, b) => divN3(next(), a, b),
|
|
75
76
|
dot: (a, b) => dot3(a, b),
|
|
76
|
-
exp: (a) => exp3(
|
|
77
|
-
exp2: (a) => exp_23(
|
|
78
|
-
faceForward: (a, b, c) => faceForward(
|
|
79
|
-
floor: (a) => floor3(
|
|
80
|
-
fract: (a) => fract3(
|
|
77
|
+
exp: (a) => exp3(next(), a),
|
|
78
|
+
exp2: (a) => exp_23(next(), a),
|
|
79
|
+
faceForward: (a, b, c) => faceForward(next(), a, b, c),
|
|
80
|
+
floor: (a) => floor3(next(), a),
|
|
81
|
+
fract: (a) => fract3(next(), a),
|
|
81
82
|
fwidth: () => ZERO3,
|
|
82
|
-
inc: (a) => addN3(
|
|
83
|
-
inversesqrt: (a) => invSqrt3(
|
|
83
|
+
inc: (a) => addN3(next(), a, 1),
|
|
84
|
+
inversesqrt: (a) => invSqrt3(next(), a),
|
|
84
85
|
length: mag,
|
|
85
|
-
log: (a) => log3(
|
|
86
|
-
log2: (a) => log_23(
|
|
87
|
-
max: (a, b) => max3(
|
|
88
|
-
min: (a, b) => min3(
|
|
89
|
-
mix: (a, b, t) => mix3(
|
|
90
|
-
mixn: (a, b, t) => mixN3(
|
|
91
|
-
mod: (a, b) => mod3(
|
|
92
|
-
modn: (a, b) => modN3(
|
|
93
|
-
mul: (a, b) => mul3(
|
|
94
|
-
mulnv: (a, b) => mulN3(
|
|
95
|
-
mulvn: (a, b) => mulN3(
|
|
96
|
-
normalize: (a) => normalize3(
|
|
97
|
-
pow: (a, b) => pow3(
|
|
98
|
-
radians: (a) => radians3(
|
|
99
|
-
reflect: (a, b) => reflect(
|
|
100
|
-
refract: (a, b, c) => refract(
|
|
101
|
-
sign: (a) => sign3(
|
|
102
|
-
sin: (a) => sin3(
|
|
103
|
-
smoothstep: (a, b, t) => smoothStep3(
|
|
104
|
-
sqrt: (a) => sqrt3(
|
|
105
|
-
step: (a, b) => step3(
|
|
106
|
-
sub: (a, b) => sub3(
|
|
107
|
-
sub1: (a) => neg(
|
|
108
|
-
subnv: (a, b) => sub3(null,
|
|
109
|
-
subvn: (a, b) => subN3(
|
|
110
|
-
tan: (a) => tan3(
|
|
86
|
+
log: (a) => log3(next(), a),
|
|
87
|
+
log2: (a) => log_23(next(), a),
|
|
88
|
+
max: (a, b) => max3(next(), a, b),
|
|
89
|
+
min: (a, b) => min3(next(), a, b),
|
|
90
|
+
mix: (a, b, t) => mix3(next(), a, b, t),
|
|
91
|
+
mixn: (a, b, t) => mixN3(next(), a, b, t),
|
|
92
|
+
mod: (a, b) => mod3(next(), a, b),
|
|
93
|
+
modn: (a, b) => modN3(next(), a, b),
|
|
94
|
+
mul: (a, b) => mul3(next(), a, b),
|
|
95
|
+
mulnv: (a, b) => mulN3(next(), b, a),
|
|
96
|
+
mulvn: (a, b) => mulN3(next(), a, b),
|
|
97
|
+
normalize: (a) => normalize3(next(), a),
|
|
98
|
+
pow: (a, b) => pow3(next(), a, b),
|
|
99
|
+
radians: (a) => radians3(next(), a),
|
|
100
|
+
reflect: (a, b) => reflect(next(), a, b),
|
|
101
|
+
refract: (a, b, c) => refract(next(), a, b, c),
|
|
102
|
+
sign: (a) => sign3(next(), a),
|
|
103
|
+
sin: (a) => sin3(next(), a),
|
|
104
|
+
smoothstep: (a, b, t) => smoothStep3(next(), a, b, t),
|
|
105
|
+
sqrt: (a) => sqrt3(next(), a),
|
|
106
|
+
step: (a, b) => step3(next(), a, b),
|
|
107
|
+
sub: (a, b) => sub3(next(), a, b),
|
|
108
|
+
sub1: (a) => neg(next(), a),
|
|
109
|
+
subnv: (a, b) => sub3(null, uniform(a), b),
|
|
110
|
+
subvn: (a, b) => subN3(next(), a, b),
|
|
111
|
+
tan: (a) => tan3(next(), a),
|
|
111
112
|
equal: (a, b) => eq3([], a, b),
|
|
112
113
|
notEqual: (a, b) => neq3([], a, b),
|
|
113
114
|
greaterThan: (a, b) => gt3([], a, b),
|
|
114
115
|
lessThan: (a, b) => lt3([], a, b),
|
|
115
116
|
greaterThanEqual: (a, b) => gte3([], a, b),
|
|
116
117
|
lessThanEqual: (a, b) => lte3([], a, b),
|
|
117
|
-
};
|
|
118
|
+
});
|
package/env/vec4.d.ts
CHANGED
package/env/vec4.js
CHANGED
|
@@ -50,66 +50,67 @@ import { step4 } from "@thi.ng/vectors/step";
|
|
|
50
50
|
import { sub4 } from "@thi.ng/vectors/sub";
|
|
51
51
|
import { subN4 } from "@thi.ng/vectors/subn";
|
|
52
52
|
import { tan4 } from "@thi.ng/vectors/tan";
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
53
|
+
import { Pool } from "../pool.js";
|
|
54
|
+
export const VEC4 = ({ next, uniform }) => ({
|
|
55
|
+
abs: (a) => abs4(next(), a),
|
|
56
|
+
acos: (a) => acos4(next(), a),
|
|
57
|
+
add: (a, b) => add4(next(), a, b),
|
|
58
|
+
addnv: (a, b) => addN4(next(), b, a),
|
|
59
|
+
addvn: (a, b) => addN4(next(), a, b),
|
|
60
|
+
asin: (a) => asin4(next(), a),
|
|
61
|
+
atan: (a) => atan4(next(), a),
|
|
62
|
+
atannn: (a, b) => atan_24(next(), a, b),
|
|
63
|
+
ceil: (a) => ceil4(next(), a),
|
|
64
|
+
clamp: (x, a, b) => clamp4(next(), x, a, b),
|
|
65
|
+
cos: (a) => cos4(next(), a),
|
|
66
|
+
dec: (a) => subN4(next(), a, 1),
|
|
67
|
+
degrees: (a) => degrees4(next(), a),
|
|
67
68
|
dFdx: () => ZERO4,
|
|
68
69
|
dFdy: () => ZERO4,
|
|
69
70
|
distance: dist,
|
|
70
|
-
div: (a, b) => div4(
|
|
71
|
-
divnv: (a, b) => div4(null,
|
|
72
|
-
divvn: (a, b) => divN4(
|
|
71
|
+
div: (a, b) => div4(next(), a, b),
|
|
72
|
+
divnv: (a, b) => div4(null, uniform(a), b),
|
|
73
|
+
divvn: (a, b) => divN4(next(), a, b),
|
|
73
74
|
dot: (a, b) => dot4(a, b),
|
|
74
|
-
exp: (a) => exp4(
|
|
75
|
-
exp2: (a) => exp_24(
|
|
76
|
-
faceForward: (a, b, c) => faceForward(
|
|
77
|
-
floor: (a) => floor4(
|
|
78
|
-
fract: (a) => fract4(
|
|
75
|
+
exp: (a) => exp4(next(), a),
|
|
76
|
+
exp2: (a) => exp_24(next(), a),
|
|
77
|
+
faceForward: (a, b, c) => faceForward(next(), a, b, c),
|
|
78
|
+
floor: (a) => floor4(next(), a),
|
|
79
|
+
fract: (a) => fract4(next(), a),
|
|
79
80
|
fwidth: () => ZERO4,
|
|
80
|
-
inc: (a) => addN4(
|
|
81
|
-
inversesqrt: (a) => invSqrt4(
|
|
81
|
+
inc: (a) => addN4(next(), a, 1),
|
|
82
|
+
inversesqrt: (a) => invSqrt4(next(), a),
|
|
82
83
|
length: mag,
|
|
83
|
-
log: (a) => log4(
|
|
84
|
-
log2: (a) => log_24(
|
|
85
|
-
max: (a, b) => max4(
|
|
86
|
-
min: (a, b) => min4(
|
|
87
|
-
mix: (a, b, t) => mix4(
|
|
88
|
-
mixn: (a, b, t) => mixN4(
|
|
89
|
-
mod: (a, b) => mod4(
|
|
90
|
-
modn: (a, b) => modN4(
|
|
91
|
-
mul: (a, b) => mul4(
|
|
92
|
-
mulnv: (a, b) => mulN4(
|
|
93
|
-
mulvn: (a, b) => mulN4(
|
|
94
|
-
normalize: (a) => normalize4(
|
|
95
|
-
pow: (a, b) => pow4(
|
|
96
|
-
radians: (a) => radians4(
|
|
97
|
-
reflect: (a, b) => reflect(
|
|
98
|
-
refract: (a, b, c) => refract(
|
|
99
|
-
sign: (a) => sign4(
|
|
100
|
-
sin: (a) => sin4(
|
|
101
|
-
smoothstep: (a, b, t) => smoothStep4(
|
|
102
|
-
sqrt: (a) => sqrt4(
|
|
103
|
-
step: (a, b) => step4(
|
|
104
|
-
sub: (a, b) => sub4(
|
|
105
|
-
sub1: (a) => neg(
|
|
106
|
-
subnv: (a, b) => sub4(null,
|
|
107
|
-
subvn: (a, b) => subN4(
|
|
108
|
-
tan: (a) => tan4(
|
|
84
|
+
log: (a) => log4(next(), a),
|
|
85
|
+
log2: (a) => log_24(next(), a),
|
|
86
|
+
max: (a, b) => max4(next(), a, b),
|
|
87
|
+
min: (a, b) => min4(next(), a, b),
|
|
88
|
+
mix: (a, b, t) => mix4(next(), a, b, t),
|
|
89
|
+
mixn: (a, b, t) => mixN4(next(), a, b, t),
|
|
90
|
+
mod: (a, b) => mod4(next(), a, b),
|
|
91
|
+
modn: (a, b) => modN4(next(), a, b),
|
|
92
|
+
mul: (a, b) => mul4(next(), a, b),
|
|
93
|
+
mulnv: (a, b) => mulN4(next(), b, a),
|
|
94
|
+
mulvn: (a, b) => mulN4(next(), a, b),
|
|
95
|
+
normalize: (a) => normalize4(next(), a),
|
|
96
|
+
pow: (a, b) => pow4(next(), a, b),
|
|
97
|
+
radians: (a) => radians4(next(), a),
|
|
98
|
+
reflect: (a, b) => reflect(next(), a, b),
|
|
99
|
+
refract: (a, b, c) => refract(next(), a, b, c),
|
|
100
|
+
sign: (a) => sign4(next(), a),
|
|
101
|
+
sin: (a) => sin4(next(), a),
|
|
102
|
+
smoothstep: (a, b, t) => smoothStep4(next(), a, b, t),
|
|
103
|
+
sqrt: (a) => sqrt4(next(), a),
|
|
104
|
+
step: (a, b) => step4(next(), a, b),
|
|
105
|
+
sub: (a, b) => sub4(next(), a, b),
|
|
106
|
+
sub1: (a) => neg(next(), a),
|
|
107
|
+
subnv: (a, b) => sub4(null, uniform(a), b),
|
|
108
|
+
subvn: (a, b) => subN4(next(), a, b),
|
|
109
|
+
tan: (a) => tan4(next(), a),
|
|
109
110
|
equal: (a, b) => eq4([], a, b),
|
|
110
111
|
notEqual: (a, b) => neq4([], a, b),
|
|
111
112
|
greaterThan: (a, b) => gt4([], a, b),
|
|
112
113
|
lessThan: (a, b) => lt4([], a, b),
|
|
113
114
|
greaterThanEqual: (a, b) => gte4([], a, b),
|
|
114
115
|
lessThanEqual: (a, b) => lte4([], a, b),
|
|
115
|
-
};
|
|
116
|
+
});
|
package/env.js
CHANGED
|
@@ -22,6 +22,16 @@ import { UVEC4 } from "./env/uvec4.js";
|
|
|
22
22
|
import { VEC2 } from "./env/vec2.js";
|
|
23
23
|
import { VEC3 } from "./env/vec3.js";
|
|
24
24
|
import { VEC4 } from "./env/vec4.js";
|
|
25
|
+
import { POOL_IVEC2, POOL_IVEC3, POOL_IVEC4, POOL_UVEC2, POOL_UVEC3, POOL_UVEC4, POOL_VEC2, POOL_VEC3, POOL_VEC4, } from "./pool.js";
|
|
26
|
+
const { next: $2, uniform: $n2 } = POOL_VEC2;
|
|
27
|
+
const { next: $3, uniform: $n3 } = POOL_VEC3;
|
|
28
|
+
const { next: $4, uniform: $n4 } = POOL_VEC4;
|
|
29
|
+
const { next: $i2, uniform: $ni2 } = POOL_IVEC2;
|
|
30
|
+
const { next: $i3, uniform: $ni3 } = POOL_IVEC3;
|
|
31
|
+
const { next: $i4, uniform: $ni4 } = POOL_IVEC4;
|
|
32
|
+
const { next: $u2, uniform: $nu2 } = POOL_UVEC2;
|
|
33
|
+
const { next: $u3, uniform: $nu3 } = POOL_UVEC3;
|
|
34
|
+
const { next: $u4, uniform: $nu4 } = POOL_UVEC4;
|
|
25
35
|
// TODO texture lookups
|
|
26
36
|
// all texture fns currently return [0,0,0,0] or 0
|
|
27
37
|
const SAMPLER_TODO = {
|
|
@@ -40,34 +50,34 @@ const SAMPLER_TODO = {
|
|
|
40
50
|
textureSize: () => ZERO3,
|
|
41
51
|
};
|
|
42
52
|
export const JS_DEFAULT_ENV = {
|
|
43
|
-
vec2: VEC2,
|
|
44
|
-
vec2b: (v) => fromBVec2(
|
|
53
|
+
vec2: VEC2(POOL_VEC2),
|
|
54
|
+
vec2b: (v) => fromBVec2($2(), v),
|
|
45
55
|
vec2i: identity,
|
|
46
|
-
vec2n:
|
|
56
|
+
vec2n: $n2,
|
|
47
57
|
vec2u: identity,
|
|
48
|
-
vec3: VEC3,
|
|
49
|
-
vec3b: (v) => fromBVec3(
|
|
58
|
+
vec3: VEC3(POOL_VEC3),
|
|
59
|
+
vec3b: (v) => fromBVec3($3(), v),
|
|
50
60
|
vec3i: identity,
|
|
51
|
-
vec3n:
|
|
61
|
+
vec3n: $n3,
|
|
52
62
|
vec3u: identity,
|
|
53
|
-
vec3vn: (a, n) => setVN3(
|
|
54
|
-
vec4: VEC4,
|
|
55
|
-
vec4b: (v) => fromBVec4(
|
|
63
|
+
vec3vn: (a, n) => setVN3($3(), a, n),
|
|
64
|
+
vec4: VEC4(POOL_VEC4),
|
|
65
|
+
vec4b: (v) => fromBVec4($4(), v),
|
|
56
66
|
vec4i: identity,
|
|
57
|
-
vec4n:
|
|
67
|
+
vec4n: $n4,
|
|
58
68
|
vec4u: identity,
|
|
59
|
-
vec4vn: (a, n) => setVN4(
|
|
60
|
-
vec4vnn: (a, z, w) => setVV4(
|
|
61
|
-
vec4vv: (a, b) => setVV4(
|
|
62
|
-
mat2n: (n) => mat22n(
|
|
63
|
-
mat2vv: (a, b) => mat22v(
|
|
69
|
+
vec4vn: (a, n) => setVN4($4(), a, n),
|
|
70
|
+
vec4vnn: (a, z, w) => setVV4($4(), a, [z, w]),
|
|
71
|
+
vec4vv: (a, b) => setVV4($4(), a, b),
|
|
72
|
+
mat2n: (n) => mat22n($4(), n),
|
|
73
|
+
mat2vv: (a, b) => mat22v($4(), a, b),
|
|
64
74
|
mat3n: (n) => mat33n([], n),
|
|
65
75
|
mat3vvv: (a, b, c) => mat33v([], a, b, c),
|
|
66
76
|
mat4n: (n) => mat44n([], n),
|
|
67
77
|
mat4vvvv: (a, b, c, d) => mat44v([], a, b, c, d),
|
|
68
|
-
swizzle2: (a, b, c) => swizzle2(
|
|
69
|
-
swizzle3: (a, b, c, d) => swizzle3(
|
|
70
|
-
swizzle4: (a, b, c, d, e) => swizzle4(
|
|
78
|
+
swizzle2: (a, b, c) => swizzle2($2(), a, b, c),
|
|
79
|
+
swizzle3: (a, b, c, d) => swizzle3($3(), a, b, c, d),
|
|
80
|
+
swizzle4: (a, b, c, d, e) => swizzle4($4(), a, b, c, d, e),
|
|
71
81
|
set_swizzle2: setSwizzle2,
|
|
72
82
|
set_swizzle3: setSwizzle3,
|
|
73
83
|
set_swizzle4: setSwizzle4,
|
|
@@ -81,23 +91,23 @@ export const JS_DEFAULT_ENV = {
|
|
|
81
91
|
bvec4: BVEC4,
|
|
82
92
|
bvec4n: (n) => ((n = !!n), [n, n, n, n]),
|
|
83
93
|
ivec2: IVEC2,
|
|
84
|
-
ivec2b: (v) => fromBVec2(
|
|
85
|
-
ivec2n:
|
|
94
|
+
ivec2b: (v) => fromBVec2($i2(), v),
|
|
95
|
+
ivec2n: $ni2,
|
|
86
96
|
ivec3: IVEC3,
|
|
87
|
-
ivec3b: (v) => fromBVec3(
|
|
88
|
-
ivec3n:
|
|
97
|
+
ivec3b: (v) => fromBVec3($i3(), v),
|
|
98
|
+
ivec3n: $ni3,
|
|
89
99
|
ivec4: IVEC4,
|
|
90
|
-
ivec4b: (v) => fromBVec4(
|
|
91
|
-
ivec4n:
|
|
100
|
+
ivec4b: (v) => fromBVec4($i4(), v),
|
|
101
|
+
ivec4n: $ni4,
|
|
92
102
|
uvec2: UVEC2,
|
|
93
|
-
uvec2b: (v) => fromBVec2(
|
|
94
|
-
uvec2n:
|
|
103
|
+
uvec2b: (v) => fromBVec2($u2(), v),
|
|
104
|
+
uvec2n: $nu2,
|
|
95
105
|
uvec3: UVEC3,
|
|
96
|
-
uvec3b: (v) => fromBVec3(
|
|
97
|
-
uvec3n:
|
|
106
|
+
uvec3b: (v) => fromBVec3($u3(), v),
|
|
107
|
+
uvec3n: $nu3,
|
|
98
108
|
uvec4: UVEC4,
|
|
99
|
-
uvec4b: (v) => fromBVec4(
|
|
100
|
-
uvec4n:
|
|
109
|
+
uvec4b: (v) => fromBVec4($u4(), v),
|
|
110
|
+
uvec4n: $nu4,
|
|
101
111
|
mat2: MAT2,
|
|
102
112
|
mat3: MAT3,
|
|
103
113
|
mat4: MAT4,
|
|
@@ -107,4 +117,15 @@ export const JS_DEFAULT_ENV = {
|
|
|
107
117
|
samplerCube: SAMPLER_TODO,
|
|
108
118
|
sampler2DShadow: SAMPLER_TODO,
|
|
109
119
|
samplerCubeShadow: SAMPLER_TODO,
|
|
120
|
+
pools: {
|
|
121
|
+
vec2: POOL_VEC2,
|
|
122
|
+
vec3: POOL_VEC3,
|
|
123
|
+
vec4: POOL_VEC4,
|
|
124
|
+
ivec2: POOL_IVEC2,
|
|
125
|
+
ivec3: POOL_IVEC3,
|
|
126
|
+
ivec4: POOL_IVEC4,
|
|
127
|
+
uvec2: POOL_UVEC2,
|
|
128
|
+
uvec3: POOL_UVEC3,
|
|
129
|
+
uvec4: POOL_UVEC4,
|
|
130
|
+
},
|
|
110
131
|
};
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/shader-ast-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Customizable JS codegen, compiler & runtime for @thi.ng/shader-ast",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
"@thi.ng/checks": "^3.4.3",
|
|
39
39
|
"@thi.ng/errors": "^2.3.3",
|
|
40
40
|
"@thi.ng/math": "^5.5.4",
|
|
41
|
-
"@thi.ng/matrices": "^2.1.
|
|
42
|
-
"@thi.ng/pixel": "^4.2.
|
|
43
|
-
"@thi.ng/shader-ast": "^0.12.
|
|
44
|
-
"@thi.ng/vectors": "^7.7.
|
|
41
|
+
"@thi.ng/matrices": "^2.1.64",
|
|
42
|
+
"@thi.ng/pixel": "^4.2.14",
|
|
43
|
+
"@thi.ng/shader-ast": "^0.12.60",
|
|
44
|
+
"@thi.ng/vectors": "^7.7.7"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@microsoft/api-extractor": "^7.36.4",
|
|
@@ -132,6 +132,9 @@
|
|
|
132
132
|
"./env": {
|
|
133
133
|
"default": "./env.js"
|
|
134
134
|
},
|
|
135
|
+
"./pool": {
|
|
136
|
+
"default": "./pool.js"
|
|
137
|
+
},
|
|
135
138
|
"./runtime": {
|
|
136
139
|
"default": "./runtime.js"
|
|
137
140
|
},
|
|
@@ -147,5 +150,5 @@
|
|
|
147
150
|
],
|
|
148
151
|
"year": 2019
|
|
149
152
|
},
|
|
150
|
-
"gitHead": "
|
|
153
|
+
"gitHead": "4e8f1abeeba7b919e069954eada917ecd2e9a8e9\n"
|
|
151
154
|
}
|
package/pool.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type IReset, type Type, type TypedArray } from "@thi.ng/api";
|
|
2
|
+
import type { Vec } from "@thi.ng/vectors";
|
|
3
|
+
/**
|
|
4
|
+
* Manager for re-using pre-allocated memory for various vector ops. If the
|
|
5
|
+
* compiled shader program includes a `main()` function, the pools will be reset
|
|
6
|
+
* automatically when that `main` function executes. Otherwise, users **MUST**
|
|
7
|
+
* call the {@link CompileResult.__reset} manually each time before invoking a
|
|
8
|
+
* compiled entry point function.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* Currently, the default capacity for each vector type is fixed at 2048 items.
|
|
12
|
+
* That means a shader program can create up to this number of temporary objects
|
|
13
|
+
* (per fragment/invocation). Should this number be insufficient, please submit
|
|
14
|
+
* an issue and explain your use case. Thanks!
|
|
15
|
+
*/
|
|
16
|
+
export declare class Pool implements IReset {
|
|
17
|
+
protected size: number;
|
|
18
|
+
protected cap: number;
|
|
19
|
+
mem: TypedArray;
|
|
20
|
+
items: Vec[];
|
|
21
|
+
index: number;
|
|
22
|
+
next: () => Vec;
|
|
23
|
+
from: (...args: number[]) => Vec;
|
|
24
|
+
uniform: (n: number) => Vec;
|
|
25
|
+
constructor(type: Type, size: number, cap: number);
|
|
26
|
+
reset(): this;
|
|
27
|
+
}
|
|
28
|
+
export declare const POOL_VEC2: Pool;
|
|
29
|
+
export declare const POOL_VEC3: Pool;
|
|
30
|
+
export declare const POOL_VEC4: Pool;
|
|
31
|
+
export declare const POOL_IVEC2: Pool;
|
|
32
|
+
export declare const POOL_IVEC3: Pool;
|
|
33
|
+
export declare const POOL_IVEC4: Pool;
|
|
34
|
+
export declare const POOL_UVEC2: Pool;
|
|
35
|
+
export declare const POOL_UVEC3: Pool;
|
|
36
|
+
export declare const POOL_UVEC4: Pool;
|
|
37
|
+
//# sourceMappingURL=pool.d.ts.map
|
package/pool.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { typedArray, } from "@thi.ng/api";
|
|
2
|
+
import { outOfBounds } from "@thi.ng/errors/out-of-bounds";
|
|
3
|
+
import { set } from "@thi.ng/vectors/set";
|
|
4
|
+
import { setC2, setC3, setC4 } from "@thi.ng/vectors/setc";
|
|
5
|
+
import { setN, setN2, setN3, setN4 } from "@thi.ng/vectors/setn";
|
|
6
|
+
/**
|
|
7
|
+
* Manager for re-using pre-allocated memory for various vector ops. If the
|
|
8
|
+
* compiled shader program includes a `main()` function, the pools will be reset
|
|
9
|
+
* automatically when that `main` function executes. Otherwise, users **MUST**
|
|
10
|
+
* call the {@link CompileResult.__reset} manually each time before invoking a
|
|
11
|
+
* compiled entry point function.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* Currently, the default capacity for each vector type is fixed at 2048 items.
|
|
15
|
+
* That means a shader program can create up to this number of temporary objects
|
|
16
|
+
* (per fragment/invocation). Should this number be insufficient, please submit
|
|
17
|
+
* an issue and explain your use case. Thanks!
|
|
18
|
+
*/
|
|
19
|
+
export class Pool {
|
|
20
|
+
constructor(type, size, cap) {
|
|
21
|
+
this.size = size;
|
|
22
|
+
this.cap = cap;
|
|
23
|
+
this.index = 0;
|
|
24
|
+
this.mem = typedArray(type, cap * size);
|
|
25
|
+
this.items = new Array(cap);
|
|
26
|
+
for (let i = 0; i < cap; i++) {
|
|
27
|
+
this.items[i] = this.mem.subarray(i * size, i * size + size);
|
|
28
|
+
}
|
|
29
|
+
const next = () => {
|
|
30
|
+
if (this.index > this.items.length)
|
|
31
|
+
outOfBounds(this.index);
|
|
32
|
+
return this.items[this.index++];
|
|
33
|
+
};
|
|
34
|
+
let from;
|
|
35
|
+
let uniform;
|
|
36
|
+
switch (this.size) {
|
|
37
|
+
case 2:
|
|
38
|
+
from = (x, y) => setC2(next(), x, y);
|
|
39
|
+
uniform = (n) => setN2(next(), n);
|
|
40
|
+
case 3:
|
|
41
|
+
from = (x, y, z) => setC3(next(), x, y, z);
|
|
42
|
+
uniform = (n) => setN3(next(), n);
|
|
43
|
+
case 4:
|
|
44
|
+
from = (x, y, z, w) => setC4(next(), x, y, z, w);
|
|
45
|
+
uniform = (n) => setN4(next(), n);
|
|
46
|
+
default:
|
|
47
|
+
from = (...args) => set(next(), args);
|
|
48
|
+
uniform = (n) => setN(next(), n);
|
|
49
|
+
}
|
|
50
|
+
this.next = next;
|
|
51
|
+
this.from = from;
|
|
52
|
+
this.uniform = uniform;
|
|
53
|
+
}
|
|
54
|
+
reset() {
|
|
55
|
+
this.index = 0;
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const CAP = 2048;
|
|
60
|
+
export const POOL_VEC2 = new Pool("f32", 2, CAP);
|
|
61
|
+
export const POOL_VEC3 = new Pool("f32", 3, CAP);
|
|
62
|
+
export const POOL_VEC4 = new Pool("f32", 4, CAP);
|
|
63
|
+
export const POOL_IVEC2 = new Pool("i32", 2, CAP);
|
|
64
|
+
export const POOL_IVEC3 = new Pool("i32", 3, CAP);
|
|
65
|
+
export const POOL_IVEC4 = new Pool("i32", 4, CAP);
|
|
66
|
+
export const POOL_UVEC2 = new Pool("u32", 2, CAP);
|
|
67
|
+
export const POOL_UVEC3 = new Pool("u32", 3, CAP);
|
|
68
|
+
export const POOL_UVEC4 = new Pool("u32", 4, CAP);
|
package/runtime.d.ts
CHANGED
|
@@ -1,41 +1,54 @@
|
|
|
1
|
-
import type { Fn } from "@thi.ng/api";
|
|
1
|
+
import type { Fn, UIntArray } from "@thi.ng/api";
|
|
2
2
|
import { type IntBuffer } from "@thi.ng/pixel/int";
|
|
3
3
|
import type { ReadonlyVec, Vec } from "@thi.ng/vectors";
|
|
4
|
+
export interface RenderPixelOpts {
|
|
5
|
+
x?: number;
|
|
6
|
+
y?: number;
|
|
7
|
+
w?: number;
|
|
8
|
+
h?: number;
|
|
9
|
+
bufW: number;
|
|
10
|
+
bufH: number;
|
|
11
|
+
offsetX?: number;
|
|
12
|
+
offsetY?: number;
|
|
13
|
+
imgH?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Format conversion from float RGBA to packed integer.
|
|
16
|
+
*/
|
|
17
|
+
fmt: Fn<ReadonlyVec, number>;
|
|
18
|
+
}
|
|
19
|
+
export declare const rgbaBgra8888: (rgba: ReadonlyVec) => number;
|
|
20
|
+
export declare const rgbaRgb565: (rgba: ReadonlyVec) => number;
|
|
4
21
|
/**
|
|
5
22
|
* Low-level function used by {@link canvasRenderer} and {@link renderBuffer}.
|
|
6
|
-
* Applies shader function `fn` to each pixel in the given region of the
|
|
7
|
-
*
|
|
8
|
-
* `y` coords and `w`, `h` dimensions. The remaining
|
|
9
|
-
* `bufOffsetX`, `bufOffsetY` and `imgH` are used to
|
|
10
|
-
* of the given buffer in the full image to be
|
|
11
|
-
* where the target array only defines a
|
|
12
|
-
*
|
|
23
|
+
* Applies shader function `fn` to each pixel in the given region of the
|
|
24
|
+
* `pixels` buffer (e.g. a `Uint32Array`). The render region is defined via
|
|
25
|
+
* options. The top-left `x`, `y` coords and `w`, `h` dimensions. The remaining
|
|
26
|
+
* parameters `bufW`, `bufH`, `bufOffsetX`, `bufOffsetY` and `imgH` are used to
|
|
27
|
+
* define the actual location of the given buffer in the full image to be
|
|
28
|
+
* computed and to support use cases where the target array only defines a
|
|
29
|
+
* sub-region of the full image (e.g. when splitting rendering over multiple
|
|
30
|
+
* workers, each with their own buffer).
|
|
13
31
|
*
|
|
14
32
|
* @param fn -
|
|
15
|
-
* @param
|
|
16
|
-
* @param
|
|
17
|
-
* @param bufH -
|
|
18
|
-
* @param x -
|
|
19
|
-
* @param y -
|
|
20
|
-
* @param w -
|
|
21
|
-
* @param h -
|
|
22
|
-
* @param bufOffsetX -
|
|
23
|
-
* @param bufOffsetY -
|
|
24
|
-
* @param imgH -
|
|
33
|
+
* @param pixels -
|
|
34
|
+
* @param opts
|
|
25
35
|
*/
|
|
26
|
-
export declare const renderPixels: (fn: Fn<ReadonlyVec, Vec>,
|
|
36
|
+
export declare const renderPixels: (fn: Fn<ReadonlyVec, Vec>, pixels: UIntArray, { x, y, w, h, bufW, bufH, offsetX, offsetY, imgH, fmt }: RenderPixelOpts) => UIntArray;
|
|
27
37
|
/**
|
|
28
38
|
* Takes a
|
|
29
39
|
* [`IntBuffer`](https://docs.thi.ng/umbrella/pixel/classes/IntBuffer.html)
|
|
30
|
-
* pixel buffer from thi.ng/pixel
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
40
|
+
* pixel buffer from thi.ng/pixel, and options to define a buffer-local render
|
|
41
|
+
* region. Applies shader function `fn` to each pixel in that region (or the
|
|
42
|
+
* full buffer by default).
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* In case the buffer only defines a sub-region of a larger image,
|
|
46
|
+
* {@link RenderPixelOpts.offsetX}, {@link RenderPixelOpts.offsetY} and
|
|
47
|
+
* {@link RenderPixelOpts.imgH} can be given to configure the location and full
|
|
48
|
+
* image height.
|
|
35
49
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* height.
|
|
50
|
+
* The default target pixel format is `ABGR8888` using {@link rgbaBgra8888} as
|
|
51
|
+
* default {@link RenderPixelOpts.fmt} conversion.
|
|
39
52
|
*
|
|
40
53
|
* @param fn -
|
|
41
54
|
* @param buf -
|
|
@@ -47,7 +60,7 @@ export declare const renderPixels: (fn: Fn<ReadonlyVec, Vec>, u32: Uint32Array,
|
|
|
47
60
|
* @param bufOffsetY -
|
|
48
61
|
* @param imgH -
|
|
49
62
|
*/
|
|
50
|
-
export declare const renderBuffer: (fn: Fn<ReadonlyVec, Vec>, buf: IntBuffer,
|
|
63
|
+
export declare const renderBuffer: (fn: Fn<ReadonlyVec, Vec>, buf: IntBuffer, opts?: Partial<RenderPixelOpts>) => IntBuffer;
|
|
51
64
|
/**
|
|
52
65
|
* Higher order function accepting an `HTMLCanvasElement` and returning a render
|
|
53
66
|
* function which accepts the following parameters:
|