sparcoon 0.1.0 → 0.3.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 (109) hide show
  1. package/dist/{elements → emitter}/FXEmitter.Internal.d.ts +4 -4
  2. package/dist/emitter/FXEmitter.Internal.js +26 -0
  3. package/dist/emitter/FXEmitter.d.ts +31 -0
  4. package/dist/{elements → emitter}/FXEmitter.js +14 -22
  5. package/dist/{behaviorModules/FXBehaviorModule.d.ts → emitter/behavior/FXBehavior.d.ts} +2 -2
  6. package/dist/{behaviorModules/FXBehaviorModule.js → emitter/behavior/FXBehavior.js} +2 -2
  7. package/dist/{behaviorModules → emitter/behavior}/FXBehaviorDirectionalGravity.d.ts +4 -4
  8. package/dist/{behaviorModules → emitter/behavior}/FXBehaviorDirectionalGravity.js +4 -4
  9. package/dist/{behaviorModules → emitter/behavior}/FXBehaviorPointGravity.d.ts +4 -4
  10. package/dist/{behaviorModules → emitter/behavior}/FXBehaviorPointGravity.js +4 -4
  11. package/dist/{behaviorModules → emitter/behavior}/FXBehaviorScaleOverLife.d.ts +3 -3
  12. package/dist/{behaviorModules → emitter/behavior}/FXBehaviorScaleOverLife.js +4 -4
  13. package/dist/{behaviorModules → emitter/behavior}/FXBehaviorTorqueDamping.d.ts +3 -3
  14. package/dist/{behaviorModules → emitter/behavior}/FXBehaviorTorqueDamping.js +4 -4
  15. package/dist/{behaviorModules → emitter/behavior}/FXBehaviorTorqueNoise.d.ts +3 -3
  16. package/dist/{behaviorModules → emitter/behavior}/FXBehaviorTorqueNoise.js +5 -5
  17. package/dist/{behaviorModules → emitter/behavior}/FXBehaviorVelocityDamping.d.ts +3 -3
  18. package/dist/{behaviorModules → emitter/behavior}/FXBehaviorVelocityDamping.js +4 -4
  19. package/dist/{behaviorModules → emitter/behavior}/FXBehaviorVelocityNoise.d.ts +3 -3
  20. package/dist/{behaviorModules → emitter/behavior}/FXBehaviorVelocityNoise.js +5 -5
  21. package/dist/emitter/spawn/FXSpawn.d.ts +9 -0
  22. package/dist/{spawnModules/FXSpawnModule.js → emitter/spawn/FXSpawn.js} +2 -2
  23. package/dist/{spawnModules → emitter/spawn}/FXSpawnBox.d.ts +4 -4
  24. package/dist/{spawnModules → emitter/spawn}/FXSpawnBox.js +4 -4
  25. package/dist/{spawnModules/FXSpawnOffset.d.ts → emitter/spawn/FXSpawnPoint.d.ts} +4 -4
  26. package/dist/{spawnModules/FXSpawnOffset.js → emitter/spawn/FXSpawnPoint.js} +5 -5
  27. package/dist/{spawnModules → emitter/spawn}/FXSpawnRandomLifetime.d.ts +3 -3
  28. package/dist/{spawnModules → emitter/spawn}/FXSpawnRandomLifetime.js +4 -4
  29. package/dist/{spawnModules → emitter/spawn}/FXSpawnRandomRotation.d.ts +3 -3
  30. package/dist/{spawnModules → emitter/spawn}/FXSpawnRandomRotation.js +4 -4
  31. package/dist/{spawnModules → emitter/spawn}/FXSpawnRandomScale.d.ts +3 -3
  32. package/dist/{spawnModules → emitter/spawn}/FXSpawnRandomScale.js +4 -4
  33. package/dist/{spawnModules → emitter/spawn}/FXSpawnRandomTorque.d.ts +3 -3
  34. package/dist/{spawnModules → emitter/spawn}/FXSpawnRandomTorque.js +4 -4
  35. package/dist/{spawnModules → emitter/spawn}/FXSpawnRandomVelocity.d.ts +3 -3
  36. package/dist/{spawnModules → emitter/spawn}/FXSpawnRandomVelocity.js +4 -4
  37. package/dist/emitter/spawn/FXSpawnSphere.d.ts +38 -0
  38. package/dist/emitter/spawn/FXSpawnSphere.js +89 -0
  39. package/dist/index.d.ts +28 -20
  40. package/dist/index.js +28 -22
  41. package/dist/instancedParticle/FXInstancedParticle.Internal.d.ts +1 -12
  42. package/dist/instancedParticle/FXInstancedParticle.Internal.js +2 -206
  43. package/dist/instancedParticle/FXInstancedParticle.d.ts +3 -5
  44. package/dist/instancedParticle/FXInstancedParticle.js +4 -10
  45. package/dist/instancedParticle/shared.d.ts +1 -1
  46. package/dist/instancedParticle/shared.js +1 -1
  47. package/dist/materials/FXDiffuseMaterial/FXDiffuseMaterial.Internal.d.ts +7 -0
  48. package/dist/materials/FXDiffuseMaterial/FXDiffuseMaterial.Internal.js +141 -0
  49. package/dist/materials/FXDiffuseMaterial/FXDiffuseMaterial.d.ts +15 -0
  50. package/dist/materials/FXDiffuseMaterial/FXDiffuseMaterial.js +26 -0
  51. package/dist/materials/FXMaterial/FXMaterial.Internal.d.ts +5 -0
  52. package/dist/materials/FXMaterial/FXMaterial.Internal.js +106 -0
  53. package/dist/materials/FXMaterial/FXMaterial.d.ts +19 -0
  54. package/dist/materials/FXMaterial/FXMaterial.js +25 -0
  55. package/dist/materials/FXUnlitMaterial/FXUnlitMaterial.Internal.d.ts +6 -0
  56. package/dist/materials/FXUnlitMaterial/FXUnlitMaterial.Internal.js +84 -0
  57. package/dist/materials/FXUnlitMaterial/FXUnlitMaterial.d.ts +6 -0
  58. package/dist/materials/FXUnlitMaterial/FXUnlitMaterial.js +14 -0
  59. package/dist/{color → miscellaneous/color}/FXColor.js +2 -2
  60. package/dist/miscellaneous/miscellaneous.d.ts +2 -1
  61. package/dist/miscellaneous/miscellaneous.js +24 -1
  62. package/dist/nodes/color/FXColorNode.d.ts +3 -0
  63. package/dist/nodes/color/FXColorNode.js +8 -0
  64. package/dist/nodes/color/FXColorOverLifeNode.d.ts +6 -0
  65. package/dist/nodes/color/FXColorOverLifeNode.js +38 -0
  66. package/dist/nodes/normal/FXFlatNormalNode.d.ts +4 -0
  67. package/dist/nodes/normal/FXFlatNormalNode.js +14 -0
  68. package/dist/nodes/normal/FXNormalNode.d.ts +3 -0
  69. package/dist/nodes/normal/FXNormalNode.js +4 -0
  70. package/dist/nodes/normal/FXSphericalNormalNode.d.ts +4 -0
  71. package/dist/nodes/normal/FXSphericalNormalNode.js +19 -0
  72. package/dist/nodes/texture/FXAnimatedTextureNode.d.ts +11 -0
  73. package/dist/nodes/texture/FXAnimatedTextureNode.js +80 -0
  74. package/dist/nodes/texture/FXStaticTextureNode.d.ts +5 -0
  75. package/dist/nodes/texture/FXStaticTextureNode.js +26 -0
  76. package/dist/nodes/texture/FXTextureNode.d.ts +3 -0
  77. package/dist/nodes/texture/FXTextureNode.js +8 -0
  78. package/package.json +1 -1
  79. package/dist/elements/FXEmitter.Internal.js +0 -12
  80. package/dist/elements/FXEmitter.d.ts +0 -38
  81. package/dist/instancedParticle/FXParticleDepthMaterial.d.ts +0 -2
  82. package/dist/instancedParticle/FXParticleDepthMaterial.js +0 -52
  83. package/dist/instancedParticle/FXParticleLambertMaterial.d.ts +0 -4
  84. package/dist/instancedParticle/FXParticleLambertMaterial.js +0 -152
  85. package/dist/instancedParticle/FXParticleNormalsMode.d.ts +0 -5
  86. package/dist/instancedParticle/FXParticleNormalsMode.js +0 -8
  87. package/dist/instancedParticle/FXParticleRenderingMode.d.ts +0 -4
  88. package/dist/instancedParticle/FXParticleRenderingMode.js +0 -7
  89. package/dist/miscellaneous/texture/FXTextureView.Internal.js +0 -6
  90. package/dist/miscellaneous/texture/FXTextureView.js +0 -234
  91. package/dist/renderingModules/FXRenderingAnimatedTexture.d.ts +0 -5
  92. package/dist/renderingModules/FXRenderingAnimatedTexture.js +0 -14
  93. package/dist/renderingModules/FXRenderingColorOverLife.d.ts +0 -14
  94. package/dist/renderingModules/FXRenderingColorOverLife.js +0 -32
  95. package/dist/renderingModules/FXRenderingColorOverVelocity.d.ts +0 -15
  96. package/dist/renderingModules/FXRenderingColorOverVelocity.js +0 -37
  97. package/dist/renderingModules/FXRenderingModule.d.ts +0 -8
  98. package/dist/renderingModules/FXRenderingModule.js +0 -9
  99. package/dist/renderingModules/FXRenderingShadow.d.ts +0 -12
  100. package/dist/renderingModules/FXRenderingTexture.d.ts +0 -14
  101. package/dist/renderingModules/FXRenderingTexture.js +0 -26
  102. package/dist/shaders/FXRenderingAnimatedTexture.glsl.js +0 -3
  103. package/dist/shaders/FXRenderingColorOverLife.glsl.js +0 -3
  104. package/dist/shaders/FXRenderingColorOverVelocity.glsl.js +0 -3
  105. package/dist/shaders/FXRenderingTexture.glsl.js +0 -3
  106. package/dist/spawnModules/FXSpawnModule.d.ts +0 -9
  107. /package/dist/{color → miscellaneous/color}/FXColor.Internal.d.ts +0 -0
  108. /package/dist/{color → miscellaneous/color}/FXColor.Internal.js +0 -0
  109. /package/dist/{color → miscellaneous/color}/FXColor.d.ts +0 -0
