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,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
|
+
})
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Fn, Vec2, Float, mat2, atan2, cos, sin, mod, vec2, float } from '../../node'
|
|
2
|
+
|
|
3
|
+
const PI = float(3.1415926535897932384626433832795)
|
|
4
|
+
const TWO_PI = float(6.283185307179586476925286766559)
|
|
5
|
+
const BRACKETING_ANGLE_DELTA = PI.div(20.0)
|
|
6
|
+
|
|
7
|
+
export const bracketingAxis0 = Fn(([dir]: [Vec2]): Vec2 => {
|
|
8
|
+
const angle = atan2(dir.y, dir.x).add(TWO_PI)
|
|
9
|
+
const fractional = mod(angle, BRACKETING_ANGLE_DELTA)
|
|
10
|
+
const angle0 = angle.sub(fractional)
|
|
11
|
+
return vec2(cos(angle0), sin(angle0))
|
|
12
|
+
}).setLayout({
|
|
13
|
+
name: 'bracketingAxis0',
|
|
14
|
+
type: 'vec2',
|
|
15
|
+
inputs: [{ name: 'dir', type: 'vec2' }],
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
export const bracketingAxis1 = Fn(([dir]: [Vec2]): Vec2 => {
|
|
19
|
+
const angle = atan2(dir.y, dir.x).add(TWO_PI)
|
|
20
|
+
const fractional = mod(angle, BRACKETING_ANGLE_DELTA)
|
|
21
|
+
const angle0 = angle.sub(fractional)
|
|
22
|
+
const vAxis0 = vec2(cos(angle0), sin(angle0))
|
|
23
|
+
const RotateByAngleDelta = mat2(
|
|
24
|
+
cos(BRACKETING_ANGLE_DELTA),
|
|
25
|
+
sin(BRACKETING_ANGLE_DELTA),
|
|
26
|
+
sin(BRACKETING_ANGLE_DELTA).negate(),
|
|
27
|
+
cos(BRACKETING_ANGLE_DELTA)
|
|
28
|
+
)
|
|
29
|
+
return RotateByAngleDelta.mul(vAxis0)
|
|
30
|
+
}).setLayout({
|
|
31
|
+
name: 'bracketingAxis1',
|
|
32
|
+
type: 'vec2',
|
|
33
|
+
inputs: [{ name: 'dir', type: 'vec2' }],
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
export const bracketingBlend = Fn(([dir]: [Vec2]): Float => {
|
|
37
|
+
const angle = atan2(dir.y, dir.x).add(TWO_PI)
|
|
38
|
+
const fractional = mod(angle, BRACKETING_ANGLE_DELTA)
|
|
39
|
+
return fractional.div(BRACKETING_ANGLE_DELTA)
|
|
40
|
+
}).setLayout({
|
|
41
|
+
name: 'bracketingBlend',
|
|
42
|
+
type: 'float',
|
|
43
|
+
inputs: [{ name: 'dir', type: 'vec2' }],
|
|
44
|
+
})
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Fn, Vec2, Vec4, Float, mod, floor, fract } from '../../node'
|
|
2
|
+
import { sqTile } from './sqTile'
|
|
3
|
+
|
|
4
|
+
export const brickTile = Fn(([t]: [Vec4]): Vec4 => {
|
|
5
|
+
const result = t.toVar('result')
|
|
6
|
+
result.x.assign(result.x.add(mod(result.w, 2).mul(0.5)))
|
|
7
|
+
result.z.assign(floor(result.z.add(result.x)))
|
|
8
|
+
result.x.assign(fract(result.x))
|
|
9
|
+
return result
|
|
10
|
+
}).setLayout({
|
|
11
|
+
name: 'brickTile',
|
|
12
|
+
type: 'vec4',
|
|
13
|
+
inputs: [{ name: 't', type: 'vec4' }],
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
export const brickTileVec2 = Fn(([st]: [Vec2]): Vec4 => {
|
|
17
|
+
return brickTile(sqTile(st))
|
|
18
|
+
}).setLayout({
|
|
19
|
+
name: 'brickTileVec2',
|
|
20
|
+
type: 'vec4',
|
|
21
|
+
inputs: [{ name: 'st', type: 'vec2' }],
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
export const brickTileFloat = Fn(([st, s]: [Vec2, Float]): Vec4 => {
|
|
25
|
+
return brickTileVec2(st.mul(s))
|
|
26
|
+
}).setLayout({
|
|
27
|
+
name: 'brickTileFloat',
|
|
28
|
+
type: 'vec4',
|
|
29
|
+
inputs: [
|
|
30
|
+
{ name: 'st', type: 'vec2' },
|
|
31
|
+
{ name: 's', type: 'float' },
|
|
32
|
+
],
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
export const brickTileVec2Scale = Fn(([st, s]: [Vec2, Vec2]): Vec4 => {
|
|
36
|
+
return brickTileVec2(st.mul(s))
|
|
37
|
+
}).setLayout({
|
|
38
|
+
name: 'brickTileVec2Scale',
|
|
39
|
+
type: 'vec4',
|
|
40
|
+
inputs: [
|
|
41
|
+
{ name: 'st', type: 'vec2' },
|
|
42
|
+
{ name: 's', type: 'vec2' },
|
|
43
|
+
],
|
|
44
|
+
})
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Fn, Vec2, Vec3, atan2, length, acos, vec2, vec3 } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const cart2polar = Fn(([st]: [Vec2]): Vec2 => {
|
|
4
|
+
return vec2(atan2(st.y, st.x), length(st))
|
|
5
|
+
}).setLayout({
|
|
6
|
+
name: 'cart2polar',
|
|
7
|
+
type: 'vec2',
|
|
8
|
+
inputs: [{ name: 'st', type: 'vec2' }],
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
export const cart2polar3D = Fn(([st]: [Vec3]): Vec3 => {
|
|
12
|
+
const r = length(st).toVar('r')
|
|
13
|
+
const phi = acos(st.z.div(r)).toVar('phi')
|
|
14
|
+
const theta = atan2(st.y, st.x).toVar('theta')
|
|
15
|
+
return vec3(r, phi, theta)
|
|
16
|
+
}).setLayout({
|
|
17
|
+
name: 'cart2polar3D',
|
|
18
|
+
type: 'vec3',
|
|
19
|
+
inputs: [{ name: 'st', type: 'vec3' }],
|
|
20
|
+
})
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Fn, Float, Vec2, Vec3 } from '../../node'
|
|
2
|
+
|
|
3
|
+
function center(x: Float): Float
|
|
4
|
+
function center(v: Vec2): Vec2
|
|
5
|
+
function center(v: Vec3): Vec3
|
|
6
|
+
function center(v: any): any {
|
|
7
|
+
return v.mul(2).sub(1)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const centerFloat = Fn(([x]: [Float]): Float => {
|
|
11
|
+
return center(x)
|
|
12
|
+
}).setLayout({
|
|
13
|
+
name: 'centerFloat',
|
|
14
|
+
type: 'float',
|
|
15
|
+
inputs: [{ name: 'x', type: 'float' }],
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
export const centerVec2 = Fn(([v]: [Vec2]): Vec2 => {
|
|
19
|
+
return center(v)
|
|
20
|
+
}).setLayout({
|
|
21
|
+
name: 'centerVec2',
|
|
22
|
+
type: 'vec2',
|
|
23
|
+
inputs: [{ name: 'v', type: 'vec2' }],
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
export const centerVec3 = Fn(([v]: [Vec3]): Vec3 => {
|
|
27
|
+
return center(v)
|
|
28
|
+
}).setLayout({
|
|
29
|
+
name: 'centerVec3',
|
|
30
|
+
type: 'vec3',
|
|
31
|
+
inputs: [{ name: 'v', type: 'vec3' }],
|
|
32
|
+
})
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Fn, Vec2, Vec4, Float, mod, abs } from '../../node'
|
|
2
|
+
import { sqTile } from './sqTile'
|
|
3
|
+
|
|
4
|
+
export const checkerTile = Fn(([t]: [Vec4]): Float => {
|
|
5
|
+
const c = mod(t.zw, 2).toVar('c')
|
|
6
|
+
return abs(c.x.sub(c.y))
|
|
7
|
+
}).setLayout({
|
|
8
|
+
name: 'checkerTile',
|
|
9
|
+
type: 'float',
|
|
10
|
+
inputs: [{ name: 't', type: 'vec4' }],
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
export const checkerTileVec2 = Fn(([v]: [Vec2]): Float => {
|
|
14
|
+
return checkerTile(sqTile(v))
|
|
15
|
+
}).setLayout({
|
|
16
|
+
name: 'checkerTileVec2',
|
|
17
|
+
type: 'float',
|
|
18
|
+
inputs: [{ name: 'v', type: 'vec2' }],
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
export const checkerTileFloat = Fn(([v, s]: [Vec2, Float]): Float => {
|
|
22
|
+
return checkerTileVec2(v.mul(s))
|
|
23
|
+
}).setLayout({
|
|
24
|
+
name: 'checkerTileFloat',
|
|
25
|
+
type: 'float',
|
|
26
|
+
inputs: [
|
|
27
|
+
{ name: 'v', type: 'vec2' },
|
|
28
|
+
{ name: 's', type: 'float' },
|
|
29
|
+
],
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
export const checkerTileVec2Scale = Fn(([v, s]: [Vec2, Vec2]): Float => {
|
|
33
|
+
return checkerTileVec2(v.mul(s))
|
|
34
|
+
}).setLayout({
|
|
35
|
+
name: 'checkerTileVec2Scale',
|
|
36
|
+
type: 'float',
|
|
37
|
+
inputs: [
|
|
38
|
+
{ name: 'v', type: 'vec2' },
|
|
39
|
+
{ name: 's', type: 'vec2' },
|
|
40
|
+
],
|
|
41
|
+
})
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Fn, Float, select } from '../../node'
|
|
2
|
+
|
|
3
|
+
// Perspective projection version
|
|
4
|
+
export const depth2viewZ = Fn(([depth, near, far]: [Float, Float, Float]): Float => {
|
|
5
|
+
return near.mul(far).div(far.sub(near).mul(depth).sub(far))
|
|
6
|
+
}).setLayout({
|
|
7
|
+
name: 'depth2viewZ',
|
|
8
|
+
type: 'float',
|
|
9
|
+
inputs: [
|
|
10
|
+
{ name: 'depth', type: 'float' },
|
|
11
|
+
{ name: 'near', type: 'float' },
|
|
12
|
+
{ name: 'far', type: 'float' },
|
|
13
|
+
],
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
// Orthographic projection version
|
|
17
|
+
export const depth2viewZOrthographic = Fn(([depth, near, far]: [Float, Float, Float]): Float => {
|
|
18
|
+
return depth.mul(near.sub(far)).sub(near)
|
|
19
|
+
}).setLayout({
|
|
20
|
+
name: 'depth2viewZOrthographic',
|
|
21
|
+
type: 'float',
|
|
22
|
+
inputs: [
|
|
23
|
+
{ name: 'depth', type: 'float' },
|
|
24
|
+
{ name: 'near', type: 'float' },
|
|
25
|
+
{ name: 'far', type: 'float' },
|
|
26
|
+
],
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
// Combined version with orthographic flag
|
|
30
|
+
export const depth2viewZCombined = Fn(([depth, near, far, orthographic]: [Float, Float, Float, Float]): Float => {
|
|
31
|
+
const perspective = near.mul(far).div(far.sub(near).mul(depth).sub(far))
|
|
32
|
+
const ortho = depth.mul(near.sub(far)).sub(near)
|
|
33
|
+
return select(ortho, perspective, orthographic.greaterThan(0.5))
|
|
34
|
+
}).setLayout({
|
|
35
|
+
name: 'depth2viewZCombined',
|
|
36
|
+
type: 'float',
|
|
37
|
+
inputs: [
|
|
38
|
+
{ name: 'depth', type: 'float' },
|
|
39
|
+
{ name: 'near', type: 'float' },
|
|
40
|
+
{ name: 'far', type: 'float' },
|
|
41
|
+
{ name: 'orthographic', type: 'float' },
|
|
42
|
+
],
|
|
43
|
+
})
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Fn, Vec3, Vec2, X, texture, float, vec3, int, Loop, If } from '../../node'
|
|
2
|
+
import { lookAtBasic } from './lookAt'
|
|
3
|
+
|
|
4
|
+
const DISPLACE_DEPTH = float(1).constant('DISPLACE_DEPTH')
|
|
5
|
+
const DISPLACE_PRECISION = float(0.01).constant('DISPLACE_PRECISION')
|
|
6
|
+
const DISPLACE_MAX_ITERATIONS = int(120).constant('DISPLACE_MAX_ITERATIONS')
|
|
7
|
+
|
|
8
|
+
export const displace = Fn(([tex, ro, rd]: [X, Vec3, Vec3]): Vec3 => {
|
|
9
|
+
const dz = ro.z.sub(DISPLACE_DEPTH).toVar('dz')
|
|
10
|
+
const t = dz.div(rd.z).toVar('t')
|
|
11
|
+
const prev = vec3(ro.x.sub(rd.x.mul(t)), ro.y.sub(rd.y.mul(t)), ro.z.sub(rd.z.mul(t))).toVar('prev')
|
|
12
|
+
const curr = prev.toVar('curr')
|
|
13
|
+
const lastD = prev.z.toVar('lastD')
|
|
14
|
+
const hmap = float(0).toVar('hmap')
|
|
15
|
+
const df = float(0).toVar('df')
|
|
16
|
+
|
|
17
|
+
Loop(DISPLACE_MAX_ITERATIONS, () => {
|
|
18
|
+
prev.assign(curr)
|
|
19
|
+
curr.assign(prev.add(rd.mul(DISPLACE_PRECISION)))
|
|
20
|
+
hmap.assign(texture(tex, curr.xy.sub(0.5)).r)
|
|
21
|
+
df.assign(curr.z.sub(hmap.mul(DISPLACE_DEPTH)))
|
|
22
|
+
|
|
23
|
+
If(df.lessThan(0), () => {
|
|
24
|
+
const t = lastD.div(df.abs().add(lastD)).toVar('t')
|
|
25
|
+
return prev.add(t.mul(curr.sub(prev))).add(vec3(0.5, 0.5, 0))
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
lastD.assign(df)
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
return vec3(0, 0, 1)
|
|
32
|
+
}).setLayout({
|
|
33
|
+
name: 'displace',
|
|
34
|
+
type: 'vec3',
|
|
35
|
+
inputs: [
|
|
36
|
+
{ name: 'tex', type: 'sampler2D' },
|
|
37
|
+
{ name: 'ro', type: 'vec3' },
|
|
38
|
+
{ name: 'rd', type: 'vec3' },
|
|
39
|
+
],
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
export const displaceUV = Fn(([tex, ro, uv]: [X, Vec3, Vec2]): Vec3 => {
|
|
43
|
+
const rd = lookAtBasic(ro.negate())
|
|
44
|
+
.mul(vec3(uv.sub(float(0.5)), 1).normalize())
|
|
45
|
+
.toVar('rd')
|
|
46
|
+
return displace(tex, ro, rd)
|
|
47
|
+
}).setLayout({
|
|
48
|
+
name: 'displaceUV',
|
|
49
|
+
type: 'vec3',
|
|
50
|
+
inputs: [
|
|
51
|
+
{ name: 'tex', type: 'sampler2D' },
|
|
52
|
+
{ name: 'ro', type: 'vec3' },
|
|
53
|
+
{ name: 'uv', type: 'vec2' },
|
|
54
|
+
],
|
|
55
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Fn, Vec2, Vec3, vec3, cos, sin, sqrt, float } from '../../node'
|
|
2
|
+
import { PI, TWO_PI } from '../math/const'
|
|
3
|
+
|
|
4
|
+
export const equirect2xyz = Fn(([uv]: [Vec2]): Vec3 => {
|
|
5
|
+
const phi = PI.sub(uv.y.mul(PI)).toVar('phi')
|
|
6
|
+
const theta = uv.x.mul(TWO_PI).toVar('theta')
|
|
7
|
+
const dir = vec3(cos(theta), 0, sin(theta)).toVar('dir')
|
|
8
|
+
dir.y.assign(cos(phi))
|
|
9
|
+
const multiplier = sqrt(float(1).sub(dir.y.mul(dir.y))).toVar('multiplier')
|
|
10
|
+
dir.x.assign(dir.x.mul(multiplier))
|
|
11
|
+
dir.z.assign(dir.z.mul(multiplier))
|
|
12
|
+
return dir
|
|
13
|
+
}).setLayout({
|
|
14
|
+
name: 'equirect2xyz',
|
|
15
|
+
type: 'vec3',
|
|
16
|
+
inputs: [{ name: 'uv', type: 'vec2' }],
|
|
17
|
+
})
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Fn, Vec3, Mat4, mat3 } from '../../node'
|
|
2
|
+
import { rotate3dX, rotate3dY, rotate3dZ } from '../math'
|
|
3
|
+
import { translateMat3 } from './translate'
|
|
4
|
+
|
|
5
|
+
export const eulerView = Fn(([position, euler]: [Vec3, Vec3]): Mat4 => {
|
|
6
|
+
const rotZ = rotate3dZ(euler.z)
|
|
7
|
+
const rotX = rotate3dX(euler.x)
|
|
8
|
+
const rotY = rotate3dY(euler.y)
|
|
9
|
+
const identity = mat3(1).toVar('identity')
|
|
10
|
+
const rotation = rotY.mul(rotX).mul(rotZ).mul(identity).toVar('rotation')
|
|
11
|
+
return translateMat3(rotation, position)
|
|
12
|
+
}).setLayout({
|
|
13
|
+
name: 'eulerView',
|
|
14
|
+
type: 'mat4',
|
|
15
|
+
inputs: [
|
|
16
|
+
{ name: 'position', type: 'vec3' },
|
|
17
|
+
{ name: 'euler', type: 'vec3' },
|
|
18
|
+
],
|
|
19
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Fn, Vec2, Vec3, vec3, sqrt, cos, float } from '../../node'
|
|
2
|
+
import { PI } from '../math/const'
|
|
3
|
+
|
|
4
|
+
export const fisheye2xyz = Fn(([uv]: [Vec2]): Vec3 => {
|
|
5
|
+
const ndc = uv.mul(2).sub(1).toVar('ndc')
|
|
6
|
+
const R = sqrt(ndc.x.mul(ndc.x).add(ndc.y.mul(ndc.y))).toVar('R')
|
|
7
|
+
const dir = vec3(ndc.x.div(R), 0, ndc.y.div(R)).toVar('dir')
|
|
8
|
+
const phi = R.mul(PI).mul(0.52).toVar('phi')
|
|
9
|
+
dir.y.assign(cos(phi))
|
|
10
|
+
const multiplier = sqrt(float(1).sub(dir.y.mul(dir.y))).toVar('multiplier')
|
|
11
|
+
dir.x.assign(dir.x.mul(multiplier))
|
|
12
|
+
dir.z.assign(dir.z.mul(multiplier))
|
|
13
|
+
return dir
|
|
14
|
+
}).setLayout({
|
|
15
|
+
name: 'fisheye2xyz',
|
|
16
|
+
type: 'vec3',
|
|
17
|
+
inputs: [{ name: 'uv', type: 'vec2' }],
|
|
18
|
+
})
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Fn, Vec2, Vec3, Vec4, vec2, vec3, vec4 } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const flipYVec2 = Fn(([v]: [Vec2]): Vec2 => {
|
|
4
|
+
return vec2(v.x, v.y.oneMinus())
|
|
5
|
+
}).setLayout({
|
|
6
|
+
name: 'flipY',
|
|
7
|
+
type: 'vec2',
|
|
8
|
+
inputs: [{ name: 'v', type: 'vec2' }],
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
export const flipYVec3 = Fn(([v]: [Vec3]): Vec3 => {
|
|
12
|
+
return vec3(v.x, v.y.oneMinus(), v.z)
|
|
13
|
+
}).setLayout({
|
|
14
|
+
name: 'flipY',
|
|
15
|
+
type: 'vec3',
|
|
16
|
+
inputs: [{ name: 'v', type: 'vec3' }],
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
export const flipYVec4 = Fn(([v]: [Vec4]): Vec4 => {
|
|
20
|
+
return vec4(v.x, v.y.oneMinus(), v.z, v.w)
|
|
21
|
+
}).setLayout({
|
|
22
|
+
name: 'flipY',
|
|
23
|
+
type: 'vec4',
|
|
24
|
+
inputs: [{ name: 'v', type: 'vec4' }],
|
|
25
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Fn, Vec2, Vec4, vec2, vec4, float, floor, dot, select } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const hexTile = Fn(([st]: [Vec2]): Vec4 => {
|
|
4
|
+
const s = vec2(1, 1.7320508).toVar('s')
|
|
5
|
+
const o = vec2(0.5, 1).toVar('o')
|
|
6
|
+
const stYX = vec2(st.y, st.x).toVar('stYX')
|
|
7
|
+
const i = floor(vec4(stYX, stYX.sub(o)).div(vec4(s, s)))
|
|
8
|
+
.add(0.5)
|
|
9
|
+
.toVar('i')
|
|
10
|
+
const f = vec4(stYX.sub(i.xy.mul(s)), stYX.sub(i.zw.add(0.5).mul(s))).toVar('f')
|
|
11
|
+
const dotXY = dot(f.xy, f.xy)
|
|
12
|
+
const dotZW = dot(f.zw, f.zw)
|
|
13
|
+
return select(vec4(f.wz.add(float(0.5)), i.zw.add(o)), vec4(f.yx.add(float(0.5)), i.xy), dotXY.lessThan(dotZW))
|
|
14
|
+
}).setLayout({
|
|
15
|
+
name: 'hexTile',
|
|
16
|
+
type: 'vec4',
|
|
17
|
+
inputs: [{ name: 'st', type: 'vec2' }],
|
|
18
|
+
})
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export * from './aspect'
|
|
2
|
+
export * from './bracketing'
|
|
3
|
+
export * from './brickTile'
|
|
4
|
+
export * from './cart2polar'
|
|
5
|
+
export * from './center'
|
|
6
|
+
export * from './checkerTile'
|
|
7
|
+
export * from './depth2viewZ'
|
|
8
|
+
export * from './displace'
|
|
9
|
+
export * from './equirect2xyz'
|
|
10
|
+
export * from './eulerView'
|
|
11
|
+
export * from './fisheye2xyz'
|
|
12
|
+
export * from './flipY'
|
|
13
|
+
export * from './hexTile'
|
|
14
|
+
export * from './kaleidoscope'
|
|
15
|
+
export * from './linearizeDepth'
|
|
16
|
+
export * from './mirrorTile'
|
|
17
|
+
export * from './nearest'
|
|
18
|
+
export * from './orthographic'
|
|
19
|
+
export * from './parallaxMapping'
|
|
20
|
+
export * from './perspective'
|
|
21
|
+
export * from './lookAt'
|
|
22
|
+
export * from './polar2cart'
|
|
23
|
+
export * from './ratio'
|
|
24
|
+
export * from './sprite'
|
|
25
|
+
export * from './sqTile'
|
|
26
|
+
export * from './tbn'
|
|
27
|
+
export * from './translate'
|
|
28
|
+
export * from './lookAtView'
|
|
29
|
+
export * from './rotate'
|
|
30
|
+
export * from './rotateX'
|
|
31
|
+
export * from './rotateY'
|
|
32
|
+
export * from './rotateZ'
|
|
33
|
+
export * from './unratio'
|
|
34
|
+
export * from './uncenter'
|
|
35
|
+
export * from './viewZ2depth'
|
|
36
|
+
export * from './xyz2equirect'
|
|
37
|
+
export * from './triTile'
|
|
38
|
+
export * from './windmillTile'
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Fn, Vec2, Float, vec2, float, length, atan2, floor, min, max, cos, sin } from '../../node'
|
|
2
|
+
|
|
3
|
+
const TWO_PI = 6.283185307179586
|
|
4
|
+
|
|
5
|
+
const kaleidoscopeCore = (coord: Vec2, segmentCount: Float, phase: Float) => {
|
|
6
|
+
const uv = coord.sub(0.5).toVar('uv')
|
|
7
|
+
const radius = length(uv).toVar('radius')
|
|
8
|
+
const angle = atan2(uv.y, uv.x).toVar('angle')
|
|
9
|
+
const segmentAngle = float(TWO_PI).div(segmentCount).toVar('segmentAngle')
|
|
10
|
+
const adjustedAngle = angle.sub(segmentAngle.mul(floor(angle.div(segmentAngle)))).toVar('adjustedAngle')
|
|
11
|
+
const finalAngle = min(adjustedAngle, segmentAngle.sub(adjustedAngle)).toVar('finalAngle')
|
|
12
|
+
const kuv = vec2(cos(finalAngle.add(phase)), sin(finalAngle.add(phase)))
|
|
13
|
+
.mul(radius)
|
|
14
|
+
.add(0.5)
|
|
15
|
+
.toVar('kuv')
|
|
16
|
+
return max(min(kuv, kuv.mul(-1).add(2)), kuv.negate())
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const kaleidoscope = Fn(([coord, segmentCount, phase]: [Vec2, Float, Float]): Vec2 => {
|
|
20
|
+
return kaleidoscopeCore(coord, segmentCount, phase)
|
|
21
|
+
}).setLayout({
|
|
22
|
+
name: 'kaleidoscope',
|
|
23
|
+
type: 'vec2',
|
|
24
|
+
inputs: [
|
|
25
|
+
{ name: 'coord', type: 'vec2' },
|
|
26
|
+
{ name: 'segmentCount', type: 'float' },
|
|
27
|
+
{ name: 'phase', type: 'float' },
|
|
28
|
+
],
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
export const kaleidoscopeDefault = Fn(([coord]: [Vec2]): Vec2 => {
|
|
32
|
+
return kaleidoscopeCore(coord, float(8), float(0))
|
|
33
|
+
}).setLayout({
|
|
34
|
+
name: 'kaleidoscopeDefault',
|
|
35
|
+
type: 'vec2',
|
|
36
|
+
inputs: [{ name: 'coord', type: 'vec2' }],
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
export const kaleidoscopeCount = Fn(([coord, segmentCount]: [Vec2, Float]): Vec2 => {
|
|
40
|
+
return kaleidoscopeCore(coord, segmentCount, float(0))
|
|
41
|
+
}).setLayout({
|
|
42
|
+
name: 'kaleidoscopeCount',
|
|
43
|
+
type: 'vec2',
|
|
44
|
+
inputs: [
|
|
45
|
+
{ name: 'coord', type: 'vec2' },
|
|
46
|
+
{ name: 'segmentCount', type: 'float' },
|
|
47
|
+
],
|
|
48
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Fn, Float } from '../../node'
|
|
2
|
+
|
|
3
|
+
export const linearizeDepth = Fn(([depth, near, far]: [Float, Float, Float]): Float => {
|
|
4
|
+
const normalizedDepth = depth.mul(2).sub(1).toVar('normalizedDepth')
|
|
5
|
+
return near
|
|
6
|
+
.mul(far)
|
|
7
|
+
.mul(2)
|
|
8
|
+
.div(far.add(near).sub(normalizedDepth.mul(far.sub(near))))
|
|
9
|
+
}).setLayout({
|
|
10
|
+
name: 'linearizeDepth',
|
|
11
|
+
type: 'float',
|
|
12
|
+
inputs: [
|
|
13
|
+
{ name: 'depth', type: 'float' },
|
|
14
|
+
{ name: 'near', type: 'float' },
|
|
15
|
+
{ name: 'far', type: 'float' },
|
|
16
|
+
],
|
|
17
|
+
})
|