@woosh/meep-engine 2.33.24 → 2.33.25

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 (74) hide show
  1. package/core/bvh2/binary/IndexedBinaryBVH.js +1 -1
  2. package/core/bvh2/traversal/ThreeClippingPlaneComputingBVHVisitor.js +5 -1
  3. package/core/bvh2/traversal/__detailed_box_volume_intersection.js +22 -5
  4. package/core/collection/array/binarySearchHighIndex.js +1 -1
  5. package/core/collection/array/copyArray.js +2 -2
  6. package/core/geom/3d/normal/hemioct/unit_hemioct.spec.js +1 -1
  7. package/core/geom/3d/shape/AbstractShape3D.js +9 -0
  8. package/core/geom/3d/shape/CompositeShape.js +188 -8
  9. package/core/geom/3d/shape/TransformedShape3D.js +58 -2
  10. package/core/geom/3d/shape/UnitCubeShape3D.js +11 -0
  11. package/core/geom/3d/shape/UnitSphereShape3D.js +8 -0
  12. package/core/geom/3d/shape/util/shape_to_visual_entity.js +159 -0
  13. package/core/geom/random/randomPointInSphere.js +3 -2
  14. package/core/json/resolvePathByArray.js +2 -2
  15. package/{engine/graphics/render/forward_plus/materials → core/primitives/strings}/insert_after.js +3 -0
  16. package/core/primitives/strings/insert_after_or_replace.js +27 -0
  17. package/editor/process/symbolic/makeHelperBoxGeometry.js +44 -0
  18. package/editor/view/ecs/EntityEditor.js +2 -2
  19. package/editor/view/ecs/components/particles/ParticleEmitterController.js +2 -2
  20. package/engine/EngineHarness.js +1 -0
  21. package/engine/animation/AnimationUtils.js +5 -5
  22. package/engine/ecs/EntityBuilder.js +25 -5
  23. package/engine/ecs/attachment/AttachmentBinding.js +8 -0
  24. package/engine/ecs/attachment/AttachmentSystem.js +4 -0
  25. package/engine/ecs/attachment/TransformAttachmentBinding.js +14 -44
  26. package/engine/ecs/components/Tag.js +27 -6
  27. package/engine/ecs/fow/FogOfWar.js +4 -0
  28. package/engine/ecs/fow/FogOfWarSystem.js +2 -0
  29. package/engine/ecs/gui/hud/HeadsUpDisplaySystem.js +2 -0
  30. package/engine/ecs/system/AbstractContextSystem.js +1 -1
  31. package/engine/ecs/systems/TagSystem.js +17 -0
  32. package/engine/ecs/transform/Transform.js +19 -6
  33. package/engine/graphics/GraphicsEngine.js +11 -6
  34. package/engine/graphics/composit/CompositLayer.js +17 -4
  35. package/engine/graphics/composit/CompositingStages.js +8 -0
  36. package/engine/graphics/composit/LayerCompositer.js +35 -6
  37. package/engine/graphics/ecs/highlight/plugin/OutlineRenderPlugin.js +11 -7
  38. package/engine/graphics/ecs/light/Light.js +2 -0
  39. package/engine/graphics/ecs/light/binding/three/ThreeLightBinding.js +5 -1
  40. package/engine/graphics/ecs/mesh-v2/DrawMode.js +5 -0
  41. package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +32 -18
  42. package/engine/graphics/particles/ParticleEmitterLibrary.js +3 -0
  43. package/engine/graphics/particles/ecs/{ParticleEmitterSystem2.js → ParticleEmitterSystem.js} +17 -9
  44. package/engine/graphics/particles/particular/engine/ParticularEngine.js +8 -2
  45. package/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +14 -25
  46. package/engine/graphics/particles/particular/engine/emitter/ParticleEmitterFlag.js +5 -0
  47. package/engine/graphics/particles/particular/engine/emitter/ParticlePool.js +90 -2
  48. package/engine/graphics/particles/particular/engine/emitter/ParticlePool.spec.js +7 -7
  49. package/engine/graphics/particles/particular/engine/renderers/billboard/BILLBOARD_PARTICLE_SPECIFICATION.js +15 -12
  50. package/engine/graphics/particles/particular/engine/renderers/billboard/ParticleBillboardMaterial.js +262 -51
  51. package/engine/graphics/particles/particular/engine/shader/ShaderManager.js +80 -46
  52. package/engine/graphics/particles/particular/engine/shader/debugAtlas.js +14 -0
  53. package/engine/graphics/particles/particular/engine/utils/volume/AttributeValue.js +141 -0
  54. package/engine/graphics/particles/particular/engine/utils/volume/ParticleVolume.js +148 -54
  55. package/engine/graphics/particles/particular/engine/utils/volume/lut_to_sampler.js +27 -0
  56. package/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +542 -165
  57. package/engine/graphics/render/buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.js +12 -6
  58. package/engine/graphics/render/forward_plus/materials/FP_INJECTION_POINT_ACCUMULATION.js +1 -0
  59. package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_ACCUMULATION.js +32 -0
  60. package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_DECODE_PARS.js +51 -0
  61. package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_PREAMBLE.js +25 -0
  62. package/engine/graphics/render/forward_plus/materials/fp_build_fragment_shader.js +31 -120
  63. package/engine/graphics/render/forward_plus/materials/fp_build_vertex_lighting_shared.js +35 -0
  64. package/engine/graphics/render/forward_plus/materials/fp_build_vertex_shader.js +4 -5
  65. package/engine/graphics/render/forward_plus/plugin/MaterialTransformer.js +10 -3
  66. package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +588 -53
  67. package/engine/graphics/render/forward_plus/prototypeLightManager.js +29 -4
  68. package/engine/graphics/shaders/TerrainShader.js +4 -5
  69. package/engine/graphics/util/composeMatrix4.js +33 -23
  70. package/engine/graphics/util/decompose_matrix_4_array.js +61 -0
  71. package/engine/intelligence/behavior/ecs/BehaviorComponent.js +30 -14
  72. package/engine/knowledge/database/StaticKnowledgeDataTable.js +6 -1
  73. package/engine/navigation/ecs/components/Path.js +0 -5
  74. package/package.json +1 -1