@@ -0,0 +1,80 @@
1
+ import { checkSRGBSupport } from '../../miscellaneous/webglCapabilities.js';
2
+ import { FXTextureNode } from './FXTextureNode.js';
3
+
4
+ class FXAnimatedTextureNode extends FXTextureNode {
5
+ constructor({ texture, columns, rows, interpolate = false }) {
6
+ super();
7
+ const gammaCorrection = checkSRGBSupport()
8
+ ? ""
9
+ : "color = vec4(pow(color.rgb, vec3(2.2)), color.a);";
10
+ this.affectsDepth = true;
11
+ this.cacheKey = interpolate ? "animated-interpolated" : "animated";
12
+ this.uniformDeclarations = [
13
+ "uniform sampler2D u_AnimatedTexture;",
14
+ "uniform float u_AnimatedTextureColumns;",
15
+ "uniform float u_AnimatedTextureRows;",
16
+ ];
17
+ this.uniforms = {
18
+ // eslint-disable-next-line @typescript-eslint/naming-convention
19
+ u_AnimatedTexture: { value: texture },
20
+ // eslint-disable-next-line @typescript-eslint/naming-convention
21
+ u_AnimatedTextureColumns: { value: columns },
22
+ // eslint-disable-next-line @typescript-eslint/naming-convention
23
+ u_AnimatedTextureRows: { value: rows },
24
+ };
25
+ this.helperFunctions = interpolate
26
+ ? `
27
+ vec2 frameToUV(vec2 uv, float frame, float columns, float rows) {
28
+ float column = mod(frame, columns);
29
+ float row = floor(frame / columns);
30
+ return vec2((column + uv.x) / columns, 1.0 - (row + 1.0 - uv.y) / rows);
31
+ }
32
+
33
+ vec4 sampleAnimatedTexture(sampler2D spriteSheet, vec2 uv, float columns, float rows) {
34
+ float totalFrames = columns * rows;
35
+
36
+ // Fractional frame position drives both frame selection and blend weight
37
+ float exactFrame = PARTICLE_AGE / PARTICLE_LIFETIME * totalFrames;
38
+ float currentFrame = clamp(floor(exactFrame), 0.0, totalFrames - 1.0);
39
+ float nextFrame = clamp(currentFrame + 1.0, 0.0, totalFrames - 1.0);
40
+ float blendWeight = fract(exactFrame);
41
+
42
+ vec4 color = mix(
43
+ texture2D(spriteSheet, frameToUV(uv, currentFrame, columns, rows)),
44
+ texture2D(spriteSheet, frameToUV(uv, nextFrame, columns, rows)),
45
+ blendWeight
46
+ );
47
+
48
+ // Apply gamma correction when sRGB textures are not natively supported
49
+ ${gammaCorrection}
50
+
51
+ return color;
52
+ }
53
+ `
54
+ : `
55
+ vec4 sampleAnimatedTexture(sampler2D spriteSheet, vec2 uv, float columns, float rows) {
56
+ // Determine which frame to display based on normalized particle age
57
+ float totalFrames = columns * rows;
58
+ float frame = floor(PARTICLE_AGE / PARTICLE_LIFETIME * totalFrames);
59
+ frame = clamp(frame, 0.0, totalFrames - 1.0);
60
+
61
+ // Locate the frame's column and row in the sprite sheet grid
62
+ float column = mod(frame, columns);
63
+ float row = floor(frame / columns);
64
+
65
+ // Remap UV to the frame's tile region within the sprite sheet
66
+ vec2 frameUV = vec2((column + uv.x) / columns, 1.0 - (row + 1.0 - uv.y) / rows);
67
+ vec4 color = texture2D(spriteSheet, frameUV);
68
+
69
+ // Apply gamma correction when sRGB textures are not natively supported
70
+ ${gammaCorrection}
71
+
72
+ return color;
73
+ }
74
+ `;
75
+ this.colorExpression =
76
+ "sampleAnimatedTexture(u_AnimatedTexture, p_uv, u_AnimatedTextureColumns, u_AnimatedTextureRows)";
77
+ }
78
+ }
79
+
80
+ export { FXAnimatedTextureNode };
@@ -0,0 +1,5 @@
1
+ import type { Texture } from "three";
2
+ import { FXTextureNode } from "./FXTextureNode";
3
+ export declare class FXStaticTextureNode extends FXTextureNode {
4
+ constructor(texture: Texture);
5
+ }
@@ -0,0 +1,26 @@
1
+ import { checkSRGBSupport } from '../../miscellaneous/webglCapabilities.js';
2
+ import { FXTextureNode } from './FXTextureNode.js';
3
+
4
+ class FXStaticTextureNode extends FXTextureNode {
5
+ constructor(texture) {
6
+ super();
7
+ this.affectsDepth = true;
8
+ this.cacheKey = "static";
9
+ this.uniformDeclarations = ["uniform sampler2D u_StaticTexture;"];
10
+ this.uniforms = {
11
+ // eslint-disable-next-line @typescript-eslint/naming-convention
12
+ u_StaticTexture: { value: texture },
13
+ };
14
+ this.helperFunctions = `
15
+ vec4 sampleStaticTexture(sampler2D colorTexture, vec2 uv) {
16
+ vec4 color = texture2D(colorTexture, uv);
17
+ // Apply gamma correction when sRGB textures are not natively supported
18
+ ${checkSRGBSupport() ? "" : "color = vec4(pow(color.rgb, vec3(2.2)), color.a);"}
19
+ return color;
20
+ }
21
+ `;
22
+ this.colorExpression = "sampleStaticTexture(u_StaticTexture, p_uv)";
23
+ }
24
+ }
25
+
26
+ export { FXStaticTextureNode };
@@ -0,0 +1,3 @@
1
+ export declare abstract class FXTextureNode {
2
+ destroy?(): void;
3
+ }
@@ -0,0 +1,8 @@
1
+ class FXTextureNode {
2
+ constructor() {
3
+ /** @internal */
4
+ this.affectsDepth = false;
5
+ }
6
+ }
7
+
8
+ export { FXTextureNode };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sparcoon",
3
- "version": "0.1.0",
3
+ "version": "0.3.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,38 +0,0 @@
1
- import { Object3D, type Blending } from "three";
2
- import type { FXBehaviorModule } from "../behaviorModules/FXBehaviorModule";
3
- import { FXParticleNormalsMode } from "../instancedParticle/FXParticleNormalsMode";
4
- import { FXParticleRenderingMode } from "../instancedParticle/FXParticleRenderingMode";
5
- import type { FXRenderingModule } from "../renderingModules/FXRenderingModule";
6
- import type { FXSpawnModule } from "../spawnModules/FXSpawnModule";
7
- import type { FXEmitterPlayOptions } from "./FXEmitter.Internal";
8
- export { FXParticleNormalsMode, FXParticleRenderingMode };
9
- export interface FXEmitterOptions {
10
- expectedCapacity: number;
11
- capacityStep: number;
12
- automaticallyDestroyModules: boolean;
13
- blending: Blending;
14
- useAlphaHashing: boolean;
15
- castShadow: boolean;
16
- receiveShadow: boolean;
17
- renderingMode: FXParticleRenderingMode;
18
- normalsMode: FXParticleNormalsMode;
19
- }
20
- export declare class FXEmitter extends Object3D {
21
- private readonly spawnSequence;
22
- private readonly behaviorSequence;
23
- private readonly renderingSequence;
24
- automaticallyDestroyModules: boolean;
25
- private readonly mesh;
26
- private emissionRate;
27
- private emissionAccumulator;
28
- private emissionDuration;
29
- private emissionElapsed;
30
- constructor(spawnSequence: FXSpawnModule[], behaviorSequence: readonly FXBehaviorModule[], renderingSequence: readonly FXRenderingModule[], options?: Partial<FXEmitterOptions>);
31
- static onWillRender: (deltaTime: number) => void;
32
- destroy(): void;
33
- burst(count: number): void;
34
- reset(): void;
35
- play(rate: number, options?: Partial<FXEmitterPlayOptions>): void;
36
- stop(): void;
37
- private readonly onRendering;
38
- }
@@ -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 };