@woosh/meep-engine 2.119.46 → 2.119.48

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/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Fully featured ECS game engine written in JavaScript",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.119.46",
8
+ "version": "2.119.48",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -1 +1 @@
1
- {"version":3,"file":"PathTracerProbeRenderer.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.js"],"names":[],"mappings":"AAuBA;IACI,mBAA0B;IAC1B,yBAAqB;IACrB,qBAAmB;IAEnB,qBAAyB;IAEzB,uBAA6B;IAE7B;;;;;;;;OAQG;IACH,kCAPW,MAAM,aACN,MAAM,YACN,MAAM,EAAE,mBACR,MAAM,UACN,MAAM,EAAE,iBACR,MAAM,QAchB;IAED,iFAuCC;IAKD,mBACC;IAED,4BAKC;CACJ;8BA9F6B,oBAAoB;2BAHvB,8BAA8B;gCADzB,mCAAmC"}
1
+ {"version":3,"file":"PathTracerProbeRenderer.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.js"],"names":[],"mappings":"AAuBA;IACI,mBAA0B;IAC1B,yBAAqB;IACrB,qBAAoB;IAEpB,qBAAyB;IAEzB,uBAA6B;IAE7B;;;;;;;;OAQG;IACH,kCAPW,MAAM,aACN,MAAM,YACN,MAAM,EAAE,mBACR,MAAM,UACN,MAAM,EAAE,iBACR,MAAM,QAchB;IAED,iFAuCC;IAKD,mBACC;IAED,4BAKC;CACJ;8BA9F6B,oBAAoB;2BAHvB,8BAA8B;gCADzB,mCAAmC"}
@@ -24,7 +24,7 @@ const sampled_irradiance = new Float32Array(3);
24
24
  export class PathTracerProbeRenderer extends ProbeRenderer {
25
25
  tracer = new PathTracer();
26
26
  max_bounce_count = 5;
27
- sample_count = 256;
27
+ sample_count = 4096;
28
28
  // sample_count = 40960;
29
29
  random = seededRandom(0);
30
30
 
@@ -3,8 +3,9 @@
3
3
  * @param {Engine} engine
4
4
  * @param {string} path
5
5
  * @param {LightProbeVolume} [volume]
6
+ * @param {number} [density] only used when building mesh, if loading this parameter is ignored
6
7
  * @return {Promise<LightProbeVolume>}
7
8
  */
8
- export function lpv_obtain_storage_cached_volume({ engine, path, volume }: Engine): Promise<LightProbeVolume>;
9
+ export function lpv_obtain_storage_cached_volume({ engine, path, volume, density }: Engine): Promise<LightProbeVolume>;
9
10
  import { LightProbeVolume } from "./LightProbeVolume.js";
10
11
  //# sourceMappingURL=lpv_obtain_storage_cached_volume.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"lpv_obtain_storage_cached_volume.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/lpv_obtain_storage_cached_volume.js"],"names":[],"mappings":"AASA;;;;;;GAMG;AACH,oFAFY,QAAQ,gBAAgB,CAAC,CAqEpC;iCA7EgC,uBAAuB"}
1
+ {"version":3,"file":"lpv_obtain_storage_cached_volume.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/lpv_obtain_storage_cached_volume.js"],"names":[],"mappings":"AASA;;;;;;;GAOG;AACH,6FAFY,QAAQ,gBAAgB,CAAC,CAsEpC;iCA/EgC,uBAAuB"}
@@ -12,12 +12,14 @@ import { LightProbeVolumeSerializationAdapter } from "./serialization/LightProbe
12
12
  * @param {Engine} engine
13
13
  * @param {string} path
14
14
  * @param {LightProbeVolume} [volume]
15
+ * @param {number} [density] only used when building mesh, if loading this parameter is ignored
15
16
  * @return {Promise<LightProbeVolume>}
16
17
  */
