glre 0.39.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 +1 -1
- package/dist/addons.cjs.map +1 -1
- package/dist/addons.d.ts +849 -19
- 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 +38 -20
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/dist/native.d.ts +48 -22
- package/dist/node.cjs +59 -30
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.ts +34 -22
- package/dist/node.js +59 -30
- package/dist/node.js.map +1 -1
- package/dist/react.d.ts +38 -20
- package/dist/solid.d.ts +38 -20
- 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 +26 -25
- package/src/node/types.ts +15 -11
- package/src/node/utils/const.ts +12 -11
- package/src/node/utils/index.ts +14 -12
- package/src/node/utils/infer.ts +15 -5
- package/src/node/utils/parse.ts +37 -13
- package/src/node/utils/utils.ts +46 -23
- package/src/types.ts +9 -2
- package/src/utils/helpers.ts +56 -0
- package/src/utils/pipeline.ts +21 -5
- package/src/utils/program.ts +57 -38
- package/src/utils/webgl.ts +41 -35
- package/src/utils/webgpu.ts +19 -35
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Fn, Float, Mat3, mat3, vec3 } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const rotate3dZ = Fn(([r]: [Float]): Mat3 => {
|
|
4
|
+
const c = r.cos()
|
|
5
|
+
const s = r.sin()
|
|
6
|
+
return mat3(
|
|
7
|
+
vec3(c, s, 0),
|
|
8
|
+
vec3(s.negate(), c, 0),
|
|
9
|
+
vec3(0, 0, 1)
|
|
10
|
+
)
|
|
11
|
+
}).setLayout({
|
|
12
|
+
name: 'rotate3dZ',
|
|
13
|
+
type: 'mat3',
|
|
14
|
+
inputs: [
|
|
15
|
+
{
|
|
16
|
+
name: 'r',
|
|
17
|
+
type: 'float'
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
})
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Fn, Float, Mat4, Vec3, float, mat4, vec4 } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const rotate4d = Fn(([a, r]: [Vec3, Float]): Mat4 => {
|
|
4
|
+
const axis = a.normalize().toVar('axis')
|
|
5
|
+
const s = r.sin().toVar('s')
|
|
6
|
+
const c = r.cos().toVar('c')
|
|
7
|
+
const oc = float(1).sub(c).toVar('oc')
|
|
8
|
+
const col1 = vec4(
|
|
9
|
+
oc.mul(axis.x).mul(axis.x).add(c),
|
|
10
|
+
oc.mul(axis.x).mul(axis.y).add(axis.z.mul(s)),
|
|
11
|
+
oc.mul(axis.z).mul(axis.x).sub(axis.y.mul(s)),
|
|
12
|
+
0
|
|
13
|
+
)
|
|
14
|
+
const col2 = vec4(
|
|
15
|
+
oc.mul(axis.x).mul(axis.y).sub(axis.z.mul(s)),
|
|
16
|
+
oc.mul(axis.y).mul(axis.y).add(c),
|
|
17
|
+
oc.mul(axis.y).mul(axis.z).add(axis.x.mul(s)),
|
|
18
|
+
0
|
|
19
|
+
)
|
|
20
|
+
const col3 = vec4(
|
|
21
|
+
oc.mul(axis.z).mul(axis.x).add(axis.y.mul(s)),
|
|
22
|
+
oc.mul(axis.y).mul(axis.z).sub(axis.x.mul(s)),
|
|
23
|
+
oc.mul(axis.z).mul(axis.z).add(c),
|
|
24
|
+
0
|
|
25
|
+
)
|
|
26
|
+
const col4 = vec4(0, 0, 0, 1)
|
|
27
|
+
return mat4(col1, col2, col3, col4)
|
|
28
|
+
}).setLayout({
|
|
29
|
+
name: 'rotate4d',
|
|
30
|
+
type: 'mat4',
|
|
31
|
+
inputs: [
|
|
32
|
+
{
|
|
33
|
+
name: 'a',
|
|
34
|
+
type: 'vec3'
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: 'r',
|
|
38
|
+
type: 'float'
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
})
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Fn, Float, Mat4, mat4, vec4 } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const rotate4dX = Fn(([r]: [Float]): Mat4 => {
|
|
4
|
+
const c = r.cos()
|
|
5
|
+
const s = r.sin()
|
|
6
|
+
return mat4(
|
|
7
|
+
vec4(1, 0, 0, 0),
|
|
8
|
+
vec4(0, c, s, 0),
|
|
9
|
+
vec4(0, s.negate(), c, 0),
|
|
10
|
+
vec4(0, 0, 0, 1)
|
|
11
|
+
)
|
|
12
|
+
}).setLayout({
|
|
13
|
+
name: 'rotate4dX',
|
|
14
|
+
type: 'mat4',
|
|
15
|
+
inputs: [
|
|
16
|
+
{
|
|
17
|
+
name: 'r',
|
|
18
|
+
type: 'float'
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Fn, Float, Mat4, mat4, vec4 } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const rotate4dY = Fn(([r]: [Float]): Mat4 => {
|
|
4
|
+
const c = r.cos()
|
|
5
|
+
const s = r.sin()
|
|
6
|
+
return mat4(vec4(c, 0, s.negate(), 0), vec4(0, 1, 0, 0), vec4(s, 0, c, 0), vec4(0, 0, 0, 1))
|
|
7
|
+
}).setLayout({
|
|
8
|
+
name: 'rotate4dY',
|
|
9
|
+
type: 'mat4',
|
|
10
|
+
inputs: [
|
|
11
|
+
{
|
|
12
|
+
name: 'r',
|
|
13
|
+
type: 'float',
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
})
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Fn, Float, Mat4, mat4, vec4 } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const rotate4dZ = Fn(([r]: [Float]): Mat4 => {
|
|
4
|
+
const c = r.cos()
|
|
5
|
+
const s = r.sin()
|
|
6
|
+
return mat4(
|
|
7
|
+
vec4(c, s, 0, 0),
|
|
8
|
+
vec4(s.negate(), c, 0, 0),
|
|
9
|
+
vec4(0, 0, 1, 0),
|
|
10
|
+
vec4(0, 0, 0, 1)
|
|
11
|
+
)
|
|
12
|
+
}).setLayout({
|
|
13
|
+
name: 'rotate4dZ',
|
|
14
|
+
type: 'mat4',
|
|
15
|
+
inputs: [
|
|
16
|
+
{
|
|
17
|
+
name: 'r',
|
|
18
|
+
type: 'float'
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Fn, X, float } from '../../node'
|
|
2
|
+
|
|
3
|
+
const MEDIUMP_FLT_MAX = float(65504.0)
|
|
4
|
+
|
|
5
|
+
export const saturateMediump = Fn(([x]: [X]): X => {
|
|
6
|
+
return x.min(MEDIUMP_FLT_MAX)
|
|
7
|
+
}).setLayout({
|
|
8
|
+
name: 'saturateMediump',
|
|
9
|
+
type: 'auto',
|
|
10
|
+
inputs: [{ name: 'x', type: 'auto' }],
|
|
11
|
+
})
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Fn, Float, Vec2, mat2, Mat2 } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const scale2d = Fn(([s]: [Float]): Mat2 => {
|
|
4
|
+
return mat2(s, 0, 0, s)
|
|
5
|
+
}).setLayout({
|
|
6
|
+
name: 'scale2d',
|
|
7
|
+
type: 'mat2',
|
|
8
|
+
inputs: [
|
|
9
|
+
{
|
|
10
|
+
name: 's',
|
|
11
|
+
type: 'float',
|
|
12
|
+
},
|
|
13
|
+
]
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
export const scale2dVec = Fn(([s]: [Vec2]): Mat2 => {
|
|
17
|
+
return mat2(s.x, 0, 0, s.y)
|
|
18
|
+
}).setLayout({
|
|
19
|
+
name: 'scale2d',
|
|
20
|
+
type: 'mat2',
|
|
21
|
+
inputs: [
|
|
22
|
+
{
|
|
23
|
+
name: 's',
|
|
24
|
+
type: 'vec2',
|
|
25
|
+
},
|
|
26
|
+
]
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
export const scale2dXY = Fn(([x, y]: [Float, Float]): Mat2 => {
|
|
30
|
+
return mat2(x, 0, 0, y)
|
|
31
|
+
}).setLayout({
|
|
32
|
+
name: 'scale2d',
|
|
33
|
+
type: 'mat2',
|
|
34
|
+
inputs: [
|
|
35
|
+
{
|
|
36
|
+
name: 'x',
|
|
37
|
+
type: 'float',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: 'y',
|
|
41
|
+
type: 'float',
|
|
42
|
+
},
|
|
43
|
+
]
|
|
44
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Fn, Float, Vec3, Mat3, mat3 } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const scale3d = Fn(([s]: [Float]): Mat3 => {
|
|
4
|
+
return mat3(s, 0, 0, 0, s, 0, 0, 0, s)
|
|
5
|
+
}).setLayout({
|
|
6
|
+
name: 'scale3d',
|
|
7
|
+
type: 'mat3',
|
|
8
|
+
inputs: [{ name: 's', type: 'float' }]
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
export const scale3dVec = Fn(([s]: [Vec3]): Mat3 => {
|
|
12
|
+
return mat3(s.x, 0, 0, 0, s.y, 0, 0, 0, s.z)
|
|
13
|
+
}).setLayout({
|
|
14
|
+
name: 'scale3d',
|
|
15
|
+
type: 'mat3',
|
|
16
|
+
inputs: [{ name: 's', type: 'vec3' }]
|
|
17
|
+
})
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Fn, Float, Vec3, Vec4, Mat4, mat4 } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const scale4d = Fn(([s]: [Float]): Mat4 => {
|
|
4
|
+
return mat4(s, 0, 0, 0, 0, s, 0, 0, 0, 0, s, 0, 0, 0, 0, 1)
|
|
5
|
+
}).setLayout({
|
|
6
|
+
name: 'scale4d',
|
|
7
|
+
type: 'mat4',
|
|
8
|
+
inputs: [{ name: 's', type: 'float' }]
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
export const scale4dXYZ = Fn(([x, y, z]: [Float, Float, Float]): Mat4 => {
|
|
12
|
+
return mat4(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1)
|
|
13
|
+
}).setLayout({
|
|
14
|
+
name: 'scale4d',
|
|
15
|
+
type: 'mat4',
|
|
16
|
+
inputs: [
|
|
17
|
+
{ name: 'x', type: 'float' },
|
|
18
|
+
{ name: 'y', type: 'float' },
|
|
19
|
+
{ name: 'z', type: 'float' }
|
|
20
|
+
]
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
export const scale4dXYZW = Fn(([x, y, z, w]: [Float, Float, Float, Float]): Mat4 => {
|
|
24
|
+
return mat4(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, w)
|
|
25
|
+
}).setLayout({
|
|
26
|
+
name: 'scale4d',
|
|
27
|
+
type: 'mat4',
|
|
28
|
+
inputs: [
|
|
29
|
+
{ name: 'x', type: 'float' },
|
|
30
|
+
{ name: 'y', type: 'float' },
|
|
31
|
+
{ name: 'z', type: 'float' },
|
|
32
|
+
{ name: 'w', type: 'float' }
|
|
33
|
+
]
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
export const scale4dVec3 = Fn(([s]: [Vec3]): Mat4 => {
|
|
37
|
+
return mat4(s.x, 0, 0, 0, 0, s.y, 0, 0, 0, 0, s.z, 0, 0, 0, 0, 1)
|
|
38
|
+
}).setLayout({
|
|
39
|
+
name: 'scale4d',
|
|
40
|
+
type: 'mat4',
|
|
41
|
+
inputs: [{ name: 's', type: 'vec3' }]
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
export const scale4dVec4 = Fn(([s]: [Vec4]): Mat4 => {
|
|
45
|
+
return mat4(s.x, 0, 0, 0, 0, s.y, 0, 0, 0, 0, s.z, 0, 0, 0, 0, s.w)
|
|
46
|
+
}).setLayout({
|
|
47
|
+
name: 'scale4d',
|
|
48
|
+
type: 'mat4',
|
|
49
|
+
inputs: [{ name: 's', type: 'vec4' }]
|
|
50
|
+
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Fn, X } from '../../node'
|
|
2
|
+
import { quintic } from './quintic'
|
|
3
|
+
|
|
4
|
+
export const smootherstep = Fn(([a, b, v]: [X, X, X]): X => {
|
|
5
|
+
const normalized = v.sub(a).div(b.sub(a)).toVar('normalized')
|
|
6
|
+
const saturated = normalized.saturate().toVar('saturated')
|
|
7
|
+
return quintic(saturated)
|
|
8
|
+
}).setLayout({
|
|
9
|
+
name: 'smootherstep',
|
|
10
|
+
type: 'auto',
|
|
11
|
+
inputs: [
|
|
12
|
+
{ name: 'a', type: 'auto' },
|
|
13
|
+
{ name: 'b', type: 'auto' },
|
|
14
|
+
{ name: 'v', type: 'auto' }
|
|
15
|
+
]
|
|
16
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Fn, Mat3, Mat4, mat3 } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const toMat3 = Fn(([m]: [Mat4]): Mat3 => {
|
|
4
|
+
return mat3(m[0].xyz, m[1].xyz, m[2].xyz)
|
|
5
|
+
}).setLayout({
|
|
6
|
+
name: 'toMat3',
|
|
7
|
+
type: 'mat3',
|
|
8
|
+
inputs: [
|
|
9
|
+
{
|
|
10
|
+
name: 'm',
|
|
11
|
+
type: 'mat4',
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Fn, Mat3, Mat4, mat4, vec4 } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const toMat4 = Fn(([m]: [Mat3]): Mat4 => {
|
|
4
|
+
return mat4(vec4(m[0], 0), vec4(m[1], 0), vec4(m[2], 0), vec4(0, 0, 0, 1))
|
|
5
|
+
}).setLayout({
|
|
6
|
+
name: 'toMat4',
|
|
7
|
+
type: 'mat4',
|
|
8
|
+
inputs: [
|
|
9
|
+
{
|
|
10
|
+
name: 'm',
|
|
11
|
+
type: 'mat3',
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
})
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Fn, Float, Mat4, Vec3, X, mat4 } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const translate4d = Fn(([x, y, z]: [X, X?, X?]): Mat4 => {
|
|
4
|
+
if (y === undefined && z === undefined) {
|
|
5
|
+
const t = x as Vec3
|
|
6
|
+
return mat4(
|
|
7
|
+
1, 0, 0, 0,
|
|
8
|
+
0, 1, 0, 0,
|
|
9
|
+
0, 0, 1, 0,
|
|
10
|
+
t.x, t.y, t.z, 1
|
|
11
|
+
)
|
|
12
|
+
} else {
|
|
13
|
+
const tx = x as Float
|
|
14
|
+
const ty = y as Float
|
|
15
|
+
const tz = z as Float
|
|
16
|
+
return mat4(
|
|
17
|
+
1, 0, 0, 0,
|
|
18
|
+
0, 1, 0, 0,
|
|
19
|
+
0, 0, 1, 0,
|
|
20
|
+
tx, ty, tz, 1
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
}).setLayout({
|
|
24
|
+
name: 'translate4d',
|
|
25
|
+
type: 'mat4',
|
|
26
|
+
inputs: [
|
|
27
|
+
{ name: 'x', type: 'auto' },
|
|
28
|
+
{ name: 'y', type: 'auto' },
|
|
29
|
+
{ name: 'z', type: 'auto' }
|
|
30
|
+
]
|
|
31
|
+
})
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Fn, Float, Vec3, Vec4, dot, vec3, vec4, float } from '../../node'
|
|
2
|
+
|
|
3
|
+
const UnpackDownscale = float(255.0 / 256.0)
|
|
4
|
+
const PackFactors = vec3(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0)
|
|
5
|
+
const UnpackFactors = UnpackDownscale.div(vec4(PackFactors, 1.0))
|
|
6
|
+
|
|
7
|
+
export const unpack8 = Fn(([v]: [Vec3]): Float => {
|
|
8
|
+
const f = vec3(8, 8 * 8, 8 * 8 * 8)
|
|
9
|
+
return dot(v, f).div(512.0)
|
|
10
|
+
}).setLayout({
|
|
11
|
+
name: 'unpack8',
|
|
12
|
+
type: 'float',
|
|
13
|
+
inputs: [{ name: 'v', type: 'vec3' }],
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
export const unpack16 = Fn(([v]: [Vec3]): Float => {
|
|
17
|
+
const f = vec3(16, 16 * 16, 16 * 16 * 16)
|
|
18
|
+
return dot(v, f).div(4096.0)
|
|
19
|
+
}).setLayout({
|
|
20
|
+
name: 'unpack16',
|
|
21
|
+
type: 'float',
|
|
22
|
+
inputs: [{ name: 'v', type: 'vec3' }],
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
export const unpack32 = Fn(([v]: [Vec3]): Float => {
|
|
26
|
+
const f = vec3(32, 32 * 32, 32 * 32 * 32)
|
|
27
|
+
return dot(v, f).div(32768.0)
|
|
28
|
+
}).setLayout({
|
|
29
|
+
name: 'unpack32',
|
|
30
|
+
type: 'float',
|
|
31
|
+
inputs: [{ name: 'v', type: 'vec3' }],
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
export const unpack64 = Fn(([v]: [Vec3]): Float => {
|
|
35
|
+
const f = vec3(64, 64 * 64, 64 * 64 * 64)
|
|
36
|
+
return dot(v, f).div(262144.0)
|
|
37
|
+
}).setLayout({
|
|
38
|
+
name: 'unpack64',
|
|
39
|
+
type: 'float',
|
|
40
|
+
inputs: [{ name: 'v', type: 'vec3' }],
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
export const unpack128 = Fn(([v]: [Vec3]): Float => {
|
|
44
|
+
const f = vec3(128, 128 * 128, 128 * 128 * 128)
|
|
45
|
+
return dot(v, f).div(2097152.0)
|
|
46
|
+
}).setLayout({
|
|
47
|
+
name: 'unpack128',
|
|
48
|
+
type: 'float',
|
|
49
|
+
inputs: [{ name: 'v', type: 'vec3' }],
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
export const unpack256 = Fn(([v]: [Vec3]): Float => {
|
|
53
|
+
const f = vec3(256, 256 * 256, 256 * 256 * 256)
|
|
54
|
+
return dot(v, f).div(16581375.0)
|
|
55
|
+
}).setLayout({
|
|
56
|
+
name: 'unpack256',
|
|
57
|
+
type: 'float',
|
|
58
|
+
inputs: [{ name: 'v', type: 'vec3' }],
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
export const unpackBase = Fn(([v, base]: [Vec3, Float]): Float => {
|
|
62
|
+
const base3 = base.mul(base).mul(base)
|
|
63
|
+
const f = vec3(base, base.mul(base), base3)
|
|
64
|
+
return dot(v, f).div(base3)
|
|
65
|
+
}).setLayout({
|
|
66
|
+
name: 'unpackBase',
|
|
67
|
+
type: 'float',
|
|
68
|
+
inputs: [
|
|
69
|
+
{ name: 'v', type: 'vec3' },
|
|
70
|
+
{ name: 'base', type: 'float' },
|
|
71
|
+
],
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
export const unpack = Fn(([v]: [Vec4]): Float => {
|
|
75
|
+
return dot(v, UnpackFactors)
|
|
76
|
+
}).setLayout({
|
|
77
|
+
name: 'unpack',
|
|
78
|
+
type: 'float',
|
|
79
|
+
inputs: [{ name: 'v', type: 'vec4' }],
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
export const unpackDefault = Fn(([v]: [Vec3]): Float => {
|
|
83
|
+
return unpack256(v)
|
|
84
|
+
}).setLayout({
|
|
85
|
+
name: 'unpackDefault',
|
|
86
|
+
type: 'float',
|
|
87
|
+
inputs: [{ name: 'v', type: 'vec3' }],
|
|
88
|
+
})
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Fn, Vec3 } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const boxSDF = Fn(([p]: [Vec3]) => {
|
|
4
|
+
const d = p.abs().toVar()
|
|
5
|
+
return d.x.max(d.y.max(d.z)).min(0).add(d.max(0).length())
|
|
6
|
+
}).setLayout({
|
|
7
|
+
name: 'boxSDF',
|
|
8
|
+
type: 'float',
|
|
9
|
+
inputs: [
|
|
10
|
+
{ name: 'p', type: 'vec3' }
|
|
11
|
+
]
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
export const boxSDFSize = Fn(([p, b]: [Vec3, Vec3]) => {
|
|
15
|
+
const d = p.abs().sub(b).toVar()
|
|
16
|
+
return d.x.max(d.y.max(d.z)).min(0).add(d.max(0).length())
|
|
17
|
+
}).setLayout({
|
|
18
|
+
name: 'boxSDFSize',
|
|
19
|
+
type: 'float',
|
|
20
|
+
inputs: [
|
|
21
|
+
{ name: 'p', type: 'vec3' },
|
|
22
|
+
{ name: 'b', type: 'vec3' }
|
|
23
|
+
]
|
|
24
|
+
})
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Fn, Vec2, vec2 } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const circleSDF = Fn(([v, center]: [Vec2, Vec2]) => {
|
|
4
|
+
return v.sub(center).length().mul(2)
|
|
5
|
+
}).setLayout({
|
|
6
|
+
name: 'circleSDF',
|
|
7
|
+
type: 'float',
|
|
8
|
+
inputs: [
|
|
9
|
+
{ name: 'v', type: 'vec2' },
|
|
10
|
+
{ name: 'center', type: 'vec2' },
|
|
11
|
+
],
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
export const circleSDFBasic = Fn(([v]: [Vec2]) => {
|
|
15
|
+
return v.sub(vec2(0.5)).length().mul(2)
|
|
16
|
+
}).setLayout({
|
|
17
|
+
name: 'circleSDFBasic',
|
|
18
|
+
type: 'float',
|
|
19
|
+
inputs: [{ name: 'v', type: 'vec2' }],
|
|
20
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Fn, vec2, min, Float, Vec2 } from '../../node'
|
|
2
|
+
import { rectSDF } from './rectSDF'
|
|
3
|
+
|
|
4
|
+
export const crossSDF = Fn(([st, s]: [Vec2, Float]): Float => {
|
|
5
|
+
const size = vec2(0.25, s)
|
|
6
|
+
return min(
|
|
7
|
+
rectSDF(st, size),
|
|
8
|
+
rectSDF(st, size.yx)
|
|
9
|
+
)
|
|
10
|
+
}).setLayout({
|
|
11
|
+
name: 'crossSDF',
|
|
12
|
+
type: 'float',
|
|
13
|
+
inputs: [
|
|
14
|
+
{ name: 'st', type: 'vec2' },
|
|
15
|
+
{ name: 's', type: 'float' }
|
|
16
|
+
]
|
|
17
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Fn, Vec2, Float, abs, max, float } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const hexSDF = Fn(([st]: [Vec2]): Float => {
|
|
4
|
+
// Transform to centered coordinates [-1, 1]
|
|
5
|
+
const normalized = st.mul(2).sub(1).toVar()
|
|
6
|
+
normalized.assign(abs(normalized))
|
|
7
|
+
|
|
8
|
+
// Hexagon SDF calculation using geometric properties
|
|
9
|
+
const sqrt3_2 = float(0.866025) // sqrt(3)/2
|
|
10
|
+
return max(
|
|
11
|
+
abs(normalized.y),
|
|
12
|
+
normalized.x.mul(sqrt3_2).add(normalized.y.div(2))
|
|
13
|
+
)
|
|
14
|
+
}).setLayout({
|
|
15
|
+
name: 'hexSDF',
|
|
16
|
+
type: 'float',
|
|
17
|
+
inputs: [{ name: 'st', type: 'vec2' }],
|
|
18
|
+
})
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Fn, Vec2, Vec3, Float, clamp, dot, length, cross } from '../../node'
|
|
2
|
+
|
|
3
|
+
// 2D line segment distance function
|
|
4
|
+
export const lineSDF2D = Fn(([st, a, b]: [Vec2, Vec2, Vec2]): Float => {
|
|
5
|
+
const b_to_a = b.sub(a).toVar('b_to_a')
|
|
6
|
+
const to_a = st.sub(a).toVar('to_a')
|
|
7
|
+
const h = clamp(dot(to_a, b_to_a).div(dot(b_to_a, b_to_a)), 0, 1).toVar('h')
|
|
8
|
+
return length(to_a.sub(h.mul(b_to_a)))
|
|
9
|
+
}).setLayout({
|
|
10
|
+
name: 'lineSDF2D',
|
|
11
|
+
type: 'float',
|
|
12
|
+
inputs: [
|
|
13
|
+
{ name: 'st', type: 'vec2' },
|
|
14
|
+
{ name: 'a', type: 'vec2' },
|
|
15
|
+
{ name: 'b', type: 'vec2' },
|
|
16
|
+
],
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
// 3D line distance function
|
|
20
|
+
export const lineSDF3D = Fn(([p, a, b]: [Vec3, Vec3, Vec3]): Float => {
|
|
21
|
+
return length(cross(p.sub(a), p.sub(b))).div(length(b.sub(a)))
|
|
22
|
+
}).setLayout({
|
|
23
|
+
name: 'lineSDF3D',
|
|
24
|
+
type: 'float',
|
|
25
|
+
inputs: [
|
|
26
|
+
{ name: 'p', type: 'vec3' },
|
|
27
|
+
{ name: 'a', type: 'vec3' },
|
|
28
|
+
{ name: 'b', type: 'vec3' },
|
|
29
|
+
],
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
// Unified lineSDF function (defaults to 2D)
|
|
33
|
+
export const lineSDF = lineSDF2D
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Fn, Vec2, Float, vec2 } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const rectSDFBasic = Fn(([st]: [Vec2]) => {
|
|
4
|
+
const normalizedSt = st.mul(2).sub(1).toVar()
|
|
5
|
+
return normalizedSt.x.abs().max(normalizedSt.y.abs())
|
|
6
|
+
}).setLayout({
|
|
7
|
+
name: 'rectSDFBasic',
|
|
8
|
+
type: 'float',
|
|
9
|
+
inputs: [{ name: 'st', type: 'vec2' }],
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
export const rectSDF = Fn(([st, s]: [Vec2, Vec2]) => {
|
|
13
|
+
const normalizedSt = st.mul(2).sub(1).toVar()
|
|
14
|
+
return normalizedSt.x.div(s.x).abs().max(normalizedSt.y.div(s.y).abs())
|
|
15
|
+
}).setLayout({
|
|
16
|
+
name: 'rectSDF',
|
|
17
|
+
type: 'float',
|
|
18
|
+
inputs: [
|
|
19
|
+
{ name: 'st', type: 'vec2' },
|
|
20
|
+
{ name: 's', type: 'vec2' },
|
|
21
|
+
],
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
export const rectSDFUniform = Fn(([st, s]: [Vec2, Float]) => {
|
|
25
|
+
return rectSDF(st, vec2(s))
|
|
26
|
+
}).setLayout({
|
|
27
|
+
name: 'rectSDFUniform',
|
|
28
|
+
type: 'float',
|
|
29
|
+
inputs: [
|
|
30
|
+
{ name: 'st', type: 'vec2' },
|
|
31
|
+
{ name: 's', type: 'float' },
|
|
32
|
+
],
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
export const rectSDFRounded = Fn(([p, b, r]: [Vec2, Vec2, Float]) => {
|
|
36
|
+
const d = p.sub(0.5).mul(4.2).abs().sub(b).add(vec2(r)).toVar()
|
|
37
|
+
return d.x.max(d.y).min(0).add(d.max(0).length()).sub(r)
|
|
38
|
+
}).setLayout({
|
|
39
|
+
name: 'rectSDFRounded',
|
|
40
|
+
type: 'float',
|
|
41
|
+
inputs: [
|
|
42
|
+
{ name: 'p', type: 'vec2' },
|
|
43
|
+
{ name: 'b', type: 'vec2' },
|
|
44
|
+
{ name: 'r', type: 'float' },
|
|
45
|
+
],
|
|
46
|
+
})
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Fn, Vec3, Float } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const sphereSDF = Fn(([p]: [Vec3]) => {
|
|
4
|
+
return p.length()
|
|
5
|
+
}).setLayout({
|
|
6
|
+
name: 'sphereSDF',
|
|
7
|
+
type: 'float',
|
|
8
|
+
inputs: [{ name: 'p', type: 'vec3' }],
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
export const sphereSDFRadius = Fn(([p, s]: [Vec3, Float]) => {
|
|
12
|
+
return p.length().sub(s)
|
|
13
|
+
}).setLayout({
|
|
14
|
+
name: 'sphereSDFRadius',
|
|
15
|
+
type: 'float',
|
|
16
|
+
inputs: [
|
|
17
|
+
{ name: 'p', type: 'vec3' },
|
|
18
|
+
{ name: 's', type: 'float' },
|
|
19
|
+
],
|
|
20
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Fn, Vec2, Float, max, abs, float } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const triSDF = Fn(([st]: [Vec2]): Float => {
|
|
4
|
+
const normalized = st.sub(0.5).mul(5).toVar()
|
|
5
|
+
const sqrt3_2 = float(0.866025) // sqrt(3)/2
|
|
6
|
+
return max(
|
|
7
|
+
abs(normalized.x).mul(sqrt3_2).add(normalized.y.div(2)),
|
|
8
|
+
normalized.y.div(-2)
|
|
9
|
+
)
|
|
10
|
+
}).setLayout({
|
|
11
|
+
name: 'triSDF',
|
|
12
|
+
type: 'float',
|
|
13
|
+
inputs: [{ name: 'st', type: 'vec2' }],
|
|
14
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Fn, Vec2 } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const aspect = Fn(([st, s]: [Vec2, Vec2]): Vec2 => {
|
|
4
|
+
const result = st.toVar('result')
|
|
5
|
+
result.x.assign(result.x.mul(s.x.div(s.y)))
|
|
6
|
+
return result
|
|
7
|
+
}).setLayout({
|
|
8
|
+
name: 'aspect',
|
|
9
|
+
type: 'vec2',
|
|
10
|
+
inputs: [
|
|
11
|
+
{ name: 'st', type: 'vec2' },
|
|
12
|
+
{ name: 's', type: 'vec2' }
|
|
13
|
+
]
|
|
14
|
+
})
|