sparcoon 0.2.0 → 0.3.1
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/dist/emitter/FXEmitter.Internal.d.ts +4 -0
- package/dist/emitter/FXEmitter.Internal.js +20 -1
- package/dist/emitter/FXEmitter.d.ts +4 -4
- package/dist/emitter/FXEmitter.js +1 -2
- package/dist/emitter/behavior/{FXBehaviorModule.d.ts → FXBehavior.d.ts} +1 -1
- package/dist/emitter/behavior/{FXBehaviorModule.js → FXBehavior.js} +2 -2
- package/dist/emitter/behavior/FXBehaviorDirectionalGravity.d.ts +3 -3
- package/dist/emitter/behavior/FXBehaviorDirectionalGravity.js +2 -2
- package/dist/emitter/behavior/FXBehaviorPointGravity.d.ts +2 -2
- package/dist/emitter/behavior/FXBehaviorPointGravity.js +2 -2
- package/dist/emitter/behavior/FXBehaviorScaleOverLife.d.ts +3 -3
- package/dist/emitter/behavior/FXBehaviorScaleOverLife.js +2 -2
- package/dist/emitter/behavior/FXBehaviorTorqueDamping.d.ts +3 -3
- package/dist/emitter/behavior/FXBehaviorTorqueDamping.js +2 -2
- package/dist/emitter/behavior/FXBehaviorTorqueNoise.d.ts +2 -2
- package/dist/emitter/behavior/FXBehaviorTorqueNoise.js +2 -2
- package/dist/emitter/behavior/FXBehaviorVelocityDamping.d.ts +3 -3
- package/dist/emitter/behavior/FXBehaviorVelocityDamping.js +2 -2
- package/dist/emitter/behavior/FXBehaviorVelocityNoise.d.ts +2 -2
- package/dist/emitter/behavior/FXBehaviorVelocityNoise.js +2 -2
- package/dist/emitter/spawn/{FXSpawnModule.d.ts → FXSpawn.d.ts} +1 -1
- package/dist/emitter/spawn/{FXSpawnModule.js → FXSpawn.js} +2 -2
- package/dist/emitter/spawn/FXSpawnBox.d.ts +3 -3
- package/dist/emitter/spawn/FXSpawnBox.js +2 -2
- package/dist/emitter/spawn/{FXSpawnOffset.d.ts → FXSpawnPoint.d.ts} +3 -3
- package/dist/emitter/spawn/{FXSpawnOffset.js → FXSpawnPoint.js} +3 -3
- package/dist/emitter/spawn/FXSpawnRandomLifetime.d.ts +3 -3
- package/dist/emitter/spawn/FXSpawnRandomLifetime.js +2 -2
- package/dist/emitter/spawn/FXSpawnRandomRotation.d.ts +3 -3
- package/dist/emitter/spawn/FXSpawnRandomRotation.js +2 -2
- package/dist/emitter/spawn/FXSpawnRandomScale.d.ts +3 -3
- package/dist/emitter/spawn/FXSpawnRandomScale.js +2 -2
- package/dist/emitter/spawn/FXSpawnRandomTorque.d.ts +3 -3
- package/dist/emitter/spawn/FXSpawnRandomTorque.js +2 -2
- package/dist/emitter/spawn/FXSpawnRandomVelocity.d.ts +3 -3
- package/dist/emitter/spawn/FXSpawnRandomVelocity.js +2 -2
- package/dist/emitter/spawn/FXSpawnSphere.d.ts +2 -2
- package/dist/emitter/spawn/FXSpawnSphere.js +2 -2
- package/dist/index.d.ts +11 -7
- package/dist/index.js +10 -7
- package/dist/instancedParticle/FXInstancedParticle.Internal.d.ts +0 -4
- package/dist/instancedParticle/FXInstancedParticle.Internal.js +1 -19
- package/dist/materials/FXDiffuseMaterial/FXDiffuseMaterial.Internal.d.ts +6 -8
- package/dist/materials/FXDiffuseMaterial/FXDiffuseMaterial.Internal.js +84 -40
- package/dist/materials/FXDiffuseMaterial/FXDiffuseMaterial.d.ts +11 -11
- package/dist/materials/FXDiffuseMaterial/FXDiffuseMaterial.js +16 -8
- package/dist/materials/{FXMaterial.Internal.d.ts → FXMaterial/FXMaterial.Internal.d.ts} +3 -2
- package/dist/materials/{FXMaterial.Internal.js → FXMaterial/FXMaterial.Internal.js} +3 -3
- package/dist/materials/{FXMaterial.d.ts → FXMaterial/FXMaterial.d.ts} +7 -2
- package/dist/materials/FXMaterial/FXMaterial.js +25 -0
- package/dist/materials/FXUnlitMaterial/FXUnlitMaterial.Internal.d.ts +5 -3
- package/dist/materials/FXUnlitMaterial/FXUnlitMaterial.Internal.js +35 -20
- package/dist/materials/FXUnlitMaterial/FXUnlitMaterial.d.ts +4 -9
- package/dist/materials/FXUnlitMaterial/FXUnlitMaterial.js +2 -5
- package/dist/miscellaneous/miscellaneous.d.ts +1 -0
- package/dist/miscellaneous/miscellaneous.js +24 -1
- package/dist/{materials/color-nodes → nodes/color}/FXColorOverLifeNode.d.ts +0 -1
- package/dist/nodes/color/FXColorOverLifeNode.js +44 -0
- package/dist/nodes/normal/FXFlatNormalNode.d.ts +4 -0
- package/dist/nodes/normal/FXFlatNormalNode.js +14 -0
- package/dist/nodes/normal/FXNormalNode.d.ts +3 -0
- package/dist/nodes/normal/FXNormalNode.js +4 -0
- package/dist/nodes/normal/FXSphericalNormalNode.d.ts +4 -0
- package/dist/nodes/normal/FXSphericalNormalNode.js +19 -0
- package/dist/nodes/texture/FXAnimatedTextureNode.d.ts +12 -0
- package/dist/nodes/texture/FXAnimatedTextureNode.js +88 -0
- package/dist/nodes/texture/FXStaticTextureNode.d.ts +6 -0
- package/dist/nodes/texture/FXStaticTextureNode.js +34 -0
- package/dist/nodes/texture/FXTextureNode.d.ts +3 -0
- package/dist/nodes/texture/FXTextureNode.js +8 -0
- package/package.json +1 -1
- package/dist/materials/FXMaterial.js +0 -21
- package/dist/materials/color-nodes/FXAnimatedTextureNode.d.ts +0 -10
- package/dist/materials/color-nodes/FXAnimatedTextureNode.js +0 -41
- package/dist/materials/color-nodes/FXColorOverLifeNode.js +0 -38
- package/dist/materials/color-nodes/FXStaticTextureNode.d.ts +0 -5
- package/dist/materials/color-nodes/FXStaticTextureNode.js +0 -23
- package/dist/materials/miscellaneous.d.ts +0 -1
- package/dist/materials/miscellaneous.js +0 -25
- /package/dist/{materials/color-nodes → nodes/color}/FXColorNode.d.ts +0 -0
- /package/dist/{materials/color-nodes → nodes/color}/FXColorNode.js +0 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { buildGradientTexture } from '../../miscellaneous/miscellaneous.js';
|
|
2
|
+
import { checkSRGBSupport } from '../../miscellaneous/webglCapabilities.js';
|
|
3
|
+
import { FXColorNode } from './FXColorNode.js';
|
|
4
|
+
|
|
5
|
+
const INSTANCES = [];
|
|
6
|
+
class FXColorOverLifeNode extends FXColorNode {
|
|
7
|
+
constructor(colors) {
|
|
8
|
+
if (colors.length === 0) {
|
|
9
|
+
throw new Error("FXColorOverLifeNode: colors array cannot be empty");
|
|
10
|
+
}
|
|
11
|
+
super();
|
|
12
|
+
INSTANCES.push(this);
|
|
13
|
+
const uniformName = `u_ColorOverLife_${INSTANCES.length - 1}`;
|
|
14
|
+
this._private_gradientTexture = buildGradientTexture(colors);
|
|
15
|
+
this.affectsDepth = true;
|
|
16
|
+
this.cacheKey = "color-over-life";
|
|
17
|
+
this.uniformDeclarations = [`uniform sampler2D ${uniformName};`];
|
|
18
|
+
this.uniforms = {
|
|
19
|
+
[uniformName]: { value: this._private_gradientTexture },
|
|
20
|
+
};
|
|
21
|
+
this.helperFunctions = `
|
|
22
|
+
vec4 sampleColorOverLife(sampler2D gradientTexture) {
|
|
23
|
+
// Normalized particle age [0, 1] maps to the gradient texture's x-axis
|
|
24
|
+
float lifetimeRatio = clamp(PARTICLE_AGE / PARTICLE_LIFETIME, 0.0, 1.0);
|
|
25
|
+
vec4 color = texture2D(gradientTexture, vec2(lifetimeRatio, 0.5));
|
|
26
|
+
|
|
27
|
+
// Apply gamma correction when sRGB textures are not natively supported
|
|
28
|
+
${checkSRGBSupport() ? "" : "color = vec4(pow(color.rgb, vec3(2.2)), color.a);"}
|
|
29
|
+
|
|
30
|
+
return color;
|
|
31
|
+
}
|
|
32
|
+
`;
|
|
33
|
+
this.colorExpression = `sampleColorOverLife(${uniformName})`;
|
|
34
|
+
}
|
|
35
|
+
destroy() {
|
|
36
|
+
this._private_gradientTexture.dispose();
|
|
37
|
+
const index = INSTANCES.indexOf(this);
|
|
38
|
+
if (index !== -1) {
|
|
39
|
+
INSTANCES.splice(index, 1);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { FXColorOverLifeNode };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FXNormalNode } from './FXNormalNode.js';
|
|
2
|
+
|
|
3
|
+
class FXFlatNormalNode extends FXNormalNode {
|
|
4
|
+
constructor() {
|
|
5
|
+
super();
|
|
6
|
+
this.cacheKey = "flat";
|
|
7
|
+
this.uniformDeclarations = [];
|
|
8
|
+
this.uniforms = {};
|
|
9
|
+
this.helperFunctions = "";
|
|
10
|
+
this.normalExpression = "vec3(0.0, 0.0, 1.0)";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { FXFlatNormalNode };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { FXNormalNode } from './FXNormalNode.js';
|
|
2
|
+
|
|
3
|
+
class FXSphericalNormalNode extends FXNormalNode {
|
|
4
|
+
constructor() {
|
|
5
|
+
super();
|
|
6
|
+
this.cacheKey = "spherical";
|
|
7
|
+
this.uniformDeclarations = [];
|
|
8
|
+
this.uniforms = {};
|
|
9
|
+
this.helperFunctions = `
|
|
10
|
+
vec3 fxComputeSphericalNormal(vec2 uv) {
|
|
11
|
+
vec2 centeredUV = uv * 2.0 - 1.0;
|
|
12
|
+
return normalize(vec3(centeredUV, sqrt(max(0.0, 1.0 - dot(centeredUV, centeredUV)))));
|
|
13
|
+
}
|
|
14
|
+
`;
|
|
15
|
+
this.normalExpression = "fxComputeSphericalNormal(p_uv)";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { FXSphericalNormalNode };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Texture } from "three";
|
|
2
|
+
import { FXTextureNode } from "./FXTextureNode";
|
|
3
|
+
export interface FXAnimatedTextureNodeOptions {
|
|
4
|
+
texture: Texture;
|
|
5
|
+
columns: number;
|
|
6
|
+
rows: number;
|
|
7
|
+
interpolate?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare class FXAnimatedTextureNode extends FXTextureNode {
|
|
10
|
+
constructor({ texture, columns, rows, interpolate }: FXAnimatedTextureNodeOptions);
|
|
11
|
+
destroy(): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { checkSRGBSupport } from '../../miscellaneous/webglCapabilities.js';
|
|
2
|
+
import { FXTextureNode } from './FXTextureNode.js';
|
|
3
|
+
|
|
4
|
+
const INSTANCES = [];
|
|
5
|
+
class FXAnimatedTextureNode extends FXTextureNode {
|
|
6
|
+
constructor({ texture, columns, rows, interpolate = false }) {
|
|
7
|
+
super();
|
|
8
|
+
INSTANCES.push(this);
|
|
9
|
+
const idx = INSTANCES.length - 1;
|
|
10
|
+
const uniformTexture = `u_AnimatedTexture_${idx}`;
|
|
11
|
+
const uniformColumns = `u_AnimatedTextureColumns_${idx}`;
|
|
12
|
+
const uniformRows = `u_AnimatedTextureRows_${idx}`;
|
|
13
|
+
const gammaCorrection = checkSRGBSupport()
|
|
14
|
+
? ""
|
|
15
|
+
: "color = vec4(pow(color.rgb, vec3(2.2)), color.a);";
|
|
16
|
+
this.affectsDepth = true;
|
|
17
|
+
this.cacheKey = interpolate ? "animated-interpolated" : "animated";
|
|
18
|
+
this.uniformDeclarations = [
|
|
19
|
+
`uniform sampler2D ${uniformTexture};`,
|
|
20
|
+
`uniform float ${uniformColumns};`,
|
|
21
|
+
`uniform float ${uniformRows};`,
|
|
22
|
+
];
|
|
23
|
+
this.uniforms = {
|
|
24
|
+
[uniformTexture]: { value: texture },
|
|
25
|
+
[uniformColumns]: { value: columns },
|
|
26
|
+
[uniformRows]: { value: rows },
|
|
27
|
+
};
|
|
28
|
+
this.helperFunctions = interpolate
|
|
29
|
+
? `
|
|
30
|
+
vec2 frameToUV(vec2 uv, float frame, float columns, float rows) {
|
|
31
|
+
float column = mod(frame, columns);
|
|
32
|
+
float row = floor(frame / columns);
|
|
33
|
+
return vec2((column + uv.x) / columns, 1.0 - (row + 1.0 - uv.y) / rows);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
vec4 sampleAnimatedTexture(sampler2D spriteSheet, vec2 uv, float columns, float rows) {
|
|
37
|
+
float totalFrames = columns * rows;
|
|
38
|
+
|
|
39
|
+
// Fractional frame position drives both frame selection and blend weight
|
|
40
|
+
float exactFrame = PARTICLE_AGE / PARTICLE_LIFETIME * totalFrames;
|
|
41
|
+
float currentFrame = clamp(floor(exactFrame), 0.0, totalFrames - 1.0);
|
|
42
|
+
float nextFrame = clamp(currentFrame + 1.0, 0.0, totalFrames - 1.0);
|
|
43
|
+
float blendWeight = fract(exactFrame);
|
|
44
|
+
|
|
45
|
+
vec4 color = mix(
|
|
46
|
+
texture2D(spriteSheet, frameToUV(uv, currentFrame, columns, rows)),
|
|
47
|
+
texture2D(spriteSheet, frameToUV(uv, nextFrame, columns, rows)),
|
|
48
|
+
blendWeight
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
// Apply gamma correction when sRGB textures are not natively supported
|
|
52
|
+
${gammaCorrection}
|
|
53
|
+
|
|
54
|
+
return color;
|
|
55
|
+
}
|
|
56
|
+
`
|
|
57
|
+
: `
|
|
58
|
+
vec4 sampleAnimatedTexture(sampler2D spriteSheet, vec2 uv, float columns, float rows) {
|
|
59
|
+
// Determine which frame to display based on normalized particle age
|
|
60
|
+
float totalFrames = columns * rows;
|
|
61
|
+
float frame = floor(PARTICLE_AGE / PARTICLE_LIFETIME * totalFrames);
|
|
62
|
+
frame = clamp(frame, 0.0, totalFrames - 1.0);
|
|
63
|
+
|
|
64
|
+
// Locate the frame's column and row in the sprite sheet grid
|
|
65
|
+
float column = mod(frame, columns);
|
|
66
|
+
float row = floor(frame / columns);
|
|
67
|
+
|
|
68
|
+
// Remap UV to the frame's tile region within the sprite sheet
|
|
69
|
+
vec2 frameUV = vec2((column + uv.x) / columns, 1.0 - (row + 1.0 - uv.y) / rows);
|
|
70
|
+
vec4 color = texture2D(spriteSheet, frameUV);
|
|
71
|
+
|
|
72
|
+
// Apply gamma correction when sRGB textures are not natively supported
|
|
73
|
+
${gammaCorrection}
|
|
74
|
+
|
|
75
|
+
return color;
|
|
76
|
+
}
|
|
77
|
+
`;
|
|
78
|
+
this.colorExpression = `sampleAnimatedTexture(${uniformTexture}, p_uv, ${uniformColumns}, ${uniformRows})`;
|
|
79
|
+
}
|
|
80
|
+
destroy() {
|
|
81
|
+
const index = INSTANCES.indexOf(this);
|
|
82
|
+
if (index !== -1) {
|
|
83
|
+
INSTANCES.splice(index, 1);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export { FXAnimatedTextureNode };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { checkSRGBSupport } from '../../miscellaneous/webglCapabilities.js';
|
|
2
|
+
import { FXTextureNode } from './FXTextureNode.js';
|
|
3
|
+
|
|
4
|
+
const INSTANCES = [];
|
|
5
|
+
class FXStaticTextureNode extends FXTextureNode {
|
|
6
|
+
constructor(texture) {
|
|
7
|
+
super();
|
|
8
|
+
INSTANCES.push(this);
|
|
9
|
+
const uniformName = `u_StaticTexture_${INSTANCES.length - 1}`;
|
|
10
|
+
this.affectsDepth = true;
|
|
11
|
+
this.cacheKey = "static";
|
|
12
|
+
this.uniformDeclarations = [`uniform sampler2D ${uniformName};`];
|
|
13
|
+
this.uniforms = {
|
|
14
|
+
[uniformName]: { value: texture },
|
|
15
|
+
};
|
|
16
|
+
this.helperFunctions = `
|
|
17
|
+
vec4 sampleStaticTexture(sampler2D colorTexture, vec2 uv) {
|
|
18
|
+
vec4 color = texture2D(colorTexture, uv);
|
|
19
|
+
// Apply gamma correction when sRGB textures are not natively supported
|
|
20
|
+
${checkSRGBSupport() ? "" : "color = vec4(pow(color.rgb, vec3(2.2)), color.a);"}
|
|
21
|
+
return color;
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
24
|
+
this.colorExpression = `sampleStaticTexture(${uniformName}, p_uv)`;
|
|
25
|
+
}
|
|
26
|
+
destroy() {
|
|
27
|
+
const index = INSTANCES.indexOf(this);
|
|
28
|
+
if (index !== -1) {
|
|
29
|
+
INSTANCES.splice(index, 1);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { FXStaticTextureNode };
|
package/package.json
CHANGED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { buildDepthMaterial } from './FXMaterial.Internal.js';
|
|
2
|
-
|
|
3
|
-
class FXMaterial {
|
|
4
|
-
constructor(options = {}) {
|
|
5
|
-
this.colorNodes = options.colorNodes ?? [];
|
|
6
|
-
this._private_depthAlphaTest = options.depthAlphaTest ?? 0.5;
|
|
7
|
-
this._private_useDepthAlphaHash = options.useDepthAlphaHash ?? false;
|
|
8
|
-
this._private_useSphericalDepth = options.useSphericalDepth ?? false;
|
|
9
|
-
}
|
|
10
|
-
destroy() {
|
|
11
|
-
for (const node of this.colorNodes) {
|
|
12
|
-
node.destroy?.();
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
/** @internal */
|
|
16
|
-
buildDepthMaterial() {
|
|
17
|
-
return buildDepthMaterial(this.colorNodes, this._private_depthAlphaTest, this._private_useDepthAlphaHash, this._private_useSphericalDepth);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export { FXMaterial };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { Texture } from "three";
|
|
2
|
-
import { FXColorNode } from "./FXColorNode";
|
|
3
|
-
export interface FXAnimatedTextureNodeOptions {
|
|
4
|
-
texture: Texture;
|
|
5
|
-
cols: number;
|
|
6
|
-
rows: number;
|
|
7
|
-
}
|
|
8
|
-
export declare class FXAnimatedTextureNode extends FXColorNode {
|
|
9
|
-
constructor({ texture, cols, rows }: FXAnimatedTextureNodeOptions);
|
|
10
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { FXColorNode } from './FXColorNode.js';
|
|
2
|
-
|
|
3
|
-
class FXAnimatedTextureNode extends FXColorNode {
|
|
4
|
-
constructor({ texture, cols, rows }) {
|
|
5
|
-
super();
|
|
6
|
-
/** @internal */
|
|
7
|
-
this.cacheKey = "animated";
|
|
8
|
-
/** @internal */
|
|
9
|
-
this.uniformDeclarations = [
|
|
10
|
-
"uniform sampler2D u_AnimatedTexture;",
|
|
11
|
-
"uniform float u_AnimatedTextureCols;",
|
|
12
|
-
"uniform float u_AnimatedTextureRows;",
|
|
13
|
-
];
|
|
14
|
-
/** @internal */
|
|
15
|
-
this.helperFunctions = `
|
|
16
|
-
vec4 _fx_sampleAnimated(sampler2D tex, vec2 uv, float cols, float rows) {
|
|
17
|
-
float totalFrames = cols * rows;
|
|
18
|
-
float frame = floor(PARTICLE_AGE / PARTICLE_LIFETIME * totalFrames);
|
|
19
|
-
frame = clamp(frame, 0.0, totalFrames - 1.0);
|
|
20
|
-
float col = mod(frame, cols);
|
|
21
|
-
float row = floor(frame / cols);
|
|
22
|
-
vec2 frameUV = vec2((col + uv.x) / cols, 1.0 - (row + 1.0 - uv.y) / rows);
|
|
23
|
-
return texture2D(tex, frameUV);
|
|
24
|
-
}
|
|
25
|
-
`;
|
|
26
|
-
/** @internal */
|
|
27
|
-
this.colorExpression = "_fx_sampleAnimated(u_AnimatedTexture, p_uv, u_AnimatedTextureCols, u_AnimatedTextureRows)";
|
|
28
|
-
/** @internal */
|
|
29
|
-
this.affectsDepth = true;
|
|
30
|
-
this.uniforms = {
|
|
31
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
32
|
-
u_AnimatedTexture: { value: texture },
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
34
|
-
u_AnimatedTextureCols: { value: cols },
|
|
35
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
36
|
-
u_AnimatedTextureRows: { value: rows },
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export { FXAnimatedTextureNode };
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { buildGradientTexture } from '../../miscellaneous/miscellaneous.js';
|
|
2
|
-
import { checkSRGBSupport } from '../../miscellaneous/webglCapabilities.js';
|
|
3
|
-
import { FXColorNode } from './FXColorNode.js';
|
|
4
|
-
|
|
5
|
-
class FXColorOverLifeNode extends FXColorNode {
|
|
6
|
-
constructor(colors) {
|
|
7
|
-
if (colors.length === 0) {
|
|
8
|
-
throw new Error("FXColorOverLifeNode: colors array cannot be empty");
|
|
9
|
-
}
|
|
10
|
-
super();
|
|
11
|
-
/** @internal */
|
|
12
|
-
this.affectsDepth = true;
|
|
13
|
-
/** @internal */
|
|
14
|
-
this.cacheKey = "color-over-life";
|
|
15
|
-
/** @internal */
|
|
16
|
-
this.uniformDeclarations = ["uniform sampler2D u_ColorOverLife;"];
|
|
17
|
-
/** @internal */
|
|
18
|
-
this.colorExpression = "_fx_sampleColorOverLife(u_ColorOverLife)";
|
|
19
|
-
this._private_gradientTexture = buildGradientTexture(colors);
|
|
20
|
-
this.uniforms = {
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
22
|
-
u_ColorOverLife: { value: this._private_gradientTexture },
|
|
23
|
-
};
|
|
24
|
-
this.helperFunctions = `
|
|
25
|
-
vec4 _fx_sampleColorOverLife(sampler2D tex) {
|
|
26
|
-
float t = clamp(PARTICLE_AGE / PARTICLE_LIFETIME, 0.0, 1.0);
|
|
27
|
-
vec4 c = texture2D(tex, vec2(t, 0.5));
|
|
28
|
-
${checkSRGBSupport() ? "" : "c = vec4(pow(c.rgb, vec3(2.2)), c.a);"}
|
|
29
|
-
return c;
|
|
30
|
-
}
|
|
31
|
-
`;
|
|
32
|
-
}
|
|
33
|
-
destroy() {
|
|
34
|
-
this._private_gradientTexture.dispose();
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export { FXColorOverLifeNode };
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { FXColorNode } from './FXColorNode.js';
|
|
2
|
-
|
|
3
|
-
class FXStaticTextureNode extends FXColorNode {
|
|
4
|
-
constructor(texture) {
|
|
5
|
-
super();
|
|
6
|
-
/** @internal */
|
|
7
|
-
this.cacheKey = "static";
|
|
8
|
-
/** @internal */
|
|
9
|
-
this.uniformDeclarations = ["uniform sampler2D u_StaticTexture;"];
|
|
10
|
-
/** @internal */
|
|
11
|
-
this.helperFunctions = "";
|
|
12
|
-
/** @internal */
|
|
13
|
-
this.colorExpression = "texture2D(u_StaticTexture, p_uv)";
|
|
14
|
-
/** @internal */
|
|
15
|
-
this.affectsDepth = true;
|
|
16
|
-
this.uniforms = {
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
18
|
-
u_StaticTexture: { value: texture },
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export { FXStaticTextureNode };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const PARTICLE_DEFINES = "\n #define PARTICLE_POSITION_X p_builtin[0][0]\n #define PARTICLE_POSITION_Y p_builtin[0][1]\n #define PARTICLE_POSITION_Z p_builtin[0][2]\n\n #define PARTICLE_VELOCITY_X p_builtin[0][3]\n #define PARTICLE_VELOCITY_Y p_builtin[1][0]\n #define PARTICLE_VELOCITY_Z p_builtin[1][1]\n\n #define PARTICLE_SCALE_X p_builtin[1][2]\n #define PARTICLE_SCALE_Y p_builtin[1][3]\n #define PARTICLE_SCALE_Z p_builtin[2][0]\n\n #define PARTICLE_ROTATION p_builtin[2][1]\n #define PARTICLE_TORQUE p_builtin[2][2]\n\n #define PARTICLE_LIFETIME p_builtin[2][3]\n #define PARTICLE_AGE p_builtin[3][0]\n\n #define PARTICLE_RANDOM_A p_builtin[3][1]\n #define PARTICLE_RANDOM_B p_builtin[3][2]\n #define PARTICLE_RANDOM_C p_builtin[3][3]\n";
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const PARTICLE_DEFINES = `
|
|
2
|
-
#define PARTICLE_POSITION_X p_builtin[0][0]
|
|
3
|
-
#define PARTICLE_POSITION_Y p_builtin[0][1]
|
|
4
|
-
#define PARTICLE_POSITION_Z p_builtin[0][2]
|
|
5
|
-
|
|
6
|
-
#define PARTICLE_VELOCITY_X p_builtin[0][3]
|
|
7
|
-
#define PARTICLE_VELOCITY_Y p_builtin[1][0]
|
|
8
|
-
#define PARTICLE_VELOCITY_Z p_builtin[1][1]
|
|
9
|
-
|
|
10
|
-
#define PARTICLE_SCALE_X p_builtin[1][2]
|
|
11
|
-
#define PARTICLE_SCALE_Y p_builtin[1][3]
|
|
12
|
-
#define PARTICLE_SCALE_Z p_builtin[2][0]
|
|
13
|
-
|
|
14
|
-
#define PARTICLE_ROTATION p_builtin[2][1]
|
|
15
|
-
#define PARTICLE_TORQUE p_builtin[2][2]
|
|
16
|
-
|
|
17
|
-
#define PARTICLE_LIFETIME p_builtin[2][3]
|
|
18
|
-
#define PARTICLE_AGE p_builtin[3][0]
|
|
19
|
-
|
|
20
|
-
#define PARTICLE_RANDOM_A p_builtin[3][1]
|
|
21
|
-
#define PARTICLE_RANDOM_B p_builtin[3][2]
|
|
22
|
-
#define PARTICLE_RANDOM_C p_builtin[3][3]
|
|
23
|
-
`;
|
|
24
|
-
|
|
25
|
-
export { PARTICLE_DEFINES };
|
|
File without changes
|
|
File without changes
|