17
18
  export async function lpv_obtain_storage_cached_volume({
18
19
  engine,
19
20
  path,
20
- volume = new LightProbeVolume()
21
+ volume = new LightProbeVolume(),
22
+ density = 500
21
23
  }) {
22
24
 
23
25
  volume.clear();
@@ -69,7 +71,7 @@ export async function lpv_obtain_storage_cached_volume({
69
71
  engine,
70
72
  ecd,
71
73
  bounds: mesh_bounds,
72
- density: 500
74
+ density: density
73
75
  });
74
76
 
75
77
  const buffer = new BinaryBuffer();
@@ -1 +1 @@
1
- {"version":3,"file":"PathTracedScene.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/PathTracedScene.js"],"names":[],"mappings":"AAiCA;IAGI;;;OAGG;IACH,eAFU,GAAG,CAEa;IAG1B;;;OAGG;IACH,QAFU,IAAI,MAAM,EAAE,cAAc,CAAC,CAElB;IAEnB;;;OAGG;IACH,UAFU,aAAa,EAAE,CAEX;IAEd;;;OAGG;IACH,WAFU,IAAI,MAAM,cAAc,EAAE,mBAAmB,CAAC,CAElC;IAmBtB;;;;OAIG;IACH,6BAA6C;IAkF7C,iBAOC;IAED;;;;OAIG;IACH,uBAHW,MAAM,cAAc,GACnB,mBAAmB,CAmB9B;IAED;;;OAGG;IACH,gBAFW,aAAa,QAMvB;IAED;;;;OAIG;IACH,cAHW,cAAc,GACZ,OAAO,CAInB;IAED;;;;OAIG;IACH,cAHW,cAAc,GACZ,OAAO,CAiCnB;IAED;;;;OAIG;IACH,iBAHW,cAAc,GACZ,OAAO,CAgBnB;IAED;;;;OAIG;IACH,yBAHW,MAAM,QAAQ,oBAKxB;IAED;;;;;OAKG;IACH,qBAJW,MAAM,cAAc,YACpB,MAAM,QAAQ,aACd,OAAK,MAAM,EAAE,QAavB;IAED;;;;;OAKG;IACH,qBAJW,MAAM,EAAE,OACR,MAAM,EAAE,gBACR,IAAI,QA0Cd;IAED;;;;OAIG;IACH,cAHW,IAAI,GACF,OAAO,CAsCnB;IAED;;;;;OAKG;IACH,WAJW,MAAM,EAAE,OACR,MAAM,EAAE,GAAC,IAAI,GACZ,MAAM,CA+CjB;IAED;;;;;;OAMG;IACH,uBALW,MAAM,EAAE,cACR,MAAM,aACN,MAAM,EAAE,oBACR,MAAM,QAIhB;IAED;;;;;OAKG;IACH,mBAJW,MAAM,EAAE,cACR,MAAM,OACN,MAAM,EAAE,QAkElB;;CACJ;oBAjhB8B,mCAAmC;+BAmBnC,qBAAqB;8BAJtB,kDAAkD;oCAC5C,0BAA0B;qBALzC,kCAAkC"}
1
+ {"version":3,"file":"PathTracedScene.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/PathTracedScene.js"],"names":[],"mappings":"AAmDA;IAGI;;;OAGG;IACH,eAFU,GAAG,CAEa;IAG1B;;;OAGG;IACH,QAFU,IAAI,MAAM,EAAE,cAAc,CAAC,CAElB;IAEnB;;;OAGG;IACH,UAFU,aAAa,EAAE,CAEX;IAEd;;;OAGG;IACH,WAFU,IAAI,MAAM,cAAc,EAAE,mBAAmB,CAAC,CAElC;IAmBtB;;;;OAIG;IACH,6BAA6C;IAkF7C,iBAOC;IAED;;;;OAIG;IACH,uBAHW,MAAM,cAAc,GACnB,mBAAmB,CAmB9B;IAED;;;OAGG;IACH,gBAFW,aAAa,QAMvB;IAED;;;;OAIG;IACH,cAHW,cAAc,GACZ,OAAO,CAInB;IAED;;;;OAIG;IACH,cAHW,cAAc,GACZ,OAAO,CAiCnB;IAED;;;;OAIG;IACH,iBAHW,cAAc,GACZ,OAAO,CAgBnB;IAED;;;;OAIG;IACH,yBAHW,MAAM,QAAQ,oBAKxB;IAED;;;;;OAKG;IACH,qBAJW,MAAM,cAAc,YACpB,MAAM,QAAQ,aACd,OAAK,MAAM,EAAE,QAavB;IAED;;;;;OAKG;IACH,qBAJW,MAAM,EAAE,OACR,MAAM,EAAE,gBACR,IAAI,QA0Cd;IAED;;;;OAIG;IACH,cAHW,IAAI,GACF,OAAO,CAsCnB;IAED;;;;;OAKG;IACH,WAJW,MAAM,EAAE,OACR,MAAM,EAAE,GAAC,IAAI,GACZ,MAAM,CA+CjB;IAED;;;;;;OAMG;IACH,uBALW,MAAM,EAAE,cACR,MAAM,aACN,MAAM,EAAE,oBACR,MAAM,QAIhB;IAED;;;;;OAKG;IACH,mBAJW,MAAM,EAAE,cACR,MAAM,OACN,MAAM,EAAE,QAwHlB;;CACJ;oBAzlB8B,mCAAmC;+BAqBnC,qBAAqB;8BAJtB,kDAAkD;oCAC5C,0BAA0B;qBAPzC,kCAAkC"}
@@ -12,6 +12,8 @@ import { v3_morton_encode_bounded } from "../../../../core/geom/3d/morton/v3_mor
12
12
  import { ray3_array_compose } from "../../../../core/geom/3d/ray/ray3_array_compose.js";
13
13
  import { Ray3 } from "../../../../core/geom/3d/Ray3.js";
14
14
  import { v3_dot } from "../../../../core/geom/vec3/v3_dot.js";
15
+ import { v3_length } from "../../../../core/geom/vec3/v3_length.js";
16
+ import { saturate } from "../../../../core/math/clamp01.js";
15
17
  import { max2 } from "../../../../core/math/max2.js";
16
18
  import { compute_geometry_polycount } from "../../geometry/compute_geometry_polycount.js";
