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
|
@@ -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
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import { durable, event } from 'reev'
|
|
2
2
|
import { createFrame, createQueue } from 'refr'
|
|
3
|
-
import { webgl } from './webgl'
|
|
4
|
-
import { webgpu } from './webgpu'
|
|
5
3
|
import { is } from './utils/helpers'
|
|
4
|
+
import { webgl } from './utils/webgl'
|
|
5
|
+
import { webgpu } from './utils/webgpu'
|
|
6
6
|
import type { EventState } from 'reev'
|
|
7
7
|
import type { GL } from './types'
|
|
8
|
-
import { float, fract, int, iResolution, position, vec4, vertexIndex } from './node'
|
|
9
|
-
export * from './node'
|
|
10
8
|
export * from './types'
|
|
11
|
-
export * from './webgl'
|
|
12
|
-
export * from './webgpu'
|
|
13
9
|
|
|
14
10
|
export const isGL = (a: unknown): a is EventState<GL> => {
|
|
15
11
|
if (!is.obj(a)) return false
|
|
@@ -28,30 +24,20 @@ export const isWebGPUSupported = () => {
|
|
|
28
24
|
|
|
29
25
|
let iTime = performance.now()
|
|
30
26
|
|
|
31
|
-
const defaultFragment = () => vec4(fract(position.xy.div(iResolution)), 0, 1)
|
|
32
|
-
const defaultVertex = () =>
|
|
33
|
-
vec4(
|
|
34
|
-
float(int(vertexIndex).mod(int(2)))
|
|
35
|
-
.mul(4)
|
|
36
|
-
.sub(1),
|
|
37
|
-
float(int(vertexIndex).div(int(2)))
|
|
38
|
-
.mul(4)
|
|
39
|
-
.sub(1),
|
|
40
|
-
0,
|
|
41
|
-
1
|
|
42
|
-
)
|
|
43
|
-
|
|
44
27
|
export const createGL = (props?: Partial<GL>) => {
|
|
45
28
|
const gl = event({
|
|
46
29
|
isNative: false,
|
|
47
30
|
isWebGL: true,
|
|
48
31
|
isError: false,
|
|
49
32
|
isLoop: true,
|
|
33
|
+
isDebug: false,
|
|
34
|
+
isDepth: false,
|
|
50
35
|
isGL: true,
|
|
51
36
|
size: [0, 0],
|
|
52
37
|
mouse: [0, 0],
|
|
53
38
|
count: 6,
|
|
54
|
-
|
|
39
|
+
instanceCount: 1,
|
|
40
|
+
particleCount: 1024,
|
|
55
41
|
webgl: {},
|
|
56
42
|
webgpu: {},
|
|
57
43
|
loading: 0,
|
|
@@ -67,16 +53,17 @@ export const createGL = (props?: Partial<GL>) => {
|
|
|
67
53
|
gl.frame = createFrame()
|
|
68
54
|
|
|
69
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)
|
|
70
57
|
gl.storage = durable((k, v) => gl.queue(() => gl._storage?.(k, v)), gl)
|
|
71
58
|
gl.uniform = durable((k, v) => gl.queue(() => gl._uniform?.(k, v)), gl)
|
|
72
59
|
gl.texture = durable((k, v) => gl.queue(() => gl._texture?.(k, v)), gl)
|
|
73
60
|
gl.uniform({ iResolution: gl.size, iMouse: [0, 0], iTime })
|
|
74
61
|
|
|
75
62
|
gl('mount', async () => {
|
|
76
|
-
gl.vs = gl.vs || gl.vert || gl.vertex || defaultVertex()
|
|
77
|
-
gl.fs = gl.fs || gl.frag || gl.fragment || defaultFragment()
|
|
78
|
-
gl.cs = gl.cs || gl.comp || gl.compute
|
|
79
63
|
if (!isWebGPUSupported()) gl.isWebGL = true
|
|
64
|
+
gl.vs = gl.vs || gl.vert || gl.vertex
|
|
65
|
+
gl.fs = gl.fs || gl.frag || gl.fragment
|
|
66
|
+
gl.cs = gl.cs || gl.comp || gl.compute
|
|
80
67
|
if (gl.isWebGL) {
|
|
81
68
|
gl((await webgl(gl)) as GL)
|
|
82
69
|
} else gl((await webgpu(gl)) as GL)
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { code } from './utils'
|
|
2
|
+
import type { NodeContext, X } from './types'
|
|
3
|
+
|
|
4
|
+
const GLSL_FRAGMENT_HEAD = `
|
|
5
|
+
#version 300 es
|
|
6
|
+
precision mediump float;
|
|
7
|
+
out vec4 fragColor;
|
|
8
|
+
`.trim()
|
|
9
|
+
|
|
10
|
+
const topological = (headers: Map<string, string>, dependencies: Map<string, Set<string>>) => {
|
|
11
|
+
const sorted: [string, string][] = []
|
|
12
|
+
const visited = new Set<string>()
|
|
13
|
+
const visiting = new Set<string>()
|
|
14
|
+
const visit = (id: string) => {
|
|
15
|
+
if (visiting.has(id)) return
|
|
16
|
+
if (visited.has(id)) return
|
|
17
|
+
visiting.add(id)
|
|
18
|
+
const deps = dependencies.get(id) || new Set()
|
|
19
|
+
for (const dep of deps) if (headers.has(dep)) visit(dep)
|
|
20
|
+
visiting.delete(id)
|
|
21
|
+
visited.add(id)
|
|
22
|
+
if (headers.has(id)) sorted.push([id, headers.get(id)!])
|
|
23
|
+
}
|
|
24
|
+
for (const [id] of headers) visit(id)
|
|
25
|
+
return sorted
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const build = (x: X, c: NodeContext) => {
|
|
29
|
+
const body = code(x, c)
|
|
30
|
+
let head = ''
|
|
31
|
+
if (c.isWebGL && c.code?.dependencies) {
|
|
32
|
+
const sorted = topological(c.code.headers, c.code.dependencies)
|
|
33
|
+
head = sorted.map(([, value]) => value).join('\n')
|
|
34
|
+
} else head = Array.from(c.code?.headers?.values() || []).join('\n')
|
|
35
|
+
let [lines, ret] = body.split('return ')
|
|
36
|
+
if (ret) ret = ret.replace(';', '')
|
|
37
|
+
else [lines, ret] = ['', body]
|
|
38
|
+
return [head, lines.trim(), ret]
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const generateStruct = (id: string, map: Map<string, string>) => {
|
|
42
|
+
return `struct ${id} {\n ${Array.from(map.values()).join(',\n ')}\n}`
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const fragment = (x: X, c: NodeContext = {}) => {
|
|
46
|
+
c.code?.headers?.clear()
|
|
47
|
+
c.label = 'frag' // for varying inputs or outputs
|
|
48
|
+
const [head, lines, ret] = build(x, c)
|
|
49
|
+
const result = []
|
|
50
|
+
if (c.isWebGL) {
|
|
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};`)
|
|
57
|
+
} else {
|
|
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};`)
|
|
63
|
+
}
|
|
64
|
+
result.push('}')
|
|
65
|
+
const main = result.filter(Boolean).join('\n').trim()
|
|
66
|
+
if (c.gl?.isDebug) console.log(`↓↓↓generated↓↓↓\n${main}`)
|
|
67
|
+
return main
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export const vertex = (x: X, c: NodeContext = {}) => {
|
|
71
|
+
c.code?.headers?.clear()
|
|
72
|
+
c.label = 'vert' // for varying inputs or outputs
|
|
73
|
+
const [head, lines, ret] = build(x, c)
|
|
74
|
+
const result = []
|
|
75
|
+
if (c.isWebGL) {
|
|
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};`)
|
|
84
|
+
} else {
|
|
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;')
|
|
95
|
+
}
|
|
96
|
+
result.push('}')
|
|
97
|
+
const main = result.filter(Boolean).join('\n').trim()
|
|
98
|
+
if (c.gl?.isDebug) console.log(`↓↓↓generated↓↓↓\n${main}`)
|
|
99
|
+
return main
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export const compute = (x: X, c: NodeContext = {}) => {
|
|
103
|
+
c.code?.headers?.clear()
|
|
104
|
+
c.label = 'compute'
|
|
105
|
+
const [head, lines, ret] = build(x, c)
|
|
106
|
+
const result = []
|
|
107
|
+
if (c.isWebGL) {
|
|
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('}')
|
|
115
|
+
} else {
|
|
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('}')
|
|
123
|
+
}
|
|
124
|
+
const main = result.filter(Boolean).join('\n').trim()
|
|
125
|
+
if (c.gl?.isDebug) console.log(`↓↓↓generated↓↓↓\n${main}`)
|
|
126
|
+
return main
|
|
127
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { compute, fragment, vertex } from './build'
|
|
2
|
+
import { addToScope, assign, toVar } from './scope'
|
|
3
|
+
import { code, getConstant, isConversion, isFunction, isOperator, getId, isArrayAccess } from './utils'
|
|
4
|
+
import { is } from '../utils/helpers'
|
|
5
|
+
import type { Constants as C, Functions, NodeProps, NodeTypes, Operators, X, Y } from './types'
|
|
6
|
+
|
|
7
|
+
const toPrimitive = (x: Y, hint: string) => {
|
|
8
|
+
if (hint === 'string') return code(x as any, null)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const create = <T extends C>(type: NodeTypes, props?: NodeProps | null, ...args: Y[]) => {
|
|
12
|
+
if (!props) props = {}
|
|
13
|
+
if (args.length) props.children = args
|
|
14
|
+
const listeners = new Set<(value: any) => void>()
|
|
15
|
+
const get = (_: unknown, key: string | Symbol) => {
|
|
16
|
+
if (key === 'type') return type
|
|
17
|
+
if (key === 'props') return props
|
|
18
|
+
if (key === '__nodeType') return undefined // Will be inferred by TypeScript
|
|
19
|
+
if (key === 'toVar') return toVar.bind(null, x)
|
|
20
|
+
if (key === 'isProxy') return true
|
|
21
|
+
if (key === 'toString') return code.bind(null, x)
|
|
22
|
+
if (key === 'fragment') return fragment.bind(null, x)
|
|
23
|
+
if (key === 'compute') return compute.bind(null, x)
|
|
24
|
+
if (key === 'vertex') return vertex.bind(null, x)
|
|
25
|
+
if (key === Symbol.toPrimitive) return toPrimitive.bind(null, x)
|
|
26
|
+
if (key === 'listeners') return listeners
|
|
27
|
+
if (key === 'attribute') return (id = getId()) => attribute(x, id)
|
|
28
|
+
if (key === 'instance') return (id = getId()) => instance(x, id)
|
|
29
|
+
if (key === 'constant') return (id = getId()) => constant(x, id)
|
|
30
|
+
if (key === 'uniform') return (id = getId()) => uniform(x, id)
|
|
31
|
+
if (key === 'variable') return (id = getId()) => variable(id)
|
|
32
|
+
if (key === 'builtin') return (id = getId()) => builtin(id)
|
|
33
|
+
if (key === 'vertexStage') return (id = getId()) => vertexStage(x, id)
|
|
34
|
+
if (key === 'element') return (arg: Y) => (type === 'storage' ? gather(x, arg) : element(x, arg))
|
|
35
|
+
if (key === 'member') return (arg: Y) => member(x, arg)
|
|
36
|
+
if (key === 'assign') return assign.bind(null, x, x.type === 'gather')
|
|
37
|
+
if (key === 'select') return select.bind(null, x)
|
|
38
|
+
if (isOperator(key)) {
|
|
39
|
+
return key.endsWith('Assign')
|
|
40
|
+
? (...args: Y[]) => addToScope(operator(key, x, ...args))
|
|
41
|
+
: (...args: Y[]) => operator(key, x, ...args)
|
|
42
|
+
}
|
|
43
|
+
if (isFunction(key)) return (...args: Y[]) => function_(key, x, ...args)
|
|
44
|
+
if (isConversion(key)) return () => conversion(getConstant(key), x)
|
|
45
|
+
if (is.str(key)) return isArrayAccess(key) ? element(x, key) : member(x, key)
|
|
46
|
+
}
|
|
47
|
+
const set = (_: unknown, key: string, arg: Y) => {
|
|
48
|
+
if (key === 'value') listeners.forEach((fun) => fun(arg))
|
|
49
|
+
if (is.str(key)) member(x, key).assign(arg)
|
|
50
|
+
return true
|
|
51
|
+
}
|
|
52
|
+
const x = new Proxy({}, { get, set }) as unknown as X<T>
|
|
53
|
+
return x
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// headers with proper type inference
|
|
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)
|
|
59
|
+
export const constant = <T extends C>(x: Y<T>, id = getId()) => create<T>('constant', { id }, x)
|
|
60
|
+
export const uniform = <T extends C>(x: Y<T>, id = getId()) => create<T>('uniform', { id }, x)
|
|
61
|
+
export const storage = <T extends C>(x: Y<T>, id = getId()) => create<T>('storage', { id }, x)
|
|
62
|
+
export const variable = <T extends C>(id = getId()) => create<T>('variable', { id })
|
|
63
|
+
export const builtin = <T extends C>(id = getId()) => create<T>('builtin', { id })
|
|
64
|
+
export const vertexStage = <T extends C>(x: X<T>, id = getId()) => {
|
|
65
|
+
return create<T>('varying', { id, inferFrom: [x] }, x)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Node shorthands with proper typing
|
|
69
|
+
export const member = <T extends C>(x: X, index: Y) => create<T>('member', null, x, index)
|
|
70
|
+
export const element = <T extends C>(x: X, index: Y) => create<T>('element', null, x, index)
|
|
71
|
+
export const gather = <T extends C>(x: X, index: Y) => create<T>('gather', null, x, index)
|
|
72
|
+
export const scatter = <T extends C>(x: X, index: Y) => create<T>('scatter', null, x, index)
|
|
73
|
+
export const select = <T extends C>(x: Y, y: Y, z: Y) => create<T>('ternary', null, x, y, z) // z ? x : y @TODO REMOVE
|
|
74
|
+
export const operator = <T extends C>(key: Operators, ...x: Y[]) => create<T>('operator', null, key, ...x)
|
|
75
|
+
export const function_ = <T extends C>(key: Functions, ...x: Y[]) => create<T>('function', null, key, ...x)
|
|
76
|
+
export const conversion = <T extends C>(key: T, ...x: Y[]) => create<T>('conversion', null, key, ...x)
|