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,49 @@
|
|
|
1
|
+
import { Fn, Vec3, Float, vec3, mat3 } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const lookAtForward = Fn(([forward, up]: [Vec3, Vec3]) => {
|
|
4
|
+
const zaxis = forward.normalize().toVar()
|
|
5
|
+
const xaxis = up.cross(zaxis).normalize().toVar()
|
|
6
|
+
const yaxis = zaxis.cross(xaxis).toVar()
|
|
7
|
+
return mat3(xaxis, yaxis, zaxis)
|
|
8
|
+
}).setLayout({
|
|
9
|
+
name: 'lookAtForward',
|
|
10
|
+
type: 'mat3',
|
|
11
|
+
inputs: [
|
|
12
|
+
{ name: 'forward', type: 'vec3' },
|
|
13
|
+
{ name: 'up', type: 'vec3' },
|
|
14
|
+
],
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
export const lookAt = Fn(([eye, target, up]: [Vec3, Vec3, Vec3]) => {
|
|
18
|
+
const forward = target.sub(eye).normalize().toVar()
|
|
19
|
+
return lookAtForward(forward, up)
|
|
20
|
+
}).setLayout({
|
|
21
|
+
name: 'lookAt',
|
|
22
|
+
type: 'mat3',
|
|
23
|
+
inputs: [
|
|
24
|
+
{ name: 'eye', type: 'vec3' },
|
|
25
|
+
{ name: 'target', type: 'vec3' },
|
|
26
|
+
{ name: 'up', type: 'vec3' },
|
|
27
|
+
],
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
export const lookAtRoll = Fn(([eye, target, roll]: [Vec3, Vec3, Float]) => {
|
|
31
|
+
const up = vec3(roll.sin(), roll.cos(), 0).toVar()
|
|
32
|
+
return lookAt(eye, target, up)
|
|
33
|
+
}).setLayout({
|
|
34
|
+
name: 'lookAtRoll',
|
|
35
|
+
type: 'mat3',
|
|
36
|
+
inputs: [
|
|
37
|
+
{ name: 'eye', type: 'vec3' },
|
|
38
|
+
{ name: 'target', type: 'vec3' },
|
|
39
|
+
{ name: 'roll', type: 'float' },
|
|
40
|
+
],
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
export const lookAtBasic = Fn(([forward]: [Vec3]) => {
|
|
44
|
+
return lookAtForward(forward, vec3(0, 1, 0))
|
|
45
|
+
}).setLayout({
|
|
46
|
+
name: 'lookAtBasic',
|
|
47
|
+
type: 'mat3',
|
|
48
|
+
inputs: [{ name: 'forward', type: 'vec3' }],
|
|
49
|
+
})
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Fn, Vec3, Float, vec3 } from '../../node'
|
|
2
|
+
import { lookAt, lookAtRoll } from './lookAt'
|
|
3
|
+
import { translateMat3 } from './translate'
|
|
4
|
+
|
|
5
|
+
export const lookAtView = Fn(([position, target, up]: [Vec3, Vec3, Vec3]) => {
|
|
6
|
+
const m = lookAt(position, target, up).toVar()
|
|
7
|
+
return translateMat3(m, position)
|
|
8
|
+
}).setLayout({
|
|
9
|
+
name: 'lookAtView',
|
|
10
|
+
type: 'mat4',
|
|
11
|
+
inputs: [
|
|
12
|
+
{ name: 'position', type: 'vec3' },
|
|
13
|
+
{ name: 'target', type: 'vec3' },
|
|
14
|
+
{ name: 'up', type: 'vec3' },
|
|
15
|
+
],
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
export const lookAtViewRoll = Fn(([position, target, roll]: [Vec3, Vec3, Float]) => {
|
|
19
|
+
const m = lookAtRoll(position, target, roll).toVar()
|
|
20
|
+
return translateMat3(m, position)
|
|
21
|
+
}).setLayout({
|
|
22
|
+
name: 'lookAtViewRoll',
|
|
23
|
+
type: 'mat4',
|
|
24
|
+
inputs: [
|
|
25
|
+
{ name: 'position', type: 'vec3' },
|
|
26
|
+
{ name: 'target', type: 'vec3' },
|
|
27
|
+
{ name: 'roll', type: 'float' },
|
|
28
|
+
],
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
export const lookAtViewBasic = Fn(([position, target]: [Vec3, Vec3]) => {
|
|
32
|
+
return lookAtView(position, target, vec3(0, 1, 0))
|
|
33
|
+
}).setLayout({
|
|
34
|
+
name: 'lookAtViewBasic',
|
|
35
|
+
type: 'mat4',
|
|
36
|
+
inputs: [
|
|
37
|
+
{ name: 'position', type: 'vec3' },
|
|
38
|
+
{ name: 'target', type: 'vec3' },
|
|
39
|
+
],
|
|
40
|
+
})
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Fn, Vec2, Vec4, Float, vec4 } from '../../node'
|
|
2
|
+
import { sqTile } from './sqTile'
|
|
3
|
+
import { mirror } from '../math/mirror'
|
|
4
|
+
|
|
5
|
+
export const mirrorTile = Fn(([t]: [Vec4]): Vec4 => {
|
|
6
|
+
return vec4(mirror(t.xy.add(t.zw)), t.z, t.w)
|
|
7
|
+
}).setLayout({
|
|
8
|
+
name: 'mirrorTile',
|
|
9
|
+
type: 'vec4',
|
|
10
|
+
inputs: [{ name: 't', type: 'vec4' }],
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
export const mirrorTileVec2 = Fn(([v]: [Vec2]): Vec4 => {
|
|
14
|
+
return mirrorTile(sqTile(v))
|
|
15
|
+
}).setLayout({
|
|
16
|
+
name: 'mirrorTileVec2',
|
|
17
|
+
type: 'vec4',
|
|
18
|
+
inputs: [{ name: 'v', type: 'vec2' }],
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
export const mirrorTileFloat = Fn(([v, s]: [Vec2, Float]): Vec4 => {
|
|
22
|
+
return mirrorTileVec2(v.mul(s))
|
|
23
|
+
}).setLayout({
|
|
24
|
+
name: 'mirrorTileFloat',
|
|
25
|
+
type: 'vec4',
|
|
26
|
+
inputs: [
|
|
27
|
+
{ name: 'v', type: 'vec2' },
|
|
28
|
+
{ name: 's', type: 'float' },
|
|
29
|
+
],
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
export const mirrorTileVec2Scale = Fn(([v, s]: [Vec2, Vec2]): Vec4 => {
|
|
33
|
+
return mirrorTileVec2(v.mul(s))
|
|
34
|
+
}).setLayout({
|
|
35
|
+
name: 'mirrorTileVec2Scale',
|
|
36
|
+
type: 'vec4',
|
|
37
|
+
inputs: [
|
|
38
|
+
{ name: 'v', type: 'vec2' },
|
|
39
|
+
{ name: 's', type: 'vec2' },
|
|
40
|
+
],
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
export const mirrorXTile = Fn(([t]: [Vec4]): Vec4 => {
|
|
44
|
+
return vec4(mirror(t.x.add(t.z)), t.y, t.z, t.w)
|
|
45
|
+
}).setLayout({
|
|
46
|
+
name: 'mirrorXTile',
|
|
47
|
+
type: 'vec4',
|
|
48
|
+
inputs: [{ name: 't', type: 'vec4' }],
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
export const mirrorXTileVec2 = Fn(([v]: [Vec2]): Vec4 => {
|
|
52
|
+
return mirrorXTile(sqTile(v))
|
|
53
|
+
}).setLayout({
|
|
54
|
+
name: 'mirrorXTileVec2',
|
|
55
|
+
type: 'vec4',
|
|
56
|
+
inputs: [{ name: 'v', type: 'vec2' }],
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
export const mirrorYTile = Fn(([t]: [Vec4]): Vec4 => {
|
|
60
|
+
return vec4(t.x, mirror(t.y.add(t.w)), t.z, t.w)
|
|
61
|
+
}).setLayout({
|
|
62
|
+
name: 'mirrorYTile',
|
|
63
|
+
type: 'vec4',
|
|
64
|
+
inputs: [{ name: 't', type: 'vec4' }],
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
export const mirrorYTileVec2 = Fn(([v]: [Vec2]): Vec4 => {
|
|
68
|
+
return mirrorYTile(sqTile(v))
|
|
69
|
+
}).setLayout({
|
|
70
|
+
name: 'mirrorYTileVec2',
|
|
71
|
+
type: 'vec4',
|
|
72
|
+
inputs: [{ name: 'v', type: 'vec2' }],
|
|
73
|
+
})
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Fn, Vec2, floor } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const nearest = Fn(([v, res]: [Vec2, Vec2]): Vec2 => {
|
|
4
|
+
const offset = res.sub(1).reciprocal().mul(0.5).toVar('offset')
|
|
5
|
+
return floor(v.mul(res)).div(res).add(offset)
|
|
6
|
+
}).setLayout({
|
|
7
|
+
name: 'nearest',
|
|
8
|
+
type: 'vec2',
|
|
9
|
+
inputs: [
|
|
10
|
+
{ name: 'v', type: 'vec2' },
|
|
11
|
+
{ name: 'res', type: 'vec2' },
|
|
12
|
+
],
|
|
13
|
+
})
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Fn, Float, Mat4, mat4, vec4 } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const orthographic = Fn(([l, r, b, t, n, f]: [Float, Float, Float, Float, Float, Float]): Mat4 => {
|
|
4
|
+
const width = r.sub(l).toVar('width')
|
|
5
|
+
const height = t.sub(b).toVar('height')
|
|
6
|
+
const depth = f.sub(n).toVar('depth')
|
|
7
|
+
|
|
8
|
+
return mat4(
|
|
9
|
+
vec4(width.reciprocal().mul(2), 0, 0, 0),
|
|
10
|
+
vec4(0, height.reciprocal().mul(2), 0, 0),
|
|
11
|
+
vec4(0, 0, depth.reciprocal().mul(-2), 0),
|
|
12
|
+
vec4(r.add(l).div(width).negate(), t.add(b).div(height).negate(), f.add(n).div(depth).negate(), 1)
|
|
13
|
+
)
|
|
14
|
+
}).setLayout({
|
|
15
|
+
name: 'orthographic',
|
|
16
|
+
type: 'mat4',
|
|
17
|
+
inputs: [
|
|
18
|
+
{ name: 'l', type: 'float' },
|
|
19
|
+
{ name: 'r', type: 'float' },
|
|
20
|
+
{ name: 'b', type: 'float' },
|
|
21
|
+
{ name: 't', type: 'float' },
|
|
22
|
+
{ name: 'n', type: 'float' },
|
|
23
|
+
{ name: 'f', type: 'float' },
|
|
24
|
+
],
|
|
25
|
+
})
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { Fn, Vec2, Vec3, Float, X, texture, float, vec2, vec3, int, Loop, If, Break } from '../../node'
|
|
2
|
+
|
|
3
|
+
const PARALLAXMAPPING_SCALE = float(0.01).constant('PARALLAXMAPPING_SCALE')
|
|
4
|
+
const PARALLAXMAPPING_NUMSEARCHES = float(10).constant('PARALLAXMAPPING_NUMSEARCHES')
|
|
5
|
+
|
|
6
|
+
export const parallaxMappingSimple = Fn(([tex, V, T]: [X, Vec3, Vec2]): Vec2 => {
|
|
7
|
+
const initialHeight = texture(tex, T).r.toVar('initialHeight')
|
|
8
|
+
const texCoordOffset = PARALLAXMAPPING_SCALE.mul(V.xy).mul(initialHeight).toVar('texCoordOffset')
|
|
9
|
+
return T.sub(texCoordOffset)
|
|
10
|
+
}).setLayout({
|
|
11
|
+
name: 'parallaxMappingSimple',
|
|
12
|
+
type: 'vec2',
|
|
13
|
+
inputs: [
|
|
14
|
+
{ name: 'tex', type: 'sampler2D' },
|
|
15
|
+
{ name: 'V', type: 'vec3' },
|
|
16
|
+
{ name: 'T', type: 'vec2' },
|
|
17
|
+
],
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
export const parallaxMappingSteep = Fn(([tex, V, T]: [X, Vec3, Vec2]): Vec2 => {
|
|
21
|
+
const minLayers = PARALLAXMAPPING_NUMSEARCHES.mul(0.5).toVar('minLayers')
|
|
22
|
+
const maxLayers = float(15).toVar('maxLayers')
|
|
23
|
+
const numLayers = minLayers.mix(maxLayers, V.dot(vec3(0, 0, 1)).abs()).toVar('numLayers')
|
|
24
|
+
const layerHeight = float(1).div(numLayers).toVar('layerHeight')
|
|
25
|
+
const currentLayerHeight = float(0).toVar('currentLayerHeight')
|
|
26
|
+
const dtex = PARALLAXMAPPING_SCALE.mul(V.xy).div(V.z).div(numLayers).toVar('dtex')
|
|
27
|
+
const currentTextureCoords = T.toVar('currentTextureCoords')
|
|
28
|
+
const heightFromTexture = texture(tex, currentTextureCoords).r.toVar('heightFromTexture')
|
|
29
|
+
|
|
30
|
+
Loop(int(50), ({ i }) => {
|
|
31
|
+
If(heightFromTexture.lessThanEqual(currentLayerHeight), () => {
|
|
32
|
+
Break()
|
|
33
|
+
})
|
|
34
|
+
currentLayerHeight.addAssign(layerHeight)
|
|
35
|
+
currentTextureCoords.subAssign(dtex)
|
|
36
|
+
heightFromTexture.assign(texture(tex, currentTextureCoords).r)
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
return currentTextureCoords
|
|
40
|
+
}).setLayout({
|
|
41
|
+
name: 'parallaxMappingSteep',
|
|
42
|
+
type: 'vec2',
|
|
43
|
+
inputs: [
|
|
44
|
+
{ name: 'tex', type: 'sampler2D' },
|
|
45
|
+
{ name: 'V', type: 'vec3' },
|
|
46
|
+
{ name: 'T', type: 'vec2' },
|
|
47
|
+
],
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
export const parallaxMappingRelief = Fn(([tex, V, T]: [X, Vec3, Vec2]): Vec2 => {
|
|
51
|
+
const minLayers = PARALLAXMAPPING_NUMSEARCHES.toVar('minLayers')
|
|
52
|
+
const maxLayers = float(15).toVar('maxLayers')
|
|
53
|
+
const numLayers = minLayers.mix(maxLayers, V.dot(vec3(0, 0, 1)).abs()).toVar('numLayers')
|
|
54
|
+
const layerHeight = float(1).div(numLayers).toVar('layerHeight')
|
|
55
|
+
const currentLayerHeight = float(0).toVar('currentLayerHeight')
|
|
56
|
+
const dtex = PARALLAXMAPPING_SCALE.mul(V.xy).div(V.z).div(numLayers).toVar('dtex')
|
|
57
|
+
const currentTextureCoords = T.toVar('currentTextureCoords')
|
|
58
|
+
const heightFromTexture = texture(tex, currentTextureCoords).r.toVar('heightFromTexture')
|
|
59
|
+
|
|
60
|
+
Loop(int(50), ({ i }) => {
|
|
61
|
+
If(heightFromTexture.lessThanEqual(currentLayerHeight), () => {
|
|
62
|
+
Break()
|
|
63
|
+
})
|
|
64
|
+
currentLayerHeight.addAssign(layerHeight)
|
|
65
|
+
currentTextureCoords.subAssign(dtex)
|
|
66
|
+
heightFromTexture.assign(texture(tex, currentTextureCoords).r)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
const deltaTexCoord = dtex.mul(0.5).toVar('deltaTexCoord')
|
|
70
|
+
const deltaHeight = layerHeight.mul(0.5).toVar('deltaHeight')
|
|
71
|
+
currentTextureCoords.addAssign(deltaTexCoord)
|
|
72
|
+
currentLayerHeight.subAssign(deltaHeight)
|
|
73
|
+
|
|
74
|
+
Loop(int(5), ({ i }) => {
|
|
75
|
+
deltaTexCoord.mulAssign(0.5)
|
|
76
|
+
deltaHeight.mulAssign(0.5)
|
|
77
|
+
heightFromTexture.assign(texture(tex, currentTextureCoords).r)
|
|
78
|
+
|
|
79
|
+
If(heightFromTexture.greaterThan(currentLayerHeight), () => {
|
|
80
|
+
currentTextureCoords.subAssign(deltaTexCoord)
|
|
81
|
+
currentLayerHeight.addAssign(deltaHeight)
|
|
82
|
+
}).Else(() => {
|
|
83
|
+
currentTextureCoords.addAssign(deltaTexCoord)
|
|
84
|
+
currentLayerHeight.subAssign(deltaHeight)
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
return currentTextureCoords
|
|
89
|
+
}).setLayout({
|
|
90
|
+
name: 'parallaxMappingRelief',
|
|
91
|
+
type: 'vec2',
|
|
92
|
+
inputs: [
|
|
93
|
+
{ name: 'tex', type: 'sampler2D' },
|
|
94
|
+
{ name: 'V', type: 'vec3' },
|
|
95
|
+
{ name: 'T', type: 'vec2' },
|
|
96
|
+
],
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
export const parallaxMappingOcclusion = Fn(([tex, V, T]: [X, Vec3, Vec2]): Vec2 => {
|
|
100
|
+
const minLayers = PARALLAXMAPPING_NUMSEARCHES.toVar('minLayers')
|
|
101
|
+
const maxLayers = float(15).toVar('maxLayers')
|
|
102
|
+
const numLayers = minLayers.mix(maxLayers, V.dot(vec3(0, 0, 1)).abs()).toVar('numLayers')
|
|
103
|
+
const layerHeight = float(1).div(numLayers).toVar('layerHeight')
|
|
104
|
+
const curLayerHeight = float(0).toVar('curLayerHeight')
|
|
105
|
+
const dtex = PARALLAXMAPPING_SCALE.mul(V.xy).div(V.z).div(numLayers).toVar('dtex')
|
|
106
|
+
const currentTextureCoords = T.toVar('currentTextureCoords')
|
|
107
|
+
const heightFromTexture = texture(tex, currentTextureCoords).r.toVar('heightFromTexture')
|
|
108
|
+
const prevTCoords = currentTextureCoords.toVar('prevTCoords')
|
|
109
|
+
|
|
110
|
+
Loop(int(50), ({ i }) => {
|
|
111
|
+
If(heightFromTexture.lessThanEqual(curLayerHeight), () => {
|
|
112
|
+
Break()
|
|
113
|
+
})
|
|
114
|
+
curLayerHeight.addAssign(layerHeight)
|
|
115
|
+
prevTCoords.assign(currentTextureCoords)
|
|
116
|
+
currentTextureCoords.subAssign(dtex)
|
|
117
|
+
heightFromTexture.assign(texture(tex, currentTextureCoords).r)
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
const nextH = heightFromTexture.sub(curLayerHeight).toVar('nextH')
|
|
121
|
+
const prevH = texture(tex, prevTCoords).r.sub(curLayerHeight).add(layerHeight).toVar('prevH')
|
|
122
|
+
const weight = nextH.div(nextH.sub(prevH)).toVar('weight')
|
|
123
|
+
const finalTexCoords = prevTCoords
|
|
124
|
+
.mul(weight)
|
|
125
|
+
.add(currentTextureCoords.mul(float(1).sub(weight)))
|
|
126
|
+
.toVar('finalTexCoords')
|
|
127
|
+
|
|
128
|
+
return finalTexCoords
|
|
129
|
+
}).setLayout({
|
|
130
|
+
name: 'parallaxMappingOcclusion',
|
|
131
|
+
type: 'vec2',
|
|
132
|
+
inputs: [
|
|
133
|
+
{ name: 'tex', type: 'sampler2D' },
|
|
134
|
+
{ name: 'V', type: 'vec3' },
|
|
135
|
+
{ name: 'T', type: 'vec2' },
|
|
136
|
+
],
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
export const parallaxMapping = Fn(([tex, V, T]: [X, Vec3, Vec2]): Vec2 => {
|
|
140
|
+
return parallaxMappingOcclusion(tex, V, T)
|
|
141
|
+
}).setLayout({
|
|
142
|
+
name: 'parallaxMapping',
|
|
143
|
+
type: 'vec2',
|
|
144
|
+
inputs: [
|
|
145
|
+
{ name: 'tex', type: 'sampler2D' },
|
|
146
|
+
{ name: 'V', type: 'vec3' },
|
|
147
|
+
{ name: 'T', type: 'vec2' },
|
|
148
|
+
],
|
|
149
|
+
})
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Fn, Float, Mat4, mat4, tan, float } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const perspective = Fn(([fov, aspect, near, far]: [Float, Float, Float, Float]): Mat4 => {
|
|
4
|
+
const f = float(1)
|
|
5
|
+
.div(tan(fov.div(2)))
|
|
6
|
+
.toVar('f')
|
|
7
|
+
const nf = float(1).div(near.sub(far)).toVar('nf')
|
|
8
|
+
// prettier-ignore
|
|
9
|
+
return mat4(
|
|
10
|
+
f.div(aspect), 0, 0, 0,
|
|
11
|
+
0, f, 0, 0,
|
|
12
|
+
0, 0, far.add(near).mul(nf), -1,
|
|
13
|
+
0, 0, float(2).mul(far).mul(near).mul(nf), 0
|
|
14
|
+
)
|
|
15
|
+
}).setLayout({
|
|
16
|
+
name: 'perspective',
|
|
17
|
+
type: 'mat4',
|
|
18
|
+
inputs: [
|
|
19
|
+
{ name: 'fov', type: 'float' },
|
|
20
|
+
{ name: 'aspect', type: 'float' },
|
|
21
|
+
{ name: 'near', type: 'float' },
|
|
22
|
+
{ name: 'far', type: 'float' },
|
|
23
|
+
],
|
|
24
|
+
})
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Fn, Vec2, Vec3, Float, cos, sin, vec2, vec3 } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const polar2cart = Fn(([polar]: [Vec2]): Vec2 => {
|
|
4
|
+
return vec2(cos(polar.x), sin(polar.x)).mul(polar.y)
|
|
5
|
+
}).setLayout({
|
|
6
|
+
name: 'polar2cart',
|
|
7
|
+
type: 'vec2',
|
|
8
|
+
inputs: [{ name: 'polar', type: 'vec2' }],
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
export const polar2cart3D = Fn(([r, phi, theta]: [Float, Float, Float]): Vec3 => {
|
|
12
|
+
const x = r.mul(cos(theta)).mul(sin(phi)).toVar('x')
|
|
13
|
+
const y = r.mul(sin(theta)).mul(sin(phi)).toVar('y')
|
|
14
|
+
const z = r.mul(cos(phi)).toVar('z')
|
|
15
|
+
return vec3(x, y, z)
|
|
16
|
+
}).setLayout({
|
|
17
|
+
name: 'polar2cart3D',
|
|
18
|
+
type: 'vec3',
|
|
19
|
+
inputs: [
|
|
20
|
+
{ name: 'r', type: 'float' },
|
|
21
|
+
{ name: 'phi', type: 'float' },
|
|
22
|
+
{ name: 'theta', type: 'float' },
|
|
23
|
+
],
|
|
24
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Fn, Vec2, mix, vec2, step } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const ratio = Fn(([v, s]: [Vec2, Vec2]): Vec2 => {
|
|
4
|
+
const wideAspect = vec2(v.x.mul(s.x.div(s.y)).sub(s.x.mul(0.5).sub(s.y.mul(0.5)).div(s.y)), v.y)
|
|
5
|
+
const tallAspect = vec2(v.x, v.y.mul(s.y.div(s.x)).sub(s.y.mul(0.5).sub(s.x.mul(0.5)).div(s.x)))
|
|
6
|
+
return mix(wideAspect, tallAspect, step(s.x, s.y))
|
|
7
|
+
}).setLayout({
|
|
8
|
+
name: 'ratio',
|
|
9
|
+
type: 'vec2',
|
|
10
|
+
inputs: [
|
|
11
|
+
{ name: 'v', type: 'vec2' },
|
|
12
|
+
{ name: 's', type: 'vec2' },
|
|
13
|
+
],
|
|
14
|
+
})
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Fn, Vec2, Float, vec2 } from '../../node'
|
|
2
|
+
import { rotate2d } from '../math/rotate2d'
|
|
3
|
+
|
|
4
|
+
export const rotate2DCenter = Fn(([v, r, c]: [Vec2, Float, Vec2]) => {
|
|
5
|
+
return rotate2d(r).mul(v.sub(c)).add(c)
|
|
6
|
+
}).setLayout({
|
|
7
|
+
name: 'rotate2DCenter',
|
|
8
|
+
type: 'vec2',
|
|
9
|
+
inputs: [
|
|
10
|
+
{ name: 'v', type: 'vec2' },
|
|
11
|
+
{ name: 'r', type: 'float' },
|
|
12
|
+
{ name: 'c', type: 'vec2' },
|
|
13
|
+
],
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
export const rotate2DBasic = Fn(([v, r]: [Vec2, Float]) => {
|
|
17
|
+
return rotate2DCenter(v, r, vec2(0.5))
|
|
18
|
+
}).setLayout({
|
|
19
|
+
name: 'rotate2DBasic',
|
|
20
|
+
type: 'vec2',
|
|
21
|
+
inputs: [
|
|
22
|
+
{ name: 'v', type: 'vec2' },
|
|
23
|
+
{ name: 'r', type: 'float' },
|
|
24
|
+
],
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
export const rotate2DAxis = Fn(([v, xAxis]: [Vec2, Vec2]) => {
|
|
28
|
+
const negYAxis = vec2(xAxis.y.negate(), xAxis.x).toVar()
|
|
29
|
+
return vec2(v.dot(negYAxis), v.dot(xAxis))
|
|
30
|
+
}).setLayout({
|
|
31
|
+
name: 'rotate2DAxis',
|
|
32
|
+
type: 'vec2',
|
|
33
|
+
inputs: [
|
|
34
|
+
{ name: 'v', type: 'vec2' },
|
|
35
|
+
{ name: 'xAxis', type: 'vec2' },
|
|
36
|
+
],
|
|
37
|
+
})
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Fn, Vec3, Vec4, Float, vec4 } from '../../node'
|
|
2
|
+
import { rotate4dX } from '../math/rotate4dX'
|
|
3
|
+
|
|
4
|
+
// vec4 rotateX(in vec4 v, in float r, in vec4 c)
|
|
5
|
+
export const rotateXVec4Center = Fn(([v, r, c]: [Vec4, Float, Vec4]): Vec4 => {
|
|
6
|
+
return rotate4dX(r).mul(v.sub(c)).add(c)
|
|
7
|
+
}).setLayout({
|
|
8
|
+
name: 'rotateXVec4Center',
|
|
9
|
+
type: 'vec4',
|
|
10
|
+
inputs: [
|
|
11
|
+
{ name: 'v', type: 'vec4' },
|
|
12
|
+
{ name: 'r', type: 'float' },
|
|
13
|
+
{ name: 'c', type: 'vec4' },
|
|
14
|
+
],
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
// vec4 rotateX(in vec4 v, in float r)
|
|
18
|
+
export const rotateXVec4 = Fn(([v, r]: [Vec4, Float]): Vec4 => {
|
|
19
|
+
return rotate4dX(r).mul(v)
|
|
20
|
+
}).setLayout({
|
|
21
|
+
name: 'rotateXVec4',
|
|
22
|
+
type: 'vec4',
|
|
23
|
+
inputs: [
|
|
24
|
+
{ name: 'v', type: 'vec4' },
|
|
25
|
+
{ name: 'r', type: 'float' },
|
|
26
|
+
],
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
// vec3 rotateX(in vec3 v, in float r, in vec3 c)
|
|
30
|
+
export const rotateXVec3Center = Fn(([v, r, c]: [Vec3, Float, Vec3]): Vec3 => {
|
|
31
|
+
return rotate4dX(r)
|
|
32
|
+
.mul(vec4(v.sub(c), 1))
|
|
33
|
+
.xyz.add(c)
|
|
34
|
+
}).setLayout({
|
|
35
|
+
name: 'rotateXVec3Center',
|
|
36
|
+
type: 'vec3',
|
|
37
|
+
inputs: [
|
|
38
|
+
{ name: 'v', type: 'vec3' },
|
|
39
|
+
{ name: 'r', type: 'float' },
|
|
40
|
+
{ name: 'c', type: 'vec3' },
|
|
41
|
+
],
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
// vec3 rotateX(in vec3 v, in float r)
|
|
45
|
+
export const rotateXVec3 = Fn(([v, r]: [Vec3, Float]): Vec3 => {
|
|
46
|
+
return rotate4dX(r).mul(vec4(v, 1)).xyz
|
|
47
|
+
}).setLayout({
|
|
48
|
+
name: 'rotateXVec3',
|
|
49
|
+
type: 'vec3',
|
|
50
|
+
inputs: [
|
|
51
|
+
{ name: 'v', type: 'vec3' },
|
|
52
|
+
{ name: 'r', type: 'float' },
|
|
53
|
+
],
|
|
54
|
+
})
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Fn, Vec3, Vec4, Float, vec4 } from '../../node'
|
|
2
|
+
import { rotate4dY } from '../math/rotate4dY'
|
|
3
|
+
|
|
4
|
+
// vec4 rotateY(in vec4 v, in float r, in vec4 c)
|
|
5
|
+
export const rotateYVec4Center = Fn(([v, r, c]: [Vec4, Float, Vec4]): Vec4 => {
|
|
6
|
+
return rotate4dY(r).mul(v.sub(c)).add(c)
|
|
7
|
+
}).setLayout({
|
|
8
|
+
name: 'rotateYVec4Center',
|
|
9
|
+
type: 'vec4',
|
|
10
|
+
inputs: [
|
|
11
|
+
{ name: 'v', type: 'vec4' },
|
|
12
|
+
{ name: 'r', type: 'float' },
|
|
13
|
+
{ name: 'c', type: 'vec4' },
|
|
14
|
+
],
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
// vec4 rotateY(in vec4 v, in float r)
|
|
18
|
+
export const rotateYVec4 = Fn(([v, r]: [Vec4, Float]): Vec4 => {
|
|
19
|
+
return rotate4dY(r).mul(v)
|
|
20
|
+
}).setLayout({
|
|
21
|
+
name: 'rotateYVec4',
|
|
22
|
+
type: 'vec4',
|
|
23
|
+
inputs: [
|
|
24
|
+
{ name: 'v', type: 'vec4' },
|
|
25
|
+
{ name: 'r', type: 'float' },
|
|
26
|
+
],
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
// vec3 rotateY(in vec3 v, in float r, in vec3 c)
|
|
30
|
+
export const rotateYVec3Center = Fn(([v, r, c]: [Vec3, Float, Vec3]): Vec3 => {
|
|
31
|
+
return rotate4dY(r)
|
|
32
|
+
.mul(vec4(v.sub(c), 1))
|
|
33
|
+
.xyz.add(c)
|
|
34
|
+
}).setLayout({
|
|
35
|
+
name: 'rotateYVec3Center',
|
|
36
|
+
type: 'vec3',
|
|
37
|
+
inputs: [
|
|
38
|
+
{ name: 'v', type: 'vec3' },
|
|
39
|
+
{ name: 'r', type: 'float' },
|
|
40
|
+
{ name: 'c', type: 'vec3' },
|
|
41
|
+
],
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
// vec3 rotateY(in vec3 v, in float r)
|
|
45
|
+
export const rotateYVec3 = Fn(([v, r]: [Vec3, Float]): Vec3 => {
|
|
46
|
+
return rotate4dY(r).mul(vec4(v, 1)).xyz
|
|
47
|
+
}).setLayout({
|
|
48
|
+
name: 'rotateYVec3',
|
|
49
|
+
type: 'vec3',
|
|
50
|
+
inputs: [
|
|
51
|
+
{ name: 'v', type: 'vec3' },
|
|
52
|
+
{ name: 'r', type: 'float' },
|
|
53
|
+
],
|
|
54
|
+
})
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Fn, Vec3, Vec4, Float, vec4 } from '../../node'
|
|
2
|
+
import { rotate4dZ } from '../math/rotate4dZ'
|
|
3
|
+
|
|
4
|
+
// vec4 rotateZ(in vec4 v, in float r, in vec4 c)
|
|
5
|
+
export const rotateZVec4Center = Fn(([v, r, c]: [Vec4, Float, Vec4]): Vec4 => {
|
|
6
|
+
return rotate4dZ(r).mul(v.sub(c)).add(c)
|
|
7
|
+
}).setLayout({
|
|
8
|
+
name: 'rotateZVec4Center',
|
|
9
|
+
type: 'vec4',
|
|
10
|
+
inputs: [
|
|
11
|
+
{ name: 'v', type: 'vec4' },
|
|
12
|
+
{ name: 'r', type: 'float' },
|
|
13
|
+
{ name: 'c', type: 'vec4' },
|
|
14
|
+
],
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
// vec4 rotateZ(in vec4 v, in float r)
|
|
18
|
+
export const rotateZVec4 = Fn(([v, r]: [Vec4, Float]): Vec4 => {
|
|
19
|
+
return rotate4dZ(r).mul(v)
|
|
20
|
+
}).setLayout({
|
|
21
|
+
name: 'rotateZVec4',
|
|
22
|
+
type: 'vec4',
|
|
23
|
+
inputs: [
|
|
24
|
+
{ name: 'v', type: 'vec4' },
|
|
25
|
+
{ name: 'r', type: 'float' },
|
|
26
|
+
],
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
// vec3 rotateZ(in vec3 v, in float r, in vec3 c)
|
|
30
|
+
export const rotateZVec3Center = Fn(([v, r, c]: [Vec3, Float, Vec3]): Vec3 => {
|
|
31
|
+
return rotate4dZ(r)
|
|
32
|
+
.mul(vec4(v.sub(c), 0))
|
|
33
|
+
.xyz.add(c)
|
|
34
|
+
}).setLayout({
|
|
35
|
+
name: 'rotateZVec3Center',
|
|
36
|
+
type: 'vec3',
|
|
37
|
+
inputs: [
|
|
38
|
+
{ name: 'v', type: 'vec3' },
|
|
39
|
+
{ name: 'r', type: 'float' },
|
|
40
|
+
{ name: 'c', type: 'vec3' },
|
|
41
|
+
],
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
// vec3 rotateZ(in vec3 v, in float r)
|
|
45
|
+
export const rotateZVec3 = Fn(([v, r]: [Vec3, Float]): Vec3 => {
|
|
46
|
+
return rotate4dZ(r).mul(vec4(v, 0)).xyz
|
|
47
|
+
}).setLayout({
|
|
48
|
+
name: 'rotateZVec3',
|
|
49
|
+
type: 'vec3',
|
|
50
|
+
inputs: [
|
|
51
|
+
{ name: 'v', type: 'vec3' },
|
|
52
|
+
{ name: 'r', type: 'float' },
|
|
53
|
+
],
|
|
54
|
+
})
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Fn, vec2, vec3, vec4, Float, Vec2, Vec3, Vec4, X } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const scale = Fn(([st, s, center]: [X, X, X]): X => {
|
|
4
|
+
return st.sub(center).mul(s).add(center)
|
|
5
|
+
}).setLayout({
|
|
6
|
+
name: 'scale',
|
|
7
|
+
type: 'auto',
|
|
8
|
+
inputs: [
|
|
9
|
+
{ name: 'st', type: 'auto' },
|
|
10
|
+
{ name: 's', type: 'auto' },
|
|
11
|
+
{ name: 'center', type: 'auto' },
|
|
12
|
+
],
|
|
13
|
+
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Fn, Vec2, Float, vec2, floor, fract } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const sprite = Fn(([st, grid, index]: [Vec2, Vec2, Float]): Vec2 => {
|
|
4
|
+
const adjustedIndex = index.add(grid.x).toVar('adjustedIndex')
|
|
5
|
+
const f = vec2(1).div(grid).toVar('f')
|
|
6
|
+
const cell = vec2(floor(adjustedIndex), grid.y.sub(floor(adjustedIndex.mul(f.x)))).toVar('cell')
|
|
7
|
+
return fract(st.add(cell).mul(f))
|
|
8
|
+
}).setLayout({
|
|
9
|
+
name: 'sprite',
|
|
10
|
+
type: 'vec2',
|
|
11
|
+
inputs: [
|
|
12
|
+
{ name: 'st', type: 'vec2' },
|
|
13
|
+
{ name: 'grid', type: 'vec2' },
|
|
14
|
+
{ name: 'index', type: 'float' },
|
|
15
|
+
],
|
|
16
|
+
})
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Fn, Vec2, Vec4, Float, vec4, fract, floor } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const sqTile = Fn(([st]: [Vec2]): Vec4 => {
|
|
4
|
+
return vec4(fract(st), floor(st))
|
|
5
|
+
}).setLayout({
|
|
6
|
+
name: 'sqTile',
|
|
7
|
+
type: 'vec4',
|
|
8
|
+
inputs: [{ name: 'st', type: 'vec2' }],
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
export const sqTileScale = Fn(([st, scale]: [Vec2, Float]): Vec4 => {
|
|
12
|
+
return sqTile(st.mul(scale))
|
|
13
|
+
}).setLayout({
|
|
14
|
+
name: 'sqTileScale',
|
|
15
|
+
type: 'vec4',
|
|
16
|
+
inputs: [
|
|
17
|
+
{ name: 'st', type: 'vec2' },
|
|
18
|
+
{ name: 'scale', type: 'float' },
|
|
19
|
+
],
|
|
20
|
+
})
|