sparcoon 0.3.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/materials/FXDiffuseMaterial/FXDiffuseMaterial.Internal.js +14 -3
- package/dist/materials/FXUnlitMaterial/FXUnlitMaterial.Internal.js +12 -1
- package/dist/nodes/color/FXColorOverLifeNode.js +10 -4
- package/dist/nodes/texture/FXAnimatedTextureNode.d.ts +1 -0
- package/dist/nodes/texture/FXAnimatedTextureNode.js +19 -11
- package/dist/nodes/texture/FXStaticTextureNode.d.ts +1 -0
- package/dist/nodes/texture/FXStaticTextureNode.js +12 -4
- package/package.json +1 -1
|
@@ -84,17 +84,28 @@ function buildFXDiffuseMaterial(varyings, blending, useAlphaHashing, alphaTest,
|
|
|
84
84
|
}
|
|
85
85
|
`
|
|
86
86
|
: "";
|
|
87
|
+
const seenCacheKeys = new Set();
|
|
88
|
+
const uniqueHelpers = (nodes) => nodes
|
|
89
|
+
.filter((n) => {
|
|
90
|
+
if (seenCacheKeys.has(n.cacheKey)) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
seenCacheKeys.add(n.cacheKey);
|
|
94
|
+
return true;
|
|
95
|
+
})
|
|
96
|
+
.map((n) => n.helperFunctions)
|
|
97
|
+
.join("\n");
|
|
87
98
|
const fragmentPreamble = [
|
|
88
99
|
PARTICLE_DEFINES,
|
|
89
100
|
"varying vec2 p_uv;",
|
|
90
101
|
varyingDeclarations.join("\n"),
|
|
91
102
|
albedoNodes.flatMap((n) => n.uniformDeclarations).join("\n"),
|
|
92
|
-
albedoNodes
|
|
103
|
+
uniqueHelpers(albedoNodes),
|
|
93
104
|
normalNodes.flatMap((n) => n.uniformDeclarations).join("\n"),
|
|
94
|
-
normalNodes
|
|
105
|
+
uniqueHelpers(normalNodes),
|
|
95
106
|
blendReorientedNormalsHelper,
|
|
96
107
|
emissionNodes.flatMap((n) => n.uniformDeclarations).join("\n"),
|
|
97
|
-
emissionNodes
|
|
108
|
+
uniqueHelpers(emissionNodes),
|
|
98
109
|
].join("\n");
|
|
99
110
|
for (const node of albedoNodes) {
|
|
100
111
|
Object.assign(shader.uniforms, node.uniforms);
|
|
@@ -59,12 +59,23 @@ function buildFXUnlitMaterial(varyings, blending, useAlphaHashing, alphaTest, al
|
|
|
59
59
|
mvPosition.xy += billboardOffset;
|
|
60
60
|
gl_Position = projectionMatrix * mvPosition;
|
|
61
61
|
`);
|
|
62
|
+
const seenCacheKeys = new Set();
|
|
63
|
+
const uniqueHelpers = (nodes) => nodes
|
|
64
|
+
.filter((n) => {
|
|
65
|
+
if (seenCacheKeys.has(n.cacheKey)) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
seenCacheKeys.add(n.cacheKey);
|
|
69
|
+
return true;
|
|
70
|
+
})
|
|
71
|
+
.map((n) => n.helperFunctions)
|
|
72
|
+
.join("\n");
|
|
62
73
|
const fragmentPreamble = [
|
|
63
74
|
PARTICLE_DEFINES,
|
|
64
75
|
"varying vec2 p_uv;",
|
|
65
76
|
varyingDeclarations.join("\n"),
|
|
66
77
|
albedoNodes.flatMap((n) => n.uniformDeclarations).join("\n"),
|
|
67
|
-
albedoNodes
|
|
78
|
+
uniqueHelpers(albedoNodes),
|
|
68
79
|
].join("\n");
|
|
69
80
|
for (const node of albedoNodes) {
|
|
70
81
|
Object.assign(shader.uniforms, node.uniforms);
|
|
@@ -2,19 +2,21 @@ import { buildGradientTexture } from '../../miscellaneous/miscellaneous.js';
|
|
|
2
2
|
import { checkSRGBSupport } from '../../miscellaneous/webglCapabilities.js';
|
|
3
3
|
import { FXColorNode } from './FXColorNode.js';
|
|
4
4
|
|
|
5
|
+
const INSTANCES = [];
|
|
5
6
|
class FXColorOverLifeNode extends FXColorNode {
|
|
6
7
|
constructor(colors) {
|
|
7
8
|
if (colors.length === 0) {
|
|
8
9
|
throw new Error("FXColorOverLifeNode: colors array cannot be empty");
|
|
9
10
|
}
|
|
10
11
|
super();
|
|
12
|
+
INSTANCES.push(this);
|
|
13
|
+
const uniformName = `u_ColorOverLife_${INSTANCES.length - 1}`;
|
|
11
14
|
this._private_gradientTexture = buildGradientTexture(colors);
|
|
12
15
|
this.affectsDepth = true;
|
|
13
16
|
this.cacheKey = "color-over-life";
|
|
14
|
-
this.uniformDeclarations = [
|
|
17
|
+
this.uniformDeclarations = [`uniform sampler2D ${uniformName};`];
|
|
15
18
|
this.uniforms = {
|
|
16
|
-
|
|
17
|
-
u_ColorOverLife: { value: this._private_gradientTexture },
|
|
19
|
+
[uniformName]: { value: this._private_gradientTexture },
|
|
18
20
|
};
|
|
19
21
|
this.helperFunctions = `
|
|
20
22
|
vec4 sampleColorOverLife(sampler2D gradientTexture) {
|
|
@@ -28,10 +30,14 @@ class FXColorOverLifeNode extends FXColorNode {
|
|
|
28
30
|
return color;
|
|
29
31
|
}
|
|
30
32
|
`;
|
|
31
|
-
this.colorExpression =
|
|
33
|
+
this.colorExpression = `sampleColorOverLife(${uniformName})`;
|
|
32
34
|
}
|
|
33
35
|
destroy() {
|
|
34
36
|
this._private_gradientTexture.dispose();
|
|
37
|
+
const index = INSTANCES.indexOf(this);
|
|
38
|
+
if (index !== -1) {
|
|
39
|
+
INSTANCES.splice(index, 1);
|
|
40
|
+
}
|
|
35
41
|
}
|
|
36
42
|
}
|
|
37
43
|
|
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
import { checkSRGBSupport } from '../../miscellaneous/webglCapabilities.js';
|
|
2
2
|
import { FXTextureNode } from './FXTextureNode.js';
|
|
3
3
|
|
|
4
|
+
const INSTANCES = [];
|
|
4
5
|
class FXAnimatedTextureNode extends FXTextureNode {
|
|
5
6
|
constructor({ texture, columns, rows, interpolate = false }) {
|
|
6
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}`;
|
|
7
13
|
const gammaCorrection = checkSRGBSupport()
|
|
8
14
|
? ""
|
|
9
15
|
: "color = vec4(pow(color.rgb, vec3(2.2)), color.a);";
|
|
10
16
|
this.affectsDepth = true;
|
|
11
17
|
this.cacheKey = interpolate ? "animated-interpolated" : "animated";
|
|
12
18
|
this.uniformDeclarations = [
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
19
|
+
`uniform sampler2D ${uniformTexture};`,
|
|
20
|
+
`uniform float ${uniformColumns};`,
|
|
21
|
+
`uniform float ${uniformRows};`,
|
|
16
22
|
];
|
|
17
23
|
this.uniforms = {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
u_AnimatedTextureColumns: { value: columns },
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
23
|
-
u_AnimatedTextureRows: { value: rows },
|
|
24
|
+
[uniformTexture]: { value: texture },
|
|
25
|
+
[uniformColumns]: { value: columns },
|
|
26
|
+
[uniformRows]: { value: rows },
|
|
24
27
|
};
|
|
25
28
|
this.helperFunctions = interpolate
|
|
26
29
|
? `
|
|
@@ -72,8 +75,13 @@ class FXAnimatedTextureNode extends FXTextureNode {
|
|
|
72
75
|
return color;
|
|
73
76
|
}
|
|
74
77
|
`;
|
|
75
|
-
this.colorExpression =
|
|
76
|
-
|
|
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
|
+
}
|
|
77
85
|
}
|
|
78
86
|
}
|
|
79
87
|
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { checkSRGBSupport } from '../../miscellaneous/webglCapabilities.js';
|
|
2
2
|
import { FXTextureNode } from './FXTextureNode.js';
|
|
3
3
|
|
|
4
|
+
const INSTANCES = [];
|
|
4
5
|
class FXStaticTextureNode extends FXTextureNode {
|
|
5
6
|
constructor(texture) {
|
|
6
7
|
super();
|
|
8
|
+
INSTANCES.push(this);
|
|
9
|
+
const uniformName = `u_StaticTexture_${INSTANCES.length - 1}`;
|
|
7
10
|
this.affectsDepth = true;
|
|
8
11
|
this.cacheKey = "static";
|
|
9
|
-
this.uniformDeclarations = [
|
|
12
|
+
this.uniformDeclarations = [`uniform sampler2D ${uniformName};`];
|
|
10
13
|
this.uniforms = {
|
|
11
|
-
|
|
12
|
-
u_StaticTexture: { value: texture },
|
|
14
|
+
[uniformName]: { value: texture },
|
|
13
15
|
};
|
|
14
16
|
this.helperFunctions = `
|
|
15
17
|
vec4 sampleStaticTexture(sampler2D colorTexture, vec2 uv) {
|
|
@@ -19,7 +21,13 @@ class FXStaticTextureNode extends FXTextureNode {
|
|
|
19
21
|
return color;
|
|
20
22
|
}
|
|
21
23
|
`;
|
|
22
|
-
this.colorExpression =
|
|
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
|
+
}
|
|
23
31
|
}
|
|
24
32
|
}
|
|
25
33
|
|