@@ -1,8 +1,141 @@
1
- import { AddEquation, CustomBlending, Matrix4, OneFactor, OneMinusSrcAlphaFactor, ShaderMaterial } from "three";
1
+ import {
2
+ AddEquation,
3
+ CustomBlending,
4
+ GLSL3,
5
+ Matrix4,
6
+ OneFactor,
7
+ OneMinusSrcAlphaFactor,
8
+ ShaderMaterial,
9
+ UniformsLib,
10
+ UniformsUtils
11
+ } from "three";
2
12
  import { Vector2 as ThreeVector2 } from "three/src/math/Vector2.js";
3
13
 
4
14
  const DEPTH_ERROR_MARGIN = 0.0001;
5
15
 
16
+ const CHUNK_LAMBERT_LIGHTING = `
17
+ vec3 diffuse = vec3( 1.0 );
18
+
19
+ GeometricContext geometry;
20
+ geometry.position = mvPosition.xyz;
21
+ geometry.normal = normalize( transformedNormal );
22
+ geometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( -mvPosition.xyz );
23
+
24
+ GeometricContext backGeometry;
25
+ backGeometry.position = geometry.position;
26
+ backGeometry.normal = -geometry.normal;
27
+ backGeometry.viewDir = geometry.viewDir;
28
+
29
+ vLightFront = vec3( 0.0 );
30
+ vIndirectFront = vec3( 0.0 );
31
+ #ifdef DOUBLE_SIDED
32
+ vLightBack = vec3( 0.0 );
33
+ vIndirectBack = vec3( 0.0 );
34
+ #endif
35
+
36
+ IncidentLight directLight;
37
+ float dotNL;
38
+ vec3 directLightColor_Diffuse;
39
+
40
+ vIndirectFront += getAmbientLightIrradiance( ambientLightColor );
41
+
42
+ vIndirectFront += getLightProbeIrradiance( lightProbe, geometry.normal );
43
+
44
+ #ifdef DOUBLE_SIDED
45
+
46
+ vIndirectBack += getAmbientLightIrradiance( ambientLightColor );
47
+
48
+ vIndirectBack += getLightProbeIrradiance( lightProbe, backGeometry.normal );
49
+
50
+ #endif
51
+
52
+ #if NUM_POINT_LIGHTS > 0
53
+
54
+ #pragma unroll_loop_start
55
+ for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {
56
+
57
+ getPointLightInfo( pointLights[ i ], geometry, directLight );
58
+
59
+ dotNL = dot( geometry.normal, directLight.direction );
60
+ directLightColor_Diffuse = directLight.color;
61
+
62
+ vLightFront += saturate( dotNL ) * directLightColor_Diffuse;
63
+
64
+ #ifdef DOUBLE_SIDED
65
+
66
+ vLightBack += saturate( - dotNL ) * directLightColor_Diffuse;
67
+
68
+ #endif
69
+
70
+ }
71
+ #pragma unroll_loop_end
72
+
73
+ #endif
74
+
75
+ #if NUM_SPOT_LIGHTS > 0
76
+
77
+ #pragma unroll_loop_start
78
+ for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {
79
+
80
+ getSpotLightInfo( spotLights[ i ], geometry, directLight );
81
+
82
+ dotNL = dot( geometry.normal, directLight.direction );
83
+ directLightColor_Diffuse = directLight.color;
84
+
85
+ vLightFront += saturate( dotNL ) * directLightColor_Diffuse;
86
+
87
+ #ifdef DOUBLE_SIDED
88
+
89
+ vLightBack += saturate( - dotNL ) * directLightColor_Diffuse;
90
+
91
+ #endif
92
+ }
93
+ #pragma unroll_loop_end
94
+
95
+ #endif
96
+
97
+ #if NUM_DIR_LIGHTS > 0
98
+
99
+ #pragma unroll_loop_start
100
+ for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
101
+
102
+ getDirectionalLightInfo( directionalLights[ i ], geometry, directLight );
103
+
104
+ dotNL = dot( geometry.normal, directLight.direction );
105
+ directLightColor_Diffuse = directLight.color;
106
+
107
+ vLightFront += saturate( dotNL ) * directLightColor_Diffuse;
108
+
109
+ #ifdef DOUBLE_SIDED
110
+
111
+ vLightBack += saturate( - dotNL ) * directLightColor_Diffuse;
112
+
113
+ #endif
114
+
115
+ }
116
+ #pragma unroll_loop_end
117
+
118
+ #endif
119
+
120
+ #if NUM_HEMI_LIGHTS > 0
121
+
122
+ #pragma unroll_loop_start
123
+ for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {
124
+
125
+ vIndirectFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry.normal );
126
+
127
+ #ifdef DOUBLE_SIDED
128
+
129
+ vIndirectBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry.normal );
130
+
131
+ #endif
132
+
133
+ }
134
+ #pragma unroll_loop_end
135
+
136
+ #endif
137
+ `;
138
+
6
139
  function make_vertex_shader() {
7
140
  return `
8
141
  uniform float cameraNear;
@@ -23,6 +156,29 @@ function make_vertex_shader() {
23
156
  varying vec2 vRotationMultiplier;
24
157
  varying float vBlending;
25
158
 
159
+
160
+ #if defined(LIGHTS_ENABLED)
161
+ #include <common>
162
+ #include <bsdfs>
163
+ #include <lights_pars_begin>
164
+
165
+ struct LambertMaterial {
166
+ vec3 diffuseColor;
167
+ };
168
+
169
+ void RE_Direct_Lambert( const in IncidentLight directLight, const in GeometricContext geometry, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {
170
+ vec3 irradiance = directLight.color;
171
+ reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
172
+ }
173
+
174
+ void RE_IndirectDiffuse_Lambert( const in vec3 irradiance, const in GeometricContext geometry, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {
175
+ reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
176
+ }
177
+
178
+ #define RE_Direct RE_Direct_Lambert
179
+ #define RE_IndirectDiffuse RE_IndirectDiffuse_Lambert
180
+ #endif
181
+
26
182
  void main() {
27
183
 
28
184
  vColor = color;
@@ -32,9 +188,20 @@ function make_vertex_shader() {
32
188
 
33
189
  mat4 modelViewProjectionMatrix = projectionMatrix * modelViewMatrix;
34
190
 
191
+ vec3 transformed = position;
192
+
35
193
  vec4 position4 = vec4( position, 1.0 );
36
-
194
+
195
+ #if defined(LIGHTS_ENABLED)
196
+ vec4 mvPosition = modelViewMatrix * position4;
197
+ vec3 vViewPosition = -mvPosition.xyz;
198
+
199
+ vec3 transformedNormal = vec3(0.0,0.0,1.0);
200
+ #else
201
+ #endif
202
+
37
203
  gl_Position = modelViewProjectionMatrix * position4;
204
+
38
205
 
39
206
  float rotationGlobal = rotation;
40
207
 
@@ -59,18 +226,48 @@ function make_vertex_shader() {
59
226
 
60
227
  vRotationMultiplier = vec2( cos(rotationGlobal),sin(rotationGlobal) );
61
228
 
62
- float radius = vSize/2.0;
229
+ float radius = vSize * 0.5;
63
230
 
231
+ float projected_radius = resolution.y * projectionMatrix[1][1] * radius / gl_Position.w;;
232
+
64
233
  #ifdef DEPTH_SOFT_ENABLED
65
234
 
66
- vFadeDistance = 1.0 / radius;
235
+ vFadeDistance = 1.0 / radius;
67
236
 
68
237
  #endif
69
-
70
- gl_PointSize = resolution.y * projectionMatrix[1][1] * radius / gl_Position.w;
238
+
239
+ gl_PointSize = projected_radius;
240
+
241
+ #if defined(LIGHTS_ENABLED)
242
+ vec3 vLightFront;
243
+ vec3 vIndirectFront;
244
+
245
+ #include <worldpos_vertex>
246
+ ${CHUNK_LAMBERT_LIGHTING}
247
+
248
+ LambertMaterial material = LambertMaterial(vColor.rgb);
249
+
250
+ ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
251
+ vec3 totalEmissiveRadiance = vec3(0.0);
252
+
253
+ reflectedLight.indirectDiffuse += vIndirectFront;
254
+ reflectedLight.indirectDiffuse *= BRDF_Lambert( vColor.rgb );
255
+
256
+ reflectedLight.directDiffuse = vLightFront;
257
+ reflectedLight.directDiffuse *= BRDF_Lambert( vColor.rgb ); // shadowmask goes here
258
+
259
+ //@injection_point FORWARD_PLUS:accumulation
260
+
261
+ vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;
262
+
263
+ vColor.rgb = outgoingLight;
264
+ #endif
265
+
71
266
  }`;
72
267
  }
