sparcoon 0.1.0 → 0.2.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.
Files changed (100) hide show
  1. package/dist/{elements → emitter}/FXEmitter.Internal.d.ts +0 -4
  2. package/dist/emitter/FXEmitter.Internal.js +7 -0
  3. package/dist/{elements → emitter}/FXEmitter.d.ts +6 -13
  4. package/dist/{elements → emitter}/FXEmitter.js +15 -22
  5. package/dist/{behaviorModules → emitter/behavior}/FXBehaviorDirectionalGravity.d.ts +2 -2
  6. package/dist/{behaviorModules → emitter/behavior}/FXBehaviorDirectionalGravity.js +2 -2
  7. package/dist/{behaviorModules → emitter/behavior}/FXBehaviorModule.d.ts +1 -1
  8. package/dist/{behaviorModules → emitter/behavior}/FXBehaviorPointGravity.d.ts +2 -2
  9. package/dist/{behaviorModules → emitter/behavior}/FXBehaviorPointGravity.js +2 -2
  10. package/dist/{behaviorModules → emitter/behavior}/FXBehaviorScaleOverLife.d.ts +1 -1
  11. package/dist/{behaviorModules → emitter/behavior}/FXBehaviorScaleOverLife.js +2 -2
  12. package/dist/{behaviorModules → emitter/behavior}/FXBehaviorTorqueDamping.d.ts +1 -1
  13. package/dist/{behaviorModules → emitter/behavior}/FXBehaviorTorqueDamping.js +2 -2
  14. package/dist/{behaviorModules → emitter/behavior}/FXBehaviorTorqueNoise.d.ts +1 -1
  15. package/dist/{behaviorModules → emitter/behavior}/FXBehaviorTorqueNoise.js +3 -3
  16. package/dist/{behaviorModules → emitter/behavior}/FXBehaviorVelocityDamping.d.ts +1 -1
  17. package/dist/{behaviorModules → emitter/behavior}/FXBehaviorVelocityDamping.js +2 -2
  18. package/dist/{behaviorModules → emitter/behavior}/FXBehaviorVelocityNoise.d.ts +1 -1
  19. package/dist/{behaviorModules → emitter/behavior}/FXBehaviorVelocityNoise.js +3 -3
  20. package/dist/{spawnModules → emitter/spawn}/FXSpawnBox.d.ts +2 -2
  21. package/dist/{spawnModules → emitter/spawn}/FXSpawnBox.js +2 -2
  22. package/dist/{spawnModules → emitter/spawn}/FXSpawnModule.d.ts +1 -1
  23. package/dist/{spawnModules → emitter/spawn}/FXSpawnOffset.d.ts +2 -2
  24. package/dist/{spawnModules → emitter/spawn}/FXSpawnOffset.js +2 -2
  25. package/dist/{spawnModules → emitter/spawn}/FXSpawnRandomLifetime.d.ts +1 -1
  26. package/dist/{spawnModules → emitter/spawn}/FXSpawnRandomLifetime.js +2 -2
  27. package/dist/{spawnModules → emitter/spawn}/FXSpawnRandomRotation.d.ts +1 -1
  28. package/dist/{spawnModules → emitter/spawn}/FXSpawnRandomRotation.js +2 -2
  29. package/dist/{spawnModules → emitter/spawn}/FXSpawnRandomScale.d.ts +1 -1
  30. package/dist/{spawnModules → emitter/spawn}/FXSpawnRandomScale.js +2 -2
  31. package/dist/{spawnModules → emitter/spawn}/FXSpawnRandomTorque.d.ts +1 -1
  32. package/dist/{spawnModules → emitter/spawn}/FXSpawnRandomTorque.js +2 -2
  33. package/dist/{spawnModules → emitter/spawn}/FXSpawnRandomVelocity.d.ts +1 -1
  34. package/dist/{spawnModules → emitter/spawn}/FXSpawnRandomVelocity.js +2 -2
  35. package/dist/emitter/spawn/FXSpawnSphere.d.ts +38 -0
  36. package/dist/emitter/spawn/FXSpawnSphere.js +89 -0
  37. package/dist/index.d.ts +24 -20
  38. package/dist/index.js +25 -22
  39. package/dist/instancedParticle/FXInstancedParticle.Internal.d.ts +2 -9
  40. package/dist/instancedParticle/FXInstancedParticle.Internal.js +2 -188
  41. package/dist/instancedParticle/FXInstancedParticle.d.ts +3 -5
  42. package/dist/instancedParticle/FXInstancedParticle.js +4 -10
  43. package/dist/instancedParticle/shared.d.ts +1 -1
  44. package/dist/instancedParticle/shared.js +1 -1
  45. package/dist/materials/FXDiffuseMaterial/FXDiffuseMaterial.Internal.d.ts +9 -0
  46. package/dist/materials/FXDiffuseMaterial/FXDiffuseMaterial.Internal.js +108 -0
  47. package/dist/materials/FXDiffuseMaterial/FXDiffuseMaterial.d.ts +15 -0
  48. package/dist/materials/FXDiffuseMaterial/FXDiffuseMaterial.js +18 -0
  49. package/dist/materials/FXMaterial.Internal.d.ts +4 -0
  50. package/dist/materials/FXMaterial.Internal.js +106 -0
  51. package/dist/materials/FXMaterial.d.ts +14 -0
  52. package/dist/materials/FXMaterial.js +21 -0
  53. package/dist/materials/FXUnlitMaterial/FXUnlitMaterial.Internal.d.ts +4 -0
  54. package/dist/materials/FXUnlitMaterial/FXUnlitMaterial.Internal.js +80 -0
  55. package/dist/materials/FXUnlitMaterial/FXUnlitMaterial.d.ts +11 -0
  56. package/dist/materials/FXUnlitMaterial/FXUnlitMaterial.js +17 -0
  57. package/dist/materials/color-nodes/FXAnimatedTextureNode.d.ts +10 -0
  58. package/dist/materials/color-nodes/FXAnimatedTextureNode.js +41 -0
  59. package/dist/materials/color-nodes/FXColorNode.d.ts +3 -0
  60. package/dist/materials/color-nodes/FXColorNode.js +8 -0
  61. package/dist/materials/color-nodes/FXColorOverLifeNode.d.ts +7 -0
  62. package/dist/materials/color-nodes/FXColorOverLifeNode.js +38 -0
  63. package/dist/materials/color-nodes/FXStaticTextureNode.d.ts +5 -0
  64. package/dist/materials/color-nodes/FXStaticTextureNode.js +23 -0
  65. package/dist/materials/miscellaneous.d.ts +1 -0
  66. package/dist/materials/miscellaneous.js +25 -0
  67. package/dist/{color → miscellaneous/color}/FXColor.js +2 -2
  68. package/dist/miscellaneous/miscellaneous.d.ts +1 -1
  69. package/package.json +1 -1
  70. package/dist/elements/FXEmitter.Internal.js +0 -12
  71. package/dist/instancedParticle/FXParticleDepthMaterial.d.ts +0 -2
  72. package/dist/instancedParticle/FXParticleDepthMaterial.js +0 -52
  73. package/dist/instancedParticle/FXParticleLambertMaterial.d.ts +0 -4
  74. package/dist/instancedParticle/FXParticleLambertMaterial.js +0 -152
  75. package/dist/instancedParticle/FXParticleNormalsMode.d.ts +0 -5
  76. package/dist/instancedParticle/FXParticleNormalsMode.js +0 -8
  77. package/dist/instancedParticle/FXParticleRenderingMode.d.ts +0 -4
  78. package/dist/instancedParticle/FXParticleRenderingMode.js +0 -7
  79. package/dist/miscellaneous/texture/FXTextureView.Internal.js +0 -6
  80. package/dist/miscellaneous/texture/FXTextureView.js +0 -234
  81. package/dist/renderingModules/FXRenderingAnimatedTexture.d.ts +0 -5
  82. package/dist/renderingModules/FXRenderingAnimatedTexture.js +0 -14
  83. package/dist/renderingModules/FXRenderingColorOverLife.d.ts +0 -14
  84. package/dist/renderingModules/FXRenderingColorOverLife.js +0 -32
  85. package/dist/renderingModules/FXRenderingColorOverVelocity.d.ts +0 -15
  86. package/dist/renderingModules/FXRenderingColorOverVelocity.js +0 -37
  87. package/dist/renderingModules/FXRenderingModule.d.ts +0 -8
  88. package/dist/renderingModules/FXRenderingModule.js +0 -9
  89. package/dist/renderingModules/FXRenderingShadow.d.ts +0 -12
  90. package/dist/renderingModules/FXRenderingTexture.d.ts +0 -14
  91. package/dist/renderingModules/FXRenderingTexture.js +0 -26
  92. package/dist/shaders/FXRenderingAnimatedTexture.glsl.js +0 -3
  93. package/dist/shaders/FXRenderingColorOverLife.glsl.js +0 -3
  94. package/dist/shaders/FXRenderingColorOverVelocity.glsl.js +0 -3
  95. package/dist/shaders/FXRenderingTexture.glsl.js +0 -3
  96. /package/dist/{behaviorModules → emitter/behavior}/FXBehaviorModule.js +0 -0
  97. /package/dist/{spawnModules → emitter/spawn}/FXSpawnModule.js +0 -0
  98. /package/dist/{color → miscellaneous/color}/FXColor.Internal.d.ts +0 -0
  99. /package/dist/{color → miscellaneous/color}/FXColor.Internal.js +0 -0
  100. /package/dist/{color → miscellaneous/color}/FXColor.d.ts +0 -0
