babylon.quarks 0.24.0 → 0.25.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/CHANGELOG.md +52 -5
- package/dist/babylon.quarks.cjs +1 -1
- package/dist/babylon.quarks.cjs.map +1 -1
- package/dist/babylon.quarks.esm.js +1 -1
- package/dist/babylon.quarks.esm.js.map +1 -1
- package/dist/babylon.quarks.umd.min.js +1 -1
- package/dist/babylon.quarks.umd.min.js.map +1 -1
- package/dist/types/index.d.ts +273 -7
- package/package.json +1 -1
- package/src/BatchedRenderer.ts +28 -1
- package/src/ParticleSystem.ts +256 -6
- package/src/QuarksLoader.ts +14 -0
- package/src/QuarksUtil.ts +97 -1
- package/src/SpriteBatch.ts +49 -9
- package/src/TrailBatch.ts +3 -0
- package/src/VFXBatch.ts +198 -1
- package/src/index.ts +21 -2
- package/src/shaders/chunks/surface.ts +188 -0
- package/src/shaders/particle_frag.glsl.ts +3 -11
- package/src/shaders/particle_frag.wgsl.ts +3 -11
- package/src/shaders/particle_physics_frag.glsl.ts +3 -11
- package/src/shaders/particle_physics_frag.wgsl.ts +3 -11
- package/src/shaders/stretched_bb_particle_vert.glsl.ts +12 -0
- package/src/shaders/stretched_bb_particle_vert.wgsl.ts +15 -0
- package/src/shaders/trail_frag.glsl.ts +3 -7
- package/src/shaders/trail_frag.wgsl.ts +3 -7
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {fogFragmentDeclarationWGSL, fogFragmentWGSL} from './chunks/fog';
|
|
2
|
+
import {surfaceColorWGSL, surfaceFragmentDeclarationWGSL} from './chunks/surface';
|
|
2
3
|
|
|
3
4
|
export default /* wgsl */ `
|
|
4
5
|
varying vUV: vec2f;
|
|
@@ -28,19 +29,10 @@ uniform alphaTest: f32;
|
|
|
28
29
|
#endif
|
|
29
30
|
|
|
30
31
|
${fogFragmentDeclarationWGSL}
|
|
32
|
+
${surfaceFragmentDeclarationWGSL}
|
|
31
33
|
@fragment
|
|
32
34
|
fn main(input: FragmentInputs) -> FragmentOutputs {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
#ifdef USE_MAP
|
|
36
|
-
var texColor = textureSample(map, mapSampler, fragmentInputs.vUV);
|
|
37
|
-
#ifdef TILE_BLEND
|
|
38
|
-
let texColor2 = textureSample(map, mapSampler, fragmentInputs.vUV2);
|
|
39
|
-
texColor = mix(texColor, texColor2, fragmentInputs.vTileBlend);
|
|
40
|
-
#endif
|
|
41
|
-
baseColor *= texColor;
|
|
42
|
-
#endif
|
|
43
|
-
|
|
35
|
+
${surfaceColorWGSL(true)}
|
|
44
36
|
#ifdef USE_COLOR_AS_ALPHA
|
|
45
37
|
baseColor.a *= (baseColor.r + baseColor.g + baseColor.b) / 3.0;
|
|
46
38
|
#endif
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {fogFragmentDeclarationGLSL, fogFragmentGLSL} from './chunks/fog';
|
|
2
|
+
import {surfaceColorGLSL, surfaceFragmentDeclarationGLSL} from './chunks/surface';
|
|
2
3
|
|
|
3
4
|
export default /* glsl */ `
|
|
4
5
|
varying vec2 vUV;
|
|
@@ -88,18 +89,9 @@ uniform float alphaTest;
|
|
|
88
89
|
#endif
|
|
89
90
|
|
|
90
91
|
${fogFragmentDeclarationGLSL}
|
|
92
|
+
${surfaceFragmentDeclarationGLSL}
|
|
91
93
|
void main() {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
#ifdef USE_MAP
|
|
95
|
-
vec4 texColor = texture2D(map, vUV);
|
|
96
|
-
#ifdef TILE_BLEND
|
|
97
|
-
vec4 texColor2 = texture2D(map, vUV2);
|
|
98
|
-
texColor = mix(texColor, texColor2, vTileBlend);
|
|
99
|
-
#endif
|
|
100
|
-
baseColor *= texColor;
|
|
101
|
-
#endif
|
|
102
|
-
|
|
94
|
+
${surfaceColorGLSL(true)}
|
|
103
95
|
#ifdef USE_ALPHATEST
|
|
104
96
|
if (baseColor.a < alphaTest) discard;
|
|
105
97
|
#else
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {fogFragmentDeclarationWGSL, fogFragmentWGSL} from './chunks/fog';
|
|
2
|
+
import {surfaceColorWGSL, surfaceFragmentDeclarationWGSL} from './chunks/surface';
|
|
2
3
|
|
|
3
4
|
export default /* wgsl */ `
|
|
4
5
|
varying vUV: vec2f;
|
|
@@ -88,19 +89,10 @@ uniform alphaTest: f32;
|
|
|
88
89
|
#endif
|
|
89
90
|
|
|
90
91
|
${fogFragmentDeclarationWGSL}
|
|
92
|
+
${surfaceFragmentDeclarationWGSL}
|
|
91
93
|
@fragment
|
|
92
94
|
fn main(input: FragmentInputs) -> FragmentOutputs {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
#ifdef USE_MAP
|
|
96
|
-
var texColor = textureSample(map, mapSampler, fragmentInputs.vUV);
|
|
97
|
-
#ifdef TILE_BLEND
|
|
98
|
-
let texColor2 = textureSample(map, mapSampler, fragmentInputs.vUV2);
|
|
99
|
-
texColor = mix(texColor, texColor2, fragmentInputs.vTileBlend);
|
|
100
|
-
#endif
|
|
101
|
-
baseColor *= texColor;
|
|
102
|
-
#endif
|
|
103
|
-
|
|
95
|
+
${surfaceColorWGSL(true)}
|
|
104
96
|
#ifdef USE_ALPHATEST
|
|
105
97
|
if (baseColor.a < uniforms.alphaTest) { discard; }
|
|
106
98
|
#else
|
|
@@ -67,11 +67,23 @@ void main() {
|
|
|
67
67
|
// Deriving it via normalize keeps the stretch aligned even when the speed contribution is ~0
|
|
68
68
|
// (e.g. speedFactor 0), instead of collapsing the whole burst onto a fixed screen axis.
|
|
69
69
|
vec3 vdir = vlength > 0.000001 ? viewVelocity / vlength : vec3(0.0, 0.0, 1.0);
|
|
70
|
+
#ifdef BEAM
|
|
71
|
+
// Seen straight along its length a beam has no side to face; any will do.
|
|
72
|
+
vec3 sideRaw = cross(mvPosition.xyz, vdir);
|
|
73
|
+
vec3 side = dot(sideRaw, sideRaw) > 1e-12 ? normalize(sideRaw) : vec3(1.0, 0.0, 0.0);
|
|
74
|
+
#else
|
|
70
75
|
vec3 side = normalize(cross(mvPosition.xyz, vdir));
|
|
76
|
+
#endif
|
|
71
77
|
mvPosition.xyz += position.y * side * avgSize;
|
|
78
|
+
#ifdef BEAM
|
|
79
|
+
// The vector runs from the particle to the beam's end: the quad spans it
|
|
80
|
+
// exactly, U from the particle (0) to the end (1), as wide as the size.
|
|
81
|
+
mvPosition.xyz += (position.x + 0.5) * viewVelocity;
|
|
82
|
+
#else
|
|
72
83
|
// Equivalent to viewVelocity * (1.0 + lengthFactor / vlength) for moving particles, but the
|
|
73
84
|
// size-based term (vdir * lengthFactor) survives when the velocity contribution vanishes.
|
|
74
85
|
mvPosition.xyz -= (position.x + 0.5) * (viewVelocity + vdir * lengthFactor) * avgSize;
|
|
86
|
+
#endif
|
|
75
87
|
#ifdef PIVOT
|
|
76
88
|
// In particle-size units along the quad's own axes: x from head to tail, y across.
|
|
77
89
|
mvPosition.xyz += (pivot.y * side - pivot.x * vdir) * avgSize;
|
|
@@ -73,12 +73,27 @@ fn main(input: VertexInputs) -> FragmentInputs {
|
|
|
73
73
|
if (vlength > 0.000001) {
|
|
74
74
|
vdir = viewVelocity / vlength;
|
|
75
75
|
}
|
|
76
|
+
#ifdef BEAM
|
|
77
|
+
// Seen straight along its length a beam has no side to face; any will do.
|
|
78
|
+
let sideRaw = cross(mvPosition.xyz, vdir);
|
|
79
|
+
var side = vec3f(1.0, 0.0, 0.0);
|
|
80
|
+
if (dot(sideRaw, sideRaw) > 1e-12) {
|
|
81
|
+
side = normalize(sideRaw);
|
|
82
|
+
}
|
|
83
|
+
#else
|
|
76
84
|
let side = normalize(cross(mvPosition.xyz, vdir));
|
|
85
|
+
#endif
|
|
77
86
|
let widthOffset = vertexInputs.position.y * side * avgSize;
|
|
78
87
|
// Equivalent to viewVelocity * (1.0 + lengthFactor / vlength) for moving particles, but the
|
|
79
88
|
// size-based term (vdir * lengthFactor) survives when the velocity contribution vanishes.
|
|
89
|
+
#ifdef BEAM
|
|
90
|
+
// The vector runs from the particle to the beam's end: the quad spans it
|
|
91
|
+
// exactly, U from the particle (0) to the end (1), as wide as the size.
|
|
92
|
+
var stretched = mvPosition.xyz + widthOffset + (vertexInputs.position.x + 0.5) * viewVelocity;
|
|
93
|
+
#else
|
|
80
94
|
let lengthOffset = (vertexInputs.position.x + 0.5) * (viewVelocity + vdir * lengthFactor) * avgSize;
|
|
81
95
|
var stretched = mvPosition.xyz + widthOffset - lengthOffset;
|
|
96
|
+
#endif
|
|
82
97
|
#ifdef PIVOT
|
|
83
98
|
// In particle-size units along the quad's own axes: x from head to tail, y across.
|
|
84
99
|
stretched += (uniforms.pivot.y * side - uniforms.pivot.x * vdir) * avgSize;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {fogFragmentDeclarationGLSL, fogFragmentGLSL} from './chunks/fog';
|
|
2
|
+
import {surfaceColorGLSL, surfaceFragmentDeclarationGLSL} from './chunks/surface';
|
|
2
3
|
|
|
3
4
|
export default /* glsl */ `
|
|
4
5
|
varying vec2 vUV;
|
|
@@ -9,14 +10,9 @@ uniform sampler2D map;
|
|
|
9
10
|
#endif
|
|
10
11
|
|
|
11
12
|
${fogFragmentDeclarationGLSL}
|
|
13
|
+
${surfaceFragmentDeclarationGLSL}
|
|
12
14
|
void main() {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
#ifdef USE_MAP
|
|
16
|
-
vec4 texColor = texture2D(map, vUV);
|
|
17
|
-
baseColor *= texColor;
|
|
18
|
-
#endif
|
|
19
|
-
|
|
15
|
+
${surfaceColorGLSL(false)}
|
|
20
16
|
if (baseColor.a < 0.01) discard;
|
|
21
17
|
|
|
22
18
|
${fogFragmentGLSL('baseColor.rgb')}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {fogFragmentDeclarationWGSL, fogFragmentWGSL} from './chunks/fog';
|
|
2
|
+
import {surfaceColorWGSL, surfaceFragmentDeclarationWGSL} from './chunks/surface';
|
|
2
3
|
|
|
3
4
|
export default /* wgsl */ `
|
|
4
5
|
varying vUV: vec2f;
|
|
@@ -10,15 +11,10 @@ var map: texture_2d<f32>;
|
|
|
10
11
|
#endif
|
|
11
12
|
|
|
12
13
|
${fogFragmentDeclarationWGSL}
|
|
14
|
+
${surfaceFragmentDeclarationWGSL}
|
|
13
15
|
@fragment
|
|
14
16
|
fn main(input: FragmentInputs) -> FragmentOutputs {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
#ifdef USE_MAP
|
|
18
|
-
let texColor = textureSample(map, mapSampler, fragmentInputs.vUV);
|
|
19
|
-
baseColor *= texColor;
|
|
20
|
-
#endif
|
|
21
|
-
|
|
17
|
+
${surfaceColorWGSL(false)}
|
|
22
18
|
if (baseColor.a < 0.01) { discard; }
|
|
23
19
|
|
|
24
20
|
${fogFragmentWGSL('baseColor')}
|