73
268
 
269
+ //${CHUNK_LAMBERT_LIGHTING}
270
+ //#include <lights_lambert_vertex>
74
271
  function make_fragment_shader() {
75
272
  return `
76
273
  uniform sampler2D tSpriteAtlas;
@@ -88,6 +285,9 @@ function make_fragment_shader() {
88
285
  varying vec2 vRotationMultiplier;
89
286
  varying float vBlending;
90
287
 
288
+
289
+ out highp vec4 pc_fragColor;
290
+
91
291
  float depthToLinear( float z ) {
92
292
  float f = cameraFar;
93
293
  float n = cameraNear;
@@ -163,7 +363,7 @@ function make_fragment_shader() {
163
363
  discard;
164
364
  }
165
365
 
166
- vec4 texel = spriteColor *vColor;
366
+ vec4 texel = spriteColor * vColor;
167
367
 
168
368
  // premultiply alpha
169
369
  texel.xyz *= texel.a;
@@ -180,68 +380,78 @@ function make_fragment_shader() {
180
380
 
181
381
  #endif
182
382
 
183
- gl_FragColor = texel;
383
+ pc_fragColor = texel;
184
384
 
185
385
  }`;
186
386
  }
187
387
 
188
- /*
189
- NOTES:
190
- - To implement per-particle blend modes, we need to have access to what we're blending on to, that is - the color buffer
191
- Having the color buffer - we can do just about any kind of a blend
192
-
193
- - Support animation by adding animation sprite sheet to the main sprite atlas, record resolution of the sheet (in frames X,Y) and interpolate over tiles based on some parameter
388
+ /**
389
+ * NOTES:
390
+ * - To implement per-particle blend modes, we need to have access to what we're blending on to, that is - the color buffer
391
+ * Having the color buffer - we can do just about any kind of a blend
392
+ *
393
+ * - Support animation by adding animation sprite sheet to the main sprite atlas, record resolution of the sheet (in frames X,Y) and interpolate over tiles based on some parameter
394
+ * @param {boolean} [lights]
194
395
  */
