glre 0.39.0 → 0.41.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 +1 -1
- package/dist/addons.cjs.map +1 -1
- package/dist/addons.d.ts +853 -22
- package/dist/addons.js +1 -1
- package/dist/addons.js.map +1 -1
- package/dist/index.cjs +8 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +47 -28
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/dist/native.d.ts +60 -33
- package/dist/node.cjs +59 -30
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.ts +39 -26
- package/dist/node.js +59 -30
- package/dist/node.js.map +1 -1
- package/dist/react.d.ts +47 -28
- package/dist/solid.d.ts +47 -28
- package/package.json +24 -24
- 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 -6
- 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 +5 -2
- package/src/node/build.ts +62 -52
- package/src/node/create.ts +3 -0
- package/src/node/index.ts +1 -2
- package/src/node/scope.ts +27 -25
- package/src/node/types.ts +16 -12
- package/src/node/utils/const.ts +12 -11
- package/src/node/utils/index.ts +15 -12
- package/src/node/utils/infer.ts +17 -6
- package/src/node/utils/parse.ts +37 -13
- package/src/node/utils/utils.ts +40 -22
- package/src/types.ts +13 -5
- package/src/utils/helpers.ts +80 -7
- package/src/utils/pipeline.ts +21 -5
- package/src/utils/program.ts +68 -42
- package/src/utils/webgl.ts +47 -37
- package/src/utils/webgpu.ts +30 -38
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Fn, Vec3, Mat3, mat3, normalize, cross } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const tbn = Fn(([t, b, n]: [Vec3, Vec3, Vec3]): Mat3 => {
|
|
4
|
+
return mat3(t, b, n)
|
|
5
|
+
}).setLayout({
|
|
6
|
+
name: 'tbn',
|
|
7
|
+
type: 'mat3',
|
|
8
|
+
inputs: [
|
|
9
|
+
{ name: 't', type: 'vec3' },
|
|
10
|
+
{ name: 'b', type: 'vec3' },
|
|
11
|
+
{ name: 'n', type: 'vec3' },
|
|
12
|
+
],
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
export const tbnFromNormal = Fn(([n, up]: [Vec3, Vec3]): Mat3 => {
|
|
16
|
+
const t = normalize(cross(up, n)).toVar('t')
|
|
17
|
+
const b = cross(n, t).toVar('b')
|
|
18
|
+
return tbn(t, b, n)
|
|
19
|
+
}).setLayout({
|
|
20
|
+
name: 'tbnFromNormal',
|
|
21
|
+
type: 'mat3',
|
|
22
|
+
inputs: [
|
|
23
|
+
{ name: 'n', type: 'vec3' },
|
|
24
|
+
{ name: 'up', type: 'vec3' },
|
|
25
|
+
],
|
|
26
|
+
})
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Fn, Mat3, Vec3, vec4, mat4 } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const translateMat3 = Fn(([m, translation]: [Mat3, Vec3]) => {
|
|
4
|
+
return mat4(vec4(m[0], 0), vec4(m[1], 0), vec4(m[2], 0), vec4(translation, 1))
|
|
5
|
+
}).setLayout({
|
|
6
|
+
name: 'translateMat3',
|
|
7
|
+
type: 'mat4',
|
|
8
|
+
inputs: [
|
|
9
|
+
{ name: 'm', type: 'mat3' },
|
|
10
|
+
{ name: 'translation', type: 'vec3' },
|
|
11
|
+
],
|
|
12
|
+
})
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Fn, Vec2, Vec4, Float, mat2, vec2, vec4, floor, fract, dot } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const triTile = Fn(([st]: [Vec2]): Vec4 => {
|
|
4
|
+
const transformed = st.mul(mat2(vec2(1, -1 / 1.7320508), vec2(0, 2 / 1.7320508))).toVar()
|
|
5
|
+
const f = vec4(transformed, transformed.negate()).toVar()
|
|
6
|
+
const i = floor(f).toVar()
|
|
7
|
+
const fFractional = fract(f).toVar()
|
|
8
|
+
|
|
9
|
+
const dotXY = dot(fFractional.xy, fFractional.xy)
|
|
10
|
+
const dotZW = dot(fFractional.zw, fFractional.zw)
|
|
11
|
+
|
|
12
|
+
const condition = dotXY.lessThan(dotZW)
|
|
13
|
+
const trueValue = vec4(fFractional.xy, vec2(2, 1).mul(i.xy))
|
|
14
|
+
const falseValue = vec4(fFractional.zw, vec2(2, 1).mul(i.zw).add(1).negate())
|
|
15
|
+
|
|
16
|
+
return falseValue.select(trueValue, condition)
|
|
17
|
+
}).setLayout({
|
|
18
|
+
name: 'triTile',
|
|
19
|
+
type: 'vec4',
|
|
20
|
+
inputs: [{ name: 'st', type: 'vec2' }],
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
export const triTileScaled = Fn(([st, scale]: [Vec2, Float]): Vec4 => {
|
|
24
|
+
return triTile(st.mul(scale))
|
|
25
|
+
}).setLayout({
|
|
26
|
+
name: 'triTileScaled',
|
|
27
|
+
type: 'vec4',
|
|
28
|
+
inputs: [
|
|
29
|
+
{ name: 'st', type: 'vec2' },
|
|
30
|
+
{ name: 'scale', type: 'float' },
|
|
31
|
+
],
|
|
32
|
+
})
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Fn, Float, Vec2, Vec3 } from '../../node'
|
|
2
|
+
|
|
3
|
+
function uncenter(x: Float): Float
|
|
4
|
+
function uncenter(v: Vec2): Vec2
|
|
5
|
+
function uncenter(v: Vec3): Vec3
|
|
6
|
+
function uncenter(v: any): any {
|
|
7
|
+
return v.mul(0.5).add(0.5)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const uncenterFloat = Fn(([x]: [Float]): Float => {
|
|
11
|
+
return uncenter(x)
|
|
12
|
+
}).setLayout({
|
|
13
|
+
name: 'uncenterFloat',
|
|
14
|
+
type: 'float',
|
|
15
|
+
inputs: [{ name: 'x', type: 'float' }],
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
export const uncenterVec2 = Fn(([v]: [Vec2]): Vec2 => {
|
|
19
|
+
return uncenter(v)
|
|
20
|
+
}).setLayout({
|
|
21
|
+
name: 'uncenterVec2',
|
|
22
|
+
type: 'vec2',
|
|
23
|
+
inputs: [{ name: 'v', type: 'vec2' }],
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
export const uncenterVec3 = Fn(([v]: [Vec3]): Vec3 => {
|
|
27
|
+
return uncenter(v)
|
|
28
|
+
}).setLayout({
|
|
29
|
+
name: 'uncenterVec3',
|
|
30
|
+
type: 'vec3',
|
|
31
|
+
inputs: [{ name: 'v', type: 'vec3' }],
|
|
32
|
+
})
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Fn, Vec2, vec2 } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const unratio = Fn(([st, s]: [Vec2, Vec2]): Vec2 => {
|
|
4
|
+
return vec2(st.x, st.y.mul(s.x.div(s.y)).add(s.y.mul(0.5).sub(s.x.mul(0.5)).div(s.y)))
|
|
5
|
+
}).setLayout({
|
|
6
|
+
name: 'unratio',
|
|
7
|
+
type: 'vec2',
|
|
8
|
+
inputs: [
|
|
9
|
+
{ name: 'st', type: 'vec2' },
|
|
10
|
+
{ name: 's', type: 'vec2' },
|
|
11
|
+
],
|
|
12
|
+
})
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Fn, Float } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const viewZ2depth = Fn(([viewZ, near, far]: [Float, Float, Float]): Float => {
|
|
4
|
+
return viewZ.add(near).mul(far).div(far.sub(near).mul(viewZ))
|
|
5
|
+
}).setLayout({
|
|
6
|
+
name: 'viewZ2depth',
|
|
7
|
+
type: 'float',
|
|
8
|
+
inputs: [
|
|
9
|
+
{ name: 'viewZ', type: 'float' },
|
|
10
|
+
{ name: 'near', type: 'float' },
|
|
11
|
+
{ name: 'far', type: 'float' },
|
|
12
|
+
],
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
export const viewZ2depthOrthographic = Fn(([viewZ, near, far]: [Float, Float, Float]): Float => {
|
|
16
|
+
return viewZ.add(near).div(near.sub(far))
|
|
17
|
+
}).setLayout({
|
|
18
|
+
name: 'viewZ2depthOrthographic',
|
|
19
|
+
type: 'float',
|
|
20
|
+
inputs: [
|
|
21
|
+
{ name: 'viewZ', type: 'float' },
|
|
22
|
+
{ name: 'near', type: 'float' },
|
|
23
|
+
{ name: 'far', type: 'float' },
|
|
24
|
+
],
|
|
25
|
+
})
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Fn, Vec2, Vec4, Float, mod, abs, vec4 } from '../../node'
|
|
2
|
+
import { rotate2DBasic } from './rotate'
|
|
3
|
+
import { sqTile } from './sqTile'
|
|
4
|
+
|
|
5
|
+
export const windmillTile = Fn(([t, turn]: [Vec4, Float]): Vec4 => {
|
|
6
|
+
const a = abs(mod(t.z, 2).sub(mod(t.w, 2)))
|
|
7
|
+
.add(mod(t.w, 2).mul(2))
|
|
8
|
+
.mul(0.25)
|
|
9
|
+
return vec4(rotate2DBasic(t.xy, a.mul(turn)), t.zw)
|
|
10
|
+
}).setLayout({
|
|
11
|
+
name: 'windmillTile',
|
|
12
|
+
type: 'vec4',
|
|
13
|
+
inputs: [
|
|
14
|
+
{ name: 't', type: 'vec4' },
|
|
15
|
+
{ name: 'turn', type: 'float' },
|
|
16
|
+
],
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
export const windmillTileDefault = Fn(([t]: [Vec4]): Vec4 => {
|
|
20
|
+
const a = abs(mod(t.z, 2).sub(mod(t.w, 2)))
|
|
21
|
+
.add(mod(t.w, 2).mul(2))
|
|
22
|
+
.mul(0.25)
|
|
23
|
+
return vec4(rotate2DBasic(t.xy, a.mul(6.283185307179586)), t.zw)
|
|
24
|
+
}).setLayout({
|
|
25
|
+
name: 'windmillTileDefault',
|
|
26
|
+
type: 'vec4',
|
|
27
|
+
inputs: [{ name: 't', type: 'vec4' }],
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
export const windmillTileVec2 = Fn(([v]: [Vec2]): Vec4 => {
|
|
31
|
+
return windmillTileDefault(sqTile(v))
|
|
32
|
+
}).setLayout({
|
|
33
|
+
name: 'windmillTileVec2',
|
|
34
|
+
type: 'vec4',
|
|
35
|
+
inputs: [{ name: 'v', type: 'vec2' }],
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
export const windmillTileFloat = Fn(([v, s]: [Vec2, Float]): Vec4 => {
|
|
39
|
+
return windmillTileVec2(v.mul(s))
|
|
40
|
+
}).setLayout({
|
|
41
|
+
name: 'windmillTileFloat',
|
|
42
|
+
type: 'vec4',
|
|
43
|
+
inputs: [
|
|
44
|
+
{ name: 'v', type: 'vec2' },
|
|
45
|
+
{ name: 's', type: 'float' },
|
|
46
|
+
],
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
export const windmillTileVec2Scale = Fn(([v, s]: [Vec2, Vec2]): Vec4 => {
|
|
50
|
+
return windmillTileVec2(v.mul(s))
|
|
51
|
+
}).setLayout({
|
|
52
|
+
name: 'windmillTileVec2Scale',
|
|
53
|
+
type: 'vec4',
|
|
54
|
+
inputs: [
|
|
55
|
+
{ name: 'v', type: 'vec2' },
|
|
56
|
+
{ name: 's', type: 'vec2' },
|
|
57
|
+
],
|
|
58
|
+
})
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Fn, Vec3, Vec2, vec2, atan2, acos } from '../../node'
|
|
2
|
+
import { PI, TWO_PI } from '../math/const'
|
|
3
|
+
|
|
4
|
+
export const xyz2equirect = Fn(([d]: [Vec3]): Vec2 => {
|
|
5
|
+
return vec2(atan2(d.z, d.x).add(PI), acos(d.y.negate())).div(vec2(TWO_PI, PI))
|
|
6
|
+
}).setLayout({
|
|
7
|
+
name: 'xyz2equirect',
|
|
8
|
+
type: 'vec2',
|
|
9
|
+
inputs: [{ name: 'd', type: 'vec3' }],
|
|
10
|
+
})
|
package/src/index.ts
CHANGED
|
@@ -30,11 +30,14 @@ export const createGL = (props?: Partial<GL>) => {
|
|
|
30
30
|
isWebGL: true,
|
|
31
31
|
isError: false,
|
|
32
32
|
isLoop: true,
|
|
33
|
+
isDebug: false,
|
|
34
|
+
isDepth: false,
|
|
33
35
|
isGL: true,
|
|
34
36
|
size: [0, 0],
|
|
35
37
|
mouse: [0, 0],
|
|
36
38
|
count: 6,
|
|
37
|
-
|
|
39
|
+
instanceCount: 1,
|
|
40
|
+
particleCount: 1024,
|
|
38
41
|
webgl: {},
|
|
39
42
|
webgpu: {},
|
|
40
43
|
loading: 0,
|
|
@@ -50,6 +53,7 @@ export const createGL = (props?: Partial<GL>) => {
|
|
|
50
53
|
gl.frame = createFrame()
|
|
51
54
|
|
|
52
55
|
gl.attribute = durable((k, v, i) => gl.queue(() => gl._attribute?.(k, v, i)), gl)
|
|
56
|
+
gl.instance = durable((k, v, at) => gl.queue(() => gl._instance?.(k, v, at)), gl)
|
|
53
57
|
gl.storage = durable((k, v) => gl.queue(() => gl._storage?.(k, v)), gl)
|
|
54
58
|
gl.uniform = durable((k, v) => gl.queue(() => gl._uniform?.(k, v)), gl)
|
|
55
59
|
gl.texture = durable((k, v) => gl.queue(() => gl._texture?.(k, v)), gl)
|
|
@@ -109,4 +113,3 @@ export const createGL = (props?: Partial<GL>) => {
|
|
|
109
113
|
}
|
|
110
114
|
|
|
111
115
|
export default createGL
|
|
112
|
-
|
package/src/node/build.ts
CHANGED
|
@@ -25,14 +25,17 @@ const topological = (headers: Map<string, string>, dependencies: Map<string, Set
|
|
|
25
25
|
return sorted
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
const
|
|
28
|
+
const build = (x: X, c: NodeContext) => {
|
|
29
29
|
const body = code(x, c)
|
|
30
30
|
let head = ''
|
|
31
31
|
if (c.isWebGL && c.code?.dependencies) {
|
|
32
32
|
const sorted = topological(c.code.headers, c.code.dependencies)
|
|
33
33
|
head = sorted.map(([, value]) => value).join('\n')
|
|
34
34
|
} else head = Array.from(c.code?.headers?.values() || []).join('\n')
|
|
35
|
-
|
|
35
|
+
let [lines, ret] = body.split('return ')
|
|
36
|
+
if (ret) ret = ret.replace(';', '')
|
|
37
|
+
else [lines, ret] = ['', body]
|
|
38
|
+
return [head, lines.trim(), ret]
|
|
36
39
|
}
|
|
37
40
|
|
|
38
41
|
const generateStruct = (id: string, map: Map<string, string>) => {
|
|
@@ -42,76 +45,83 @@ const generateStruct = (id: string, map: Map<string, string>) => {
|
|
|
42
45
|
export const fragment = (x: X, c: NodeContext = {}) => {
|
|
43
46
|
c.code?.headers?.clear()
|
|
44
47
|
c.label = 'frag' // for varying inputs or outputs
|
|
45
|
-
const [head,
|
|
46
|
-
const
|
|
48
|
+
const [head, lines, ret] = build(x, c)
|
|
49
|
+
const result = []
|
|
47
50
|
if (c.isWebGL) {
|
|
48
|
-
|
|
49
|
-
for (const code of c.code?.fragInputs?.values() || [])
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
result.push(GLSL_FRAGMENT_HEAD)
|
|
52
|
+
for (const code of c.code?.fragInputs?.values() || []) result.push(`in ${code}`)
|
|
53
|
+
result.push(head)
|
|
54
|
+
result.push('void main() {')
|
|
55
|
+
result.push(` ${lines}`)
|
|
56
|
+
result.push(` fragColor = ${ret};`)
|
|
52
57
|
} else {
|
|
53
|
-
if (c.code?.fragInputs?.size)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
if (c.code?.fragInputs?.size) result.push(generateStruct('Out', c.code.fragInputs))
|
|
59
|
+
result.push(head)
|
|
60
|
+
result.push(`@fragment\nfn main(out: Out) -> @location(0) vec4f {`)
|
|
61
|
+
result.push(` ${lines}`)
|
|
62
|
+
result.push(` return ${ret};`)
|
|
57
63
|
}
|
|
58
|
-
|
|
59
|
-
const main =
|
|
60
|
-
|
|
64
|
+
result.push('}')
|
|
65
|
+
const main = result.filter(Boolean).join('\n').trim()
|
|
66
|
+
if (c.gl?.isDebug) console.log(`↓↓↓generated↓↓↓\n${main}`)
|
|
61
67
|
return main
|
|
62
68
|
}
|
|
63
69
|
|
|
64
70
|
export const vertex = (x: X, c: NodeContext = {}) => {
|
|
65
71
|
c.code?.headers?.clear()
|
|
66
72
|
c.label = 'vert' // for varying inputs or outputs
|
|
67
|
-
const [head,
|
|
68
|
-
const
|
|
73
|
+
const [head, lines, ret] = build(x, c)
|
|
74
|
+
const result = []
|
|
69
75
|
if (c.isWebGL) {
|
|
70
|
-
|
|
71
|
-
for (const code of c.code?.vertInputs?.values() || [])
|
|
72
|
-
for (const code of c.code?.vertOutputs?.values() || [])
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
result.push('#version 300 es')
|
|
77
|
+
for (const code of c.code?.vertInputs?.values() || []) result.push(`in ${code}`)
|
|
78
|
+
for (const code of c.code?.vertOutputs?.values() || []) result.push(`out ${code}`)
|
|
79
|
+
result.push(head)
|
|
80
|
+
result.push('void main() {')
|
|
81
|
+
result.push(` ${lines}`)
|
|
82
|
+
result.push(` gl_Position = ${ret};`)
|
|
83
|
+
for (const [id, code] of c.code?.vertVaryings?.entries() || []) result.push(` ${id} = ${code};`)
|
|
77
84
|
} else {
|
|
78
|
-
if (c.code?.vertInputs?.size)
|
|
79
|
-
if (c.code?.vertOutputs?.size)
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
if (c.code?.vertInputs?.size) result.push(generateStruct('In', c.code.vertInputs))
|
|
86
|
+
if (c.code?.vertOutputs?.size) result.push(generateStruct('Out', c.code.vertOutputs))
|
|
87
|
+
result.push(head)
|
|
88
|
+
result.push('@vertex')
|
|
89
|
+
result.push(`fn main(${c.code?.vertInputs?.size ? 'in: In' : ''}) -> Out {`)
|
|
90
|
+
result.push(' var out: Out;')
|
|
91
|
+
result.push(` ${lines}`)
|
|
92
|
+
result.push(` out.position = ${ret};`)
|
|
93
|
+
for (const [id, code] of c.code?.vertVaryings?.entries() || []) result.push(` out.${id} = ${code};`)
|
|
94
|
+
result.push(' return out;')
|
|
87
95
|
}
|
|
88
|
-
|
|
89
|
-
const main =
|
|
90
|
-
|
|
96
|
+
result.push('}')
|
|
97
|
+
const main = result.filter(Boolean).join('\n').trim()
|
|
98
|
+
if (c.gl?.isDebug) console.log(`↓↓↓generated↓↓↓\n${main}`)
|
|
91
99
|
return main
|
|
92
100
|
}
|
|
93
101
|
|
|
94
102
|
export const compute = (x: X, c: NodeContext = {}) => {
|
|
95
103
|
c.code?.headers?.clear()
|
|
96
104
|
c.label = 'compute'
|
|
97
|
-
const [head,
|
|
98
|
-
const
|
|
105
|
+
const [head, lines, ret] = build(x, c)
|
|
106
|
+
const result = []
|
|
99
107
|
if (c.isWebGL) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
108
|
+
result.push('#version 300 es')
|
|
109
|
+
result.push('precision mediump float;')
|
|
110
|
+
result.push(head)
|
|
111
|
+
result.push('void main() {')
|
|
112
|
+
result.push(` ${lines}`)
|
|
113
|
+
result.push(` ${ret};`)
|
|
114
|
+
result.push('}')
|
|
106
115
|
} else {
|
|
107
|
-
if (c.code?.computeInputs?.size)
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
116
|
+
if (c.code?.computeInputs?.size) result.push(generateStruct('In', c.code.computeInputs))
|
|
117
|
+
result.push(head)
|
|
118
|
+
result.push('@compute @workgroup_size(32)')
|
|
119
|
+
result.push(`fn main(${c.code?.computeInputs?.size ? 'in: In' : ''}) {`)
|
|
120
|
+
result.push(` ${lines}`)
|
|
121
|
+
result.push(` ${ret};`)
|
|
122
|
+
result.push('}')
|
|
113
123
|
}
|
|
114
|
-
const main =
|
|
115
|
-
|
|
124
|
+
const main = result.filter(Boolean).join('\n').trim()
|
|
125
|
+
if (c.gl?.isDebug) console.log(`↓↓↓generated↓↓↓\n${main}`)
|
|
116
126
|
return main
|
|
117
127
|
}
|
package/src/node/create.ts
CHANGED
|
@@ -25,6 +25,7 @@ export const create = <T extends C>(type: NodeTypes, props?: NodeProps | null, .
|
|
|
25
25
|
if (key === Symbol.toPrimitive) return toPrimitive.bind(null, x)
|
|
26
26
|
if (key === 'listeners') return listeners
|
|
27
27
|
if (key === 'attribute') return (id = getId()) => attribute(x, id)
|
|
28
|
+
if (key === 'instance') return (id = getId()) => instance(x, id)
|
|
28
29
|
if (key === 'constant') return (id = getId()) => constant(x, id)
|
|
29
30
|
if (key === 'uniform') return (id = getId()) => uniform(x, id)
|
|
30
31
|
if (key === 'variable') return (id = getId()) => variable(id)
|
|
@@ -33,6 +34,7 @@ export const create = <T extends C>(type: NodeTypes, props?: NodeProps | null, .
|
|
|
33
34
|
if (key === 'element') return (arg: Y) => (type === 'storage' ? gather(x, arg) : element(x, arg))
|
|
34
35
|
if (key === 'member') return (arg: Y) => member(x, arg)
|
|
35
36
|
if (key === 'assign') return assign.bind(null, x, x.type === 'gather')
|
|
37
|
+
if (key === 'select') return select.bind(null, x)
|
|
36
38
|
if (isOperator(key)) {
|
|
37
39
|
return key.endsWith('Assign')
|
|
38
40
|
? (...args: Y[]) => addToScope(operator(key, x, ...args))
|
|
@@ -53,6 +55,7 @@ export const create = <T extends C>(type: NodeTypes, props?: NodeProps | null, .
|
|
|
53
55
|
|
|
54
56
|
// headers with proper type inference
|
|
55
57
|
export const attribute = <T extends C>(x: Y<T>, id = getId()) => create<T>('attribute', { id }, x)
|
|
58
|
+
export const instance = <T extends C>(x: Y<T>, id = getId()) => create<T>('instance', { id }, x)
|
|
56
59
|
export const constant = <T extends C>(x: Y<T>, id = getId()) => create<T>('constant', { id }, x)
|
|
57
60
|
export const uniform = <T extends C>(x: Y<T>, id = getId()) => create<T>('uniform', { id }, x)
|
|
58
61
|
export const storage = <T extends C>(x: Y<T>, id = getId()) => create<T>('storage', { id }, x)
|
package/src/node/index.ts
CHANGED
|
@@ -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')
|
|
@@ -124,7 +124,6 @@ export const oneMinus = <T extends C>(x: X<T>) => f<T>('oneMinus', x)
|
|
|
124
124
|
export const radians = <T extends C>(x: X<T>) => f<T>('radians', x)
|
|
125
125
|
export const reciprocal = <T extends C>(x: X<T>) => f<T>('reciprocal', x)
|
|
126
126
|
export const round = <T extends C>(x: X<T>) => f<T>('round', x)
|
|
127
|
-
export const saturate = <T extends C>(x: X<T>) => f<T>('saturate', x)
|
|
128
127
|
export const sign = <T extends C>(x: X<T>) => f<T>('sign', x)
|
|
129
128
|
export const sin = <T extends C>(x: X<T>) => f<T>('sin', x)
|
|
130
129
|
export const sinh = <T extends C>(x: X<T>) => f<T>('sinh', x)
|
package/src/node/scope.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { getId } from './utils'
|
|
2
1
|
import { conversion, create } from './create'
|
|
3
2
|
import type {
|
|
4
3
|
FnLayout,
|
|
@@ -12,6 +11,7 @@ import type {
|
|
|
12
11
|
X,
|
|
13
12
|
Y,
|
|
14
13
|
} from './types'
|
|
14
|
+
import { getId } from './utils'
|
|
15
15
|
|
|
16
16
|
let scope: X | null = null
|
|
17
17
|
let define: X | null = null
|
|
@@ -42,7 +42,7 @@ export const assign = <T extends C>(x: X<T>, isScatter = false, y: Y<T>): X<T> =
|
|
|
42
42
|
return x
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
export const Return = <T extends C>(x
|
|
45
|
+
export const Return = <T extends C>(x?: Y<T>): Y<T> => {
|
|
46
46
|
return addToScope(create<T>('return', { inferFrom: [x] }, x))
|
|
47
47
|
}
|
|
48
48
|
|
|
@@ -71,21 +71,24 @@ export const scoped = (x: X, fun: () => X | void, y = define) => {
|
|
|
71
71
|
;[scope, define] = [_scope, _define]
|
|
72
72
|
}
|
|
73
73
|
|
|
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
|
+
|
|
74
80
|
export const If = (x: Y, fun: () => void) => {
|
|
75
|
-
const y =
|
|
76
|
-
scoped(y, fun)
|
|
81
|
+
const y = Scope(fun)
|
|
77
82
|
const ifNode = create('if', null, x, y)
|
|
78
83
|
addToScope(ifNode)
|
|
79
84
|
const ret = () => ({
|
|
80
85
|
ElseIf: (_x: X, _fun: () => void) => {
|
|
81
|
-
const _y =
|
|
82
|
-
scoped(_y, _fun)
|
|
86
|
+
const _y = Scope(_fun)
|
|
83
87
|
ifNode.props.children!.push(_x, _y)
|
|
84
88
|
return ret()
|
|
85
89
|
},
|
|
86
90
|
Else: (_fun: () => void) => {
|
|
87
|
-
const _x =
|
|
88
|
-
scoped(_x, _fun)
|
|
91
|
+
const _x = Scope(_fun)
|
|
89
92
|
ifNode.props.children!.push(_x)
|
|
90
93
|
},
|
|
91
94
|
})
|
|
@@ -93,9 +96,8 @@ export const If = (x: Y, fun: () => void) => {
|
|
|
93
96
|
}
|
|
94
97
|
|
|
95
98
|
export const Loop = (x: Y, fun: (params: { i: Int }) => void) => {
|
|
96
|
-
const y = create('scope')
|
|
97
99
|
const id = getId()
|
|
98
|
-
|
|
100
|
+
const y = Scope(() => fun({ i: create<'int'>('variable', { id, inferFrom: [conversion('int', 0)] }) }))
|
|
99
101
|
const ret = create('loop', { id }, x, y)
|
|
100
102
|
return addToScope(ret)
|
|
101
103
|
}
|
|
@@ -106,42 +108,42 @@ export const Switch = (x: Y) => {
|
|
|
106
108
|
const ret = () => ({
|
|
107
109
|
Case: (...values: X[]) => {
|
|
108
110
|
return (fun: () => void) => {
|
|
109
|
-
const y =
|
|
110
|
-
scoped(y, fun)
|
|
111
|
+
const y = Scope(fun)
|
|
111
112
|
for (const _x of values) switchNode.props.children!.push(_x, y)
|
|
112
113
|
return ret()
|
|
113
114
|
}
|
|
114
115
|
},
|
|
115
116
|
Default: (fun: () => void) => {
|
|
116
|
-
const scope =
|
|
117
|
-
scoped(scope, fun)
|
|
117
|
+
const scope = Scope(fun)
|
|
118
118
|
switchNode.props.children!.push(scope)
|
|
119
119
|
},
|
|
120
120
|
})
|
|
121
121
|
return ret()
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
export function Fn<T extends X | Struct | void, Args extends any[]>(fun: (args: Args) => T,
|
|
125
|
-
|
|
124
|
+
export function Fn<T extends X | Struct | void, Args extends any[]>(fun: (args: Args) => T, layout?: FnLayout) {
|
|
125
|
+
const defaultId = getId()
|
|
126
126
|
const ret = (...args: any[]) => {
|
|
127
127
|
const id = layout?.name || defaultId
|
|
128
|
-
const x = create('scope')
|
|
129
128
|
const paramVars: X[] = []
|
|
130
129
|
const paramDefs: NodeProps[] = []
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
130
|
+
for (let i = 0; i < args.length; i++) {
|
|
131
|
+
const input = layout?.inputs?.[i]
|
|
132
|
+
if (!input) paramDefs.push({ id: `p${i}`, inferFrom: [args[i]] })
|
|
133
|
+
else
|
|
134
|
+
paramDefs.push({
|
|
135
|
+
id: input.name,
|
|
136
|
+
inferFrom:
|
|
137
|
+
input.type === 'auto' ? [args[i]] : [conversion(input.type, args[i])],
|
|
138
|
+
})
|
|
139
139
|
}
|
|
140
140
|
for (const props of paramDefs) paramVars.push(create('variable', props))
|
|
141
|
+
const x = create('scope')
|
|
141
142
|
const y = create('define', { id, layout }, x, ...args)
|
|
142
143
|
scoped(x, () => fun(paramVars as Args) as any, y)
|
|
143
144
|
return y
|
|
144
145
|
}
|
|
146
|
+
ret.getLayout = () => layout
|
|
145
147
|
ret.setLayout = (_layout: FnLayout) => {
|
|
146
148
|
layout = _layout
|
|
147
149
|
return ret
|
package/src/node/types.ts
CHANGED
|
@@ -14,12 +14,13 @@ export interface FnLayout {
|
|
|
14
14
|
type: C | 'auto'
|
|
15
15
|
inputs?: Array<{
|
|
16
16
|
name: string
|
|
17
|
-
type: C
|
|
17
|
+
type: C | 'auto'
|
|
18
18
|
}>
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export interface FnType<T extends X | Struct | void, Args extends any[]> {
|
|
22
22
|
(...args: Args): T extends void ? Void : T
|
|
23
|
+
getLayout(): FnLayout
|
|
23
24
|
setLayout(layout: FnLayout): FnType<T, Args>
|
|
24
25
|
}
|
|
25
26
|
|
|
@@ -35,6 +36,7 @@ export interface StructFactory<T extends StructFields> {
|
|
|
35
36
|
export type NodeTypes =
|
|
36
37
|
// headers
|
|
37
38
|
| 'attribute'
|
|
39
|
+
| 'instance'
|
|
38
40
|
| 'storage'
|
|
39
41
|
| 'uniform'
|
|
40
42
|
| 'constant'
|
|
@@ -222,7 +224,7 @@ type XImpl<T extends C> = _X<T> & {
|
|
|
222
224
|
type C = Constants
|
|
223
225
|
|
|
224
226
|
export type X<T extends C = C> = T extends keyof ConstantsToType ? ConstantsToType[T] : _X<T>
|
|
225
|
-
export type Y<T extends C = C> = number | number[] | string | boolean | undefined | X<T>
|
|
227
|
+
export type Y<T extends C = C> = number | number[] | string | boolean | undefined | HTMLElement | X<T>
|
|
226
228
|
|
|
227
229
|
type Methods =
|
|
228
230
|
| Functions
|
|
@@ -238,11 +240,13 @@ type Methods =
|
|
|
238
240
|
| 'toVar'
|
|
239
241
|
| 'toString'
|
|
240
242
|
| 'element'
|
|
243
|
+
| 'select'
|
|
241
244
|
|
|
242
245
|
interface _X<T extends C> {
|
|
243
246
|
// System properties
|
|
244
247
|
readonly __nodeType?: T
|
|
245
248
|
assign(x: any): X<T>
|
|
249
|
+
select(x: number | X<T>, y: X<'bool'>): X<T>
|
|
246
250
|
fragment(c: NodeContext): string
|
|
247
251
|
toVar(name?: string): X<T>
|
|
248
252
|
toString(c?: NodeContext): string
|
|
@@ -298,20 +302,20 @@ interface _X<T extends C> {
|
|
|
298
302
|
|
|
299
303
|
// Conversion methods
|
|
300
304
|
toBool(): Bool
|
|
301
|
-
|
|
305
|
+
toUInt(): UInt
|
|
302
306
|
toInt(): Int
|
|
303
307
|
toFloat(): Float
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
308
|
+
toBVec2(): BVec2
|
|
309
|
+
toIVec2(): IVec2
|
|
310
|
+
toUVec2(): UVec2
|
|
307
311
|
toVec2(): Vec2
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
312
|
+
toBVec3(): BVec3
|
|
313
|
+
toIVec3(): IVec3
|
|
314
|
+
toUVec3(): UVec3
|
|
311
315
|
toVec3(): Vec3
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
316
|
+
toBVec4(): BVec4
|
|
317
|
+
toIVec4(): IVec4
|
|
318
|
+
toUVec4(): UVec4
|
|
315
319
|
toVec4(): Vec4
|
|
316
320
|
toColor(): Color
|
|
317
321
|
toMat2(): Mat2
|