@@ -0,0 +1,80 @@
1
+ import { MeshBasicMaterial, DoubleSide } from 'three';
2
+ import { PARTICLE_DEFINES } from '../miscellaneous.js';
3
+
4
+ function buildFXUnlitMaterial(varyings, blending, useAlphaHashing, colorNodes) {
5
+ const attributeDeclarations = [];
6
+ const varyingDeclarations = [];
7
+ const vertexAssignments = [];
8
+ for (const name in varyings) {
9
+ const { glslTypeName } = varyings[name];
10
+ attributeDeclarations.push(`attribute ${glslTypeName} a_${name};`);
11
+ varyingDeclarations.push(`varying ${glslTypeName} p_${name};`);
12
+ vertexAssignments.push(`p_${name} = a_${name};`);
13
+ }
14
+ const material = new MeshBasicMaterial({
15
+ transparent: !useAlphaHashing,
16
+ depthWrite: useAlphaHashing,
17
+ depthTest: true,
18
+ alphaHash: useAlphaHashing,
19
+ blending,
20
+ side: DoubleSide,
21
+ forceSinglePass: true,
22
+ alphaTest: 1 / 255,
23
+ });
24
+ material.onBeforeCompile = (shader) => {
25
+ const vertexPreamble = [
26
+ PARTICLE_DEFINES,
27
+ attributeDeclarations.join("\n"),
28
+ "varying vec2 p_uv;",
29
+ varyingDeclarations.join("\n"),
30
+ ].join("\n");
31
+ shader.vertexShader =
32
+ vertexPreamble +
33
+ "\n" +
34
+ shader.vertexShader
35
+ .replace("#include <begin_vertex>", [
36
+ "p_uv = uv;",
37
+ vertexAssignments.join("\n"),
38
+ "vec3 transformed = position;",
39
+ "#ifdef USE_ALPHAHASH",
40
+ " vPosition = vec3(PARTICLE_POSITION_X, PARTICLE_POSITION_Y, PARTICLE_POSITION_Z) + vec3(position.xy, 0.0);",
41
+ "#endif",
42
+ ].join("\n"))
43
+ .replace("#include <project_vertex>", `
44
+ vec2 p_bp = position.xy;
45
+ p_bp.x *= PARTICLE_SCALE_X;
46
+ p_bp.y *= PARTICLE_SCALE_Y;
47
+ float p_cosR = cos(PARTICLE_ROTATION);
48
+ float p_sinR = sin(PARTICLE_ROTATION);
49
+ p_bp = vec2(
50
+ p_bp.x * p_cosR - p_bp.y * p_sinR,
51
+ p_bp.x * p_sinR + p_bp.y * p_cosR
52
+ );
53
+ vec3 p_c = vec3(PARTICLE_POSITION_X, PARTICLE_POSITION_Y, PARTICLE_POSITION_Z);
54
+ vec4 mvPosition = modelViewMatrix * vec4(p_c, 1.0);
55
+ mvPosition.xy += p_bp;
56
+ gl_Position = projectionMatrix * mvPosition;
57
+ `);
58
+ const fragmentPreamble = [
59
+ PARTICLE_DEFINES,
60
+ "varying vec2 p_uv;",
61
+ varyingDeclarations.join("\n"),
62
+ colorNodes.flatMap((n) => n.uniformDeclarations).join("\n"),
63
+ colorNodes.map((n) => n.helperFunctions).join("\n"),
64
+ ].join("\n");
65
+ for (const node of colorNodes) {
66
+ Object.assign(shader.uniforms, node.uniforms);
67
+ }
68
+ let fragmentShader = shader.fragmentShader;
69
+ if (colorNodes.length > 0) {
70
+ const combinedExpression = colorNodes.map((n) => n.colorExpression).join(" * ");
71
+ const discardLine = useAlphaHashing ? "" : "if (diffuseColor.a < 0.0035) discard;";
72
+ fragmentShader = fragmentShader.replace("#include <map_fragment>", `diffuseColor = ${combinedExpression}; ${discardLine}`);
73
+ }
74
+ shader.fragmentShader = fragmentPreamble + "\n" + fragmentShader;
75
+ };
76
+ material.customProgramCacheKey = () => `fx-unlit-${colorNodes.map((n) => n.cacheKey).join("-") || "none"}`;
77
+ return material;
78
+ }
79
+
80
+ export { buildFXUnlitMaterial };
@@ -0,0 +1,11 @@
1
+ import { type Blending } from "three";
2
+ import { FXMaterial, type FXMaterialOptions } from "../FXMaterial";
3
+ export interface FXUnlitMaterialOptions extends FXMaterialOptions {
4
+ blending: Blending;
5
+ useAlphaHashing: boolean;
6
+ }
7
+ export declare class FXUnlitMaterial extends FXMaterial {
8
+ private readonly blending;
9
+ private readonly useAlphaHashing;
10
+ constructor(options?: Partial<FXUnlitMaterialOptions>);
11
+ }
@@ -0,0 +1,17 @@
1
+ import { NormalBlending } from 'three';
2
+ import { FXMaterial } from '../FXMaterial.js';
3
+ import { buildFXUnlitMaterial } from './FXUnlitMaterial.Internal.js';
4
+
5
+ class FXUnlitMaterial extends FXMaterial {
6
+ constructor(options = {}) {
7
+ super(options);
8
+ this._private_blending = options.blending ?? NormalBlending;
9
+ this._private_useAlphaHashing = options.useAlphaHashing ?? false;
10
+ }
11
+ /** @internal */
12
+ buildThreeMaterial(varyings) {
13
+ return buildFXUnlitMaterial(varyings, this._private_blending, this._private_useAlphaHashing, this.colorNodes);
14
+ }
15
+ }
16
+
17
+ export { FXUnlitMaterial };
@@ -0,0 +1,10 @@
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
+ }
@@ -0,0 +1,41 @@
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 };
@@ -0,0 +1,3 @@
1
+ export declare abstract class FXColorNode {
2
+ destroy?(): void;
3
+ }
@@ -0,0 +1,8 @@
1
+ class FXColorNode {
2
+ constructor() {
3
+ /** @internal */
4
+ this.affectsDepth = false;
5
+ }
6
+ }
7
+
8
+ export { FXColorNode };
@@ -0,0 +1,7 @@
1
+ import type { FXColor } from "../../miscellaneous/color/FXColor";
2
+ import { FXColorNode } from "./FXColorNode";
3
+ export declare class FXColorOverLifeNode extends FXColorNode {
4
+ private readonly gradientTexture;
5
+ constructor(colors: FXColor[]);
6
+ destroy(): void;
7
+ }
@@ -0,0 +1,38 @@
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 };
@@ -0,0 +1,5 @@
1
+ import type { Texture } from "three";
2
+ import { FXColorNode } from "./FXColorNode";
3
+ export declare class FXStaticTextureNode extends FXColorNode {
4
+ constructor(texture: Texture);
5
+ }
@@ -0,0 +1,23 @@
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 };
@@ -0,0 +1 @@
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";
@@ -0,0 +1,25 @@
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 };
@@ -1,6 +1,6 @@
1
1
  import { MathUtils, Color, Vector4 } from 'three';