195
- export function make_particle_billboard_shader() {
396
+ export function make_particle_billboard_shader({ lights = false } = {}) {
397
+ let uniforms = {
398
+ tSpriteAtlas: {
399
+ type: 't',
400
+ value: null
401
+ },
402
+ cameraNear: {
403
+ type: 'f',
404
+ value: 1,
405
+ },
406
+ cameraFar: {
407
+ type: 'f',
408
+ value: 1,
409
+ },
410
+ tDepth: {
411
+ type: 't',
412
+ value: null
413
+ },
414
+ tColor: {
415
+ type: 't',
416
+ value: null
417
+ },
418
+ modelViewMatrix: {
419
+ type: 'm4',
420
+ value: new Matrix4()
421
+ },
422
+ projectionMatrix: {
423
+ type: 'm4',
424
+ value: new Matrix4()
425
+ },
426
+ resolution: {
427
+ type: 'v2',
428
+ value: new ThreeVector2()
429
+ }
430
+ };
431
+
432
+ if (lights) {
433
+ // mix in light uniforms
434
+ uniforms = Object.assign(uniforms, UniformsUtils.clone(UniformsLib.lights));
435
+ }
436
+
196
437
  const shader = new ShaderMaterial({
197
438
  defines: {
198
439
  DEPTH_READ_ENABLED: true,
199
440
  DEPTH_SOFT_ENABLED: true,
200
441
  ALIGN_DIRECTION_ENABLED: false,
442
+ LIGHTS_ENABLED: lights,
443
+ LIGHTING_VERTEX_ONLY: true
201
444
  },
202
- uniforms: {
203
- tSpriteAtlas: {
204
- type: 't',
205
- value: null
206
- },
207
- cameraNear: {
208
- type: 'f',
209
- value: 1,
210
- },
211
- cameraFar: {
212
- type: 'f',
213
- value: 1,
214
- },
215
- tDepth: {
216
- type: 't',
217
- value: null
218
- },
219
- tColor: {
220
- type: 't',
221
- value: null
222
- },
223
- modelViewMatrix: {
224
- type: 'm4',
225
- value: new Matrix4()
226
- },
227
- projectionMatrix: {
228
- type: 'm4',
229
- value: new Matrix4()
230
- },
231
- resolution: {
232
- type: 'v2',
233
- value: new ThreeVector2()
234
- }
235
- },
445
+ uniforms: uniforms,
236
446
  vertexShader: make_vertex_shader(),
237
447
  fragmentShader: make_fragment_shader(),
238
448
  blending: CustomBlending,
239
- lights: false,
449
+ lights: lights,
240
450
  depthTest: true,
241
451
  depthWrite: false,
242
452
  transparent: true,
243
453
  vertexColors: false,
244
- glslVersion: 2
454
+ glslVersion: GLSL3
245
455
  });
246
456
 
247
457
  shader.blending = CustomBlending;
@@ -249,5 +459,6 @@ export function make_particle_billboard_shader() {
249
459
  shader.blendSrc = OneFactor;
250
460
  shader.blendDst = OneMinusSrcAlphaFactor;
251
461
 
462
+
252
463
  return shader;
253
464
  }
@@ -6,17 +6,22 @@ import {
6
6
  LinearMipMapLinearFilter,
7
7
  Matrix4,
8
8
  RGBAFormat,
9
- UnsignedByteType
9
+ UnsignedByteType,
10
+ Vector2 as ThreeVector2
10
11
  } from "three";
11
12
  import Vector2 from "../../../../../../core/geom/Vector2.js";
12
13
  import { HashMap } from "../../../../../../core/collection/HashMap.js";
13
14
  import { ParticleEmitterFlag } from "../emitter/ParticleEmitterFlag.js";
14
15
  import { writeSample2DDataToDataTexture } from "../../../../texture/sampler/writeSampler2DDataToDataTexture.js";
15
- import { TextureAtlasDebugger } from "../../../../texture/atlas/TextureAtlasDebugger.js";
16
16
  import { MaterialRecord } from "./MaterialRecord.js";
17
17
  import { make_particle_billboard_shader } from "../renderers/billboard/ParticleBillboardMaterial.js";
18
18
 
19
- const EMITTER_MATERIAL_FLAGS = ParticleEmitterFlag.DepthSoftDisabled | ParticleEmitterFlag.DepthReadDisabled | ParticleEmitterFlag.AlignOnVelocity;
19
+ const EMITTER_MATERIAL_FLAGS =
20
+ ParticleEmitterFlag.DepthSoftDisabled
21
+ | ParticleEmitterFlag.DepthReadDisabled
22
+ | ParticleEmitterFlag.AlignOnVelocity
23
+ | ParticleEmitterFlag.Lit
24
+ ;
20
25
 
21
26
  /**
22
27
  *
@@ -82,21 +87,21 @@ function buildDataTexture(
82
87
  return result;
83
88
  }
84
89
 
85
- function debugAtlas(atlas, options) {
86
-
87
- const spriteAtlasDebugger = new TextureAtlasDebugger(atlas, options);
88
-
89
- spriteAtlasDebugger.vAtlasContent.link();
90
- document.body.appendChild(spriteAtlasDebugger.vAtlasContent.el);
91
- }
92
-
93
90
  export class ShaderManager {
94
91
  /**
95
92
  *
96
93
  * @param {AssetManager} assetManager
94
+ * @param {MaterialManager} material_manager
97
95
  * @constructor
98
96
  */
99
- constructor(assetManager) {
97
+ constructor(assetManager, material_manager) {
98
+ /**
99
+ *
100
+ * @type {MaterialManager}
101
+ * @private
102
+ */
103
+ this.__material_manager = material_manager;
104
+
100
105
  /**
101
106
  *
102
107
  * @type {ManagedAtlas}
@@ -159,6 +164,34 @@ export class ShaderManager {
159
164
  //watch atlas updates
160
165
  this.spriteAtlas.atlas.on.painted.add(this.updateSpriteTexture, this);
161
166
 
167
+ /**
168
+ * Common shader uniforms, inherited by every material and updated centrally (here)
169
+ * @private
170
+ */
171
+ this.__common_uniforms = {
172
+ tSpriteAtlas: {
173
+ value: this.spriteTexture
174
+ },
175
+ tDepth: {
176
+ value: null
177
+ },
178
+ resolution: {
179
+ value: new ThreeVector2()
180
+ },
181
+ projectionMatrix: {
182
+ value: null
183
+ },
184
+ modelViewMatrix: {
185
+ value: null
186
+ },
187
+ cameraNear: {
188
+ value: 0
189
+ },
190
+ cameraFar: {
191
+ value: 0
192
+ }
193
+ };
194
+
162
195
  // debugAtlas(this.parameterSheet.atlas, { scale: new Vector2(16, 16) });
163
196
  // debugAtlas(this.spriteAtlas.atlas, { scale: new Vector2(0.5, 0.5) });
164
197
  }
@@ -184,8 +217,6 @@ export class ShaderManager {
184
217
  writeSample2DDataToDataTexture(atlas, dataTexture);
185
218
 
186
219
  this.materialMap.forEach(function (entry) {
187
- const material = entry.material;
188
- material.uniforms.tSpriteAtlas.value = dataTexture;
189
220
 
190
221
  entry.emitters.forEach(function (emitter) {
191
222
  //mark sprites for an update
@@ -202,19 +233,24 @@ export class ShaderManager {
202
233
  * @param {ParticleEmitter} emitter
203
234
  */
204
235
  buildMaterial(emitter) {
205
- const shader = make_particle_billboard_shader();
236
+ const lights_enabled = emitter.getFlag(ParticleEmitterFlag.Lit);
206
237
 
207
- shader.uniforms.tSpriteAtlas.value = this.spriteTexture;
208
- shader.uniforms.tDepth.value = this.depthTexture;
209
- shader.uniforms.resolution.value.set(this.viewportSize.x, this.viewportSize.y)
238
+ const shader = make_particle_billboard_shader({ lights: lights_enabled });
210
239
 
211
- shader.defines = {
212
- DEPTH_READ_ENABLED: !emitter.getFlag(ParticleEmitterFlag.DepthReadDisabled),
213
- DEPTH_SOFT_ENABLED: !emitter.getFlag(ParticleEmitterFlag.DepthSoftDisabled),
214
- ALIGN_DIRECTION_ENABLED: emitter.getFlag(ParticleEmitterFlag.AlignOnVelocity)
215
- };
240
+ shader.uniforms = Object.assign(shader.uniforms, this.__common_uniforms);
241
+
242
+ // write defines
243
+ const defs = shader.defines;
216
244
 
217
- return shader;
245
+ defs.DEPTH_READ_ENABLED = !emitter.getFlag(ParticleEmitterFlag.DepthReadDisabled);
246
+ defs.DEPTH_SOFT_ENABLED = !emitter.getFlag(ParticleEmitterFlag.DepthSoftDisabled);
247
+ defs.ALIGN_DIRECTION_ENABLED = emitter.getFlag(ParticleEmitterFlag.AlignOnVelocity);
248
+
249
+ const ref = this.__material_manager.obtain(shader);
250
+
251
+ // TODO track referecen and release it eventually
252
+
253
+ return ref.getValue();
218
254
  }
219
255
 
220
256
  /**
@@ -225,7 +261,12 @@ export class ShaderManager {
225
261
  const spriteAtlas = this.spriteAtlas;
226
262
 
227
263
  // load sprites
228
- emitter.layers.forEach(function (layer) {
264
+ const particle_layers = emitter.layers;
265
+ const layer_count = particle_layers.length;
266
+
267
+ for (let i = 0; i < layer_count; i++) {
268
+ const layer = particle_layers.get(i);
269
+
229
270
  const patchPromise = spriteAtlas.acquire(layer.imageURL);
230
271
 
231
272
  patchPromise.then(function (patch) {
@@ -233,7 +274,7 @@ export class ShaderManager {
233
274
  }, (e) => {
234
275
  console.warn(`Failed to load sprite '${layer.imageURL}':`, e);
235
276
  });
236
- });
277
+ }
237
278
 
238
279
  // obtain material
239
280
  let material, entry;
@@ -312,10 +353,12 @@ export class ShaderManager {
312
353
  const spriteAtlas = this.spriteAtlas;
313
354
 
314
355
  //release sprites
315
- emitter.layers.forEach(function (layer) {
356
+ const particle_layers = emitter.layers;
357
+ const layer_count = particle_layers.length;
358
+ for (let i = 0; i < layer_count; i++) {
359
+ const layer = particle_layers.get(i);
316
360
  spriteAtlas.release(layer.imageURL);
317
- });
318
-
361
+ }
319
362
 
320
363
  if (entry.count <= 0) {
321
364
  //last usage removed
@@ -348,15 +391,12 @@ export class ShaderManager {
348
391
  const cameraNear = camera.near;
349
392
  const cameraFar = camera.far;
350
393
 
351
- // TODO use a shader uniform structure to avoid iteration
352
- this.materialMap.forEach(function (entry) {
353
- const uniforms = entry.material.uniforms;
394
+ const uniforms = this.__common_uniforms;
354
395
 
355
- uniforms.projectionMatrix.value = projectionMatrix;
356
- uniforms.modelViewMatrix.value = modelViewMatrix;
357
- uniforms.cameraNear.value = cameraNear;
358
- uniforms.cameraFar.value = cameraFar;
359
- });
396
+ uniforms.projectionMatrix.value = projectionMatrix;
397
+ uniforms.modelViewMatrix.value = modelViewMatrix;
398
+ uniforms.cameraNear.value = cameraNear;
399
+ uniforms.cameraFar.value = cameraFar;
360
400
  }
361
401
 
362
402
  /**
@@ -366,11 +406,8 @@ export class ShaderManager {
366
406
  setDepthTexture(texture) {
367
407
  this.depthTexture = texture;
368
408
 
369
- // TODO use a shader uniform structure to avoid iteration
370
- this.materialMap.forEach(function (entry) {
371
- const material = entry.material;
372
- material.uniforms.tDepth.value = texture;
373
- });
409
+ this.__common_uniforms.tDepth.value = texture;
410
+
374
411
  }
375
412
 
376
413
  /**
@@ -381,10 +418,7 @@ export class ShaderManager {
381
418
  setViewportSize(x, y) {
382
419
  this.viewportSize.set(x, y);
383
420
 
384
- // TODO use a shader uniform structure to avoid iteration
385
- this.materialMap.forEach(function (entry) {
386
- entry.material.uniforms.resolution.value.set(x, y);
387
- });
421
+ this.__common_uniforms.resolution.value.set(x, y);
388
422
  }
389
423
  }
390
424
 
@@ -0,0 +1,14 @@
1
+ import { TextureAtlasDebugger } from "../../../../texture/atlas/TextureAtlasDebugger.js";
2
+
3
+ /**
4
+ *
5
+ * @param {TextureAtlas} atlas
6
+ * @param {*} options
7
+ */
8
+ function debugAtlas(atlas, options) {
9
+
10
+ const spriteAtlasDebugger = new TextureAtlasDebugger(atlas, options);
11
+
12
+ spriteAtlasDebugger.vAtlasContent.link();
13
+ document.body.appendChild(spriteAtlasDebugger.vAtlasContent.el);
14
+ }