glre 0.38.0 → 0.40.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/README.md +8 -4
- package/dist/addons.cjs +2 -0
- package/dist/addons.cjs.map +1 -0
- package/dist/addons.d.ts +1287 -0
- package/dist/addons.js +2 -0
- package/dist/addons.js.map +1 -0
- package/dist/index.cjs +31 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +187 -323
- package/dist/index.js +31 -43
- package/dist/index.js.map +1 -1
- package/dist/native.cjs +1 -48
- package/dist/native.cjs.map +1 -1
- package/dist/native.d.ts +536 -10
- package/dist/native.js +1 -48
- package/dist/native.js.map +1 -1
- package/dist/node.cjs +69 -0
- package/dist/node.cjs.map +1 -0
- package/dist/node.d.ts +626 -0
- package/dist/node.js +69 -0
- package/dist/node.js.map +1 -0
- package/dist/react.cjs +1 -48
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.ts +524 -4
- package/dist/react.js +1 -48
- package/dist/react.js.map +1 -1
- package/dist/solid.cjs +1 -48
- package/dist/solid.cjs.map +1 -1
- package/dist/solid.d.ts +524 -4
- package/dist/solid.js +1 -48
- package/dist/solid.js.map +1 -1
- package/package.json +64 -11
- package/src/addons/animation/easing/backIn.ts +10 -0
- package/src/addons/animation/easing/backInOut.ts +12 -0
- package/src/addons/animation/easing/backOut.ts +10 -0
- package/src/addons/animation/easing/bounceIn.ts +10 -0
- package/src/addons/animation/easing/bounceInOut.ts +13 -0
- package/src/addons/animation/easing/bounceOut.ts +30 -0
- package/src/addons/animation/easing/circularIn.ts +9 -0
- package/src/addons/animation/easing/circularInOut.ts +11 -0
- package/src/addons/animation/easing/circularOut.ts +9 -0
- package/src/addons/animation/easing/cubicIn.ts +9 -0
- package/src/addons/animation/easing/cubicInOut.ts +11 -0
- package/src/addons/animation/easing/cubicOut.ts +10 -0
- package/src/addons/animation/easing/elasticIn.ts +10 -0
- package/src/addons/animation/easing/elasticInOut.ts +21 -0
- package/src/addons/animation/easing/elasticOut.ts +12 -0
- package/src/addons/animation/easing/exponentialIn.ts +9 -0
- package/src/addons/animation/easing/exponentialInOut.ts +13 -0
- package/src/addons/animation/easing/exponentialOut.ts +9 -0
- package/src/addons/animation/easing/index.ts +33 -0
- package/src/addons/animation/easing/linearIn.ts +9 -0
- package/src/addons/animation/easing/linearInOut.ts +9 -0
- package/src/addons/animation/easing/linearOut.ts +9 -0
- package/src/addons/animation/easing/quadraticIn.ts +9 -0
- package/src/addons/animation/easing/quadraticInOut.ts +10 -0
- package/src/addons/animation/easing/quadraticOut.ts +9 -0
- package/src/addons/animation/easing/quarticIn.ts +9 -0
- package/src/addons/animation/easing/quarticInOut.ts +11 -0
- package/src/addons/animation/easing/quarticOut.ts +10 -0
- package/src/addons/animation/easing/quinticIn.ts +9 -0
- package/src/addons/animation/easing/quinticInOut.ts +11 -0
- package/src/addons/animation/easing/quinticOut.ts +9 -0
- package/src/addons/animation/easing/sineIn.ts +10 -0
- package/src/addons/animation/easing/sineInOut.ts +10 -0
- package/src/addons/animation/easing/sineOut.ts +10 -0
- package/src/addons/color/palette/macbeth.ts +42 -0
- package/src/addons/color/space/cmyk2rgb.ts +12 -0
- package/src/addons/color/space/gamma2linear.ts +19 -0
- package/src/addons/color/space/hsl2rgb.ts +20 -0
- package/src/addons/color/space/hsv2rgb.ts +18 -0
- package/src/addons/color/space/hue2rgb.ts +12 -0
- package/src/addons/color/space/index.ts +29 -0
- package/src/addons/color/space/lab2lch.ts +22 -0
- package/src/addons/color/space/lab2rgb.ts +19 -0
- package/src/addons/color/space/lab2xyz.ts +32 -0
- package/src/addons/color/space/lch2lab.ts +21 -0
- package/src/addons/color/space/lch2rgb.ts +22 -0
- package/src/addons/color/space/linear2gamma.ts +19 -0
- package/src/addons/color/space/oklab2rgb.ts +35 -0
- package/src/addons/color/space/rgb2cmyk.ts +13 -0
- package/src/addons/color/space/rgb2hcv.ts +29 -0
- package/src/addons/color/space/rgb2hsl.ts +23 -0
- package/src/addons/color/space/rgb2hsv.ts +36 -0
- package/src/addons/color/space/rgb2hue.ts +29 -0
- package/src/addons/color/space/rgb2lab.ts +19 -0
- package/src/addons/color/space/rgb2lch.ts +22 -0
- package/src/addons/color/space/rgb2oklab.ts +45 -0
- package/src/addons/color/space/rgb2srgb.ts +34 -0
- package/src/addons/color/space/rgb2xyz.ts +20 -0
- package/src/addons/color/space/rgb2yiq.ts +22 -0
- package/src/addons/color/space/rgb2yuv.ts +32 -0
- package/src/addons/color/space/srgb2rgb.ts +34 -0
- package/src/addons/color/space/xyz2lab.ts +27 -0
- package/src/addons/color/space/xyz2rgb.ts +30 -0
- package/src/addons/color/space/yiq2rgb.ts +22 -0
- package/src/addons/color/space/yuv2rgb.ts +32 -0
- package/src/addons/draw/arrows.ts +75 -0
- package/src/addons/draw/axis.ts +57 -0
- package/src/addons/draw/bridge.ts +81 -0
- package/src/addons/draw/char.ts +30 -0
- package/src/addons/draw/circle.ts +29 -0
- package/src/addons/draw/fill.ts +25 -0
- package/src/addons/draw/flip.ts +45 -0
- package/src/addons/draw/hex.ts +29 -0
- package/src/addons/draw/index.ts +13 -0
- package/src/addons/draw/line.ts +16 -0
- package/src/addons/draw/point.ts +30 -0
- package/src/addons/draw/rect.ts +52 -0
- package/src/addons/draw/stroke.ts +31 -0
- package/src/addons/draw/tri.ts +29 -0
- package/src/addons/generative/cnoise.ts +239 -0
- package/src/addons/generative/curl.ts +64 -0
- package/src/addons/generative/fbm.ts +69 -0
- package/src/addons/generative/gerstnerWave.ts +21 -0
- package/src/addons/generative/gnoise.ts +113 -0
- package/src/addons/generative/index.ts +15 -0
- package/src/addons/generative/noised.ts +139 -0
- package/src/addons/generative/pnoise.ts +249 -0
- package/src/addons/generative/psrdnoise.ts +277 -0
- package/src/addons/generative/random.ts +136 -0
- package/src/addons/generative/snoise.ts +199 -0
- package/src/addons/generative/srandom.ts +90 -0
- package/src/addons/generative/voronoi.ts +134 -0
- package/src/addons/generative/voronoise.ts +69 -0
- package/src/addons/generative/wavelet.ts +77 -0
- package/src/addons/generative/worley.ts +99 -0
- package/src/addons/geometry/aabb/aabb.ts +8 -0
- package/src/addons/geometry/aabb/centroid.ts +10 -0
- package/src/addons/geometry/aabb/contain.ts +19 -0
- package/src/addons/geometry/aabb/diagonal.ts +10 -0
- package/src/addons/geometry/aabb/expand.ts +16 -0
- package/src/addons/geometry/aabb/index.ts +7 -0
- package/src/addons/geometry/aabb/intersect.ts +20 -0
- package/src/addons/geometry/aabb/square.ts +17 -0
- package/src/addons/geometry/index.ts +2 -0
- package/src/addons/geometry/triangle/area.ts +10 -0
- package/src/addons/geometry/triangle/barycentric.ts +50 -0
- package/src/addons/geometry/triangle/centroid.ts +10 -0
- package/src/addons/geometry/triangle/closestPoint.ts +85 -0
- package/src/addons/geometry/triangle/contain.ts +19 -0
- package/src/addons/geometry/triangle/distanceSq.ts +38 -0
- package/src/addons/geometry/triangle/index.ts +10 -0
- package/src/addons/geometry/triangle/intersect.ts +49 -0
- package/src/addons/geometry/triangle/normal.ts +12 -0
- package/src/addons/geometry/triangle/signedDistance.ts +31 -0
- package/src/addons/geometry/triangle/triangle.ts +9 -0
- package/src/addons/index.ts +8 -0
- package/src/addons/lighting/ray.ts +8 -0
- package/src/addons/math/aafloor.ts +13 -0
- package/src/addons/math/aafract.ts +38 -0
- package/src/addons/math/aamirror.ts +12 -0
- package/src/addons/math/aastep.ts +14 -0
- package/src/addons/math/absi.ts +9 -0
- package/src/addons/math/adaptiveThreshold.ts +24 -0
- package/src/addons/math/bump.ts +20 -0
- package/src/addons/math/const.ts +19 -0
- package/src/addons/math/cubic.ts +101 -0
- package/src/addons/math/cubicMix.ts +49 -0
- package/src/addons/math/decimate.ts +12 -0
- package/src/addons/math/dist.ts +143 -0
- package/src/addons/math/fcos.ts +11 -0
- package/src/addons/math/frac.ts +9 -0
- package/src/addons/math/gain.ts +14 -0
- package/src/addons/math/gaussian.ts +14 -0
- package/src/addons/math/grad4.ts +19 -0
- package/src/addons/math/hammersley.ts +54 -0
- package/src/addons/math/highPass.ts +12 -0
- package/src/addons/math/index.ts +63 -0
- package/src/addons/math/inside.ts +68 -0
- package/src/addons/math/invCubic.ts +9 -0
- package/src/addons/math/invQuartic.ts +9 -0
- package/src/addons/math/inverse.ts +9 -0
- package/src/addons/math/lengthSq.ts +10 -0
- package/src/addons/math/map.ts +27 -0
- package/src/addons/math/mirror.ts +12 -0
- package/src/addons/math/mmax.ts +27 -0
- package/src/addons/math/mmin.ts +28 -0
- package/src/addons/math/mmix.ts +47 -0
- package/src/addons/math/mod2.ts +44 -0
- package/src/addons/math/mod289.ts +46 -0
- package/src/addons/math/modi.ts +15 -0
- package/src/addons/math/nyquist.ts +15 -0
- package/src/addons/math/pack.ts +15 -0
- package/src/addons/math/parabola.ts +12 -0
- package/src/addons/math/permute.ts +42 -0
- package/src/addons/math/pow2.ts +10 -0
- package/src/addons/math/pow3.ts +9 -0
- package/src/addons/math/pow5.ts +10 -0
- package/src/addons/math/pow7.ts +12 -0
- package/src/addons/math/powFast.ts +18 -0
- package/src/addons/math/quartic.ts +15 -0
- package/src/addons/math/quat/index.ts +14 -0
- package/src/addons/math/quat/quat2mat3.ts +28 -0
- package/src/addons/math/quat/quat2mat4.ts +16 -0
- package/src/addons/math/quat/quatAdd.ts +18 -0
- package/src/addons/math/quat/quatConj.ts +14 -0
- package/src/addons/math/quat/quatDiv.ts +18 -0
- package/src/addons/math/quat/quatIdentity.ts +9 -0
- package/src/addons/math/quat/quatInverse.ts +17 -0
- package/src/addons/math/quat/quatLength.ts +15 -0
- package/src/addons/math/quat/quatLengthSq.ts +14 -0
- package/src/addons/math/quat/quatLerp.ts +40 -0
- package/src/addons/math/quat/quatMul.ts +38 -0
- package/src/addons/math/quat/quatNeg.ts +14 -0
- package/src/addons/math/quat/quatNorm.ts +16 -0
- package/src/addons/math/quat/quatSub.ts +18 -0
- package/src/addons/math/quintic.ts +16 -0
- package/src/addons/math/rotate2d.ts +16 -0
- package/src/addons/math/rotate3d.ts +37 -0
- package/src/addons/math/rotate3dX.ts +20 -0
- package/src/addons/math/rotate3dY.ts +20 -0
- package/src/addons/math/rotate3dZ.ts +20 -0
- package/src/addons/math/rotate4d.ts +41 -0
- package/src/addons/math/rotate4dX.ts +21 -0
- package/src/addons/math/rotate4dY.ts +16 -0
- package/src/addons/math/rotate4dZ.ts +21 -0
- package/src/addons/math/saturateMediump.ts +11 -0
- package/src/addons/math/scale2d.ts +44 -0
- package/src/addons/math/scale3d.ts +17 -0
- package/src/addons/math/scale4d.ts +50 -0
- package/src/addons/math/smootherstep.ts +16 -0
- package/src/addons/math/taylorInvSqrt.ts +9 -0
- package/src/addons/math/toMat3.ts +14 -0
- package/src/addons/math/toMat4.ts +14 -0
- package/src/addons/math/translate4d.ts +31 -0
- package/src/addons/math/unpack.ts +88 -0
- package/src/addons/sdf/boxSDF.ts +24 -0
- package/src/addons/sdf/circleSDF.ts +20 -0
- package/src/addons/sdf/crossSDF.ts +17 -0
- package/src/addons/sdf/hexSDF.ts +18 -0
- package/src/addons/sdf/index.ts +7 -0
- package/src/addons/sdf/lineSDF.ts +33 -0
- package/src/addons/sdf/rectSDF.ts +46 -0
- package/src/addons/sdf/sphereSDF.ts +20 -0
- package/src/addons/sdf/triSDF.ts +14 -0
- package/src/addons/space/aspect.ts +14 -0
- package/src/addons/space/bracketing.ts +44 -0
- package/src/addons/space/brickTile.ts +44 -0
- package/src/addons/space/cart2polar.ts +20 -0
- package/src/addons/space/center.ts +32 -0
- package/src/addons/space/checkerTile.ts +41 -0
- package/src/addons/space/depth2viewZ.ts +43 -0
- package/src/addons/space/displace.ts +55 -0
- package/src/addons/space/equirect2xyz.ts +17 -0
- package/src/addons/space/eulerView.ts +19 -0
- package/src/addons/space/fisheye2xyz.ts +18 -0
- package/src/addons/space/flipY.ts +25 -0
- package/src/addons/space/hexTile.ts +18 -0
- package/src/addons/space/index.ts +38 -0
- package/src/addons/space/kaleidoscope.ts +48 -0
- package/src/addons/space/linearizeDepth.ts +17 -0
- package/src/addons/space/lookAt.ts +49 -0
- package/src/addons/space/lookAtView.ts +40 -0
- package/src/addons/space/mirrorTile.ts +73 -0
- package/src/addons/space/nearest.ts +13 -0
- package/src/addons/space/orthographic.ts +25 -0
- package/src/addons/space/parallaxMapping.ts +149 -0
- package/src/addons/space/perspective.ts +24 -0
- package/src/addons/space/polar2cart.ts +24 -0
- package/src/addons/space/ratio.ts +14 -0
- package/src/addons/space/rotate.ts +37 -0
- package/src/addons/space/rotateX.ts +54 -0
- package/src/addons/space/rotateY.ts +54 -0
- package/src/addons/space/rotateZ.ts +54 -0
- package/src/addons/space/scale.ts +13 -0
- package/src/addons/space/sprite.ts +16 -0
- package/src/addons/space/sqTile.ts +20 -0
- package/src/addons/space/tbn.ts +26 -0
- package/src/addons/space/translate.ts +12 -0
- package/src/addons/space/triTile.ts +32 -0
- package/src/addons/space/uncenter.ts +32 -0
- package/src/addons/space/unratio.ts +12 -0
- package/src/addons/space/viewZ2depth.ts +25 -0
- package/src/addons/space/windmillTile.ts +58 -0
- package/src/addons/space/xyz2equirect.ts +10 -0
- package/src/index.ts +10 -23
- package/src/node/build.ts +127 -0
- package/src/node/create.ts +76 -0
- package/src/node/index.ts +64 -49
- package/src/node/scope.ts +66 -62
- package/src/node/types.ts +221 -187
- package/src/node/utils/const.ts +74 -13
- package/src/node/utils/index.ts +19 -14
- package/src/node/utils/infer.ts +32 -34
- package/src/node/utils/parse.ts +48 -24
- package/src/node/utils/utils.ts +52 -29
- package/src/types.ts +11 -6
- package/src/utils/helpers.ts +56 -0
- package/src/utils/pipeline.ts +24 -8
- package/src/utils/program.ts +62 -38
- package/src/{webgl.ts → utils/webgl.ts} +46 -30
- package/src/{webgpu.ts → utils/webgpu.ts} +22 -17
- package/src/node/core.ts +0 -121
- package/src/node/node.ts +0 -65
package/src/node/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { hex2rgb } from './utils'
|
|
2
|
-
import { builtin as b, conversion as c, function_ as f, uniform as u } from './
|
|
2
|
+
import { builtin as b, conversion as c, function_ as f, uniform as u } from './create'
|
|
3
3
|
import { is } from '../utils/helpers'
|
|
4
|
-
import type { Constants as C, X,
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
4
|
+
import type { Constants as C, Float, X, Y } from './types'
|
|
5
|
+
export * from './build'
|
|
6
|
+
export * from './create'
|
|
7
7
|
export * from './scope'
|
|
8
8
|
export * from './types'
|
|
9
9
|
|
|
@@ -16,7 +16,7 @@ export const fragDepth = b<'float'>('frag_depth')
|
|
|
16
16
|
export const sampleIndex = b<'uint'>('sample_index')
|
|
17
17
|
export const sampleMask = b<'uint'>('sample_mask')
|
|
18
18
|
export const pointCoord = b<'vec2'>('point_coord')
|
|
19
|
-
export const id = b<'
|
|
19
|
+
export const id = b<'uvec3'>('global_invocation_id')
|
|
20
20
|
|
|
21
21
|
// TSL Compatible Builtin Variables
|
|
22
22
|
export const positionLocal = b<'vec3'>('position')
|
|
@@ -29,28 +29,28 @@ export const screenCoordinate = b<'vec2'>('screenCoordinate')
|
|
|
29
29
|
export const screenUV = b<'vec2'>('screenUV')
|
|
30
30
|
|
|
31
31
|
// Type constructors with proper type inference
|
|
32
|
-
export const float = (x?:
|
|
33
|
-
export const int = (x?:
|
|
34
|
-
export const uint = (x?:
|
|
35
|
-
export const bool = (x?:
|
|
36
|
-
export const vec2 = (x?:
|
|
37
|
-
export const vec3 = (x?:
|
|
38
|
-
export const vec4 = (x?:
|
|
39
|
-
export const mat2 = (...args:
|
|
40
|
-
export const mat3 = (...args:
|
|
41
|
-
export const mat4 = (...args:
|
|
42
|
-
export const ivec2 = (x?:
|
|
43
|
-
export const ivec3 = (x?:
|
|
44
|
-
export const ivec4 = (x?:
|
|
45
|
-
export const uvec2 = (x?:
|
|
46
|
-
export const uvec3 = (x?:
|
|
47
|
-
export const uvec4 = (x?:
|
|
48
|
-
export const bvec2 = (x?:
|
|
49
|
-
export const bvec3 = (x?:
|
|
50
|
-
export const bvec4 = (x?:
|
|
51
|
-
export const texture2D = (x?:
|
|
32
|
+
export const float = (x?: Y) => c('float', x)
|
|
33
|
+
export const int = (x?: Y) => c('int', x)
|
|
34
|
+
export const uint = (x?: Y) => c('uint', x)
|
|
35
|
+
export const bool = (x?: Y) => c('bool', x)
|
|
36
|
+
export const vec2 = (x?: Y, y?: Y) => c('vec2', x, y)
|
|
37
|
+
export const vec3 = (x?: Y, y?: Y, z?: Y) => c('vec3', x, y, z)
|
|
38
|
+
export const vec4 = (x?: Y, y?: Y, z?: Y, w?: Y) => c('vec4', x, y, z, w)
|
|
39
|
+
export const mat2 = (...args: Y[]) => c('mat2', ...args)
|
|
40
|
+
export const mat3 = (...args: Y[]) => c('mat3', ...args)
|
|
41
|
+
export const mat4 = (...args: Y[]) => c('mat4', ...args)
|
|
42
|
+
export const ivec2 = (x?: Y, y?: Y) => c('ivec2', x, y)
|
|
43
|
+
export const ivec3 = (x?: Y, y?: Y, z?: Y) => c('ivec3', x, y, z)
|
|
44
|
+
export const ivec4 = (x?: Y, y?: Y, z?: Y, w?: Y) => c('ivec4', x, y, z, w)
|
|
45
|
+
export const uvec2 = (x?: Y, y?: Y) => c('uvec2', x, y)
|
|
46
|
+
export const uvec3 = (x?: Y, y?: Y, z?: Y) => c('uvec3', x, y, z)
|
|
47
|
+
export const uvec4 = (x?: Y, y?: Y, z?: Y, w?: Y) => c('uvec4', x, y, z, w)
|
|
48
|
+
export const bvec2 = (x?: Y, y?: Y) => c('bvec2', x, y)
|
|
49
|
+
export const bvec3 = (x?: Y, y?: Y, z?: Y) => c('bvec3', x, y, z)
|
|
50
|
+
export const bvec4 = (x?: Y, y?: Y, z?: Y, w?: Y) => c('bvec4', x, y, z, w)
|
|
51
|
+
export const texture2D = (x?: Y) => c('texture', x)
|
|
52
52
|
export const sampler2D = () => c('sampler2D')
|
|
53
|
-
export const color = (r?:
|
|
53
|
+
export const color = (r?: Y, g?: Y, b?: Y) => {
|
|
54
54
|
if (is.num(r) && is.und(g) && is.und(b)) return vec3(...hex2rgb(r))
|
|
55
55
|
return vec3(r, g, b)
|
|
56
56
|
}
|
|
@@ -64,20 +64,26 @@ export const uv = position.xy.div(iResolution)
|
|
|
64
64
|
/**
|
|
65
65
|
* 1.1. unified with:
|
|
66
66
|
* 2.1. const.ts BUILTIN_VARIABLES and
|
|
67
|
-
* 3.1. types.ts
|
|
67
|
+
* 3.1. types.ts _N
|
|
68
68
|
*/
|
|
69
69
|
// 0. Always return bool
|
|
70
70
|
export const all = <T extends C>(x: X<T>) => f<'bool'>('all', x)
|
|
71
71
|
export const any = <T extends C>(x: X<T>) => f<'bool'>('any', x)
|
|
72
72
|
|
|
73
|
-
// 2. Always return float
|
|
74
|
-
export const
|
|
73
|
+
// 2. Always return float with WGSL-compliant type constraints and unified parameter types
|
|
74
|
+
export const determinant = <T extends 'mat2' | 'mat3' | 'mat4'>(x: X<T>) => f<'float'>('determinant', x)
|
|
75
|
+
export const distance = <T extends 'vec2' | 'vec3' | 'vec4', U extends C>(x: X<T>, y: number | X<U>) =>
|
|
76
|
+
f<'float'>('distance', x, y)
|
|
77
|
+
export const dot = <T extends 'vec2' | 'vec3' | 'vec4' | 'ivec2' | 'ivec3' | 'ivec4', U extends C>(
|
|
78
|
+
x: X<T>,
|
|
79
|
+
y: number | X<U>
|
|
80
|
+
) => f<T extends `ivec${string}` ? 'int' : 'float'>('dot', x, y)
|
|
81
|
+
export const length = <T extends 'vec2' | 'vec3' | 'vec4'>(x: X<T>) => f<'float'>('length', x)
|
|
75
82
|
export const lengthSq = (x: X) => f<'float'>('lengthSq', x)
|
|
76
|
-
export const
|
|
77
|
-
export const dot = (x: X, y: X) => f<'float'>('dot', x, y)
|
|
83
|
+
export const luminance = (x: X) => f<'float'>('luminance', x)
|
|
78
84
|
|
|
79
|
-
// 3. Always return vec3
|
|
80
|
-
export const cross = (x: X<'vec3'>, y: X<
|
|
85
|
+
// 3. Always return vec3 with vec3 constraint and unified parameter types
|
|
86
|
+
export const cross = <U extends C = 'vec3'>(x: X<'vec3'>, y: number | X<U>) => f<'vec3'>('cross', x, y)
|
|
81
87
|
|
|
82
88
|
// 4. Always return vec4
|
|
83
89
|
export const cubeTexture = (x: X, y: X, z?: X) => f<'vec4'>('cubeTexture', x, y, z)
|
|
@@ -88,7 +94,7 @@ export const textureLod = (x: X, y: X, z?: X) => f<'vec4'>('textureLod', x, y, z
|
|
|
88
94
|
/**
|
|
89
95
|
* 1.2. unified with:
|
|
90
96
|
* 2.2. const.ts FUNCTIONS and
|
|
91
|
-
* 3.2. types.ts
|
|
97
|
+
* 3.2. types.ts _N
|
|
92
98
|
*/
|
|
93
99
|
// 0. Component-wise functions
|
|
94
100
|
export const abs = <T extends C>(x: X<T>) => f<T>('abs', x)
|
|
@@ -113,12 +119,11 @@ export const inverseSqrt = <T extends C>(x: X<T>) => f<T>('inverseSqrt', x)
|
|
|
113
119
|
export const log = <T extends C>(x: X<T>) => f<T>('log', x)
|
|
114
120
|
export const log2 = <T extends C>(x: X<T>) => f<T>('log2', x)
|
|
115
121
|
export const negate = <T extends C>(x: X<T>) => f<T>('negate', x)
|
|
116
|
-
export const normalize = <T extends
|
|
122
|
+
export const normalize = <T extends 'vec2' | 'vec3' | 'vec4'>(x: X<T>) => f<T>('normalize', x)
|
|
117
123
|
export const oneMinus = <T extends C>(x: X<T>) => f<T>('oneMinus', x)
|
|
118
124
|
export const radians = <T extends C>(x: X<T>) => f<T>('radians', x)
|
|
119
125
|
export const reciprocal = <T extends C>(x: X<T>) => f<T>('reciprocal', x)
|
|
120
126
|
export const round = <T extends C>(x: X<T>) => f<T>('round', x)
|
|
121
|
-
export const saturate = <T extends C>(x: X<T>) => f<T>('saturate', x)
|
|
122
127
|
export const sign = <T extends C>(x: X<T>) => f<T>('sign', x)
|
|
123
128
|
export const sin = <T extends C>(x: X<T>) => f<T>('sin', x)
|
|
124
129
|
export const sinh = <T extends C>(x: X<T>) => f<T>('sinh', x)
|
|
@@ -127,17 +132,27 @@ export const tan = <T extends C>(x: X<T>) => f<T>('tan', x)
|
|
|
127
132
|
export const tanh = <T extends C>(x: X<T>) => f<T>('tanh', x)
|
|
128
133
|
export const trunc = <T extends C>(x: X<T>) => f<T>('trunc', x)
|
|
129
134
|
|
|
130
|
-
// 1. Functions where first argument determines return type
|
|
131
|
-
export const atan2 = <T extends C>(x: X<T>, y: X) => f<T>('atan2', x, y)
|
|
132
|
-
export const clamp = <T extends C>(x: X<T>,
|
|
133
|
-
|
|
134
|
-
export const
|
|
135
|
-
export const
|
|
136
|
-
export const
|
|
137
|
-
|
|
138
|
-
export const
|
|
135
|
+
// 1. Functions where first argument determines return type with unified parameter types
|
|
136
|
+
export const atan2 = <T extends C, U extends C>(x: X<T>, y: number | X<U>) => f<T>('atan2', x, y)
|
|
137
|
+
export const clamp = <T extends C, U extends C>(x: X<T>, min: number | X<U>, max: number | X<U>) =>
|
|
138
|
+
f<T>('clamp', x, min, max)
|
|
139
|
+
export const max = <T extends C, U extends C>(x: X<T>, y: number | X<U>) => f<T>('max', x, y)
|
|
140
|
+
export const min = <T extends C, U extends C>(x: X<T>, y: number | X<U>) => f<T>('min', x, y)
|
|
141
|
+
export const mix = <T extends C, U extends C>(x: X<T>, y: number | X<U>, a: number | Float | X<U>) =>
|
|
142
|
+
f<T>('mix', x, y, a)
|
|
143
|
+
export const pow = <T extends C, U extends C>(x: X<T>, y: number | X<U>) => f<T>('pow', x, y)
|
|
144
|
+
export const reflect = <T extends 'vec2' | 'vec3' | 'vec4', U extends C>(I: X<T>, N: number | X<U>) =>
|
|
145
|
+
f<T>('reflect', I, N)
|
|
146
|
+
export const refract = <T extends 'vec2' | 'vec3' | 'vec4', U extends C>(
|
|
147
|
+
I: X<T>,
|
|
148
|
+
N: number | X<U>,
|
|
149
|
+
eta: number | Float
|
|
150
|
+
) => f<T>('refract', I, N, eta)
|
|
139
151
|
|
|
140
|
-
// 2. Functions where not first argument determines return type
|
|
141
|
-
export const smoothstep = <T extends C>(e0: X
|
|
142
|
-
|
|
143
|
-
export const
|
|
152
|
+
// 2. Functions where not first argument determines return type with unified parameter types
|
|
153
|
+
export const smoothstep = <T extends C, U extends C>(e0: number | X<U>, e1: number | X<U>, x: X<T>) =>
|
|
154
|
+
f<T>('smoothstep', e0, e1, x)
|
|
155
|
+
export const step = <T extends C, U extends C>(edge: number | X<U>, x: X<T>) => f<T>('step', edge, x)
|
|
156
|
+
export const mod = <T extends C, U extends C>(x: X<T>, y: number | X<U>) => {
|
|
157
|
+
return (x as any).sub((x as any).div(y).floor().mul(y)) as X<T>
|
|
158
|
+
}
|
package/src/node/scope.ts
CHANGED
|
@@ -1,62 +1,69 @@
|
|
|
1
1
|
import { getId } from './utils'
|
|
2
|
-
import { conversion,
|
|
2
|
+
import { conversion, create } from './create'
|
|
3
3
|
import type {
|
|
4
4
|
FnLayout,
|
|
5
5
|
FnType,
|
|
6
|
-
|
|
7
|
-
NodeProxy,
|
|
8
|
-
X,
|
|
9
|
-
Constants,
|
|
6
|
+
Constants as C,
|
|
10
7
|
Int,
|
|
8
|
+
NodeProps,
|
|
9
|
+
Struct,
|
|
11
10
|
StructFactory,
|
|
12
|
-
StructNode,
|
|
13
11
|
StructFields,
|
|
12
|
+
X,
|
|
13
|
+
Y,
|
|
14
14
|
} from './types'
|
|
15
15
|
|
|
16
|
-
let scope:
|
|
17
|
-
let define:
|
|
16
|
+
let scope: X | null = null
|
|
17
|
+
let define: X | null = null
|
|
18
18
|
|
|
19
|
-
const addToScope = (x:
|
|
19
|
+
export const addToScope = <T extends C>(x: X<T>) => {
|
|
20
20
|
if (!scope) return
|
|
21
21
|
if (!scope.props.children) scope.props.children = []
|
|
22
22
|
scope.props.children.push(x)
|
|
23
|
-
if (x.type !== 'return' || !define) return
|
|
23
|
+
if (x.type !== 'return' || !define) return x
|
|
24
24
|
const { props } = define
|
|
25
25
|
if (!props.inferFrom) props.inferFrom = []
|
|
26
26
|
props.inferFrom.push(x)
|
|
27
|
+
return x
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
export function toVar<T extends StructFields>(x:
|
|
30
|
-
export function toVar<T extends
|
|
30
|
+
export function toVar<T extends StructFields>(x: Struct<T>, id?: string): Struct<T>
|
|
31
|
+
export function toVar<T extends C>(x: X<T>, id?: string): X<T> {
|
|
31
32
|
if (!id) id = getId()
|
|
32
|
-
const y =
|
|
33
|
-
const z =
|
|
33
|
+
const y = create<T>('variable', { id, inferFrom: [x] })
|
|
34
|
+
const z = create<T>('declare', null, x as X, y)
|
|
34
35
|
addToScope(z)
|
|
35
36
|
return y
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
export const assign = <T extends
|
|
39
|
-
const z =
|
|
39
|
+
export const assign = <T extends C>(x: X<T>, isScatter = false, y: Y<T>): X<T> => {
|
|
40
|
+
const z = create(isScatter ? 'scatter' : 'assign', null, x, y)
|
|
40
41
|
addToScope(z)
|
|
41
42
|
return x
|
|
42
43
|
}
|
|
43
44
|
|
|
44
|
-
export const Return = <T extends
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
export const Return = <T extends C>(x?: Y<T>): Y<T> => {
|
|
46
|
+
return addToScope(create<T>('return', { inferFrom: [x] }, x))
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const Break = (): Y => {
|
|
50
|
+
return addToScope(create('break'))
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const Continue = (): Y => {
|
|
54
|
+
return addToScope(create('continue'))
|
|
48
55
|
}
|
|
49
56
|
|
|
50
57
|
export const struct = <T extends StructFields>(fields: T, id = getId()): StructFactory<T> => {
|
|
51
58
|
return (initialValues: StructFields = {}, instanceId = getId()) => {
|
|
52
|
-
const x =
|
|
53
|
-
const y =
|
|
59
|
+
const x = create('variable', { id: instanceId, inferFrom: [id] })
|
|
60
|
+
const y = create('struct', { id, fields, initialValues }, x)
|
|
54
61
|
addToScope(y)
|
|
55
|
-
return x as
|
|
62
|
+
return x as Struct<T>
|
|
56
63
|
}
|
|
57
64
|
}
|
|
58
65
|
|
|
59
|
-
const scoped = (x:
|
|
66
|
+
export const scoped = (x: X, fun: () => X | void, y = define) => {
|
|
60
67
|
const [_scope, _define] = [scope, define]
|
|
61
68
|
;[scope, define] = [x, y]
|
|
62
69
|
const z = fun()
|
|
@@ -64,81 +71,78 @@ const scoped = (x: NodeProxy, fun: () => NodeProxy | void, y = define) => {
|
|
|
64
71
|
;[scope, define] = [_scope, _define]
|
|
65
72
|
}
|
|
66
73
|
|
|
67
|
-
export const
|
|
68
|
-
const
|
|
69
|
-
scoped(
|
|
70
|
-
|
|
74
|
+
export const Scope = <T extends X>(fun: () => T | void) => {
|
|
75
|
+
const scope = create('scope')
|
|
76
|
+
scoped(scope, fun)
|
|
77
|
+
return scope as T
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export const If = (x: Y, fun: () => void) => {
|
|
81
|
+
const y = Scope(fun)
|
|
82
|
+
const ifNode = create('if', null, x, y)
|
|
71
83
|
addToScope(ifNode)
|
|
72
84
|
const ret = () => ({
|
|
73
85
|
ElseIf: (_x: X, _fun: () => void) => {
|
|
74
|
-
const _y =
|
|
75
|
-
scoped(_y, _fun)
|
|
86
|
+
const _y = Scope(_fun)
|
|
76
87
|
ifNode.props.children!.push(_x, _y)
|
|
77
88
|
return ret()
|
|
78
89
|
},
|
|
79
90
|
Else: (_fun: () => void) => {
|
|
80
|
-
const _x =
|
|
81
|
-
scoped(_x, _fun)
|
|
91
|
+
const _x = Scope(_fun)
|
|
82
92
|
ifNode.props.children!.push(_x)
|
|
83
93
|
},
|
|
84
94
|
})
|
|
85
95
|
return ret()
|
|
86
96
|
}
|
|
87
97
|
|
|
88
|
-
export const Loop = (x:
|
|
89
|
-
const y = node('scope')
|
|
98
|
+
export const Loop = (x: Y, fun: (params: { i: Int }) => void) => {
|
|
90
99
|
const id = getId()
|
|
91
|
-
|
|
92
|
-
const ret =
|
|
93
|
-
addToScope(ret)
|
|
94
|
-
return ret
|
|
100
|
+
const y = Scope(() => fun({ i: create<'int'>('variable', { id, inferFrom: [conversion('int', 0)] }) }))
|
|
101
|
+
const ret = create('loop', { id }, x, y)
|
|
102
|
+
return addToScope(ret)
|
|
95
103
|
}
|
|
96
104
|
|
|
97
|
-
export const Switch = (x:
|
|
98
|
-
const switchNode =
|
|
105
|
+
export const Switch = (x: Y) => {
|
|
106
|
+
const switchNode = create('switch', null, x)
|
|
99
107
|
addToScope(switchNode)
|
|
100
108
|
const ret = () => ({
|
|
101
109
|
Case: (...values: X[]) => {
|
|
102
110
|
return (fun: () => void) => {
|
|
103
|
-
const y =
|
|
104
|
-
scoped(y, fun)
|
|
111
|
+
const y = Scope(fun)
|
|
105
112
|
for (const _x of values) switchNode.props.children!.push(_x, y)
|
|
106
113
|
return ret()
|
|
107
114
|
}
|
|
108
115
|
},
|
|
109
116
|
Default: (fun: () => void) => {
|
|
110
|
-
const scope =
|
|
111
|
-
scoped(scope, fun)
|
|
117
|
+
const scope = Scope(fun)
|
|
112
118
|
switchNode.props.children!.push(scope)
|
|
113
119
|
},
|
|
114
120
|
})
|
|
115
121
|
return ret()
|
|
116
122
|
}
|
|
117
123
|
|
|
118
|
-
export function Fn<T extends
|
|
119
|
-
fun: (args: Args) => T,
|
|
120
|
-
defaultId = getId()
|
|
121
|
-
) {
|
|
122
|
-
let layout: FnLayout
|
|
124
|
+
export function Fn<T extends X | Struct | void, Args extends any[]>(fun: (args: Args) => T, layout?: FnLayout) {
|
|
123
125
|
const ret = (...args: any[]) => {
|
|
124
|
-
const id = layout?.name ||
|
|
125
|
-
const
|
|
126
|
-
const paramVars: NodeProxy[] = []
|
|
126
|
+
const id = layout?.name || getId()
|
|
127
|
+
const paramVars: X[] = []
|
|
127
128
|
const paramDefs: NodeProps[] = []
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
129
|
+
for (let i = 0; i < args.length; i++) {
|
|
130
|
+
const input = layout?.inputs?.[i]
|
|
131
|
+
if (!input) paramDefs.push({ id: `p${i}`, inferFrom: [args[i]] })
|
|
132
|
+
else
|
|
133
|
+
paramDefs.push({
|
|
134
|
+
id: input.name,
|
|
135
|
+
inferFrom:
|
|
136
|
+
input.type === 'auto' ? [args[i]] : [conversion(input.type, args[i])],
|
|
137
|
+
})
|
|
136
138
|
}
|
|
137
|
-
for (const props of paramDefs) paramVars.push(
|
|
138
|
-
const
|
|
139
|
+
for (const props of paramDefs) paramVars.push(create('variable', props))
|
|
140
|
+
const x = create('scope')
|
|
141
|
+
const y = create('define', { id, layout }, x, ...args)
|
|
139
142
|
scoped(x, () => fun(paramVars as Args) as any, y)
|
|
140
143
|
return y
|
|
141
144
|
}
|
|
145
|
+
ret.getLayout = () => layout
|
|
142
146
|
ret.setLayout = (_layout: FnLayout) => {
|
|
143
147
|
layout = _layout
|
|
144
148
|
return ret
|