2
- import { assertValidNumber } from '../miscellaneous/asserts.js';
3
- import { srgbToLinear, linearToSRGB } from '../miscellaneous/math.js';
2
+ import { assertValidNumber } from '../asserts.js';
3
+ import { srgbToLinear, linearToSRGB } from '../math.js';
4
4
  import { COLORS } from './FXColor.Internal.js';
5
5
 
6
6
  /** RGBA color with RGB, HSL, hex, and named color support */
@@ -1,8 +1,8 @@
1
1
  import type { Vector3Tuple } from "three";
2
2
  import { DataTexture } from "three";
3
- import type { FXColor } from "../color/FXColor";
4
3
  import type { Vector3Like } from "../miscellaneous/math";
5
4
  import type { FXTextureConfig } from "../miscellaneous/texture/FXTextureView.Internal";
5
+ import type { FXColor } from "./color/FXColor";
6
6
  export interface FXRange {
7
7
  min: number;
8
8
  max: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sparcoon",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "particles",
@@ -1,12 +0,0 @@
1
- import { FXParticleNormalsMode } from '../instancedParticle/FXParticleNormalsMode.js';
2
- import { FXParticleRenderingMode } from '../instancedParticle/FXParticleRenderingMode.js';
3
-
4
- const EMITTER_DEFAULT_EXPECTED_CAPACITY = 32;
5
- const EMITTER_DEFAULT_CAPACITY_STEP = 32;
6
- const EMITTER_DEFAULT_AUTOMATICALLY_DESTROY_MODULES = true;
7
- const EMITTER_DEFAULT_CAST_SHADOW = false;
8
- const EMITTER_DEFAULT_RECEIVE_SHADOW = false;
9
- const EMITTER_DEFAULT_RENDERING_MODE = FXParticleRenderingMode.Unlit;
10
- const EMITTER_DEFAULT_NORMALS_MODE = FXParticleNormalsMode.Flat;
11
-
12
- export { EMITTER_DEFAULT_AUTOMATICALLY_DESTROY_MODULES, EMITTER_DEFAULT_CAPACITY_STEP, EMITTER_DEFAULT_CAST_SHADOW, EMITTER_DEFAULT_EXPECTED_CAPACITY, EMITTER_DEFAULT_NORMALS_MODE, EMITTER_DEFAULT_RECEIVE_SHADOW, EMITTER_DEFAULT_RENDERING_MODE };
@@ -1,2 +0,0 @@
1
- import { MeshDepthMaterial } from "three";
2
- export declare function buildParticleDepthMaterial(): MeshDepthMaterial;
@@ -1,52 +0,0 @@
1
- import { MeshDepthMaterial, RGBADepthPacking } from 'three';
2
-
3
- const PARTICLE_DEPTH_VERTEX_SHADER = `
4
- #define PARTICLE_POSITION_X a_builtin[0][0]
5
- #define PARTICLE_POSITION_Y a_builtin[0][1]
6
- #define PARTICLE_POSITION_Z a_builtin[0][2]
7
-
8
- #define PARTICLE_SCALE_X a_builtin[1][2]
9
- #define PARTICLE_SCALE_Y a_builtin[1][3]
10
-
11
- #define PARTICLE_ROTATION a_builtin[2][1]
12
-
13
- attribute mat4 a_builtin;
14
-
15
- varying vec2 vHighPrecisionZW;
16
-
17
- void main() {
18
- vec2 transformedPosition = position.xy;
19
-
20
- transformedPosition.x *= PARTICLE_SCALE_X;
21
- transformedPosition.y *= PARTICLE_SCALE_Y;
22
-
23
- float cosR = cos(PARTICLE_ROTATION);
24
- float sinR = sin(PARTICLE_ROTATION);
25
-
26
- transformedPosition = vec2(
27
- transformedPosition.x * cosR - transformedPosition.y * sinR,
28
- transformedPosition.x * sinR + transformedPosition.y * cosR
29
- );
30
-
31
- vec3 center = vec3(
32
- PARTICLE_POSITION_X,
33
- PARTICLE_POSITION_Y,
34
- PARTICLE_POSITION_Z
35
- );
36
-
37
- vec4 modelViewCenter = modelViewMatrix * vec4(center, 1.0);
38
- modelViewCenter.xy += transformedPosition;
39
- gl_Position = projectionMatrix * modelViewCenter;
40
- vHighPrecisionZW = gl_Position.zw;
41
- }
42
- `;
43
- function buildParticleDepthMaterial() {
44
- const material = new MeshDepthMaterial({ depthPacking: RGBADepthPacking });
45
- material.onBeforeCompile = (shader) => {
46
- shader.vertexShader = PARTICLE_DEPTH_VERTEX_SHADER;
47
- };
48
- material.customProgramCacheKey = () => "fx-particle-depth";
49
- return material;
50
- }
51
-
52
- export { buildParticleDepthMaterial };
@@ -1,4 +0,0 @@
1
- import { MeshLambertMaterial, type Blending } from "three";
2
- import { FXParticleNormalsMode } from "./FXParticleNormalsMode";
3
- import type { GLProperty, GLTypeInfo } from "./shared";
4
- export declare function buildParticleLambertMaterial(sources: string[], uniformProperties: Record<string, GLProperty>, varyingProperties: Record<string, GLTypeInfo>, blending: Blending, useAlphaHashing: boolean, normalsMode: FXParticleNormalsMode): MeshLambertMaterial;
@@ -1,152 +0,0 @@
1
- import { MeshLambertMaterial } from 'three';
2
- import { FXColor } from '../color/FXColor.js';
3
- import { checkSRGBSupport } from '../miscellaneous/webglCapabilities.js';
4
- import { FXParticleNormalsMode } from './FXParticleNormalsMode.js';
5
-
6
- const PARTICLE_DEFINES = `
7
- #define PARTICLE_POSITION_X p_builtin[0][0]
8
- #define PARTICLE_POSITION_Y p_builtin[0][1]
9
- #define PARTICLE_POSITION_Z p_builtin[0][2]
10
-
11
- #define PARTICLE_VELOCITY_X p_builtin[0][3]
12
- #define PARTICLE_VELOCITY_Y p_builtin[1][0]
13
- #define PARTICLE_VELOCITY_Z p_builtin[1][1]
14
-
15
- #define PARTICLE_SCALE_X p_builtin[1][2]
16
- #define PARTICLE_SCALE_Y p_builtin[1][3]
17
- #define PARTICLE_SCALE_Z p_builtin[2][0]
18
-
19
- #define PARTICLE_ROTATION p_builtin[2][1]
20
- #define PARTICLE_TORQUE p_builtin[2][2]
21
-
22
- #define PARTICLE_LIFETIME p_builtin[2][3]
23
- #define PARTICLE_AGE p_builtin[3][0]
24
-
25
- #define PARTICLE_RANDOM_A p_builtin[3][1]
26
- #define PARTICLE_RANDOM_B p_builtin[3][2]
27
- #define PARTICLE_RANDOM_C p_builtin[3][3]
28
- `;
29
- function buildParticleLambertMaterial(sources, uniformProperties, varyingProperties, blending, useAlphaHashing, normalsMode) {
30
- const uniformValues = {};
31
- const uniformDeclarations = [];
32
- const attributeDeclarations = [];
33
- const varyingDeclarations = [];
34
- const vertexAssignments = [];
35
- for (const name in uniformProperties) {
36
- const { value, glslTypeInfo } = uniformProperties[name];
37
- uniformValues[`p_${name}`] = { value: value instanceof FXColor ? value.toGLSLColor() : value };
38
- uniformDeclarations.push(`uniform ${glslTypeInfo.glslTypeName} p_${name};`);
39
- }
40
- for (const name in varyingProperties) {
41
- const { glslTypeName } = varyingProperties[name];
42
- attributeDeclarations.push(`attribute ${glslTypeName} a_${name};`);
43
- varyingDeclarations.push(`varying ${glslTypeName} p_${name};`);
44
- vertexAssignments.push(`p_${name} = a_${name};`);
45
- }
46
- const renamedSources = sources.map((source, index) => source.replace(/vec4\s+draw\s*\(\s*\)/g, `vec4 draw${index}()`));
47
- let drawCalls = "";
48
- for (let i = 0; i < sources.length; i++) {
49
- drawCalls += i !== 0 ? " * " : "";
50
- drawCalls += `draw${i}()`;
51
- }
52
- const srgbSupported = checkSRGBSupport() ? "1" : "0";
53
- const srgbHelper = `
54
- vec4 srgbTexture2D(sampler2D textureSampler, vec2 uv) {
55
- #if SRGB_SUPPORTED
56
- return texture2D(textureSampler, uv);
57
- #else
58
- vec4 textureValue = texture2D(textureSampler, uv);
59
- return vec4(pow(textureValue.rgb, vec3(2.2)), textureValue.a);
60
- #endif
61
- }
62
- `;
63
- const material = new MeshLambertMaterial({
64
- transparent: true,
65
- depthWrite: false,
66
- depthTest: true,
67
- alphaHash: useAlphaHashing,
68
- blending,
69
- });
70
- material.onBeforeCompile = (shader) => {
71
- Object.assign(shader.uniforms, uniformValues);
72
- // --- Vertex shader ---
73
- const vertexPreamble = [
74
- PARTICLE_DEFINES,
75
- attributeDeclarations.join("\n"),
76
- "varying vec2 p_uv;",
77
- varyingDeclarations.join("\n"),
78
- ].join("\n");
79
- shader.vertexShader =
80
- vertexPreamble +
81
- "\n" +
82
- shader.vertexShader
83
- // Hardcode objectNormal — no normal attribute on billboard geometry
84
- .replace("#include <beginnormal_vertex>", "vec3 objectNormal = vec3(0.0, 0.0, 1.0);")
85
- // Hardcode transformedNormal as view-space camera-facing (0,0,1)
86
- .replace("#include <defaultnormal_vertex>", "vec3 transformedNormal = vec3(0.0, 0.0, 1.0);")
87
- // Set p_uv, user varyings, placeholder transformed for downstream chunks
88
- .replace("#include <begin_vertex>", ["p_uv = uv;", vertexAssignments.join("\n"), "vec3 transformed = position;"].join("\n"))
89
- // Billboard projection: computes p_bp (screen offset) and p_c (center), sets mvPosition
90
- .replace("#include <project_vertex>", `
91
- vec2 p_bp = position.xy;
92
- p_bp.x *= PARTICLE_SCALE_X;
93
- p_bp.y *= PARTICLE_SCALE_Y;
94
- float p_cosR = cos(PARTICLE_ROTATION);
95
- float p_sinR = sin(PARTICLE_ROTATION);
96
- p_bp = vec2(
97
- p_bp.x * p_cosR - p_bp.y * p_sinR,
98
- p_bp.x * p_sinR + p_bp.y * p_cosR
99
- );
100
- vec3 p_c = vec3(PARTICLE_POSITION_X, PARTICLE_POSITION_Y, PARTICLE_POSITION_Z);
101
- vec4 mvPosition = modelViewMatrix * vec4(p_c, 1.0);
102
- mvPosition.xy += p_bp;
103
- gl_Position = projectionMatrix * mvPosition;
104
- `)
105
- // Billboard world position — p_c and p_bp in scope from project_vertex above
106
- .replace("#include <worldpos_vertex>", `
107
- #if defined(USE_SHADOWMAP) || defined(USE_ENVMAP) || defined(DISTANCE) || (NUM_SPOT_LIGHT_COORDS > 0)
108
- vec3 p_cr = vec3(viewMatrix[0][0], viewMatrix[1][0], viewMatrix[2][0]);
109
- vec3 p_cu = vec3(viewMatrix[0][1], viewMatrix[1][1], viewMatrix[2][1]);
110
- vec4 worldPosition = vec4(
111
- (modelMatrix * vec4(p_c, 1.0)).xyz + p_cr * p_bp.x + p_cu * p_bp.y,
112
- 1.0
113
- );
114
- #endif
115
- `);
116
- // --- Fragment shader ---
117
- const fragmentPreamble = [
118
- PARTICLE_DEFINES,
119
- `#define SRGB_SUPPORTED ${srgbSupported}`,
120
- uniformDeclarations.join("\n"),
121
- "varying vec2 p_uv;",
122
- varyingDeclarations.join("\n"),
123
- srgbHelper,
124
- renamedSources.join("\n"),
125
- ].join("\n");
126
- let fragmentShader = shader.fragmentShader;
127
- if (normalsMode === FXParticleNormalsMode.Spherical) {
128
- fragmentShader = fragmentShader.replace("#include <normal_fragment_begin>", `
129
- float faceDirection = gl_FrontFacing ? 1.0 : -1.0;
130
- vec2 p_sn = p_uv * 2.0 - 1.0;
131
- vec3 normal = normalize(vec3(p_sn, sqrt(max(0.0, 1.0 - dot(p_sn, p_sn)))));
132
- `);
133
- }
134
- else if (normalsMode === FXParticleNormalsMode.TowardsLight) {
135
- fragmentShader = fragmentShader.replace("float dotNL = saturate( dot( geometryNormal, directLight.direction ) );", "float dotNL = 1.0;");
136
- }
137
- shader.fragmentShader =
138
- fragmentPreamble +
139
- "\n" +
140
- fragmentShader
141
- // Inject custom diffuse color from draw() pipeline
142
- .replace("#include <map_fragment>", `
143
- vec4 p_color = ${drawCalls};
144
- if (p_color.a < 0.0035) discard;
145
- diffuseColor = p_color;
146
- `);
147
- };
148
- material.customProgramCacheKey = () => `fx-particle-lambert-${normalsMode}-${sources.join("|")}`;
149
- return material;
150
- }
151
-
152
- export { buildParticleLambertMaterial };
@@ -1,5 +0,0 @@
1
- export declare enum FXParticleNormalsMode {
2
- Flat = "flat",
3
- Spherical = "spherical",
4
- TowardsLight = "towards-light"
5
- }
@@ -1,8 +0,0 @@
1
- var FXParticleNormalsMode;
2
- (function (FXParticleNormalsMode) {
3
- FXParticleNormalsMode["Flat"] = "flat";
4
- FXParticleNormalsMode["Spherical"] = "spherical";
5
- FXParticleNormalsMode["TowardsLight"] = "towards-light";
6
- })(FXParticleNormalsMode || (FXParticleNormalsMode = {}));
7
-
8
- export { FXParticleNormalsMode };
@@ -1,4 +0,0 @@
1
- export declare enum FXParticleRenderingMode {
2
- Unlit = "unlit",
3
- Lambert = "lambert"
4
- }
@@ -1,7 +0,0 @@
1
- var FXParticleRenderingMode;
2
- (function (FXParticleRenderingMode) {
3
- FXParticleRenderingMode["Unlit"] = "unlit";
4
- FXParticleRenderingMode["Lambert"] = "lambert";
5
- })(FXParticleRenderingMode || (FXParticleRenderingMode = {}));
6
-
7
- export { FXParticleRenderingMode };
@@ -1,6 +0,0 @@
1
- import { Texture } from 'three';
2
-
3
- const TEXTURE_DEFAULT_TEXTURE = new Texture();
4
- const TEXTURE_DEFAULT_SIZE = 2;
5
-
6
- export { TEXTURE_DEFAULT_SIZE, TEXTURE_DEFAULT_TEXTURE };