17
19
  import { AbstractLight } from "../../render/forward_plus/model/AbstractLight.js";
@@ -21,6 +23,22 @@ import { MaterialConverter } from "./material/MaterialConverter.js";
21
23
  import { PathTracedMesh } from "./PathTracedMesh.js";
22
24
  import { sample_material } from "./texture/sample_material.js";
23
25
 
26
+ function light_getDistanceAttenuation( distance, cutoff_distance, decay_exponent){
27
+
28
+ let distanceFalloff = 1.0 / Math.max( Math.pow( distance, decay_exponent ), 0.01 );
29
+
30
+ if ( cutoff_distance > 0.0 ) {
31
+ const b = distance / cutoff_distance;
32
+ const b2 = b*b;
33
+ const b4 = b2*b2;
34
+
35
+ const c= saturate( 1.0 - b4 );
36
+
37
+ distanceFalloff *= c*c;
38
+ }
39
+
40
+ return distanceFalloff;
41
+ }
24
42
  /**
25
43
  *
26
44
  * @type {number[]|Uint32Array}
@@ -473,6 +491,14 @@ export class PathTracedScene {
473
491
  out[out_offset + i] = 0;
474
492
  }
475
493
 
494
+ const ray_origin_x = ray[0];
495
+ const ray_origin_y = ray[1];
496
+ const ray_origin_z = ray[2];
497
+
498
+ const ray_direction_x = ray[3];
499
+ const ray_direction_y = ray[4];
500
+ const ray_direction_z = ray[5];
501
+
476
502
  for (let i = 0; i < light_count; i++) {
477
503
  const light = lights[i];
478
504
 
@@ -481,10 +507,6 @@ export class PathTracedScene {
481
507
 
482
508
  // see https://github.com/mrdoob/three.js/blob/f0a9e0cf90a2f1ba5017fcb7fd46f02748b920cf/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js#L172
483
509
 
484
- const ray_direction_x = ray[3];
485
- const ray_direction_y = ray[4];
486
- const ray_direction_z = ray[5];
487
-
488
510
  const light_dir_inv_x = -dir.x;
489
511
  const light_dir_inv_y = -dir.y;
490
512
  const light_dir_inv_z = -dir.z;
@@ -499,9 +521,6 @@ export class PathTracedScene {
499
521
  continue;
500
522
  }
501
523
 
502
- const ray_origin_x = ray[0];
503
- const ray_origin_y = ray[1];
504
- const ray_origin_z = ray[2];
505
524
 
506
525
  ray3_array_compose(_ray_1,
507
526
  ray_origin_x, ray_origin_y, ray_origin_z,
@@ -525,6 +544,59 @@ export class PathTracedScene {
525
544
  out[out_offset + 2] += light_color.b * intensity;
526
545
 
527
546
 
547
+ } else if (light.isPointLight === true) {
548
+
549
+ const light_offset_x = ray_origin_x - light.position.x;
550
+ const light_offset_y = ray_origin_y - light.position.y;
551
+ const light_offset_z = ray_origin_z - light.position.z;
552
+
553
+ const distance_to_light = v3_length(light_offset_x, light_offset_y, light_offset_z);
554
+
555
+ const radius = light.radius.getValue();
556
+
557
+ if (distance_to_light > radius) {
558
+ // too far
559
+ continue;
560
+ }
561
+
562
+ const light_norm_inv = 1 / distance_to_light;
563
+
564
+ // see https://github.com/mrdoob/three.js/blob/f0a9e0cf90a2f1ba5017fcb7fd46f02748b920cf/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js#L172
565
+
566
+ const light_dir_inv_x = -light_offset_x * light_norm_inv;
567
+ const light_dir_inv_y = -light_offset_y * light_norm_inv;
568
+ const light_dir_inv_z = -light_offset_z * light_norm_inv;
569
+
570
+ const dotNL = v3_dot(
571
+ ray_direction_x, ray_direction_y, ray_direction_z,
572
+ light_dir_inv_x, light_dir_inv_y, light_dir_inv_z
573
+ );
574
+
575
+ if (dotNL <= 0) {
576
+ // no contribution, facing away from the light
577
+ continue;
578
+ }
579
+ ray3_array_compose(_ray_1,
580
+ ray_origin_x, ray_origin_y, ray_origin_z,
581
+ light_dir_inv_x, light_dir_inv_y, light_dir_inv_z
582
+ );
583
+
584
+ _ray_1.tMax = radius;
585
+
586
+ // check if there are any obstacles in the direction of the light
587
+ if (this.occluded(_ray_1)) {
588
+ // light is occluded
589
+ continue;
590
+ }
591
+
592
+ const attenuation = light_getDistanceAttenuation(distance_to_light,radius,2);
593
+
594
+ const intensity = dotNL * light.intensity.getValue()*attenuation;
595
+ const light_color = light.color;
596
+
597
+ out[out_offset] += light_color.r * intensity;
598
+ out[out_offset + 1] += light_color.g * intensity;
599
+ out[out_offset + 2] += light_color.b * intensity;
528
600
  }
529
601
  }
530
602
  }