sparcoon 0.0.8 → 0.1.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/dist/elements/FXEmitter.Internal.d.ts +6 -4
- package/dist/elements/FXEmitter.Internal.js +8 -1
- package/dist/elements/FXEmitter.d.ts +7 -0
- package/dist/elements/FXEmitter.js +12 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -0
- package/dist/instancedParticle/FXInstancedParticle.Internal.js +2 -1
- package/dist/instancedParticle/FXInstancedParticle.d.ts +4 -2
- package/dist/instancedParticle/FXInstancedParticle.js +10 -5
- package/dist/instancedParticle/FXParticleDepthMaterial.d.ts +2 -0
- package/dist/instancedParticle/FXParticleDepthMaterial.js +52 -0
- package/dist/instancedParticle/FXParticleLambertMaterial.d.ts +4 -0
- package/dist/instancedParticle/FXParticleLambertMaterial.js +152 -0
- package/dist/instancedParticle/FXParticleNormalsMode.d.ts +5 -0
- package/dist/instancedParticle/FXParticleNormalsMode.js +8 -0
- package/dist/instancedParticle/FXParticleRenderingMode.d.ts +4 -0
- package/dist/instancedParticle/FXParticleRenderingMode.js +7 -0
- package/dist/renderingModules/FXRenderingShadow.d.ts +12 -0
- package/dist/shaders/FXRenderingAnimatedTexture.glsl.js +1 -1
- package/dist/shaders/FXRenderingColorOverLife.glsl.js +1 -1
- package/dist/shaders/FXRenderingColorOverVelocity.glsl.js +1 -1
- package/dist/shaders/FXRenderingTexture.glsl.js +1 -1
- package/package.json +1 -1
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
capacityStep: number;
|
|
4
|
-
}
|
|
1
|
+
import { FXParticleNormalsMode } from "../instancedParticle/FXParticleNormalsMode";
|
|
2
|
+
import { FXParticleRenderingMode } from "../instancedParticle/FXParticleRenderingMode";
|
|
5
3
|
export interface FXEmitterPlayOptions {
|
|
6
4
|
duration: number;
|
|
7
5
|
}
|
|
8
6
|
export declare const EMITTER_DEFAULT_EXPECTED_CAPACITY = 32;
|
|
9
7
|
export declare const EMITTER_DEFAULT_CAPACITY_STEP = 32;
|
|
10
8
|
export declare const EMITTER_DEFAULT_AUTOMATICALLY_DESTROY_MODULES = true;
|
|
9
|
+
export declare const EMITTER_DEFAULT_CAST_SHADOW = false;
|
|
10
|
+
export declare const EMITTER_DEFAULT_RECEIVE_SHADOW = false;
|
|
11
|
+
export declare const EMITTER_DEFAULT_RENDERING_MODE = FXParticleRenderingMode.Unlit;
|
|
12
|
+
export declare const EMITTER_DEFAULT_NORMALS_MODE = FXParticleNormalsMode.Flat;
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
+
import { FXParticleNormalsMode } from '../instancedParticle/FXParticleNormalsMode.js';
|
|
2
|
+
import { FXParticleRenderingMode } from '../instancedParticle/FXParticleRenderingMode.js';
|
|
3
|
+
|
|
1
4
|
const EMITTER_DEFAULT_EXPECTED_CAPACITY = 32;
|
|
2
5
|
const EMITTER_DEFAULT_CAPACITY_STEP = 32;
|
|
3
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;
|
|
4
11
|
|
|
5
|
-
export { EMITTER_DEFAULT_AUTOMATICALLY_DESTROY_MODULES, EMITTER_DEFAULT_CAPACITY_STEP, EMITTER_DEFAULT_EXPECTED_CAPACITY };
|
|
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,14 +1,21 @@
|
|
|
1
1
|
import { Object3D, type Blending } from "three";
|
|
2
2
|
import type { FXBehaviorModule } from "../behaviorModules/FXBehaviorModule";
|
|
3
|
+
import { FXParticleNormalsMode } from "../instancedParticle/FXParticleNormalsMode";
|
|
4
|
+
import { FXParticleRenderingMode } from "../instancedParticle/FXParticleRenderingMode";
|
|
3
5
|
import type { FXRenderingModule } from "../renderingModules/FXRenderingModule";
|
|
4
6
|
import type { FXSpawnModule } from "../spawnModules/FXSpawnModule";
|
|
5
7
|
import type { FXEmitterPlayOptions } from "./FXEmitter.Internal";
|
|
8
|
+
export { FXParticleNormalsMode, FXParticleRenderingMode };
|
|
6
9
|
export interface FXEmitterOptions {
|
|
7
10
|
expectedCapacity: number;
|
|
8
11
|
capacityStep: number;
|
|
9
12
|
automaticallyDestroyModules: boolean;
|
|
10
13
|
blending: Blending;
|
|
11
14
|
useAlphaHashing: boolean;
|
|
15
|
+
castShadow: boolean;
|
|
16
|
+
receiveShadow: boolean;
|
|
17
|
+
renderingMode: FXParticleRenderingMode;
|
|
18
|
+
normalsMode: FXParticleNormalsMode;
|
|
12
19
|
}
|
|
13
20
|
export declare class FXEmitter extends Object3D {
|
|
14
21
|
private readonly spawnSequence;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { Object3D, NormalBlending } from 'three';
|
|
2
2
|
import { FXInstancedParticle } from '../instancedParticle/FXInstancedParticle.js';
|
|
3
3
|
import { collectProperties, collectUniforms } from '../instancedParticle/FXInstancedParticle.Internal.js';
|
|
4
|
+
import { buildParticleDepthMaterial } from '../instancedParticle/FXParticleDepthMaterial.js';
|
|
5
|
+
export { FXParticleNormalsMode } from '../instancedParticle/FXParticleNormalsMode.js';
|
|
6
|
+
export { FXParticleRenderingMode } from '../instancedParticle/FXParticleRenderingMode.js';
|
|
4
7
|
import { resolveGLSLTypeInfo } from '../instancedParticle/shared.js';
|
|
5
8
|
import { BUILTIN_OFFSET_AGE, BUILTIN_OFFSET_POSITION_X, BUILTIN_OFFSET_VELOCITY_X, BUILTIN_OFFSET_POSITION_Y, BUILTIN_OFFSET_VELOCITY_Y, BUILTIN_OFFSET_POSITION_Z, BUILTIN_OFFSET_VELOCITY_Z, BUILTIN_OFFSET_ROTATION, BUILTIN_OFFSET_TORQUE, BUILTIN_OFFSET_RANDOM_A, BUILTIN_OFFSET_RANDOM_B, BUILTIN_OFFSET_RANDOM_C } from '../miscellaneous/miscellaneous.js';
|
|
6
|
-
import { EMITTER_DEFAULT_EXPECTED_CAPACITY, EMITTER_DEFAULT_CAPACITY_STEP, EMITTER_DEFAULT_AUTOMATICALLY_DESTROY_MODULES } from './FXEmitter.Internal.js';
|
|
9
|
+
import { EMITTER_DEFAULT_EXPECTED_CAPACITY, EMITTER_DEFAULT_CAPACITY_STEP, EMITTER_DEFAULT_RENDERING_MODE, EMITTER_DEFAULT_NORMALS_MODE, EMITTER_DEFAULT_CAST_SHADOW, EMITTER_DEFAULT_RECEIVE_SHADOW, EMITTER_DEFAULT_AUTOMATICALLY_DESTROY_MODULES } from './FXEmitter.Internal.js';
|
|
7
10
|
|
|
8
11
|
const INSTANCES = new Array();
|
|
9
12
|
class FXEmitter extends Object3D {
|
|
@@ -80,7 +83,14 @@ class FXEmitter extends Object3D {
|
|
|
80
83
|
collectProperties(collectedProperties, _private_renderingSequence, "FXEmitter.constructor.renderingSequence");
|
|
81
84
|
const collectedUniforms = {};
|
|
82
85
|
collectUniforms(collectedUniforms, _private_renderingSequence, "FXEmitter.constructor.renderingSequence");
|
|
83
|
-
this._private_mesh = new FXInstancedParticle(
|
|
86
|
+
this._private_mesh = new FXInstancedParticle(_private_renderingSequence.map((module) => module.source), collectedUniforms, collectedProperties, options.expectedCapacity ?? EMITTER_DEFAULT_EXPECTED_CAPACITY, options.capacityStep ?? EMITTER_DEFAULT_CAPACITY_STEP, options.blending ?? NormalBlending, options.useAlphaHashing ?? false, options.renderingMode ?? EMITTER_DEFAULT_RENDERING_MODE, options.normalsMode ?? EMITTER_DEFAULT_NORMALS_MODE);
|
|
87
|
+
if (options.castShadow ?? EMITTER_DEFAULT_CAST_SHADOW) {
|
|
88
|
+
this._private_mesh.castShadow = true;
|
|
89
|
+
this._private_mesh.customDepthMaterial = buildParticleDepthMaterial();
|
|
90
|
+
}
|
|
91
|
+
if (options.receiveShadow ?? EMITTER_DEFAULT_RECEIVE_SHADOW) {
|
|
92
|
+
this._private_mesh.receiveShadow = true;
|
|
93
|
+
}
|
|
84
94
|
this.automaticallyDestroyModules =
|
|
85
95
|
options.automaticallyDestroyModules ?? EMITTER_DEFAULT_AUTOMATICALLY_DESTROY_MODULES;
|
|
86
96
|
this.add(this._private_mesh);
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export { FXBehaviorTorqueNoise } from "./behaviorModules/FXBehaviorTorqueNoise";
|
|
|
6
6
|
export { FXBehaviorVelocityDamping } from "./behaviorModules/FXBehaviorVelocityDamping";
|
|
7
7
|
export { FXBehaviorVelocityNoise } from "./behaviorModules/FXBehaviorVelocityNoise";
|
|
8
8
|
export { FXColor } from "./color/FXColor";
|
|
9
|
-
export { FXEmitter } from "./elements/FXEmitter";
|
|
9
|
+
export { FXEmitter, FXParticleNormalsMode, FXParticleRenderingMode } from "./elements/FXEmitter";
|
|
10
10
|
export { FXRenderingAnimatedTexture } from "./renderingModules/FXRenderingAnimatedTexture";
|
|
11
11
|
export { FXRenderingColorOverLife } from "./renderingModules/FXRenderingColorOverLife";
|
|
12
12
|
export { FXRenderingColorOverVelocity } from "./renderingModules/FXRenderingColorOverVelocity";
|
package/dist/index.js
CHANGED
|
@@ -18,3 +18,5 @@ export { FXSpawnRandomRotation } from './spawnModules/FXSpawnRandomRotation.js';
|
|
|
18
18
|
export { FXSpawnRandomScale } from './spawnModules/FXSpawnRandomScale.js';
|
|
19
19
|
export { FXSpawnRandomTorque } from './spawnModules/FXSpawnRandomTorque.js';
|
|
20
20
|
export { FXSpawnRandomVelocity } from './spawnModules/FXSpawnRandomVelocity.js';
|
|
21
|
+
export { FXParticleNormalsMode } from './instancedParticle/FXParticleNormalsMode.js';
|
|
22
|
+
export { FXParticleRenderingMode } from './instancedParticle/FXParticleRenderingMode.js';
|
|
@@ -121,8 +121,9 @@ function buildParticleFragmentShader(uniformDeclarations, varyingDeclarations, s
|
|
|
121
121
|
drawCalls += `draw${i}()`;
|
|
122
122
|
}
|
|
123
123
|
return `
|
|
124
|
+
#include <common>
|
|
125
|
+
|
|
124
126
|
// Defines
|
|
125
|
-
#define PI 3.14159265359
|
|
126
127
|
#define SRGB_SUPPORTED ${checkSRGBSupport() ? "1" : "0"}
|
|
127
128
|
|
|
128
129
|
#define PARTICLE_POSITION_X p_builtin[0][0]
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { Blending } from "three";
|
|
2
2
|
import { InstancedBufferAttribute, Mesh } from "three";
|
|
3
|
+
import { FXParticleNormalsMode } from "./FXParticleNormalsMode";
|
|
4
|
+
import { FXParticleRenderingMode } from "./FXParticleRenderingMode";
|
|
3
5
|
import type { GLProperty, GLTypeInfo } from "./shared";
|
|
4
6
|
export declare class FXInstancedParticle extends Mesh {
|
|
5
7
|
private readonly capacityStep;
|
|
6
8
|
readonly propertyBuffers: Record<string, InstancedBufferAttribute>;
|
|
7
9
|
private readonly instancedGeometry;
|
|
8
|
-
private readonly
|
|
10
|
+
private readonly particleMaterial;
|
|
9
11
|
private capacity;
|
|
10
|
-
constructor(sources: string[], uniforms: Record<string, GLProperty>, varyings: Record<string, GLTypeInfo>, expectedCapacity: number, capacityStep: number, blending: Blending, useAlphaHashing: boolean);
|
|
12
|
+
constructor(sources: string[], uniforms: Record<string, GLProperty>, varyings: Record<string, GLTypeInfo>, expectedCapacity: number, capacityStep: number, blending: Blending, useAlphaHashing: boolean, renderingMode: FXParticleRenderingMode, normalsMode: FXParticleNormalsMode);
|
|
11
13
|
get instanceCount(): number;
|
|
12
14
|
createInstances(count: number): void;
|
|
13
15
|
removeDeadParticles(): void;
|
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
import { Mesh, InstancedBufferAttribute, StreamDrawUsage } from 'three';
|
|
2
2
|
import { BUILTIN_OFFSET_AGE, BUILTIN_OFFSET_LIFETIME } from '../miscellaneous/miscellaneous.js';
|
|
3
3
|
import { INSTANCED_PARTICLE_GEOMETRY, buildParticleMaterial } from './FXInstancedParticle.Internal.js';
|
|
4
|
+
import { buildParticleLambertMaterial } from './FXParticleLambertMaterial.js';
|
|
5
|
+
import './FXParticleNormalsMode.js';
|
|
6
|
+
import { FXParticleRenderingMode } from './FXParticleRenderingMode.js';
|
|
4
7
|
|
|
5
8
|
class FXInstancedParticle extends Mesh {
|
|
6
|
-
constructor(sources, uniforms, varyings, expectedCapacity, _private_capacityStep, blending, useAlphaHashing) {
|
|
9
|
+
constructor(sources, uniforms, varyings, expectedCapacity, _private_capacityStep, blending, useAlphaHashing, renderingMode, normalsMode) {
|
|
7
10
|
const instancedGeometry = INSTANCED_PARTICLE_GEOMETRY.clone();
|
|
8
|
-
const
|
|
9
|
-
|
|
11
|
+
const particleMaterial = renderingMode === FXParticleRenderingMode.Lambert
|
|
12
|
+
? buildParticleLambertMaterial(sources, uniforms, varyings, blending, useAlphaHashing, normalsMode)
|
|
13
|
+
: buildParticleMaterial(sources, uniforms, varyings, blending, useAlphaHashing);
|
|
14
|
+
super(instancedGeometry, particleMaterial);
|
|
10
15
|
this._private_capacityStep = _private_capacityStep;
|
|
11
16
|
this.propertyBuffers = {};
|
|
12
17
|
this.frustumCulled = false;
|
|
13
18
|
this._private_instancedGeometry = instancedGeometry;
|
|
14
19
|
this._private_instancedGeometry.instanceCount = 0;
|
|
15
|
-
this.
|
|
20
|
+
this._private_particleMaterial = particleMaterial;
|
|
16
21
|
this._private_capacity = Math.max(Math.ceil(expectedCapacity / this._private_capacityStep) * this._private_capacityStep, this._private_capacityStep);
|
|
17
22
|
for (const name in varyings) {
|
|
18
23
|
const { bufferSize } = varyings[name];
|
|
@@ -61,7 +66,7 @@ class FXInstancedParticle extends Mesh {
|
|
|
61
66
|
}
|
|
62
67
|
destroy() {
|
|
63
68
|
this._private_instancedGeometry.dispose();
|
|
64
|
-
this.
|
|
69
|
+
this._private_particleMaterial.dispose();
|
|
65
70
|
}
|
|
66
71
|
_private_ensureCapacity(requiredCapacity) {
|
|
67
72
|
if (requiredCapacity <= this._private_capacity) {
|
|
@@ -0,0 +1,52 @@
|
|
|
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 };
|
|
@@ -0,0 +1,4 @@
|
|
|
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;
|
|
@@ -0,0 +1,152 @@
|
|
|
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 };
|
|
@@ -0,0 +1,8 @@
|
|
|
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 };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
var FXParticleRenderingMode;
|
|
2
|
+
(function (FXParticleRenderingMode) {
|
|
3
|
+
FXParticleRenderingMode["Unlit"] = "unlit";
|
|
4
|
+
FXParticleRenderingMode["Lambert"] = "lambert";
|
|
5
|
+
})(FXParticleRenderingMode || (FXParticleRenderingMode = {}));
|
|
6
|
+
|
|
7
|
+
export { FXParticleRenderingMode };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FXRenderingModule } from "./FXRenderingModule";
|
|
2
|
+
/**
|
|
3
|
+
* Applies directional light shadow attenuation to particles.
|
|
4
|
+
*
|
|
5
|
+
* Samples the first directional light's shadow map per billboard fragment,
|
|
6
|
+
* multiplying the particle color by the shadow factor.
|
|
7
|
+
*
|
|
8
|
+
* Requires a DirectionalLight with `castShadow = true` in the scene,
|
|
9
|
+
* and `receiveShadow = true` on the emitter (or its parent).
|
|
10
|
+
*/
|
|
11
|
+
export declare class FXRenderingShadow extends FXRenderingModule {
|
|
12
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var source = "vec4 draw(){float totalFrames=p_count.x*p_count.y
|
|
1
|
+
var source = "vec4 draw(){\n float totalFrames=p_count.x*p_count.y;\n float frame=floor(PARTICLE_AGE/PARTICLE_LIFETIME*totalFrames);\n frame=clamp(frame,0.0,totalFrames-1.0);\n float col=mod(frame,p_count.x);\n float row=floor(frame/p_count.x);\n vec2 frameSize=vec2(1.0/p_count.x,1.0/p_count.y);\n vec2 uv=(p_uv+vec2(col,(p_count.y-1.0-row)))*frameSize;\n return srgbTexture2D(p_texture,uv);\n}";
|
|
2
2
|
|
|
3
3
|
export { source as default };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var source = "vec4 draw(){float t=clamp(PARTICLE_AGE/PARTICLE_LIFETIME,0.0,1.0)
|
|
1
|
+
var source = "vec4 draw(){\n float t=clamp(PARTICLE_AGE/PARTICLE_LIFETIME,0.0,1.0);\n return srgbTexture2D(p_colorOverLifeTexture,vec2(t,0.5));\n}";
|
|
2
2
|
|
|
3
3
|
export { source as default };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var source = "#define COLOR_OVER_VELOCITY_MAX
|
|
1
|
+
var source = "#define COLOR_OVER_VELOCITY_MAX \nvec4 draw(){\n float t=clamp(length(vec3(PARTICLE_VELOCITY_X,PARTICLE_VELOCITY_Y,PARTICLE_VELOCITY_Z))/COLOR_OVER_VELOCITY_MAX,0.0,1.0);\n return srgbTexture2D(p_colorOverVelocityTexture,vec2(t,0.5));\n}";
|
|
2
2
|
|
|
3
3
|
export { source as default };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var source = "vec4 draw(){vec2 transformedUV=(p_textureTransform*vec3(p_uv,1.0)).xy
|
|
1
|
+
var source = "vec4 draw(){\n vec2 transformedUV=(p_textureTransform*vec3(p_uv,1.0)).xy;\n return srgbTexture2D(p_texture,transformedUV);\n}";
|
|
2
2
|
|
|
3
3
|
export { source as default };
|