babylon.quarks 0.17.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/LICENSE +21 -0
- package/dist/babylon.quarks.cjs +2 -0
- package/dist/babylon.quarks.cjs.map +1 -0
- package/dist/babylon.quarks.esm.js +2 -0
- package/dist/babylon.quarks.esm.js.map +1 -0
- package/dist/types/BatchedParticleRenderer.d.ts +2 -0
- package/dist/types/BatchedRenderer.d.ts +40 -0
- package/dist/types/MeshSurfaceEmitter.d.ts +19 -0
- package/dist/types/ParticleEmitter.d.ts +16 -0
- package/dist/types/ParticleSystem.d.ts +226 -0
- package/dist/types/QuarksLoader.d.ts +28 -0
- package/dist/types/QuarksPrefab.d.ts +48 -0
- package/dist/types/QuarksUtil.d.ts +14 -0
- package/dist/types/SpriteBatch.d.ts +32 -0
- package/dist/types/TrailBatch.d.ts +27 -0
- package/dist/types/VFXBatch.d.ts +51 -0
- package/dist/types/index.d.ts +19 -0
- package/dist/types/materials/ParticleMaterials.d.ts +12 -0
- package/dist/types/materials/index.d.ts +1 -0
- package/dist/types/shaders/chunks/index.d.ts +1 -0
- package/dist/types/shaders/chunks/register-shader-chunks.d.ts +3 -0
- package/dist/types/shaders/chunks/soft_fragment.glsl.d.ts +2 -0
- package/dist/types/shaders/chunks/soft_pars_fragment.glsl.d.ts +2 -0
- package/dist/types/shaders/chunks/soft_pars_vertex.glsl.d.ts +2 -0
- package/dist/types/shaders/chunks/soft_vertex.glsl.d.ts +2 -0
- package/dist/types/shaders/chunks/tile_fragment.glsl.d.ts +2 -0
- package/dist/types/shaders/chunks/tile_pars_fragment.glsl.d.ts +2 -0
- package/dist/types/shaders/chunks/tile_pars_vertex.glsl.d.ts +2 -0
- package/dist/types/shaders/chunks/tile_vertex.glsl.d.ts +2 -0
- package/dist/types/shaders/index.d.ts +9 -0
- package/dist/types/shaders/local_particle_physics_vert.glsl.d.ts +2 -0
- package/dist/types/shaders/local_particle_vert.glsl.d.ts +2 -0
- package/dist/types/shaders/particle_frag.glsl.d.ts +2 -0
- package/dist/types/shaders/particle_physics_frag.glsl.d.ts +2 -0
- package/dist/types/shaders/particle_vert.glsl.d.ts +2 -0
- package/dist/types/shaders/stretched_bb_particle_vert.glsl.d.ts +2 -0
- package/dist/types/shaders/trail_frag.glsl.d.ts +2 -0
- package/dist/types/shaders/trail_vert.glsl.d.ts +2 -0
- package/package.json +58 -0
- package/src/BatchedParticleRenderer.ts +3 -0
- package/src/BatchedRenderer.ts +135 -0
- package/src/MeshSurfaceEmitter.ts +137 -0
- package/src/ParticleEmitter.ts +86 -0
- package/src/ParticleSystem.ts +1162 -0
- package/src/QuarksLoader.ts +503 -0
- package/src/QuarksPrefab.ts +307 -0
- package/src/QuarksUtil.ts +66 -0
- package/src/SpriteBatch.ts +391 -0
- package/src/TrailBatch.ts +345 -0
- package/src/VFXBatch.ts +102 -0
- package/src/index.ts +54 -0
- package/src/materials/ParticleMaterials.ts +23 -0
- package/src/materials/index.ts +1 -0
- package/src/shaders/chunks/index.ts +1 -0
- package/src/shaders/chunks/register-shader-chunks.ts +32 -0
- package/src/shaders/chunks/soft_fragment.glsl.ts +13 -0
- package/src/shaders/chunks/soft_pars_fragment.glsl.ts +20 -0
- package/src/shaders/chunks/soft_pars_vertex.glsl.ts +6 -0
- package/src/shaders/chunks/soft_vertex.glsl.ts +6 -0
- package/src/shaders/chunks/tile_fragment.glsl.ts +9 -0
- package/src/shaders/chunks/tile_pars_fragment.glsl.ts +9 -0
- package/src/shaders/chunks/tile_pars_vertex.glsl.ts +28 -0
- package/src/shaders/chunks/tile_vertex.glsl.ts +18 -0
- package/src/shaders/index.ts +9 -0
- package/src/shaders/local_particle_physics_vert.glsl.ts +66 -0
- package/src/shaders/local_particle_vert.glsl.ts +50 -0
- package/src/shaders/particle_frag.glsl.ts +61 -0
- package/src/shaders/particle_physics_frag.glsl.ts +67 -0
- package/src/shaders/particle_vert.glsl.ts +85 -0
- package/src/shaders/stretched_bb_particle_vert.glsl.ts +74 -0
- package/src/shaders/trail_frag.glsl.ts +21 -0
- package/src/shaders/trail_vert.glsl.ts +58 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export default /* glsl */ `
|
|
2
|
+
#ifdef UV_TILE
|
|
3
|
+
mat3 tileTransform = makeTileTransform(floor(uvTile));
|
|
4
|
+
#ifdef TILE_BLEND
|
|
5
|
+
mat3 nextTileTransform = makeTileTransform(ceil(uvTile));
|
|
6
|
+
vUvBlend = fract(uvTile);
|
|
7
|
+
#endif
|
|
8
|
+
#else
|
|
9
|
+
mat3 tileTransform = makeTileTransform(0.0);
|
|
10
|
+
#endif
|
|
11
|
+
|
|
12
|
+
#if defined(USE_UV)
|
|
13
|
+
vUv = (tileTransform * vec3(uv, 1.0)).xy;
|
|
14
|
+
#if defined(TILE_BLEND) && defined(UV_TILE)
|
|
15
|
+
vUvNext = (nextTileTransform * vec3(uv, 1.0)).xy;
|
|
16
|
+
#endif
|
|
17
|
+
#endif
|
|
18
|
+
`;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './chunks';
|
|
2
|
+
export {default as particleVertShader} from './particle_vert.glsl';
|
|
3
|
+
export {default as particleFragShader} from './particle_frag.glsl';
|
|
4
|
+
export {default as localParticleVertShader} from './local_particle_vert.glsl';
|
|
5
|
+
export {default as localParticlePhysicsVertShader} from './local_particle_physics_vert.glsl';
|
|
6
|
+
export {default as particlePhysicsFragShader} from './particle_physics_frag.glsl';
|
|
7
|
+
export {default as stretchedBillboardVertShader} from './stretched_bb_particle_vert.glsl';
|
|
8
|
+
export {default as trailVertShader} from './trail_vert.glsl';
|
|
9
|
+
export {default as trailFragShader} from './trail_frag.glsl';
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export default /* glsl */ `
|
|
2
|
+
attribute vec3 position;
|
|
3
|
+
attribute vec2 uv;
|
|
4
|
+
attribute vec3 normal;
|
|
5
|
+
attribute vec3 offset;
|
|
6
|
+
attribute vec4 color;
|
|
7
|
+
attribute vec3 size;
|
|
8
|
+
attribute vec4 rotation;
|
|
9
|
+
attribute float uvTile;
|
|
10
|
+
|
|
11
|
+
uniform mat4 world;
|
|
12
|
+
uniform mat4 view;
|
|
13
|
+
uniform mat4 projection;
|
|
14
|
+
|
|
15
|
+
#ifdef UV_TILE
|
|
16
|
+
uniform float tileCountX;
|
|
17
|
+
uniform float tileCountY;
|
|
18
|
+
#endif
|
|
19
|
+
|
|
20
|
+
varying vec2 vUV;
|
|
21
|
+
varying vec4 vColor;
|
|
22
|
+
varying vec3 vNormal;
|
|
23
|
+
varying vec3 vWorldPos;
|
|
24
|
+
|
|
25
|
+
#ifdef SOFT_PARTICLES
|
|
26
|
+
varying vec4 projPosition;
|
|
27
|
+
varying float linearDepth;
|
|
28
|
+
#endif
|
|
29
|
+
|
|
30
|
+
vec3 applyQuaternion(vec3 v, vec4 q) {
|
|
31
|
+
vec3 qVec = q.xyz;
|
|
32
|
+
float qW = q.w;
|
|
33
|
+
vec3 t = 2.0 * cross(qVec, v);
|
|
34
|
+
return v + qW * t + cross(qVec, t);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
void main() {
|
|
38
|
+
vec3 scaledPosition = position * size;
|
|
39
|
+
vec3 rotatedPosition = applyQuaternion(scaledPosition, rotation);
|
|
40
|
+
vec3 rotatedNormal = normalize(applyQuaternion(normal, rotation));
|
|
41
|
+
vec3 localPos = rotatedPosition + offset;
|
|
42
|
+
|
|
43
|
+
vec4 worldPos = world * vec4(localPos, 1.0);
|
|
44
|
+
vec4 viewPos = view * worldPos;
|
|
45
|
+
gl_Position = projection * viewPos;
|
|
46
|
+
|
|
47
|
+
vWorldPos = worldPos.xyz;
|
|
48
|
+
vNormal = normalize((world * vec4(rotatedNormal, 0.0)).xyz);
|
|
49
|
+
|
|
50
|
+
#ifdef SOFT_PARTICLES
|
|
51
|
+
projPosition = gl_Position;
|
|
52
|
+
linearDepth = -viewPos.z;
|
|
53
|
+
#endif
|
|
54
|
+
|
|
55
|
+
#ifdef UV_TILE
|
|
56
|
+
vec2 tc = vec2(tileCountX, tileCountY);
|
|
57
|
+
float tileU = mod(uvTile, tc.x) / tc.x;
|
|
58
|
+
float tileV = 1.0 - floor(uvTile / tc.x) / tc.y - 1.0 / tc.y;
|
|
59
|
+
vUV = uv / tc + vec2(tileU, tileV);
|
|
60
|
+
#else
|
|
61
|
+
vUV = uv;
|
|
62
|
+
#endif
|
|
63
|
+
|
|
64
|
+
vColor = color;
|
|
65
|
+
}
|
|
66
|
+
`;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export default /* glsl */ `
|
|
2
|
+
// Per-vertex attributes
|
|
3
|
+
attribute vec3 position;
|
|
4
|
+
attribute vec2 uv;
|
|
5
|
+
|
|
6
|
+
// Per-instance attributes
|
|
7
|
+
attribute vec3 offset;
|
|
8
|
+
attribute vec4 color;
|
|
9
|
+
attribute vec3 size;
|
|
10
|
+
attribute vec4 rotation;
|
|
11
|
+
attribute float uvTile;
|
|
12
|
+
|
|
13
|
+
// Uniforms
|
|
14
|
+
uniform mat4 worldViewProjection;
|
|
15
|
+
|
|
16
|
+
#ifdef UV_TILE
|
|
17
|
+
uniform float tileCountX;
|
|
18
|
+
uniform float tileCountY;
|
|
19
|
+
#endif
|
|
20
|
+
|
|
21
|
+
// Varyings
|
|
22
|
+
varying vec2 vUV;
|
|
23
|
+
varying vec4 vColor;
|
|
24
|
+
|
|
25
|
+
vec3 applyQuaternion(vec3 v, vec4 q) {
|
|
26
|
+
vec3 qVec = q.xyz;
|
|
27
|
+
float qW = q.w;
|
|
28
|
+
vec3 t = 2.0 * cross(qVec, v);
|
|
29
|
+
return v + qW * t + cross(qVec, t);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
void main() {
|
|
33
|
+
vec3 rotatedPosition = applyQuaternion(position * size, rotation);
|
|
34
|
+
vec3 worldPos = rotatedPosition + offset;
|
|
35
|
+
|
|
36
|
+
gl_Position = worldViewProjection * vec4(worldPos, 1.0);
|
|
37
|
+
|
|
38
|
+
#ifdef UV_TILE
|
|
39
|
+
vec2 tc = vec2(tileCountX, tileCountY);
|
|
40
|
+
float baseTile = floor(uvTile);
|
|
41
|
+
float tileU = mod(baseTile, tc.x) / tc.x;
|
|
42
|
+
float tileV = 1.0 - floor(baseTile / tc.x) / tc.y - 1.0 / tc.y;
|
|
43
|
+
vUV = uv / tc + vec2(tileU, tileV);
|
|
44
|
+
#else
|
|
45
|
+
vUV = uv;
|
|
46
|
+
#endif
|
|
47
|
+
|
|
48
|
+
vColor = color;
|
|
49
|
+
}
|
|
50
|
+
`;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export default /* glsl */ `
|
|
2
|
+
varying vec2 vUV;
|
|
3
|
+
varying vec4 vColor;
|
|
4
|
+
|
|
5
|
+
#ifdef TILE_BLEND
|
|
6
|
+
varying vec2 vUV2;
|
|
7
|
+
varying float vTileBlend;
|
|
8
|
+
#endif
|
|
9
|
+
|
|
10
|
+
#ifdef USE_MAP
|
|
11
|
+
uniform sampler2D map;
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
#ifdef SOFT_PARTICLES
|
|
15
|
+
uniform sampler2D depthTexture;
|
|
16
|
+
uniform vec2 softParams;
|
|
17
|
+
uniform vec4 projParams;
|
|
18
|
+
varying vec4 projPosition;
|
|
19
|
+
varying float linearDepth;
|
|
20
|
+
#endif
|
|
21
|
+
|
|
22
|
+
#ifdef USE_ALPHATEST
|
|
23
|
+
uniform float alphaTest;
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
void main() {
|
|
27
|
+
vec4 baseColor = vColor;
|
|
28
|
+
|
|
29
|
+
#ifdef USE_MAP
|
|
30
|
+
vec4 texColor = texture2D(map, vUV);
|
|
31
|
+
#ifdef TILE_BLEND
|
|
32
|
+
vec4 texColor2 = texture2D(map, vUV2);
|
|
33
|
+
texColor = mix(texColor, texColor2, vTileBlend);
|
|
34
|
+
#endif
|
|
35
|
+
baseColor *= texColor;
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
#ifdef USE_COLOR_AS_ALPHA
|
|
39
|
+
baseColor.a *= (baseColor.r + baseColor.g + baseColor.b) / 3.0;
|
|
40
|
+
#endif
|
|
41
|
+
|
|
42
|
+
#ifdef USE_ALPHATEST
|
|
43
|
+
if (baseColor.a < alphaTest) discard;
|
|
44
|
+
#else
|
|
45
|
+
if (baseColor.a < 0.01) discard;
|
|
46
|
+
#endif
|
|
47
|
+
|
|
48
|
+
gl_FragColor = baseColor;
|
|
49
|
+
|
|
50
|
+
#ifdef SOFT_PARTICLES
|
|
51
|
+
vec2 p2 = projPosition.xy / projPosition.w;
|
|
52
|
+
p2 = 0.5 * p2 + 0.5;
|
|
53
|
+
float readDepth = texture2D(depthTexture, p2.xy).r;
|
|
54
|
+
float zNear = projParams.x;
|
|
55
|
+
float zFar = projParams.y;
|
|
56
|
+
float viewDepth = (zFar * zNear) / (zFar - readDepth * (zFar - zNear));
|
|
57
|
+
float fade = clamp(softParams.y * ((viewDepth - softParams.x) - linearDepth), 0.0, 1.0);
|
|
58
|
+
gl_FragColor *= fade;
|
|
59
|
+
#endif
|
|
60
|
+
}
|
|
61
|
+
`;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export default /* glsl */ `
|
|
2
|
+
varying vec2 vUV;
|
|
3
|
+
varying vec4 vColor;
|
|
4
|
+
varying vec3 vNormal;
|
|
5
|
+
|
|
6
|
+
uniform vec3 lightDirection;
|
|
7
|
+
uniform vec3 lightColor;
|
|
8
|
+
uniform vec3 ambientColor;
|
|
9
|
+
|
|
10
|
+
#ifdef TILE_BLEND
|
|
11
|
+
varying vec2 vUV2;
|
|
12
|
+
varying float vTileBlend;
|
|
13
|
+
#endif
|
|
14
|
+
|
|
15
|
+
#ifdef USE_MAP
|
|
16
|
+
uniform sampler2D map;
|
|
17
|
+
#endif
|
|
18
|
+
|
|
19
|
+
#ifdef SOFT_PARTICLES
|
|
20
|
+
uniform sampler2D depthTexture;
|
|
21
|
+
uniform vec2 softParams;
|
|
22
|
+
uniform vec4 projParams;
|
|
23
|
+
varying vec4 projPosition;
|
|
24
|
+
varying float linearDepth;
|
|
25
|
+
#endif
|
|
26
|
+
|
|
27
|
+
#ifdef USE_ALPHATEST
|
|
28
|
+
uniform float alphaTest;
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
void main() {
|
|
32
|
+
vec4 baseColor = vColor;
|
|
33
|
+
|
|
34
|
+
#ifdef USE_MAP
|
|
35
|
+
vec4 texColor = texture2D(map, vUV);
|
|
36
|
+
#ifdef TILE_BLEND
|
|
37
|
+
vec4 texColor2 = texture2D(map, vUV2);
|
|
38
|
+
texColor = mix(texColor, texColor2, vTileBlend);
|
|
39
|
+
#endif
|
|
40
|
+
baseColor *= texColor;
|
|
41
|
+
#endif
|
|
42
|
+
|
|
43
|
+
#ifdef USE_ALPHATEST
|
|
44
|
+
if (baseColor.a < alphaTest) discard;
|
|
45
|
+
#else
|
|
46
|
+
if (baseColor.a < 0.01) discard;
|
|
47
|
+
#endif
|
|
48
|
+
|
|
49
|
+
vec3 N = normalize(vNormal);
|
|
50
|
+
vec3 L = normalize(-lightDirection);
|
|
51
|
+
float NdotL = max(dot(N, L), 0.0);
|
|
52
|
+
vec3 litColor = ambientColor + lightColor * NdotL;
|
|
53
|
+
|
|
54
|
+
gl_FragColor = vec4(baseColor.rgb * litColor, baseColor.a);
|
|
55
|
+
|
|
56
|
+
#ifdef SOFT_PARTICLES
|
|
57
|
+
vec2 p2 = projPosition.xy / projPosition.w;
|
|
58
|
+
p2 = 0.5 * p2 + 0.5;
|
|
59
|
+
float readDepth = texture2D(depthTexture, p2.xy).r;
|
|
60
|
+
float zNear = projParams.x;
|
|
61
|
+
float zFar = projParams.y;
|
|
62
|
+
float viewDepth = (zFar * zNear) / (zFar - readDepth * (zFar - zNear));
|
|
63
|
+
float fade = clamp(softParams.y * ((viewDepth - softParams.x) - linearDepth), 0.0, 1.0);
|
|
64
|
+
gl_FragColor *= fade;
|
|
65
|
+
#endif
|
|
66
|
+
}
|
|
67
|
+
`;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
export default /* glsl */ `
|
|
2
|
+
// Per-vertex attributes
|
|
3
|
+
attribute vec3 position;
|
|
4
|
+
attribute vec2 uv;
|
|
5
|
+
|
|
6
|
+
// Per-instance attributes
|
|
7
|
+
attribute vec3 offset;
|
|
8
|
+
attribute vec4 color;
|
|
9
|
+
attribute vec3 size;
|
|
10
|
+
attribute float rotation;
|
|
11
|
+
attribute float uvTile;
|
|
12
|
+
|
|
13
|
+
// Uniforms
|
|
14
|
+
uniform mat4 world;
|
|
15
|
+
uniform mat4 view;
|
|
16
|
+
uniform mat4 projection;
|
|
17
|
+
uniform mat4 worldViewProjection;
|
|
18
|
+
|
|
19
|
+
#ifdef UV_TILE
|
|
20
|
+
uniform float tileCountX;
|
|
21
|
+
uniform float tileCountY;
|
|
22
|
+
#endif
|
|
23
|
+
|
|
24
|
+
// Varyings
|
|
25
|
+
varying vec2 vUV;
|
|
26
|
+
varying vec4 vColor;
|
|
27
|
+
#ifdef TILE_BLEND
|
|
28
|
+
varying vec2 vUV2;
|
|
29
|
+
varying float vTileBlend;
|
|
30
|
+
#endif
|
|
31
|
+
#ifdef SOFT_PARTICLES
|
|
32
|
+
varying vec4 projPosition;
|
|
33
|
+
varying float linearDepth;
|
|
34
|
+
#endif
|
|
35
|
+
|
|
36
|
+
void main() {
|
|
37
|
+
float c = cos(rotation);
|
|
38
|
+
float s = sin(rotation);
|
|
39
|
+
|
|
40
|
+
vec2 alignedPosition = position.xy * size.xy;
|
|
41
|
+
vec2 rotatedPosition;
|
|
42
|
+
rotatedPosition.x = c * alignedPosition.x - s * alignedPosition.y;
|
|
43
|
+
rotatedPosition.y = s * alignedPosition.x + c * alignedPosition.y;
|
|
44
|
+
|
|
45
|
+
#ifdef HORIZONTAL
|
|
46
|
+
vec4 mvPosition = world * vec4(offset, 1.0);
|
|
47
|
+
mvPosition.x += rotatedPosition.x;
|
|
48
|
+
mvPosition.z -= rotatedPosition.y;
|
|
49
|
+
mvPosition = view * mvPosition;
|
|
50
|
+
#elif defined(VERTICAL)
|
|
51
|
+
vec4 mvPosition = world * vec4(offset, 1.0);
|
|
52
|
+
mvPosition.y += rotatedPosition.y;
|
|
53
|
+
mvPosition = view * mvPosition;
|
|
54
|
+
mvPosition.x += rotatedPosition.x;
|
|
55
|
+
#else
|
|
56
|
+
vec4 mvPosition = view * world * vec4(offset, 1.0);
|
|
57
|
+
mvPosition.xy += rotatedPosition;
|
|
58
|
+
#endif
|
|
59
|
+
|
|
60
|
+
gl_Position = projection * mvPosition;
|
|
61
|
+
#ifdef SOFT_PARTICLES
|
|
62
|
+
projPosition = gl_Position;
|
|
63
|
+
linearDepth = -mvPosition.z;
|
|
64
|
+
#endif
|
|
65
|
+
|
|
66
|
+
#ifdef UV_TILE
|
|
67
|
+
vec2 tc = vec2(tileCountX, tileCountY);
|
|
68
|
+
float baseTile = floor(uvTile);
|
|
69
|
+
float tileU = mod(baseTile, tc.x) / tc.x;
|
|
70
|
+
float tileV = 1.0 - floor(baseTile / tc.x) / tc.y - 1.0 / tc.y;
|
|
71
|
+
vUV = uv / tc + vec2(tileU, tileV);
|
|
72
|
+
#ifdef TILE_BLEND
|
|
73
|
+
float nextTile = ceil(uvTile);
|
|
74
|
+
float nextU = mod(nextTile, tc.x) / tc.x;
|
|
75
|
+
float nextV = 1.0 - floor(nextTile / tc.x) / tc.y - 1.0 / tc.y;
|
|
76
|
+
vUV2 = uv / tc + vec2(nextU, nextV);
|
|
77
|
+
vTileBlend = fract(uvTile);
|
|
78
|
+
#endif
|
|
79
|
+
#else
|
|
80
|
+
vUV = uv;
|
|
81
|
+
#endif
|
|
82
|
+
|
|
83
|
+
vColor = color;
|
|
84
|
+
}
|
|
85
|
+
`;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export default /* glsl */ `
|
|
2
|
+
// Per-vertex attributes
|
|
3
|
+
attribute vec3 position;
|
|
4
|
+
attribute vec2 uv;
|
|
5
|
+
|
|
6
|
+
// Per-instance attributes
|
|
7
|
+
attribute vec3 offset;
|
|
8
|
+
attribute vec4 color;
|
|
9
|
+
attribute vec3 size;
|
|
10
|
+
attribute float rotation;
|
|
11
|
+
attribute float uvTile;
|
|
12
|
+
attribute vec4 velocity;
|
|
13
|
+
|
|
14
|
+
// Uniforms
|
|
15
|
+
uniform mat4 world;
|
|
16
|
+
uniform mat4 view;
|
|
17
|
+
uniform mat4 projection;
|
|
18
|
+
uniform float speedFactor;
|
|
19
|
+
|
|
20
|
+
#ifdef UV_TILE
|
|
21
|
+
uniform float tileCountX;
|
|
22
|
+
uniform float tileCountY;
|
|
23
|
+
#endif
|
|
24
|
+
|
|
25
|
+
// Varyings
|
|
26
|
+
varying vec2 vUV;
|
|
27
|
+
varying vec4 vColor;
|
|
28
|
+
#ifdef TILE_BLEND
|
|
29
|
+
varying vec2 vUV2;
|
|
30
|
+
varying float vTileBlend;
|
|
31
|
+
#endif
|
|
32
|
+
#ifdef SOFT_PARTICLES
|
|
33
|
+
varying vec4 projPosition;
|
|
34
|
+
varying float linearDepth;
|
|
35
|
+
#endif
|
|
36
|
+
|
|
37
|
+
void main() {
|
|
38
|
+
float lengthFactor = velocity.w;
|
|
39
|
+
float avgSize = (size.x + size.y) * 0.5;
|
|
40
|
+
vec4 mvPosition = view * world * vec4(offset, 1.0);
|
|
41
|
+
vec3 viewVelocity = mat3(view * world) * velocity.xyz;
|
|
42
|
+
float vlength = length(viewVelocity);
|
|
43
|
+
if (vlength < 0.0001) {
|
|
44
|
+
vlength = 0.0001;
|
|
45
|
+
viewVelocity = vec3(0.0, 0.0, 1.0);
|
|
46
|
+
}
|
|
47
|
+
mvPosition.xyz += position.y * normalize(cross(mvPosition.xyz, viewVelocity)) * avgSize;
|
|
48
|
+
mvPosition.xyz -= (position.x + 0.5) * viewVelocity * (1.0 + lengthFactor / vlength) * avgSize;
|
|
49
|
+
gl_Position = projection * mvPosition;
|
|
50
|
+
#ifdef SOFT_PARTICLES
|
|
51
|
+
projPosition = gl_Position;
|
|
52
|
+
linearDepth = -mvPosition.z;
|
|
53
|
+
#endif
|
|
54
|
+
|
|
55
|
+
#ifdef UV_TILE
|
|
56
|
+
vec2 tc = vec2(tileCountX, tileCountY);
|
|
57
|
+
float baseTile = floor(uvTile);
|
|
58
|
+
float tileU = mod(baseTile, tc.x) / tc.x;
|
|
59
|
+
float tileV = 1.0 - floor(baseTile / tc.x) / tc.y - 1.0 / tc.y;
|
|
60
|
+
vUV = uv / tc + vec2(tileU, tileV);
|
|
61
|
+
#ifdef TILE_BLEND
|
|
62
|
+
float nextTile = ceil(uvTile);
|
|
63
|
+
float nextU = mod(nextTile, tc.x) / tc.x;
|
|
64
|
+
float nextV = 1.0 - floor(nextTile / tc.x) / tc.y - 1.0 / tc.y;
|
|
65
|
+
vUV2 = uv / tc + vec2(nextU, nextV);
|
|
66
|
+
vTileBlend = fract(uvTile);
|
|
67
|
+
#endif
|
|
68
|
+
#else
|
|
69
|
+
vUV = uv;
|
|
70
|
+
#endif
|
|
71
|
+
|
|
72
|
+
vColor = color;
|
|
73
|
+
}
|
|
74
|
+
`;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export default /* glsl */ `
|
|
2
|
+
varying vec2 vUV;
|
|
3
|
+
varying vec4 vColor;
|
|
4
|
+
|
|
5
|
+
#ifdef USE_MAP
|
|
6
|
+
uniform sampler2D map;
|
|
7
|
+
#endif
|
|
8
|
+
|
|
9
|
+
void main() {
|
|
10
|
+
vec4 baseColor = vColor;
|
|
11
|
+
|
|
12
|
+
#ifdef USE_MAP
|
|
13
|
+
vec4 texColor = texture2D(map, vUV);
|
|
14
|
+
baseColor *= texColor;
|
|
15
|
+
#endif
|
|
16
|
+
|
|
17
|
+
if (baseColor.a < 0.01) discard;
|
|
18
|
+
|
|
19
|
+
gl_FragColor = baseColor;
|
|
20
|
+
}
|
|
21
|
+
`;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export default /* glsl */ `
|
|
2
|
+
attribute vec3 position;
|
|
3
|
+
attribute vec3 previous;
|
|
4
|
+
attribute vec3 next;
|
|
5
|
+
attribute float side;
|
|
6
|
+
attribute float width;
|
|
7
|
+
attribute vec2 uv;
|
|
8
|
+
attribute vec4 color;
|
|
9
|
+
|
|
10
|
+
uniform mat4 view;
|
|
11
|
+
uniform mat4 projection;
|
|
12
|
+
uniform float lineWidth;
|
|
13
|
+
uniform vec2 resolution;
|
|
14
|
+
uniform float sizeAttenuation;
|
|
15
|
+
|
|
16
|
+
varying vec2 vUV;
|
|
17
|
+
varying vec4 vColor;
|
|
18
|
+
|
|
19
|
+
vec2 fix(vec4 i, float aspect) {
|
|
20
|
+
vec2 res = i.xy / i.w;
|
|
21
|
+
res.x *= aspect;
|
|
22
|
+
return res;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
void main() {
|
|
26
|
+
float aspect = resolution.x / resolution.y;
|
|
27
|
+
vec4 finalPosition = projection * view * vec4(position, 1.0);
|
|
28
|
+
vec4 prevPos = projection * view * vec4(previous, 1.0);
|
|
29
|
+
vec4 nextPos = projection * view * vec4(next, 1.0);
|
|
30
|
+
|
|
31
|
+
vec2 currentP = fix(finalPosition, aspect);
|
|
32
|
+
vec2 prevP = fix(prevPos, aspect);
|
|
33
|
+
vec2 nextP = fix(nextPos, aspect);
|
|
34
|
+
|
|
35
|
+
float w = lineWidth * width;
|
|
36
|
+
vec2 dir;
|
|
37
|
+
if (distance(nextP, currentP) < 0.0001) {
|
|
38
|
+
dir = normalize(currentP - prevP);
|
|
39
|
+
} else if (distance(prevP, currentP) < 0.0001) {
|
|
40
|
+
dir = normalize(nextP - currentP);
|
|
41
|
+
} else {
|
|
42
|
+
vec2 dir1 = normalize(currentP - prevP);
|
|
43
|
+
vec2 dir2 = normalize(nextP - currentP);
|
|
44
|
+
dir = normalize(dir1 + dir2);
|
|
45
|
+
}
|
|
46
|
+
vec4 normal = vec4(-dir.y, dir.x, 0.0, 1.0);
|
|
47
|
+
normal.xy *= 0.5 * w;
|
|
48
|
+
normal *= projection;
|
|
49
|
+
if (sizeAttenuation == 0.0) {
|
|
50
|
+
normal.xy *= finalPosition.w;
|
|
51
|
+
normal.xy /= (vec4(resolution, 0.0, 1.0) * projection).xy;
|
|
52
|
+
}
|
|
53
|
+
finalPosition.xy += normal.xy * side;
|
|
54
|
+
gl_Position = finalPosition;
|
|
55
|
+
vUV = uv;
|
|
56
|
+
vColor = color;
|
|
57
|
+
}
|
|
58
|
+
`;
|