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,81 @@
|
|
|
1
|
+
import { Fn, Float, Vec2, Vec3, Vec4, X, float } from '../../node'
|
|
2
|
+
import { stroke } from './stroke'
|
|
3
|
+
|
|
4
|
+
// Bridge effect for float
|
|
5
|
+
export const bridgeFloat = Fn(([c, d, s, w]: [Float, Float, Float, Float]): Float => {
|
|
6
|
+
const maskedC = c.mul(float(1).sub(stroke(d, s, w.mul(2))))
|
|
7
|
+
return maskedC.add(stroke(d, s, w))
|
|
8
|
+
}).setLayout({
|
|
9
|
+
name: 'bridgeFloat',
|
|
10
|
+
type: 'float',
|
|
11
|
+
inputs: [
|
|
12
|
+
{ name: 'c', type: 'float' },
|
|
13
|
+
{ name: 'd', type: 'float' },
|
|
14
|
+
{ name: 's', type: 'float' },
|
|
15
|
+
{ name: 'w', type: 'float' },
|
|
16
|
+
],
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
// Bridge effect for vec2
|
|
20
|
+
export const bridgeVec2 = Fn(([c, d, s, w]: [Vec2, Float, Float, Float]): Vec2 => {
|
|
21
|
+
const strokeMask = stroke(d, s, w.mul(2))
|
|
22
|
+
const maskedC = c.mul(float(1).sub(strokeMask))
|
|
23
|
+
return maskedC.add(strokeMask)
|
|
24
|
+
}).setLayout({
|
|
25
|
+
name: 'bridgeVec2',
|
|
26
|
+
type: 'vec2',
|
|
27
|
+
inputs: [
|
|
28
|
+
{ name: 'c', type: 'vec2' },
|
|
29
|
+
{ name: 'd', type: 'float' },
|
|
30
|
+
{ name: 's', type: 'float' },
|
|
31
|
+
{ name: 'w', type: 'float' },
|
|
32
|
+
],
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
// Bridge effect for vec3
|
|
36
|
+
export const bridgeVec3 = Fn(([c, d, s, w]: [Vec3, Float, Float, Float]): Vec3 => {
|
|
37
|
+
const strokeMask = stroke(d, s, w.mul(2))
|
|
38
|
+
const maskedC = c.mul(float(1).sub(strokeMask))
|
|
39
|
+
return maskedC.add(strokeMask)
|
|
40
|
+
}).setLayout({
|
|
41
|
+
name: 'bridgeVec3',
|
|
42
|
+
type: 'vec3',
|
|
43
|
+
inputs: [
|
|
44
|
+
{ name: 'c', type: 'vec3' },
|
|
45
|
+
{ name: 'd', type: 'float' },
|
|
46
|
+
{ name: 's', type: 'float' },
|
|
47
|
+
{ name: 'w', type: 'float' },
|
|
48
|
+
],
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
// Bridge effect for vec4
|
|
52
|
+
export const bridgeVec4 = Fn(([c, d, s, w]: [Vec4, Float, Float, Float]): Vec4 => {
|
|
53
|
+
const strokeMask = stroke(d, s, w.mul(2))
|
|
54
|
+
const maskedC = c.mul(float(1).sub(strokeMask))
|
|
55
|
+
return maskedC.add(strokeMask)
|
|
56
|
+
}).setLayout({
|
|
57
|
+
name: 'bridgeVec4',
|
|
58
|
+
type: 'vec4',
|
|
59
|
+
inputs: [
|
|
60
|
+
{ name: 'c', type: 'vec4' },
|
|
61
|
+
{ name: 'd', type: 'float' },
|
|
62
|
+
{ name: 's', type: 'float' },
|
|
63
|
+
{ name: 'w', type: 'float' },
|
|
64
|
+
],
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
// Generic bridge function using auto type
|
|
68
|
+
export const bridge = Fn(([c, d, s, w]: [X, Float, Float, Float]): X => {
|
|
69
|
+
const strokeMask = stroke(d, s, (w as any).mul(2))
|
|
70
|
+
const maskedC = (c as any).mul(float(1).sub(strokeMask))
|
|
71
|
+
return maskedC.add(strokeMask)
|
|
72
|
+
}).setLayout({
|
|
73
|
+
name: 'bridge',
|
|
74
|
+
type: 'auto',
|
|
75
|
+
inputs: [
|
|
76
|
+
{ name: 'c', type: 'auto' },
|
|
77
|
+
{ name: 'd', type: 'float' },
|
|
78
|
+
{ name: 's', type: 'float' },
|
|
79
|
+
{ name: 'w', type: 'float' },
|
|
80
|
+
],
|
|
81
|
+
})
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Fn, Vec2, Int, Float, float, vec2, floor, ivec2 } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const charLookupSimple = Fn(([index]: [Int]): Float => {
|
|
4
|
+
const isValidChar = index.greaterThan(31).and(index.lessThan(127))
|
|
5
|
+
return float(0).select(float(1), isValidChar)
|
|
6
|
+
}).setLayout({
|
|
7
|
+
name: 'charLookupSimple',
|
|
8
|
+
type: 'float',
|
|
9
|
+
inputs: [{ name: 'index', type: 'int' }],
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
export const charSimple = Fn(([uv, charCode]: [Vec2, Int]): Float => {
|
|
13
|
+
const charCoord = ivec2(floor(uv.mul(vec2(8, 16)))).toVar()
|
|
14
|
+
charCoord.x.assign(charCoord.x.clamp(0, 7))
|
|
15
|
+
charCoord.y.assign(charCoord.y.clamp(0, 15))
|
|
16
|
+
const centerX = charCoord.x.sub(4).abs()
|
|
17
|
+
const centerY = charCoord.y.sub(8).abs()
|
|
18
|
+
const pattern = centerX.add(centerY).lessThan(charCode.mod(8) as any)
|
|
19
|
+
return float(0).select(float(1), pattern)
|
|
20
|
+
}).setLayout({
|
|
21
|
+
name: 'charSimple',
|
|
22
|
+
type: 'float',
|
|
23
|
+
inputs: [
|
|
24
|
+
{ name: 'uv', type: 'vec2' },
|
|
25
|
+
{ name: 'charCode', type: 'int' },
|
|
26
|
+
],
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
// Default char function using simplified implementation
|
|
30
|
+
export const char = charSimple
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Fn, Vec2, Float } from '../../node'
|
|
2
|
+
import { circleSDFBasic } from '../sdf/circleSDF'
|
|
3
|
+
import { fill } from './fill'
|
|
4
|
+
import { stroke } from './stroke'
|
|
5
|
+
|
|
6
|
+
export const circleFill = Fn(([st, size]: [Vec2, Float]): Float => {
|
|
7
|
+
return fill(circleSDFBasic(st), size)
|
|
8
|
+
}).setLayout({
|
|
9
|
+
name: 'circleFill',
|
|
10
|
+
type: 'float',
|
|
11
|
+
inputs: [
|
|
12
|
+
{ name: 'st', type: 'vec2' },
|
|
13
|
+
{ name: 'size', type: 'float' },
|
|
14
|
+
],
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
export const circleStroke = Fn(([st, size, strokeWidth]: [Vec2, Float, Float]): Float => {
|
|
18
|
+
return stroke(circleSDFBasic(st), size, strokeWidth)
|
|
19
|
+
}).setLayout({
|
|
20
|
+
name: 'circleStroke',
|
|
21
|
+
type: 'float',
|
|
22
|
+
inputs: [
|
|
23
|
+
{ name: 'st', type: 'vec2' },
|
|
24
|
+
{ name: 'size', type: 'float' },
|
|
25
|
+
{ name: 'strokeWidth', type: 'float' },
|
|
26
|
+
],
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
export const circle = circleFill
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Fn, Float, smoothstep } from '../../node'
|
|
2
|
+
import { aastep } from '../math/aastep'
|
|
3
|
+
|
|
4
|
+
export const fillWithEdge = Fn(([x, size, edge]: [Float, Float, Float]): Float => {
|
|
5
|
+
return smoothstep(size.sub(edge), size.add(edge), x).oneMinus()
|
|
6
|
+
}).setLayout({
|
|
7
|
+
name: 'fillWithEdge',
|
|
8
|
+
type: 'float',
|
|
9
|
+
inputs: [
|
|
10
|
+
{ name: 'x', type: 'float' },
|
|
11
|
+
{ name: 'size', type: 'float' },
|
|
12
|
+
{ name: 'edge', type: 'float' },
|
|
13
|
+
],
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
export const fill = Fn(([x, size]: [Float, Float]): Float => {
|
|
17
|
+
return aastep(size, x).oneMinus()
|
|
18
|
+
}).setLayout({
|
|
19
|
+
name: 'fill',
|
|
20
|
+
type: 'float',
|
|
21
|
+
inputs: [
|
|
22
|
+
{ name: 'x', type: 'float' },
|
|
23
|
+
{ name: 'size', type: 'float' },
|
|
24
|
+
],
|
|
25
|
+
})
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Fn, Float, Vec3, Vec4, X, float, vec3, vec4, mix } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const flipFloat = Fn(([v, pct]: [Float, Float]): Float => {
|
|
4
|
+
return mix(v, float(1).sub(v), pct)
|
|
5
|
+
}).setLayout({
|
|
6
|
+
name: 'flipFloat',
|
|
7
|
+
type: 'float',
|
|
8
|
+
inputs: [
|
|
9
|
+
{ name: 'v', type: 'float' },
|
|
10
|
+
{ name: 'pct', type: 'float' },
|
|
11
|
+
],
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
export const flipVec3 = Fn(([v, pct]: [Vec3, Float]): Vec3 => {
|
|
15
|
+
return mix(v, vec3(1).sub(v), pct)
|
|
16
|
+
}).setLayout({
|
|
17
|
+
name: 'flipVec3',
|
|
18
|
+
type: 'vec3',
|
|
19
|
+
inputs: [
|
|
20
|
+
{ name: 'v', type: 'vec3' },
|
|
21
|
+
{ name: 'pct', type: 'float' },
|
|
22
|
+
],
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
export const flipVec4 = Fn(([v, pct]: [Vec4, Float]): Vec4 => {
|
|
26
|
+
return mix(v, vec4(1).sub(v), pct)
|
|
27
|
+
}).setLayout({
|
|
28
|
+
name: 'flipVec4',
|
|
29
|
+
type: 'vec4',
|
|
30
|
+
inputs: [
|
|
31
|
+
{ name: 'v', type: 'vec4' },
|
|
32
|
+
{ name: 'pct', type: 'float' },
|
|
33
|
+
],
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
export const flip = Fn(([v, pct]: [X, Float]): X => {
|
|
37
|
+
return mix(v, v.oneMinus(), pct)
|
|
38
|
+
}).setLayout({
|
|
39
|
+
name: 'flip',
|
|
40
|
+
type: 'auto',
|
|
41
|
+
inputs: [
|
|
42
|
+
{ name: 'v', type: 'auto' },
|
|
43
|
+
{ name: 'pct', type: 'float' },
|
|
44
|
+
],
|
|
45
|
+
})
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Fn, Vec2, Float } from '../../node'
|
|
2
|
+
import { hexSDF } from '../sdf/hexSDF'
|
|
3
|
+
import { fill } from './fill'
|
|
4
|
+
import { stroke } from './stroke'
|
|
5
|
+
|
|
6
|
+
export const hexFill = Fn(([st, size]: [Vec2, Float]): Float => {
|
|
7
|
+
return fill(hexSDF(st), size)
|
|
8
|
+
}).setLayout({
|
|
9
|
+
name: 'hexFill',
|
|
10
|
+
type: 'float',
|
|
11
|
+
inputs: [
|
|
12
|
+
{ name: 'st', type: 'vec2' },
|
|
13
|
+
{ name: 'size', type: 'float' },
|
|
14
|
+
],
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
export const hexStroke = Fn(([st, size, strokeWidth]: [Vec2, Float, Float]): Float => {
|
|
18
|
+
return stroke(hexSDF(st), size, strokeWidth)
|
|
19
|
+
}).setLayout({
|
|
20
|
+
name: 'hexStroke',
|
|
21
|
+
type: 'float',
|
|
22
|
+
inputs: [
|
|
23
|
+
{ name: 'st', type: 'vec2' },
|
|
24
|
+
{ name: 'size', type: 'float' },
|
|
25
|
+
{ name: 'strokeWidth', type: 'float' },
|
|
26
|
+
],
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
export const hex = hexFill
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from './arrows'
|
|
2
|
+
export * from './axis'
|
|
3
|
+
export * from './bridge'
|
|
4
|
+
export * from './char'
|
|
5
|
+
export * from './circle'
|
|
6
|
+
export * from './fill'
|
|
7
|
+
export * from './flip'
|
|
8
|
+
export * from './hex'
|
|
9
|
+
export * from './line'
|
|
10
|
+
export * from './point'
|
|
11
|
+
export * from './rect'
|
|
12
|
+
export * from './stroke'
|
|
13
|
+
export * from './tri'
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Fn, Vec2, Float } from '../../node'
|
|
2
|
+
import { lineSDF } from '../sdf/lineSDF'
|
|
3
|
+
import { fill } from './fill'
|
|
4
|
+
|
|
5
|
+
export const line = Fn(([st, a, b, thickness]: [Vec2, Vec2, Vec2, Float]): Float => {
|
|
6
|
+
return fill(lineSDF(st, a, b), thickness)
|
|
7
|
+
}).setLayout({
|
|
8
|
+
name: 'line',
|
|
9
|
+
type: 'float',
|
|
10
|
+
inputs: [
|
|
11
|
+
{ name: 'st', type: 'vec2' },
|
|
12
|
+
{ name: 'a', type: 'vec2' },
|
|
13
|
+
{ name: 'b', type: 'vec2' },
|
|
14
|
+
{ name: 'thickness', type: 'float' },
|
|
15
|
+
],
|
|
16
|
+
})
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Fn, Vec2, Vec3, Vec4, Float, vec3, vec4, float } from '../../node'
|
|
2
|
+
import { circleFill } from './circle'
|
|
3
|
+
|
|
4
|
+
export const point2D = Fn(([st, pos, color, radius]: [Vec2, Vec2, Vec3, Float]): Vec4 => {
|
|
5
|
+
const st_p = st.sub(pos)
|
|
6
|
+
const circle = circleFill(st_p.add(0.5), radius)
|
|
7
|
+
return vec4(color, 1).mul(circle)
|
|
8
|
+
}).setLayout({
|
|
9
|
+
name: 'point2D',
|
|
10
|
+
type: 'vec4',
|
|
11
|
+
inputs: [
|
|
12
|
+
{ name: 'st', type: 'vec2' },
|
|
13
|
+
{ name: 'pos', type: 'vec2' },
|
|
14
|
+
{ name: 'color', type: 'vec3' },
|
|
15
|
+
{ name: 'radius', type: 'float' },
|
|
16
|
+
],
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
export const pointSimple = Fn(([st, pos]: [Vec2, Vec2]): Vec4 => {
|
|
20
|
+
return point2D(st, pos, vec3(1, 0, 0), float(0.02))
|
|
21
|
+
}).setLayout({
|
|
22
|
+
name: 'pointSimple',
|
|
23
|
+
type: 'vec4',
|
|
24
|
+
inputs: [
|
|
25
|
+
{ name: 'st', type: 'vec2' },
|
|
26
|
+
{ name: 'pos', type: 'vec2' },
|
|
27
|
+
],
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
export const point = pointSimple
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Fn, Vec2, Float, float } from '../../node'
|
|
2
|
+
import { rectSDF, rectSDFUniform } from '../sdf/rectSDF'
|
|
3
|
+
import { fill } from './fill'
|
|
4
|
+
import { stroke } from './stroke'
|
|
5
|
+
|
|
6
|
+
export const rectStroke = Fn(([st, size, strokeWidth]: [Vec2, Vec2, Float]): Float => {
|
|
7
|
+
return stroke(rectSDF(st, size), float(1), strokeWidth)
|
|
8
|
+
}).setLayout({
|
|
9
|
+
name: 'rectStroke',
|
|
10
|
+
type: 'float',
|
|
11
|
+
inputs: [
|
|
12
|
+
{ name: 'st', type: 'vec2' },
|
|
13
|
+
{ name: 'size', type: 'vec2' },
|
|
14
|
+
{ name: 'strokeWidth', type: 'float' },
|
|
15
|
+
],
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
export const rectStrokeUniform = Fn(([st, size, strokeWidth]: [Vec2, Float, Float]): Float => {
|
|
19
|
+
return stroke(rectSDFUniform(st, size), float(1), strokeWidth)
|
|
20
|
+
}).setLayout({
|
|
21
|
+
name: 'rectStrokeUniform',
|
|
22
|
+
type: 'float',
|
|
23
|
+
inputs: [
|
|
24
|
+
{ name: 'st', type: 'vec2' },
|
|
25
|
+
{ name: 'size', type: 'float' },
|
|
26
|
+
{ name: 'strokeWidth', type: 'float' },
|
|
27
|
+
],
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
export const rectFill = Fn(([st, size]: [Vec2, Vec2]): Float => {
|
|
31
|
+
return fill(rectSDF(st, size), float(1))
|
|
32
|
+
}).setLayout({
|
|
33
|
+
name: 'rectFill',
|
|
34
|
+
type: 'float',
|
|
35
|
+
inputs: [
|
|
36
|
+
{ name: 'st', type: 'vec2' },
|
|
37
|
+
{ name: 'size', type: 'vec2' },
|
|
38
|
+
],
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
export const rectFillUniform = Fn(([st, size]: [Vec2, Float]): Float => {
|
|
42
|
+
return fill(rectSDFUniform(st, size), float(1))
|
|
43
|
+
}).setLayout({
|
|
44
|
+
name: 'rectFillUniform',
|
|
45
|
+
type: 'float',
|
|
46
|
+
inputs: [
|
|
47
|
+
{ name: 'st', type: 'vec2' },
|
|
48
|
+
{ name: 'size', type: 'float' },
|
|
49
|
+
],
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
export const rect = rectFill
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Fn, Float, smoothstep, clamp } from '../../node'
|
|
2
|
+
import { aastep } from '../math/aastep'
|
|
3
|
+
|
|
4
|
+
export const strokeWithEdge = Fn(([x, size, w, edge]: [Float, Float, Float, Float]): Float => {
|
|
5
|
+
const d = smoothstep(size.sub(edge), size.add(edge), x.add(w.div(2))).sub(
|
|
6
|
+
smoothstep(size.sub(edge), size.add(edge), x.sub(w.div(2)))
|
|
7
|
+
)
|
|
8
|
+
return clamp(d, 0, 1)
|
|
9
|
+
}).setLayout({
|
|
10
|
+
name: 'strokeWithEdge',
|
|
11
|
+
type: 'float',
|
|
12
|
+
inputs: [
|
|
13
|
+
{ name: 'x', type: 'float' },
|
|
14
|
+
{ name: 'size', type: 'float' },
|
|
15
|
+
{ name: 'w', type: 'float' },
|
|
16
|
+
{ name: 'edge', type: 'float' },
|
|
17
|
+
],
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
export const stroke = Fn(([x, size, w]: [Float, Float, Float]): Float => {
|
|
21
|
+
const d = aastep(size, x.add(w.div(2))).sub(aastep(size, x.sub(w.div(2))))
|
|
22
|
+
return clamp(d, 0, 1)
|
|
23
|
+
}).setLayout({
|
|
24
|
+
name: 'stroke',
|
|
25
|
+
type: 'float',
|
|
26
|
+
inputs: [
|
|
27
|
+
{ name: 'x', type: 'float' },
|
|
28
|
+
{ name: 'size', type: 'float' },
|
|
29
|
+
{ name: 'w', type: 'float' },
|
|
30
|
+
],
|
|
31
|
+
})
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Fn, Vec2, Float } from '../../node'
|
|
2
|
+
import { triSDF } from '../sdf/triSDF'
|
|
3
|
+
import { fill } from './fill'
|
|
4
|
+
import { stroke } from './stroke'
|
|
5
|
+
|
|
6
|
+
export const triFill = Fn(([st, size]: [Vec2, Float]): Float => {
|
|
7
|
+
return fill(triSDF(st), size)
|
|
8
|
+
}).setLayout({
|
|
9
|
+
name: 'triFill',
|
|
10
|
+
type: 'float',
|
|
11
|
+
inputs: [
|
|
12
|
+
{ name: 'st', type: 'vec2' },
|
|
13
|
+
{ name: 'size', type: 'float' },
|
|
14
|
+
],
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
export const triStroke = Fn(([st, size, strokeWidth]: [Vec2, Float, Float]): Float => {
|
|
18
|
+
return stroke(triSDF(st), size, strokeWidth)
|
|
19
|
+
}).setLayout({
|
|
20
|
+
name: 'triStroke',
|
|
21
|
+
type: 'float',
|
|
22
|
+
inputs: [
|
|
23
|
+
{ name: 'st', type: 'vec2' },
|
|
24
|
+
{ name: 'size', type: 'float' },
|
|
25
|
+
{ name: 'strokeWidth', type: 'float' },
|
|
26
|
+
],
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
export const tri = triFill
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { Fn, Vec2, Vec3, Vec4, Float, vec2, vec3, vec4, mix, step } from '../../node'
|
|
2
|
+
import { mod289Vec3, mod289Vec4 } from '../math/mod289'
|
|
3
|
+
import { permuteVec4 } from '../math/permute'
|
|
4
|
+
import { taylorInvSqrt } from '../math/taylorInvSqrt'
|
|
5
|
+
import { quintic } from '../math/quintic'
|
|
6
|
+
|
|
7
|
+
export const cnoiseVec2 = Fn(([P]: [Vec2]): Float => {
|
|
8
|
+
const Pi = P.xyxy.floor().add(vec4(0, 0, 1, 1)).toVar('Pi')
|
|
9
|
+
const Pf = P.xyxy.fract().sub(vec4(0, 0, 1, 1)).toVar('Pf')
|
|
10
|
+
Pi.assign(mod289Vec4(Pi))
|
|
11
|
+
const ix = Pi.xzxz.toVar('ix')
|
|
12
|
+
const iy = Pi.yyww.toVar('iy')
|
|
13
|
+
const fx = Pf.xzxz.toVar('fx')
|
|
14
|
+
const fy = Pf.yyww.toVar('fy')
|
|
15
|
+
const i = permuteVec4(permuteVec4(ix).add(iy)).toVar('i')
|
|
16
|
+
const gx = i.div(41).fract().mul(2).sub(1).toVar('gx')
|
|
17
|
+
const gy = gx.abs().sub(0.5).toVar('gy')
|
|
18
|
+
const tx = gx.add(0.5).floor().toVar('tx')
|
|
19
|
+
gx.assign(gx.sub(tx))
|
|
20
|
+
const g00 = vec2(gx.x, gy.x).toVar('g00')
|
|
21
|
+
const g10 = vec2(gx.y, gy.y).toVar('g10')
|
|
22
|
+
const g01 = vec2(gx.z, gy.z).toVar('g01')
|
|
23
|
+
const g11 = vec2(gx.w, gy.w).toVar('g11')
|
|
24
|
+
const norm = taylorInvSqrt(vec4(g00.dot(g00), g01.dot(g01), g10.dot(g10), g11.dot(g11))).toVar('norm')
|
|
25
|
+
g00.mulAssign(norm.x)
|
|
26
|
+
g01.mulAssign(norm.y)
|
|
27
|
+
g10.mulAssign(norm.z)
|
|
28
|
+
g11.mulAssign(norm.w)
|
|
29
|
+
const n00 = g00.dot(vec2(fx.x, fy.x)).toVar('n00')
|
|
30
|
+
const n10 = g10.dot(vec2(fx.y, fy.y)).toVar('n10')
|
|
31
|
+
const n01 = g01.dot(vec2(fx.z, fy.z)).toVar('n01')
|
|
32
|
+
const n11 = g11.dot(vec2(fx.w, fy.w)).toVar('n11')
|
|
33
|
+
const fade_xy = quintic(Pf.xy).toVar('fade_xy')
|
|
34
|
+
const n_x = vec2(n00, n01).mix(vec2(n10, n11), fade_xy.x).toVar('n_x')
|
|
35
|
+
const n_xy = n_x.x.mix(n_x.y, fade_xy.y)
|
|
36
|
+
return n_xy.mul(2.3)
|
|
37
|
+
}).setLayout({
|
|
38
|
+
name: 'cnoiseVec2',
|
|
39
|
+
type: 'float',
|
|
40
|
+
inputs: [{ name: 'P', type: 'vec2' }],
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
export const cnoiseVec3 = Fn(([P]: [Vec3]): Float => {
|
|
44
|
+
const Pi0 = P.floor().toVar('Pi0')
|
|
45
|
+
const Pi1 = Pi0.add(vec3(1)).toVar('Pi1')
|
|
46
|
+
Pi0.assign(mod289Vec3(Pi0))
|
|
47
|
+
Pi1.assign(mod289Vec3(Pi1))
|
|
48
|
+
const Pf0 = P.fract().toVar('Pf0')
|
|
49
|
+
const Pf1 = Pf0.sub(vec3(1)).toVar('Pf1')
|
|
50
|
+
const ix = vec4(Pi0.x, Pi1.x, Pi0.x, Pi1.x).toVar('ix')
|
|
51
|
+
const iy = vec4(Pi0.yy, Pi1.yy).toVar('iy')
|
|
52
|
+
const iz0 = Pi0.zzzz.toVar('iz0')
|
|
53
|
+
const iz1 = Pi1.zzzz.toVar('iz1')
|
|
54
|
+
const ixy = permuteVec4(permuteVec4(ix).add(iy)).toVar('ixy')
|
|
55
|
+
const ixy0 = permuteVec4(ixy.add(iz0)).toVar('ixy0')
|
|
56
|
+
const ixy1 = permuteVec4(ixy.add(iz1)).toVar('ixy1')
|
|
57
|
+
const gx0 = ixy0.div(7).toVar('gx0')
|
|
58
|
+
const gy0 = gx0.floor().div(7).fract().sub(0.5).toVar('gy0')
|
|
59
|
+
gx0.assign(gx0.fract())
|
|
60
|
+
const gz0 = vec4(0.5).sub(gx0.abs()).sub(gy0.abs()).toVar('gz0')
|
|
61
|
+
const sz0 = gz0.step(vec4(0)).toVar('sz0')
|
|
62
|
+
gx0.subAssign(sz0.mul(gx0.step(vec4(0)).sub(0.5)))
|
|
63
|
+
gy0.subAssign(sz0.mul(gy0.step(vec4(0)).sub(0.5)))
|
|
64
|
+
const gx1 = ixy1.div(7).toVar('gx1')
|
|
65
|
+
const gy1 = gx1.floor().div(7).fract().sub(0.5).toVar('gy1')
|
|
66
|
+
gx1.assign(gx1.fract())
|
|
67
|
+
const gz1 = vec4(0.5).sub(gx1.abs()).sub(gy1.abs()).toVar('gz1')
|
|
68
|
+
const sz1 = gz1.step(vec4(0)).toVar('sz1')
|
|
69
|
+
gx1.subAssign(sz1.mul(gx1.step(vec4(0)).sub(0.5)))
|
|
70
|
+
gy1.subAssign(sz1.mul(gy1.step(vec4(0)).sub(0.5)))
|
|
71
|
+
const g000 = vec3(gx0.x, gy0.x, gz0.x).toVar('g000')
|
|
72
|
+
const g100 = vec3(gx0.y, gy0.y, gz0.y).toVar('g100')
|
|
73
|
+
const g010 = vec3(gx0.z, gy0.z, gz0.z).toVar('g010')
|
|
74
|
+
const g110 = vec3(gx0.w, gy0.w, gz0.w).toVar('g110')
|
|
75
|
+
const g001 = vec3(gx1.x, gy1.x, gz1.x).toVar('g001')
|
|
76
|
+
const g101 = vec3(gx1.y, gy1.y, gz1.y).toVar('g101')
|
|
77
|
+
const g011 = vec3(gx1.z, gy1.z, gz1.z).toVar('g011')
|
|
78
|
+
const g111 = vec3(gx1.w, gy1.w, gz1.w).toVar('g111')
|
|
79
|
+
const norm0 = taylorInvSqrt(vec4(g000.dot(g000), g010.dot(g010), g100.dot(g100), g110.dot(g110))).toVar('norm0')
|
|
80
|
+
g000.mulAssign(norm0.x)
|
|
81
|
+
g010.mulAssign(norm0.y)
|
|
82
|
+
g100.mulAssign(norm0.z)
|
|
83
|
+
g110.mulAssign(norm0.w)
|
|
84
|
+
const norm1 = taylorInvSqrt(vec4(g001.dot(g001), g011.dot(g011), g101.dot(g101), g111.dot(g111))).toVar('norm1')
|
|
85
|
+
g001.mulAssign(norm1.x)
|
|
86
|
+
g011.mulAssign(norm1.y)
|
|
87
|
+
g101.mulAssign(norm1.z)
|
|
88
|
+
g111.mulAssign(norm1.w)
|
|
89
|
+
const n000 = g000.dot(Pf0).toVar('n000')
|
|
90
|
+
const n100 = g100.dot(vec3(Pf1.x, Pf0.yz)).toVar('n100')
|
|
91
|
+
const n010 = g010.dot(vec3(Pf0.x, Pf1.y, Pf0.z)).toVar('n010')
|
|
92
|
+
const n110 = g110.dot(vec3(Pf1.xy, Pf0.z)).toVar('n110')
|
|
93
|
+
const n001 = g001.dot(vec3(Pf0.xy, Pf1.z)).toVar('n001')
|
|
94
|
+
const n101 = g101.dot(vec3(Pf1.x, Pf0.y, Pf1.z)).toVar('n101')
|
|
95
|
+
const n011 = g011.dot(vec3(Pf0.x, Pf1.yz)).toVar('n011')
|
|
96
|
+
const n111 = g111.dot(Pf1).toVar('n111')
|
|
97
|
+
const fade_xyz = quintic(Pf0).toVar('fade_xyz')
|
|
98
|
+
const n_z = vec4(n000, n100, n010, n110).mix(vec4(n001, n101, n011, n111), fade_xyz.z).toVar('n_z')
|
|
99
|
+
const n_yz = n_z.xy.mix(n_z.zw, fade_xyz.y).toVar('n_yz')
|
|
100
|
+
const n_xyz = n_yz.x.mix(n_yz.y, fade_xyz.x)
|
|
101
|
+
return n_xyz.mul(2.2)
|
|
102
|
+
}).setLayout({
|
|
103
|
+
name: 'cnoiseVec3',
|
|
104
|
+
type: 'float',
|
|
105
|
+
inputs: [{ name: 'P', type: 'vec3' }],
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
export const cnoiseVec4 = Fn(([P]: [Vec4]): Float => {
|
|
109
|
+
const Pi0 = P.floor().toVar('Pi0')
|
|
110
|
+
const Pi1 = Pi0.add(1).toVar('Pi1')
|
|
111
|
+
Pi0.assign(mod289Vec4(Pi0))
|
|
112
|
+
Pi1.assign(mod289Vec4(Pi1))
|
|
113
|
+
const Pf0 = P.fract().toVar('Pf0')
|
|
114
|
+
const Pf1 = Pf0.sub(1).toVar('Pf1')
|
|
115
|
+
const ix = vec4(Pi0.x, Pi1.x, Pi0.x, Pi1.x).toVar('ix')
|
|
116
|
+
const iy = vec4(Pi0.yy, Pi1.yy).toVar('iy')
|
|
117
|
+
const iz0 = vec4(Pi0.zzzz).toVar('iz0')
|
|
118
|
+
const iz1 = vec4(Pi1.zzzz).toVar('iz1')
|
|
119
|
+
const iw0 = vec4(Pi0.wwww).toVar('iw0')
|
|
120
|
+
const iw1 = vec4(Pi1.wwww).toVar('iw1')
|
|
121
|
+
const ixy = permuteVec4(permuteVec4(ix).add(iy)).toVar('ixy')
|
|
122
|
+
const ixy0 = permuteVec4(ixy.add(iz0)).toVar('ixy0')
|
|
123
|
+
const ixy1 = permuteVec4(ixy.add(iz1)).toVar('ixy1')
|
|
124
|
+
const ixy00 = permuteVec4(ixy0.add(iw0)).toVar('ixy00')
|
|
125
|
+
const ixy01 = permuteVec4(ixy0.add(iw1)).toVar('ixy01')
|
|
126
|
+
const ixy10 = permuteVec4(ixy1.add(iw0)).toVar('ixy10')
|
|
127
|
+
const ixy11 = permuteVec4(ixy1.add(iw1)).toVar('ixy11')
|
|
128
|
+
const gx00 = ixy00.div(7).toVar('gx00')
|
|
129
|
+
const gy00 = gx00.floor().div(7).toVar('gy00')
|
|
130
|
+
const gz00 = gy00.floor().div(6).toVar('gz00')
|
|
131
|
+
gx00.assign(gx00.fract().sub(0.5))
|
|
132
|
+
gy00.assign(gy00.fract().sub(0.5))
|
|
133
|
+
gz00.assign(gz00.fract().sub(0.5))
|
|
134
|
+
const gw00 = vec4(0.75).sub(gx00.abs()).sub(gy00.abs()).sub(gz00.abs()).toVar('gw00')
|
|
135
|
+
const sw00 = gw00.step(vec4(0)).toVar('sw00')
|
|
136
|
+
gx00.subAssign(sw00.mul(gx00.step(vec4(0)).sub(0.5)))
|
|
137
|
+
gy00.subAssign(sw00.mul(gy00.step(vec4(0)).sub(0.5)))
|
|
138
|
+
const gx01 = ixy01.div(7).toVar('gx01')
|
|
139
|
+
const gy01 = gx01.floor().div(7).toVar('gy01')
|
|
140
|
+
const gz01 = gy01.floor().div(6).toVar('gz01')
|
|
141
|
+
gx01.assign(gx01.fract().sub(0.5))
|
|
142
|
+
gy01.assign(gy01.fract().sub(0.5))
|
|
143
|
+
gz01.assign(gz01.fract().sub(0.5))
|
|
144
|
+
const gw01 = vec4(0.75).sub(gx01.abs()).sub(gy01.abs()).sub(gz01.abs()).toVar('gw01')
|
|
145
|
+
const sw01 = gw01.step(vec4(0)).toVar('sw01')
|
|
146
|
+
gx01.subAssign(sw01.mul(gx01.step(vec4(0)).sub(0.5)))
|
|
147
|
+
gy01.subAssign(sw01.mul(gy01.step(vec4(0)).sub(0.5)))
|
|
148
|
+
const gx10 = ixy10.div(7).toVar('gx10')
|
|
149
|
+
const gy10 = gx10.floor().div(7).toVar('gy10')
|
|
150
|
+
const gz10 = gy10.floor().div(6).toVar('gz10')
|
|
151
|
+
gx10.assign(gx10.fract().sub(0.5))
|
|
152
|
+
gy10.assign(gy10.fract().sub(0.5))
|
|
153
|
+
gz10.assign(gz10.fract().sub(0.5))
|
|
154
|
+
const gw10 = vec4(0.75).sub(gx10.abs()).sub(gy10.abs()).sub(gz10.abs()).toVar('gw10')
|
|
155
|
+
const sw10 = gw10.step(vec4(0)).toVar('sw10')
|
|
156
|
+
gx10.subAssign(sw10.mul(gx10.step(vec4(0)).sub(0.5)))
|
|
157
|
+
gy10.subAssign(sw10.mul(gy10.step(vec4(0)).sub(0.5)))
|
|
158
|
+
const gx11 = ixy11.div(7).toVar('gx11')
|
|
159
|
+
const gy11 = gx11.floor().div(7).toVar('gy11')
|
|
160
|
+
const gz11 = gy11.floor().div(6).toVar('gz11')
|
|
161
|
+
gx11.assign(gx11.fract().sub(0.5))
|
|
162
|
+
gy11.assign(gy11.fract().sub(0.5))
|
|
163
|
+
gz11.assign(gz11.fract().sub(0.5))
|
|
164
|
+
const gw11 = vec4(0.75).sub(gx11.abs()).sub(gy11.abs()).sub(gz11.abs()).toVar('gw11')
|
|
165
|
+
const sw11 = gw11.step(vec4(0)).toVar('sw11')
|
|
166
|
+
gx11.subAssign(sw11.mul(gx11.step(vec4(0)).sub(0.5)))
|
|
167
|
+
gy11.subAssign(sw11.mul(gy11.step(vec4(0)).sub(0.5)))
|
|
168
|
+
const g0000 = vec4(gx00.x, gy00.x, gz00.x, gw00.x).toVar('g0000')
|
|
169
|
+
const g1000 = vec4(gx00.y, gy00.y, gz00.y, gw00.y).toVar('g1000')
|
|
170
|
+
const g0100 = vec4(gx00.z, gy00.z, gz00.z, gw00.z).toVar('g0100')
|
|
171
|
+
const g1100 = vec4(gx00.w, gy00.w, gz00.w, gw00.w).toVar('g1100')
|
|
172
|
+
const g0010 = vec4(gx10.x, gy10.x, gz10.x, gw10.x).toVar('g0010')
|
|
173
|
+
const g1010 = vec4(gx10.y, gy10.y, gz10.y, gw10.y).toVar('g1010')
|
|
174
|
+
const g0110 = vec4(gx10.z, gy10.z, gz10.z, gw10.z).toVar('g0110')
|
|
175
|
+
const g1110 = vec4(gx10.w, gy10.w, gz10.w, gw10.w).toVar('g1110')
|
|
176
|
+
const g0001 = vec4(gx01.x, gy01.x, gz01.x, gw01.x).toVar('g0001')
|
|
177
|
+
const g1001 = vec4(gx01.y, gy01.y, gz01.y, gw01.y).toVar('g1001')
|
|
178
|
+
const g0101 = vec4(gx01.z, gy01.z, gz01.z, gw01.z).toVar('g0101')
|
|
179
|
+
const g1101 = vec4(gx01.w, gy01.w, gz01.w, gw01.w).toVar('g1101')
|
|
180
|
+
const g0011 = vec4(gx11.x, gy11.x, gz11.x, gw11.x).toVar('g0011')
|
|
181
|
+
const g1011 = vec4(gx11.y, gy11.y, gz11.y, gw11.y).toVar('g1011')
|
|
182
|
+
const g0111 = vec4(gx11.z, gy11.z, gz11.z, gw11.z).toVar('g0111')
|
|
183
|
+
const g1111 = vec4(gx11.w, gy11.w, gz11.w, gw11.w).toVar('g1111')
|
|
184
|
+
const norm00 = taylorInvSqrt(
|
|
185
|
+
vec4(g0000.dot(g0000), g0100.dot(g0100), g1000.dot(g1000), g1100.dot(g1100))
|
|
186
|
+
).toVar('norm00')
|
|
187
|
+
g0000.mulAssign(norm00.x)
|
|
188
|
+
g0100.mulAssign(norm00.y)
|
|
189
|
+
g1000.mulAssign(norm00.z)
|
|
190
|
+
g1100.mulAssign(norm00.w)
|
|
191
|
+
const norm01 = taylorInvSqrt(
|
|
192
|
+
vec4(g0001.dot(g0001), g0101.dot(g0101), g1001.dot(g1001), g1101.dot(g1101))
|
|
193
|
+
).toVar('norm01')
|
|
194
|
+
g0001.mulAssign(norm01.x)
|
|
195
|
+
g0101.mulAssign(norm01.y)
|
|
196
|
+
g1001.mulAssign(norm01.z)
|
|
197
|
+
g1101.mulAssign(norm01.w)
|
|
198
|
+
const norm10 = taylorInvSqrt(
|
|
199
|
+
vec4(g0010.dot(g0010), g0110.dot(g0110), g1010.dot(g1010), g1110.dot(g1110))
|
|
200
|
+
).toVar('norm10')
|
|
201
|
+
g0010.mulAssign(norm10.x)
|
|
202
|
+
g0110.mulAssign(norm10.y)
|
|
203
|
+
g1010.mulAssign(norm10.z)
|
|
204
|
+
g1110.mulAssign(norm10.w)
|
|
205
|
+
const norm11 = taylorInvSqrt(
|
|
206
|
+
vec4(g0011.dot(g0011), g0111.dot(g0111), g1011.dot(g1011), g1111.dot(g1111))
|
|
207
|
+
).toVar('norm11')
|
|
208
|
+
g0011.mulAssign(norm11.x)
|
|
209
|
+
g0111.mulAssign(norm11.y)
|
|
210
|
+
g1011.mulAssign(norm11.z)
|
|
211
|
+
g1111.mulAssign(norm11.w)
|
|
212
|
+
const n0000 = g0000.dot(Pf0).toVar('n0000')
|
|
213
|
+
const n1000 = g1000.dot(vec4(Pf1.x, Pf0.yzw)).toVar('n1000')
|
|
214
|
+
const n0100 = g0100.dot(vec4(Pf0.x, Pf1.y, Pf0.zw)).toVar('n0100')
|
|
215
|
+
const n1100 = g1100.dot(vec4(Pf1.xy, Pf0.zw)).toVar('n1100')
|
|
216
|
+
const n0010 = g0010.dot(vec4(Pf0.xy, Pf1.z, Pf0.w)).toVar('n0010')
|
|
217
|
+
const n1010 = g1010.dot(vec4(Pf1.x, Pf0.y, Pf1.z, Pf0.w)).toVar('n1010')
|
|
218
|
+
const n0110 = g0110.dot(vec4(Pf0.x, Pf1.yz, Pf0.w)).toVar('n0110')
|
|
219
|
+
const n1110 = g1110.dot(vec4(Pf1.xyz, Pf0.w)).toVar('n1110')
|
|
220
|
+
const n0001 = g0001.dot(vec4(Pf0.xyz, Pf1.w)).toVar('n0001')
|
|
221
|
+
const n1001 = g1001.dot(vec4(Pf1.x, Pf0.yz, Pf1.w)).toVar('n1001')
|
|
222
|
+
const n0101 = g0101.dot(vec4(Pf0.x, Pf1.y, Pf0.z, Pf1.w)).toVar('n0101')
|
|
223
|
+
const n1101 = g1101.dot(vec4(Pf1.xy, Pf0.z, Pf1.w)).toVar('n1101')
|
|
224
|
+
const n0011 = g0011.dot(vec4(Pf0.xy, Pf1.zw)).toVar('n0011')
|
|
225
|
+
const n1011 = g1011.dot(vec4(Pf1.x, Pf0.y, Pf1.zw)).toVar('n1011')
|
|
226
|
+
const n0111 = g0111.dot(vec4(Pf0.x, Pf1.yzw)).toVar('n0111')
|
|
227
|
+
const n1111 = g1111.dot(Pf1).toVar('n1111')
|
|
228
|
+
const fade_xyzw = quintic(Pf0).toVar('fade_xyzw')
|
|
229
|
+
const n_0w = vec4(n0000, n1000, n0100, n1100).mix(vec4(n0001, n1001, n0101, n1101), fade_xyzw.w).toVar('n_0w')
|
|
230
|
+
const n_1w = vec4(n0010, n1010, n0110, n1110).mix(vec4(n0011, n1011, n0111, n1111), fade_xyzw.w).toVar('n_1w')
|
|
231
|
+
const n_zw = n_0w.mix(n_1w, fade_xyzw.z).toVar('n_zw')
|
|
232
|
+
const n_yzw = n_zw.xy.mix(n_zw.zw, fade_xyzw.y).toVar('n_yzw')
|
|
233
|
+
const n_xyzw = n_yzw.x.mix(n_yzw.y, fade_xyzw.x)
|
|
234
|
+
return n_xyzw.mul(2.2)
|
|
235
|
+
}).setLayout({
|
|
236
|
+
name: 'cnoiseVec4',
|
|
237
|
+
type: 'float',
|
|
238
|
+
inputs: [{ name: 'P', type: 'vec4' }],
|
|
239
|
+
})
|