sparcoon 0.7.3 → 0.9.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 +124 -76
- package/dist/artifact/FXArtifact.d.ts +120 -0
- package/dist/artifact/FXArtifact.js +1 -0
- package/dist/coreLayout.d.ts +22 -0
- package/dist/coreLayout.js +32 -0
- package/dist/effect/FXEffect.d.ts +77 -0
- package/dist/effect/FXEffect.js +454 -0
- package/dist/effect/FXEffectSampling.Internal.d.ts +24 -0
- package/dist/effect/FXEffectSampling.Internal.js +165 -0
- package/dist/effect/FXEffectSpec.d.ts +115 -0
- package/dist/effect/FXEffectSpec.js +1 -0
- package/dist/emitter/FXEmitter.Internal.d.ts +23 -58
- package/dist/emitter/FXEmitter.Internal.js +13 -29
- package/dist/emitter/FXEmitter.d.ts +46 -48
- package/dist/emitter/FXEmitter.js +355 -186
- package/dist/emitter/FXFromArtifactsOptions.d.ts +13 -0
- package/dist/emitter/FXFromArtifactsOptions.js +1 -0
- package/dist/emitter/FXObjectMotion.Internal.d.ts +33 -0
- package/dist/emitter/FXObjectMotion.Internal.js +87 -0
- package/dist/emitter/FXSimulationHolder.d.ts +1 -0
- package/dist/emitter/FXSimulationHolder.js +43 -0
- package/dist/index.d.ts +10 -39
- package/dist/index.js +13 -36
- package/dist/instancedParticle/FXInstancedParticle.d.ts +1 -22
- package/dist/instancedParticle/FXInstancedParticle.js +145 -85
- package/dist/instancedParticle/glTypeInfo.d.ts +5 -0
- package/dist/instancedParticle/glTypeInfo.js +3 -0
- package/dist/instancedParticle/primitiveGeometry.d.ts +1 -0
- package/dist/instancedParticle/primitiveGeometry.js +30 -0
- package/dist/miscellaneous/asserts.d.ts +1 -18
- package/dist/miscellaneous/asserts.js +21 -28
- package/dist/miscellaneous/fxMath.d.ts +26 -0
- package/dist/miscellaneous/fxMath.js +261 -0
- package/dist/miscellaneous/math.d.ts +2 -7
- package/dist/miscellaneous/math.js +8 -9
- package/dist/miscellaneous/texture/fxDataTexture.d.ts +26 -0
- package/dist/miscellaneous/texture/fxDataTexture.js +20 -0
- package/dist/render/FXArtifactMaterial.Internal.d.ts +16 -0
- package/dist/render/FXArtifactMaterial.Internal.js +944 -0
- package/dist/render/FXArtifactMaterial.d.ts +1 -0
- package/dist/render/FXArtifactMaterial.js +79 -0
- package/dist/render/FXMaterialOptions.d.ts +27 -0
- package/dist/render/FXMaterialOptions.js +5 -0
- package/dist/render/FXMeshMaterial.d.ts +40 -0
- package/dist/render/FXMeshMaterial.js +77 -0
- package/dist/world/FXWorld.d.ts +42 -0
- package/dist/world/FXWorld.js +103 -0
- package/package.json +45 -29
- package/dist/_virtual/2d.js +0 -3
- package/dist/_virtual/3d.js +0 -3
- package/dist/_virtual/4d.js +0 -3
- package/dist/_virtual/mod.js +0 -5
- package/dist/_virtual/mod2.js +0 -3
- package/dist/emitter/behavior/FXBehavior.d.ts +0 -24
- package/dist/emitter/behavior/FXBehavior.js +0 -10
- package/dist/emitter/behavior/FXBehaviorDirectionalForce.d.ts +0 -23
- package/dist/emitter/behavior/FXBehaviorDirectionalForce.js +0 -72
- package/dist/emitter/behavior/FXBehaviorPointForce.d.ts +0 -36
- package/dist/emitter/behavior/FXBehaviorPointForce.js +0 -94
- package/dist/emitter/behavior/FXBehaviorScaleOverLife.d.ts +0 -24
- package/dist/emitter/behavior/FXBehaviorScaleOverLife.js +0 -55
- package/dist/emitter/behavior/FXBehaviorTorqueDamping.d.ts +0 -20
- package/dist/emitter/behavior/FXBehaviorTorqueDamping.js +0 -48
- package/dist/emitter/behavior/FXBehaviorTorqueNoise.d.ts +0 -25
- package/dist/emitter/behavior/FXBehaviorTorqueNoise.js +0 -67
- package/dist/emitter/behavior/FXBehaviorTorqueOverLife.d.ts +0 -19
- package/dist/emitter/behavior/FXBehaviorTorqueOverLife.js +0 -41
- package/dist/emitter/behavior/FXBehaviorVelocityDamping.d.ts +0 -20
- package/dist/emitter/behavior/FXBehaviorVelocityDamping.js +0 -50
- package/dist/emitter/behavior/FXBehaviorVelocityNoise.d.ts +0 -25
- package/dist/emitter/behavior/FXBehaviorVelocityNoise.js +0 -76
- package/dist/emitter/behavior/FXBehaviorVelocityOverLife.d.ts +0 -22
- package/dist/emitter/behavior/FXBehaviorVelocityOverLife.js +0 -55
- package/dist/emitter/spawn/FXSpawn.d.ts +0 -11
- package/dist/emitter/spawn/FXSpawn.js +0 -10
- package/dist/emitter/spawn/FXSpawnBox.d.ts +0 -18
- package/dist/emitter/spawn/FXSpawnBox.js +0 -50
- package/dist/emitter/spawn/FXSpawnLifetime.d.ts +0 -17
- package/dist/emitter/spawn/FXSpawnLifetime.js +0 -44
- package/dist/emitter/spawn/FXSpawnOffset.d.ts +0 -21
- package/dist/emitter/spawn/FXSpawnOffset.js +0 -49
- package/dist/emitter/spawn/FXSpawnPoint.d.ts +0 -18
- package/dist/emitter/spawn/FXSpawnPoint.js +0 -46
- package/dist/emitter/spawn/FXSpawnRotation.d.ts +0 -17
- package/dist/emitter/spawn/FXSpawnRotation.js +0 -42
- package/dist/emitter/spawn/FXSpawnScale.d.ts +0 -22
- package/dist/emitter/spawn/FXSpawnScale.js +0 -56
- package/dist/emitter/spawn/FXSpawnSphere.d.ts +0 -36
- package/dist/emitter/spawn/FXSpawnSphere.js +0 -87
- package/dist/emitter/spawn/FXSpawnTorque.d.ts +0 -17
- package/dist/emitter/spawn/FXSpawnTorque.js +0 -42
- package/dist/emitter/spawn/FXSpawnVelocity.d.ts +0 -29
- package/dist/emitter/spawn/FXSpawnVelocity.js +0 -91
- package/dist/instancedParticle/FXInstancedParticle.Internal.d.ts +0 -2
- package/dist/instancedParticle/shared.d.ts +0 -19
- package/dist/instancedParticle/shared.js +0 -116
- package/dist/materials/FXDiffuseMaterial/FXDiffuseMaterial.Internal.d.ts +0 -24
- package/dist/materials/FXDiffuseMaterial/FXDiffuseMaterial.Internal.js +0 -275
- package/dist/materials/FXDiffuseMaterial/FXDiffuseMaterial.d.ts +0 -75
- package/dist/materials/FXDiffuseMaterial/FXDiffuseMaterial.js +0 -63
- package/dist/materials/FXMaterial/FXBlending.Internal.d.ts +0 -24
- package/dist/materials/FXMaterial/FXBlending.Internal.js +0 -64
- package/dist/materials/FXMaterial/FXDepthMaterial.Internal.d.ts +0 -4
- package/dist/materials/FXMaterial/FXDepthMaterial.Internal.js +0 -144
- package/dist/materials/FXMaterial/FXDistanceMaterial.Internal.d.ts +0 -4
- package/dist/materials/FXMaterial/FXDistanceMaterial.Internal.js +0 -175
- package/dist/materials/FXMaterial/FXMaterial.d.ts +0 -70
- package/dist/materials/FXMaterial/FXMaterial.js +0 -51
- package/dist/materials/FXUnlitMaterial/FXUnlitMaterial.Internal.d.ts +0 -7
- package/dist/materials/FXUnlitMaterial/FXUnlitMaterial.Internal.js +0 -103
- package/dist/materials/FXUnlitMaterial/FXUnlitMaterial.d.ts +0 -7
- package/dist/materials/FXUnlitMaterial/FXUnlitMaterial.js +0 -21
- package/dist/miscellaneous/color/FXColor.Internal.d.ts +0 -7
- package/dist/miscellaneous/color/FXColor.Internal.js +0 -42
- package/dist/miscellaneous/color/FXColor.d.ts +0 -234
- package/dist/miscellaneous/color/FXColor.js +0 -636
- package/dist/miscellaneous/curve/FXCurve1D.Internal.d.ts +0 -20
- package/dist/miscellaneous/curve/FXCurve1D.d.ts +0 -17
- package/dist/miscellaneous/curve/FXCurve1D.js +0 -94
- package/dist/miscellaneous/miscellaneous.d.ts +0 -34
- package/dist/miscellaneous/miscellaneous.js +0 -85
- package/dist/miscellaneous/texture/FXTextureView.Internal.d.ts +0 -49
- package/dist/miscellaneous/texture/FXTextureView.Internal.js +0 -6
- package/dist/miscellaneous/texture/FXTextureView.d.ts +0 -72
- package/dist/miscellaneous/texture/FXTextureView.js +0 -234
- package/dist/miscellaneous/webglCapabilities.d.ts +0 -1
- package/dist/miscellaneous/webglCapabilities.js +0 -45
- package/dist/node_modules/fast-simplex-noise/lib/2d.js +0 -93
- package/dist/node_modules/fast-simplex-noise/lib/3d.js +0 -142
- package/dist/node_modules/fast-simplex-noise/lib/4d.js +0 -196
- package/dist/node_modules/fast-simplex-noise/lib/mod.js +0 -24
- package/dist/nodes/FXNode.d.ts +0 -5
- package/dist/nodes/FXNode.js +0 -10
- package/dist/nodes/blending/FXNodeBlending.d.ts +0 -6
- package/dist/nodes/blending/FXNodeBlending.js +0 -9
- package/dist/nodes/blending/FXNodeLightnessBlendingMask.d.ts +0 -19
- package/dist/nodes/blending/FXNodeLightnessBlendingMask.js +0 -65
- package/dist/nodes/color/FXNodeColor.d.ts +0 -6
- package/dist/nodes/color/FXNodeColor.js +0 -9
- package/dist/nodes/color/FXNodeColorOverLife.d.ts +0 -22
- package/dist/nodes/color/FXNodeColorOverLife.js +0 -64
- package/dist/nodes/color/FXNodeSphericalClip.d.ts +0 -21
- package/dist/nodes/color/FXNodeSphericalClip.js +0 -54
- package/dist/nodes/normal/FXNodeFlatNormal.d.ts +0 -6
- package/dist/nodes/normal/FXNodeFlatNormal.js +0 -16
- package/dist/nodes/normal/FXNodeNormal.d.ts +0 -6
- package/dist/nodes/normal/FXNodeNormal.js +0 -9
- package/dist/nodes/normal/FXNodeSphericalNormal.d.ts +0 -6
- package/dist/nodes/normal/FXNodeSphericalNormal.js +0 -23
- package/dist/nodes/texture/FXNodeAnimatedTexture.d.ts +0 -52
- package/dist/nodes/texture/FXNodeAnimatedTexture.js +0 -151
- package/dist/nodes/texture/FXNodeStaticTexture.d.ts +0 -20
- package/dist/nodes/texture/FXNodeStaticTexture.js +0 -67
- package/dist/nodes/texture/FXNodeTexture.d.ts +0 -6
- package/dist/nodes/texture/FXNodeTexture.js +0 -9
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CPU-side twins of the compiler's math/noise builtins (`fxMix`, `fxSnoise3`, ...). A behavior
|
|
3
|
+
* kernel's authored `spawn`/`update` body calls these by name - the editor's compiler prints those
|
|
4
|
+
* exact calls - so every exported name here is a frozen contract with already-compiled kernels,
|
|
5
|
+
* like the `a_`/`p_` buffer prefixes. Never rename one without updating the compiler side in
|
|
6
|
+
* lockstep.
|
|
7
|
+
*/
|
|
8
|
+
export function fxFract(x) {
|
|
9
|
+
return x - Math.floor(x);
|
|
10
|
+
}
|
|
11
|
+
export function fxMod(a, b) {
|
|
12
|
+
return a - b * Math.floor(a / b);
|
|
13
|
+
}
|
|
14
|
+
export function fxMix(a, b, t) {
|
|
15
|
+
return a + (b - a) * t;
|
|
16
|
+
}
|
|
17
|
+
export function fxSmoothstep(edge0, edge1, x) {
|
|
18
|
+
const t = Math.min(Math.max((x - edge0) / (edge1 - edge0), 0.0), 1.0);
|
|
19
|
+
return t * t * (3.0 - 2.0 * t);
|
|
20
|
+
}
|
|
21
|
+
export function fxHash(n) {
|
|
22
|
+
const s = Math.sin(n * 127.1) * 43758.5453123;
|
|
23
|
+
return s - Math.floor(s);
|
|
24
|
+
}
|
|
25
|
+
/** Cheap deterministic 1D value-noise (smoothed hash interpolation), range [-1, 1]. */
|
|
26
|
+
export function fxValueNoise(x) {
|
|
27
|
+
const i = Math.floor(x);
|
|
28
|
+
const fractional = x - i;
|
|
29
|
+
const u = fractional * fractional * (3 - 2 * fractional);
|
|
30
|
+
return (fxHash(i) * (1 - u) + fxHash(i + 1) * u) * 2 - 1;
|
|
31
|
+
}
|
|
32
|
+
// Mirrors FBM_MAX_OCTAVES in the editor engine: clamps a runaway octave count (a
|
|
33
|
+
// value parameter rebinds with no recompile/sanity gate) so it cannot blow up the update kernel.
|
|
34
|
+
const FBM_MAX_OCTAVES = 8;
|
|
35
|
+
/** Fractal Brownian motion over {@link fxValueNoise} (gain 0.5, lacunarity 2). */
|
|
36
|
+
export function fxFbm(x, octaves) {
|
|
37
|
+
const octaveCount = Math.min(Math.max(Math.floor(octaves), 0), FBM_MAX_OCTAVES);
|
|
38
|
+
let sum = 0;
|
|
39
|
+
let amplitude = 1;
|
|
40
|
+
let frequency = 1;
|
|
41
|
+
for (let i = 0; i < octaveCount; i += 1) {
|
|
42
|
+
sum += fxValueNoise(x * frequency) * amplitude;
|
|
43
|
+
amplitude *= 0.5;
|
|
44
|
+
frequency *= 2;
|
|
45
|
+
}
|
|
46
|
+
return sum;
|
|
47
|
+
}
|
|
48
|
+
/** Linearly samples a curve LUT at `t` in [0, 1] (clamped), interpolating between entries. */
|
|
49
|
+
export function fxSampleLut(lut, t) {
|
|
50
|
+
const length = lut.length;
|
|
51
|
+
const last = length - 1;
|
|
52
|
+
const clamped = t < 0 ? 0 : t > 1 ? 1 : t;
|
|
53
|
+
const x = clamped * last;
|
|
54
|
+
const i = Math.floor(x);
|
|
55
|
+
const fraction = x - i;
|
|
56
|
+
const lowerValue = lut[i];
|
|
57
|
+
const upperValue = lut[i + 1 < length ? i + 1 : last];
|
|
58
|
+
return lowerValue + (upperValue - lowerValue) * fraction;
|
|
59
|
+
}
|
|
60
|
+
// Ashima/Gustavson simplex-noise sub-helpers (mod289/permute/fract), private to fxSnoise2/3.
|
|
61
|
+
function fxsnMod289(x) {
|
|
62
|
+
return x - Math.floor(x * (1.0 / 289.0)) * 289.0;
|
|
63
|
+
}
|
|
64
|
+
function fxsnPermute(x) {
|
|
65
|
+
return fxsnMod289((x * 34.0 + 1.0) * x);
|
|
66
|
+
}
|
|
67
|
+
function fxsnFract(x) {
|
|
68
|
+
return x - Math.floor(x);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Ashima/Gustavson "webgl-noise" simplex noise, 2D - the CPU twin of the compiler's GLSL `snoise`
|
|
72
|
+
* helper. Component arguments (rather than a vector) so it mirrors how the scalarized JS backend calls
|
|
73
|
+
* it; the arithmetic tracks the GLSL version op-for-op. Output is roughly `[-1, 1]`.
|
|
74
|
+
*/
|
|
75
|
+
export function fxSnoise2(vx, vy) {
|
|
76
|
+
const cx = 0.211324865405187;
|
|
77
|
+
const cy = 0.366025403784439;
|
|
78
|
+
const cz = -0.577350269189626;
|
|
79
|
+
const cw = 0.024390243902439;
|
|
80
|
+
const s = (vx + vy) * cy;
|
|
81
|
+
let ix = Math.floor(vx + s);
|
|
82
|
+
let iy = Math.floor(vy + s);
|
|
83
|
+
const t = (ix + iy) * cx;
|
|
84
|
+
const x0x = vx - ix + t;
|
|
85
|
+
const x0y = vy - iy + t;
|
|
86
|
+
let i1x;
|
|
87
|
+
let i1y;
|
|
88
|
+
if (x0x > x0y) {
|
|
89
|
+
i1x = 1.0;
|
|
90
|
+
i1y = 0.0;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
i1x = 0.0;
|
|
94
|
+
i1y = 1.0;
|
|
95
|
+
}
|
|
96
|
+
const x1x = x0x - i1x + cx;
|
|
97
|
+
const x1y = x0y - i1y + cx;
|
|
98
|
+
const x2x = x0x + cz;
|
|
99
|
+
const x2y = x0y + cz;
|
|
100
|
+
ix = fxsnMod289(ix);
|
|
101
|
+
iy = fxsnMod289(iy);
|
|
102
|
+
const p0 = fxsnPermute(fxsnPermute(iy + 0.0) + ix + 0.0);
|
|
103
|
+
const p1 = fxsnPermute(fxsnPermute(iy + i1y) + ix + i1x);
|
|
104
|
+
const p2 = fxsnPermute(fxsnPermute(iy + 1.0) + ix + 1.0);
|
|
105
|
+
let m0 = Math.max(0.5 - (x0x * x0x + x0y * x0y), 0.0);
|
|
106
|
+
let m1 = Math.max(0.5 - (x1x * x1x + x1y * x1y), 0.0);
|
|
107
|
+
let m2 = Math.max(0.5 - (x2x * x2x + x2y * x2y), 0.0);
|
|
108
|
+
m0 = m0 * m0;
|
|
109
|
+
m0 = m0 * m0;
|
|
110
|
+
m1 = m1 * m1;
|
|
111
|
+
m1 = m1 * m1;
|
|
112
|
+
m2 = m2 * m2;
|
|
113
|
+
m2 = m2 * m2;
|
|
114
|
+
const gx0 = 2.0 * fxsnFract(p0 * cw) - 1.0;
|
|
115
|
+
const gx1 = 2.0 * fxsnFract(p1 * cw) - 1.0;
|
|
116
|
+
const gx2 = 2.0 * fxsnFract(p2 * cw) - 1.0;
|
|
117
|
+
const h0 = Math.abs(gx0) - 0.5;
|
|
118
|
+
const h1 = Math.abs(gx1) - 0.5;
|
|
119
|
+
const h2 = Math.abs(gx2) - 0.5;
|
|
120
|
+
const ox0 = Math.floor(gx0 + 0.5);
|
|
121
|
+
const ox1 = Math.floor(gx1 + 0.5);
|
|
122
|
+
const ox2 = Math.floor(gx2 + 0.5);
|
|
123
|
+
const a0 = gx0 - ox0;
|
|
124
|
+
const a1 = gx1 - ox1;
|
|
125
|
+
const a2 = gx2 - ox2;
|
|
126
|
+
m0 *= 1.79284291400159 - 0.85373472095314 * (a0 * a0 + h0 * h0);
|
|
127
|
+
m1 *= 1.79284291400159 - 0.85373472095314 * (a1 * a1 + h1 * h1);
|
|
128
|
+
m2 *= 1.79284291400159 - 0.85373472095314 * (a2 * a2 + h2 * h2);
|
|
129
|
+
const g0 = a0 * x0x + h0 * x0y;
|
|
130
|
+
const g1 = a1 * x1x + h1 * x1y;
|
|
131
|
+
const g2 = a2 * x2x + h2 * x2y;
|
|
132
|
+
return 130.0 * (m0 * g0 + m1 * g1 + m2 * g2);
|
|
133
|
+
}
|
|
134
|
+
/** 3D twin of {@link fxSnoise2}, mirroring the GLSL `snoise(vec3)` overload op-for-op. */
|
|
135
|
+
export function fxSnoise3(vx, vy, vz) {
|
|
136
|
+
const cx = 1.0 / 6.0;
|
|
137
|
+
const cy = 1.0 / 3.0;
|
|
138
|
+
const s = (vx + vy + vz) * cy;
|
|
139
|
+
let ix = Math.floor(vx + s);
|
|
140
|
+
let iy = Math.floor(vy + s);
|
|
141
|
+
let iz = Math.floor(vz + s);
|
|
142
|
+
const t = (ix + iy + iz) * cx;
|
|
143
|
+
const x0x = vx - ix + t;
|
|
144
|
+
const x0y = vy - iy + t;
|
|
145
|
+
const x0z = vz - iz + t;
|
|
146
|
+
const gx = x0x >= x0y ? 1.0 : 0.0;
|
|
147
|
+
const gy = x0y >= x0z ? 1.0 : 0.0;
|
|
148
|
+
const gz = x0z >= x0x ? 1.0 : 0.0;
|
|
149
|
+
const lx = 1.0 - gx;
|
|
150
|
+
const ly = 1.0 - gy;
|
|
151
|
+
const lz = 1.0 - gz;
|
|
152
|
+
const i1x = Math.min(gx, lz);
|
|
153
|
+
const i1y = Math.min(gy, lx);
|
|
154
|
+
const i1z = Math.min(gz, ly);
|
|
155
|
+
const i2x = Math.max(gx, lz);
|
|
156
|
+
const i2y = Math.max(gy, lx);
|
|
157
|
+
const i2z = Math.max(gz, ly);
|
|
158
|
+
const x1x = x0x - i1x + cx;
|
|
159
|
+
const x1y = x0y - i1y + cx;
|
|
160
|
+
const x1z = x0z - i1z + cx;
|
|
161
|
+
const x2x = x0x - i2x + cy;
|
|
162
|
+
const x2y = x0y - i2y + cy;
|
|
163
|
+
const x2z = x0z - i2z + cy;
|
|
164
|
+
const x3x = x0x - 0.5;
|
|
165
|
+
const x3y = x0y - 0.5;
|
|
166
|
+
const x3z = x0z - 0.5;
|
|
167
|
+
ix = fxsnMod289(ix);
|
|
168
|
+
iy = fxsnMod289(iy);
|
|
169
|
+
iz = fxsnMod289(iz);
|
|
170
|
+
const offz = [0.0, i1z, i2z, 1.0];
|
|
171
|
+
const offy = [0.0, i1y, i2y, 1.0];
|
|
172
|
+
const offx = [0.0, i1x, i2x, 1.0];
|
|
173
|
+
const p = [0.0, 0.0, 0.0, 0.0];
|
|
174
|
+
for (let k = 0; k < 4; k += 1) {
|
|
175
|
+
p[k] = fxsnPermute(fxsnPermute(fxsnPermute(iz + offz[k]) + iy + offy[k]) + ix + offx[k]);
|
|
176
|
+
}
|
|
177
|
+
const oneOverSeven = 1.0 / 7.0;
|
|
178
|
+
const nsx = oneOverSeven * 2.0;
|
|
179
|
+
const nsy = oneOverSeven * 0.5 - 1.0;
|
|
180
|
+
const nsz = oneOverSeven;
|
|
181
|
+
const xx = [0.0, 0.0, 0.0, 0.0];
|
|
182
|
+
const yy = [0.0, 0.0, 0.0, 0.0];
|
|
183
|
+
const hh = [0.0, 0.0, 0.0, 0.0];
|
|
184
|
+
for (let k = 0; k < 4; k += 1) {
|
|
185
|
+
const j = p[k] - 49.0 * Math.floor(p[k] * nsz * nsz);
|
|
186
|
+
const xf = Math.floor(j * nsz);
|
|
187
|
+
const yf = Math.floor(j - 7.0 * xf);
|
|
188
|
+
xx[k] = xf * nsx + nsy;
|
|
189
|
+
yy[k] = yf * nsx + nsy;
|
|
190
|
+
hh[k] = 1.0 - Math.abs(xx[k]) - Math.abs(yy[k]);
|
|
191
|
+
}
|
|
192
|
+
const b0 = [xx[0], xx[1], yy[0], yy[1]];
|
|
193
|
+
const b1 = [xx[2], xx[3], yy[2], yy[3]];
|
|
194
|
+
const s0 = [
|
|
195
|
+
Math.floor(b0[0]) * 2.0 + 1.0,
|
|
196
|
+
Math.floor(b0[1]) * 2.0 + 1.0,
|
|
197
|
+
Math.floor(b0[2]) * 2.0 + 1.0,
|
|
198
|
+
Math.floor(b0[3]) * 2.0 + 1.0,
|
|
199
|
+
];
|
|
200
|
+
const s1 = [
|
|
201
|
+
Math.floor(b1[0]) * 2.0 + 1.0,
|
|
202
|
+
Math.floor(b1[1]) * 2.0 + 1.0,
|
|
203
|
+
Math.floor(b1[2]) * 2.0 + 1.0,
|
|
204
|
+
Math.floor(b1[3]) * 2.0 + 1.0,
|
|
205
|
+
];
|
|
206
|
+
const sh = [
|
|
207
|
+
-(hh[0] <= 0.0 ? 1.0 : 0.0),
|
|
208
|
+
-(hh[1] <= 0.0 ? 1.0 : 0.0),
|
|
209
|
+
-(hh[2] <= 0.0 ? 1.0 : 0.0),
|
|
210
|
+
-(hh[3] <= 0.0 ? 1.0 : 0.0),
|
|
211
|
+
];
|
|
212
|
+
const a00 = b0[0] + s0[0] * sh[0];
|
|
213
|
+
const a01 = b0[2] + s0[2] * sh[0];
|
|
214
|
+
const a02 = b0[1] + s0[1] * sh[1];
|
|
215
|
+
const a03 = b0[3] + s0[3] * sh[1];
|
|
216
|
+
const a10 = b1[0] + s1[0] * sh[2];
|
|
217
|
+
const a11 = b1[2] + s1[2] * sh[2];
|
|
218
|
+
const a12 = b1[1] + s1[1] * sh[3];
|
|
219
|
+
const a13 = b1[3] + s1[3] * sh[3];
|
|
220
|
+
let p0x = a00;
|
|
221
|
+
let p0y = a01;
|
|
222
|
+
let p0z = hh[0];
|
|
223
|
+
let p1x = a02;
|
|
224
|
+
let p1y = a03;
|
|
225
|
+
let p1z = hh[1];
|
|
226
|
+
let p2x = a10;
|
|
227
|
+
let p2y = a11;
|
|
228
|
+
let p2z = hh[2];
|
|
229
|
+
let p3x = a12;
|
|
230
|
+
let p3y = a13;
|
|
231
|
+
let p3z = hh[3];
|
|
232
|
+
const nrm0 = 1.79284291400159 - 0.85373472095314 * (p0x * p0x + p0y * p0y + p0z * p0z);
|
|
233
|
+
const nrm1 = 1.79284291400159 - 0.85373472095314 * (p1x * p1x + p1y * p1y + p1z * p1z);
|
|
234
|
+
const nrm2 = 1.79284291400159 - 0.85373472095314 * (p2x * p2x + p2y * p2y + p2z * p2z);
|
|
235
|
+
const nrm3 = 1.79284291400159 - 0.85373472095314 * (p3x * p3x + p3y * p3y + p3z * p3z);
|
|
236
|
+
p0x *= nrm0;
|
|
237
|
+
p0y *= nrm0;
|
|
238
|
+
p0z *= nrm0;
|
|
239
|
+
p1x *= nrm1;
|
|
240
|
+
p1y *= nrm1;
|
|
241
|
+
p1z *= nrm1;
|
|
242
|
+
p2x *= nrm2;
|
|
243
|
+
p2y *= nrm2;
|
|
244
|
+
p2z *= nrm2;
|
|
245
|
+
p3x *= nrm3;
|
|
246
|
+
p3y *= nrm3;
|
|
247
|
+
p3z *= nrm3;
|
|
248
|
+
let m0 = Math.max(0.6 - (x0x * x0x + x0y * x0y + x0z * x0z), 0.0);
|
|
249
|
+
let m1 = Math.max(0.6 - (x1x * x1x + x1y * x1y + x1z * x1z), 0.0);
|
|
250
|
+
let m2 = Math.max(0.6 - (x2x * x2x + x2y * x2y + x2z * x2z), 0.0);
|
|
251
|
+
let m3 = Math.max(0.6 - (x3x * x3x + x3y * x3y + x3z * x3z), 0.0);
|
|
252
|
+
m0 = m0 * m0;
|
|
253
|
+
m1 = m1 * m1;
|
|
254
|
+
m2 = m2 * m2;
|
|
255
|
+
m3 = m3 * m3;
|
|
256
|
+
const dp0 = p0x * x0x + p0y * x0y + p0z * x0z;
|
|
257
|
+
const dp1 = p1x * x1x + p1y * x1y + p1z * x1z;
|
|
258
|
+
const dp2 = p2x * x2x + p2y * x2y + p2z * x2z;
|
|
259
|
+
const dp3 = p3x * x3x + p3y * x3y + p3z * x3z;
|
|
260
|
+
return 42.0 * (m0 * m0 * dp0 + m1 * m1 * dp1 + m2 * m2 * dp2 + m3 * m3 * dp3);
|
|
261
|
+
}
|
|
@@ -1,8 +1,3 @@
|
|
|
1
1
|
export declare const EPSILON = 0.000001;
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
readonly y: number;
|
|
5
|
-
readonly z: number;
|
|
6
|
-
}
|
|
7
|
-
export declare function srgbToLinear(color: number): number;
|
|
8
|
-
export declare function linearToSRGB(color: number): number;
|
|
2
|
+
export declare function srgbToLinear(channel: number): number;
|
|
3
|
+
export declare function linearToSRGB(channel: number): number;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
const EPSILON = 1e-6;
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export const EPSILON = 1e-6;
|
|
2
|
+
// sRGB <-> linear transfer matching three's GLSL curve (constants are the piecewise sRGB coefficients).
|
|
3
|
+
export function srgbToLinear(channel) {
|
|
4
|
+
return channel < 0.04045
|
|
5
|
+
? channel * 0.0773993808
|
|
6
|
+
: Math.pow(channel * 0.9478672986 + 0.0521327014, 2.4);
|
|
6
7
|
}
|
|
7
|
-
function linearToSRGB(
|
|
8
|
-
return
|
|
8
|
+
export function linearToSRGB(channel) {
|
|
9
|
+
return channel < 0.0031308 ? channel * 12.92 : 1.055 * Math.pow(channel, 0.41666) - 0.055;
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
-
export { EPSILON, linearToSRGB, srgbToLinear };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ColorSpace, MagnificationTextureFilter, MinificationTextureFilter, PixelFormat, TextureDataType, Wrapping } from "three";
|
|
2
|
+
import { DataTexture } from "three";
|
|
3
|
+
/** Format/filter overrides for {@link fxDataTexture}; each defaults to a gradient-LUT-friendly value. */
|
|
4
|
+
export interface FXDataTextureOptions {
|
|
5
|
+
/** default RGBAFormat */
|
|
6
|
+
format?: PixelFormat;
|
|
7
|
+
/** must match `data` (Float32Array <-> FloatType). default FloatType */
|
|
8
|
+
type?: TextureDataType;
|
|
9
|
+
/** default LinearFilter */
|
|
10
|
+
minFilter?: MinificationTextureFilter;
|
|
11
|
+
/** default LinearFilter */
|
|
12
|
+
magFilter?: MagnificationTextureFilter;
|
|
13
|
+
/** default ClampToEdgeWrapping */
|
|
14
|
+
wrapS?: Wrapping;
|
|
15
|
+
/** default ClampToEdgeWrapping */
|
|
16
|
+
wrapT?: Wrapping;
|
|
17
|
+
/** default NoColorSpace (linear) */
|
|
18
|
+
colorSpace?: ColorSpace;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Rebuilds a generated (baked) Three {@link DataTexture} from flat pixel data - the stable helper an
|
|
22
|
+
* editor-emitted module calls; the runtime only constructs the GPU resource, no baking logic here.
|
|
23
|
+
* `data.length` must be `width * height * channels`. Module-scoped and shared by every importing
|
|
24
|
+
* emitter, never disposed by the runtime (see the `fromArtifacts` texture-ownership contract).
|
|
25
|
+
*/
|
|
26
|
+
export declare function fxDataTexture(data: Float32Array, width: number, height: number, options?: FXDataTextureOptions): DataTexture;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ClampToEdgeWrapping, DataTexture, FloatType, LinearFilter, NoColorSpace, RGBAFormat, } from "three";
|
|
2
|
+
/**
|
|
3
|
+
* Rebuilds a generated (baked) Three {@link DataTexture} from flat pixel data - the stable helper an
|
|
4
|
+
* editor-emitted module calls; the runtime only constructs the GPU resource, no baking logic here.
|
|
5
|
+
* `data.length` must be `width * height * channels`. Module-scoped and shared by every importing
|
|
6
|
+
* emitter, never disposed by the runtime (see the `fromArtifacts` texture-ownership contract).
|
|
7
|
+
*/
|
|
8
|
+
export function fxDataTexture(data, width, height, options = {}) {
|
|
9
|
+
const texture = new DataTexture(
|
|
10
|
+
// TS 5.7 widens `Float32Array` to `Float32Array<ArrayBufferLike>`, which no longer matches
|
|
11
|
+
// three's ArrayBuffer-backed `BufferSource` parameter; the runtime value is a plain typed array.
|
|
12
|
+
data, width, height, options.format ?? RGBAFormat, options.type ?? FloatType);
|
|
13
|
+
texture.minFilter = options.minFilter ?? LinearFilter;
|
|
14
|
+
texture.magFilter = options.magFilter ?? LinearFilter;
|
|
15
|
+
texture.wrapS = options.wrapS ?? ClampToEdgeWrapping;
|
|
16
|
+
texture.wrapT = options.wrapT ?? ClampToEdgeWrapping;
|
|
17
|
+
texture.colorSpace = options.colorSpace ?? NoColorSpace;
|
|
18
|
+
texture.needsUpdate = true;
|
|
19
|
+
return texture;
|
|
20
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Texture } from "three";
|
|
2
|
+
import { ShaderMaterial } from "three";
|
|
3
|
+
import type { FXRenderArtifact, FXValueSlot } from "../artifact/FXArtifact.js";
|
|
4
|
+
import type { GLTypeInfo } from "../instancedParticle/glTypeInfo.js";
|
|
5
|
+
export interface FXFrameTimeUniform {
|
|
6
|
+
value: number;
|
|
7
|
+
}
|
|
8
|
+
export interface FXFrameVec3Uniform {
|
|
9
|
+
value: readonly [number, number, number];
|
|
10
|
+
}
|
|
11
|
+
export declare function fxRenderArtifactCacheKey(render: FXRenderArtifact): string;
|
|
12
|
+
export declare function buildUnlitArtifactMaterial(render: FXRenderArtifact, varyings: Record<string, GLTypeInfo>, timeUniform: FXFrameTimeUniform, deltaUniform: FXFrameTimeUniform, velocityUniform: FXFrameVec3Uniform, angularVelocityUniform: FXFrameVec3Uniform, externalSlots?: Readonly<Record<string, FXValueSlot<Texture>>>): ShaderMaterial;
|
|
13
|
+
export declare function buildArtifactMaterial(render: FXRenderArtifact, varyings: Record<string, GLTypeInfo>, timeUniform: FXFrameTimeUniform, deltaUniform: FXFrameTimeUniform, velocityUniform: FXFrameVec3Uniform, angularVelocityUniform: FXFrameVec3Uniform, externalSlots?: Readonly<Record<string, FXValueSlot<Texture>>>): ShaderMaterial;
|
|
14
|
+
export declare function buildMeshArtifactMaterial(render: FXRenderArtifact, timeUniform: FXFrameTimeUniform, deltaUniform: FXFrameTimeUniform, velocityUniform: FXFrameVec3Uniform, angularVelocityUniform: FXFrameVec3Uniform, externalSlots?: Readonly<Record<string, FXValueSlot<Texture>>>): ShaderMaterial;
|
|
15
|
+
export declare function buildArtifactDepthMaterial(render: FXRenderArtifact, varyings: Record<string, GLTypeInfo>, timeUniform: FXFrameTimeUniform, deltaUniform: FXFrameTimeUniform, velocityUniform: FXFrameVec3Uniform, angularVelocityUniform: FXFrameVec3Uniform, externalSlots?: Readonly<Record<string, FXValueSlot<Texture>>>): ShaderMaterial;
|
|
16
|
+
export declare function buildMeshArtifactDepthMaterial(render: FXRenderArtifact, timeUniform: FXFrameTimeUniform, deltaUniform: FXFrameTimeUniform, velocityUniform: FXFrameVec3Uniform, angularVelocityUniform: FXFrameVec3Uniform, externalSlots?: Readonly<Record<string, FXValueSlot<Texture>>>): ShaderMaterial;
|