@woosh/meep-engine 2.109.25 → 2.110.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.
Files changed (102) hide show
  1. package/build/meep.cjs +229 -461
  2. package/build/meep.min.js +1 -1
  3. package/build/meep.module.js +229 -461
  4. package/editor/tools/GridPaintTool.js +12 -11
  5. package/editor/tools/engine/ToolEngine.js +2 -1
  6. package/package.json +1 -1
  7. package/src/core/collection/heap/{FastBinaryHeap.d.ts → BinaryHeap.d.ts} +4 -4
  8. package/src/core/collection/heap/BinaryHeap.d.ts.map +1 -0
  9. package/src/core/collection/heap/{FastBinaryHeap.js → BinaryHeap.js} +3 -3
  10. package/src/core/collection/heap/BinaryHeap.spec.d.ts +2 -0
  11. package/src/core/collection/heap/BinaryHeap.spec.d.ts.map +1 -0
  12. package/src/core/collection/heap/{FastBinaryHeap.spec.js → BinaryHeap.spec.js} +10 -10
  13. package/src/core/collection/heap/Uint32Heap.spec.d.ts +2 -0
  14. package/src/core/collection/heap/Uint32Heap.spec.d.ts.map +1 -0
  15. package/src/core/geom/3d/topology/simplify/simplifyTopoMesh.d.ts +1 -0
  16. package/src/core/geom/3d/topology/simplify/simplifyTopoMesh.d.ts.map +1 -1
  17. package/src/core/geom/3d/topology/simplify/simplifyTopoMesh.js +5 -5
  18. package/src/core/geom/3d/triangle/computeTriangleRayIntersectionBarycentricEdge.d.ts.map +1 -1
  19. package/src/core/geom/3d/triangle/computeTriangleRayIntersectionBarycentricEdge.js +14 -8
  20. package/src/core/geom/packing/max-rect/MaxRectanglesPacker.js +2 -2
  21. package/src/core/graph/Edge.d.ts +1 -0
  22. package/src/core/graph/Edge.d.ts.map +1 -1
  23. package/src/core/graph/Edge.js +5 -0
  24. package/src/core/graph/graph_compute_distance_matrix.js +2 -2
  25. package/src/core/graph/metis/cluster_mesh_metis.d.ts +9 -0
  26. package/src/core/graph/metis/cluster_mesh_metis.d.ts.map +1 -0
  27. package/src/core/graph/metis/cluster_mesh_metis.js +31 -0
  28. package/src/core/graph/metis/mesh_to_metis_graph.d.ts +10 -0
  29. package/src/core/graph/metis/mesh_to_metis_graph.d.ts.map +1 -0
  30. package/src/core/graph/metis/mesh_to_metis_graph.js +64 -0
  31. package/src/core/graph/metis/metis_cluster_bs.d.ts +12 -0
  32. package/src/core/graph/metis/metis_cluster_bs.d.ts.map +1 -0
  33. package/src/core/graph/{cluster_mesh_metis.js → metis/metis_cluster_bs.js} +12 -98
  34. package/src/core/graph/mn_graph_coarsen.d.ts.map +1 -1
  35. package/src/core/graph/mn_graph_coarsen.js +7 -3
  36. package/src/core/graph/mn_graph_coarsen.spec.js +2 -0
  37. package/src/core/math/interval/NumericInterval.d.ts +13 -7
  38. package/src/core/math/interval/NumericInterval.d.ts.map +1 -1
  39. package/src/core/math/interval/NumericInterval.js +35 -15
  40. package/src/engine/asset/AssetManager.js +3 -3
  41. package/src/engine/graphics/camera/makeOrbitalCameraController.d.ts.map +1 -1
  42. package/src/engine/graphics/camera/makeOrbitalCameraController.js +4 -4
  43. package/src/engine/graphics/geometry/VertexDataSpec.d.ts.map +1 -1
  44. package/src/engine/graphics/geometry/VertexDataSpec.js +4 -7
  45. package/src/engine/graphics/sh3/gi/material/common.glsl +45 -54
  46. package/src/engine/graphics/sh3/gi/material/makeOctahedralDepthAtlas.d.ts.map +1 -1
  47. package/src/engine/graphics/sh3/gi/material/makeOctahedralDepthAtlas.js +5 -3
  48. package/src/engine/graphics/sh3/lpv/LightProbeVolume.js +2 -2
  49. package/src/engine/graphics/sh3/lpv/LightProbeVolumeBaker.js +1 -1
  50. package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.d.ts.map +1 -1
  51. package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.js +3 -2
  52. package/src/engine/graphics/sh3/lpv/depth/octahedral/bake_octahedral_depth_map.d.ts.map +1 -1
  53. package/src/engine/graphics/sh3/lpv/depth/octahedral/bake_octahedral_depth_map.js +14 -7
  54. package/src/engine/graphics/sh3/lpv/depth/octahedral/v2/visualise.frag.glsl +17 -15
  55. package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.d.ts.map +1 -1
  56. package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.js +6 -2
  57. package/src/engine/graphics/sh3/lpv/serialization/LightProbeVolumeSerializationAdapter.js +2 -2
  58. package/src/engine/graphics/sh3/path_tracer/PathTracedScene.d.ts.map +1 -1
  59. package/src/engine/graphics/sh3/path_tracer/PathTracedScene.js +10 -0
  60. package/src/engine/graphics/sh3/prototypeSH3Probe.js +3 -3
  61. package/src/engine/input/devices/LocationalInteractionMetadata.d.ts +4 -0
  62. package/src/engine/input/devices/LocationalInteractionMetadata.d.ts.map +1 -1
  63. package/src/engine/input/devices/LocationalInteractionMetadata.js +6 -1
  64. package/src/engine/input/devices/PointerDevice.d.ts +0 -3
  65. package/src/engine/input/devices/PointerDevice.d.ts.map +1 -1
  66. package/src/engine/input/devices/PointerDevice.js +49 -306
  67. package/src/engine/input/devices/events/PointerEvents.d.ts +14 -0
  68. package/src/engine/input/devices/events/PointerEvents.d.ts.map +1 -0
  69. package/src/engine/input/devices/events/PointerEvents.js +16 -0
  70. package/src/engine/input/devices/events/eventToSourceIdentifier.d.ts.map +1 -0
  71. package/src/engine/input/devices/mouse/decodeMouseEventButtons.d.ts +10 -0
  72. package/src/engine/input/devices/mouse/decodeMouseEventButtons.d.ts.map +1 -0
  73. package/src/engine/input/devices/mouse/decodeMouseEventButtons.js +19 -0
  74. package/src/engine/input/devices/mouse/suppressContextMenu.d.ts +7 -0
  75. package/src/engine/input/devices/mouse/suppressContextMenu.d.ts.map +1 -0
  76. package/src/engine/input/devices/mouse/suppressContextMenu.js +11 -0
  77. package/src/engine/input/devices/touch/TouchDevice.d.ts +20 -0
  78. package/src/engine/input/devices/touch/TouchDevice.d.ts.map +1 -0
  79. package/src/engine/input/devices/touch/TouchDevice.js +95 -0
  80. package/src/engine/input/devices/touch/getTouchCenter.d.ts +7 -0
  81. package/src/engine/input/devices/touch/getTouchCenter.d.ts.map +1 -0
  82. package/src/engine/input/devices/touch/getTouchCenter.js +32 -0
  83. package/src/engine/input/devices/touch/observePinch.d.ts +12 -0
  84. package/src/engine/input/devices/touch/observePinch.d.ts.map +1 -0
  85. package/src/engine/input/devices/touch/observePinch.js +128 -0
  86. package/src/engine/network/PriorityFetch.d.ts.map +1 -1
  87. package/src/engine/network/PriorityFetch.js +2 -2
  88. package/src/generation/grid/generation/discrete/GridTaskConnectRooms.js +3 -3
  89. package/src/generation/grid/generation/discrete/layer/GridTaskBuildSourceDistanceMap.js +2 -2
  90. package/src/generation/grid/generation/discrete/layer/GridTaskDistanceToMarkers.js +2 -2
  91. package/src/generation/grid/generation/road/GridTaskGenerateRoads.js +2 -2
  92. package/src/core/collection/heap/FastBinaryHeap.d.ts.map +0 -1
  93. package/src/core/collection/heap/FastBinaryHeap.spec.d.ts +0 -2
  94. package/src/core/collection/heap/FastBinaryHeap.spec.d.ts.map +0 -1
  95. package/src/core/collection/heap/Uin32Heap.spec.d.ts +0 -2
  96. package/src/core/collection/heap/Uin32Heap.spec.d.ts.map +0 -1
  97. package/src/core/graph/cluster_mesh_metis.d.ts +0 -28
  98. package/src/core/graph/cluster_mesh_metis.d.ts.map +0 -1
  99. package/src/engine/input/devices/eventToSourceIdentifier.d.ts.map +0 -1
  100. /package/src/core/collection/heap/{Uin32Heap.spec.js → Uint32Heap.spec.js} +0 -0
  101. /package/src/engine/input/devices/{eventToSourceIdentifier.d.ts → events/eventToSourceIdentifier.d.ts} +0 -0
  102. /package/src/engine/input/devices/{eventToSourceIdentifier.js → events/eventToSourceIdentifier.js} +0 -0
@@ -1,4 +1,4 @@
1
- import FastBinaryHeap from "../collection/heap/FastBinaryHeap.js";
1
+ import BinaryHeap from "../collection/heap/BinaryHeap.js";
2
2
  import { mn_graph_collapse_weighted_edge } from "./mn_graph_collapse_weighted_edge.js";
3
3
  import { WeightedEdge } from "./WeightedEdge.js";
4
4
 
@@ -15,7 +15,7 @@ export function mn_graph_coarsen(graph, max_node_limit) {
15
15
  *
16
16
  * @type {BinaryHeap<WeightedEdge>}
17
17
  */
18
- const open_set = new FastBinaryHeap(WeightedEdge.extractNegativeWeight);
18
+ const open_set = new BinaryHeap(WeightedEdge.extractNegativeWeight);
19
19
 
20
20
  // add all edges to the heap
21
21
  const edges = graph.getEdges();
@@ -28,6 +28,10 @@ export function mn_graph_coarsen(graph, max_node_limit) {
28
28
  const edge = open_set.pop();
29
29
 
30
30
  // attempt collapse of the heaviest edge
31
- mn_graph_collapse_weighted_edge(graph, edge, max_node_limit, open_set);
31
+ const collapsed = mn_graph_collapse_weighted_edge(graph, edge, max_node_limit, open_set);
32
+
33
+ if(!collapsed){
34
+ throw new Error(`Failed to collapse edge ${edge}`);
35
+ }
32
36
  }
33
37
  }
@@ -14,6 +14,8 @@ test('coarsen 2 node graph with 1 edge', () => {
14
14
  graph.addEdge(new WeightedEdge(n0, n1));
15
15
 
16
16
  mn_graph_coarsen(graph, 2);
17
+
18
+ expect(graph.getNodeCount()).toBe(1);
17
19
  });
18
20
 
19
21
  test('coarsen chain, all nodes must still be linked', () => {
@@ -16,18 +16,17 @@ export class NumericInterval {
16
16
  * @type {number}
17
17
  */
18
18
  max: number;
19
- onChanged: Signal<any, any, any, any, any, any, any, any>;
19
+ /**
20
+ * @readonly
21
+ * @type {Signal<number, number, number, number>}
22
+ */
23
+ readonly onChanged: Signal<number, number, number, number>;
20
24
  /**
21
25
  *
22
26
  * @param {number} min
23
27
  * @param {number} max
24
28
  */
25
29
  set(min: number, max: number): void;
26
- /**
27
- *
28
- * @param {NumericInterval} other
29
- */
30
- copy(other: NumericInterval): void;
31
30
  /**
32
31
  *
33
32
  * @param {number} value
@@ -66,6 +65,7 @@ export class NumericInterval {
66
65
  min: number;
67
66
  max: number;
68
67
  };
68
+ toString(): string;
69
69
  /**
70
70
  *
71
71
  * @param {BinaryBuffer} buffer
@@ -76,6 +76,11 @@ export class NumericInterval {
76
76
  * @param {BinaryBuffer} buffer
77
77
  */
78
78
  fromBinaryBuffer(buffer: BinaryBuffer): void;
79
+ /**
80
+ *
81
+ * @param {NumericInterval} other
82
+ */
83
+ copy(other: NumericInterval): void;
79
84
  /**
80
85
  *
81
86
  * @param {NumericInterval} other
@@ -99,8 +104,9 @@ export class NumericInterval {
99
104
  readonly isNumericInterval: boolean;
100
105
  }
101
106
  export namespace NumericInterval {
102
- let one_one: NumericInterval;
103
107
  let zero_zero: NumericInterval;
108
+ let zero_one: NumericInterval;
109
+ let one_one: NumericInterval;
104
110
  }
105
111
  import Signal from "../../events/signal/Signal.js";
106
112
  //# sourceMappingURL=NumericInterval.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"NumericInterval.d.ts","sourceRoot":"","sources":["../../../../../src/core/math/interval/NumericInterval.js"],"names":[],"mappings":"AAKA;IACI;;;;;OAKG;IACH,kBAJW,MAAM,QACN,MAAM,EAwBhB;IAZG;;;OAGG;IACH,KAFU,MAAM,CAEF;IACd;;;OAGG;IACH,KAFU,MAAM,CAEF;IAEd,0DAA6B;IAIjC;;;;OAIG;IACH,SAHW,MAAM,OACN,MAAM,QAsBhB;IAED;;;OAGG;IACH,YAFW,eAAe,QAIzB;IAED;;;OAGG;IACH,sBAFW,MAAM,QAahB;IAED;;;;OAIG;IACH,kBAHW,MAAM,GACJ,MAAM,CAIlB;IAED;;;OAGG;IACH,UAFa,OAAO,CAInB;IAED;;;;OAIG;IACH,WAFa,OAAO,CAInB;IAED;;;OAGG;IACH,kBAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,gCAFa,MAAM,CAMlB;IAED,0BAEC;IAED;;;MAKC;IAED;;;OAGG;IACH,2CAGC;IAED;;;OAGG;IACH,6CAGC;IAED;;;;OAIG;IACH,cAHW,eAAe,GACb,OAAO,CAInB;IAED;;;OAGG;IACH,QAFa,MAAM,CAQlB;IAED;;;OAGG;IACH,mBAEC;IAGL;;;OAGG;IACH,4BAFU,OAAO,CAE0B;CAN1C;;iBAUS,eAAe;mBAKf,eAAe;;mBA5MN,+BAA+B"}
1
+ {"version":3,"file":"NumericInterval.d.ts","sourceRoot":"","sources":["../../../../../src/core/math/interval/NumericInterval.js"],"names":[],"mappings":"AAKA;IACI;;;;;OAKG;IACH,kBAJW,MAAM,QACN,MAAM,EA4BhB;IAhBG;;;OAGG;IACH,KAFU,MAAM,CAEF;IACd;;;OAGG;IACH,KAFU,MAAM,CAEF;IAEd;;;OAGG;IACH,oBAFU,OAAO,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAEnB;IAIjC;;;;OAIG;IACH,SAHW,MAAM,OACN,MAAM,QA0BhB;IAGD;;;OAGG;IACH,sBAFW,MAAM,QAahB;IAED;;;;OAIG;IACH,kBAHW,MAAM,GACJ,MAAM,CAIlB;IAED;;;OAGG;IACH,UAFa,OAAO,CAInB;IAED;;;;OAIG;IACH,WAFa,OAAO,CAInB;IAED;;;OAGG;IACH,kBAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,gCAFa,MAAM,CAMlB;IAED,0BAEC;IAED;;;MAKC;IAED,mBAEC;IAED;;;OAGG;IACH,2CAGC;IAED;;;OAGG;IACH,6CAGC;IAED;;;OAGG;IACH,YAFW,eAAe,QAIzB;IAED;;;;OAIG;IACH,cAHW,eAAe,GACb,OAAO,CAInB;IAED;;;OAGG;IACH,QAFa,MAAM,CAQlB;IAED;;;OAGG;IACH,mBAEC;IAGL;;;OAGG;IACH,4BAFU,OAAO,CAE0B;CAN1C;;mBAUS,eAAe;kBAMf,eAAe;iBAMf,eAAe;;mBAhON,+BAA+B"}
@@ -30,6 +30,10 @@ export class NumericInterval {
30
30
  */
31
31
  this.max = max;
32
32
 
33
+ /**
34
+ * @readonly
35
+ * @type {Signal<number, number, number, number>}
36
+ */
33
37
  this.onChanged = new Signal();
34
38
  }
35
39
 
@@ -51,24 +55,21 @@ export class NumericInterval {
51
55
  const oldMin = this.min;
52
56
  const oldMax = this.max;
53
57
 
54
- if (min !== oldMin || max !== oldMax) {
55
- this.min = min;
56
- this.max = max;
58
+ if (min === oldMin && max === oldMax) {
59
+ return;
60
+ }
57
61
 
58
- if (this.onChanged.hasHandlers()) {
59
- this.onChanged.send4(min, max, oldMin, oldMax);
60
- }
62
+ this.min = min;
63
+ this.max = max;
64
+
65
+ if (!this.onChanged.hasHandlers()) {
66
+ return;
61
67
  }
62
- }
63
68
 
64
- /**
65
- *
66
- * @param {NumericInterval} other
67
- */
68
- copy(other) {
69
- this.set(other.min, other.max);
69
+ this.onChanged.send4(min, max, oldMin, oldMax);
70
70
  }
71
71
 
72
+
72
73
  /**
73
74
  *
74
75
  * @param {number} value
@@ -142,6 +143,10 @@ export class NumericInterval {
142
143
  };
143
144
  }
144
145
 
146
+ toString() {
147
+ return `NumericInterval{ min=${this.min}, max=${this.max} }`;
148
+ }
149
+
145
150
  /**
146
151
  *
147
152
  * @param {BinaryBuffer} buffer
@@ -160,6 +165,14 @@ export class NumericInterval {
160
165
  this.max = buffer.readFloat64();
161
166
  }
162
167
 
168
+ /**
169
+ *
170
+ * @param {NumericInterval} other
171
+ */
172
+ copy(other) {
173
+ this.set(other.min, other.max);
174
+ }
175
+
163
176
  /**
164
177
  *
165
178
  * @param {NumericInterval} other
@@ -200,10 +213,17 @@ NumericInterval.prototype.isNumericInterval = true;
200
213
  * @readonly
201
214
  * @type {NumericInterval}
202
215
  */
203
- NumericInterval.one_one = Object.freeze(new NumericInterval(1, 1));
216
+ NumericInterval.zero_zero = Object.freeze(new NumericInterval(0, 0));
217
+
204
218
  /**
205
219
  * @readonly
206
220
  * @type {NumericInterval}
207
221
  */
208
- NumericInterval.zero_zero = Object.freeze(new NumericInterval(0, 0));
222
+ NumericInterval.zero_one = Object.freeze(new NumericInterval(0, 1));
223
+
224
+ /**
225
+ * @readonly
226
+ * @type {NumericInterval}
227
+ */
228
+ NumericInterval.one_one = Object.freeze(new NumericInterval(1, 1));
209
229
 
@@ -1,7 +1,7 @@
1
1
  import { assert } from "../../core/assert.js";
2
2
  import { array_push_if_unique } from "../../core/collection/array/array_push_if_unique.js";
3
3
  import { array_remove_first } from "../../core/collection/array/array_remove_first.js";
4
- import FastBinaryHeap from "../../core/collection/heap/FastBinaryHeap.js";
4
+ import BinaryHeap from "../../core/collection/heap/BinaryHeap.js";
5
5
  import { HashMap } from "../../core/collection/map/HashMap.js";
6
6
  import { ObservedMap } from "../../core/collection/map/ObservedMap.js";
7
7
  import { Deque } from "../../core/collection/queue/Deque.js";
@@ -33,7 +33,7 @@ class Response {
33
33
  }
34
34
 
35
35
  /**
36
- * Used by the priority queue, so the priority is inverted as the FastBinaryHeap returns elements in ascending score order (from lowest)
36
+ * Used by the priority queue, so the priority is inverted as the BinaryHeap returns elements in ascending score order (from lowest)
37
37
  * @param {PendingAsset} pending_asset
38
38
  * @returns {number}
39
39
  */
@@ -68,7 +68,7 @@ export class AssetManager {
68
68
  * @type {BinaryHeap<PendingAsset>}
69
69
  * @private
70
70
  */
71
- #pending_asset_wait_queue = new FastBinaryHeap(get_pending_asset_priority_score);
71
+ #pending_asset_wait_queue = new BinaryHeap(get_pending_asset_priority_score);
72
72
  /**
73
73
  * Assets currently being processed by #loaders
74
74
  * @type {Set<PendingAsset>}
@@ -1 +1 @@
1
- {"version":3,"file":"makeOrbitalCameraController.d.ts","sourceRoot":"","sources":["../../../../../src/engine/graphics/camera/makeOrbitalCameraController.js"],"names":[],"mappings":"AAOA;;;;;;;GAOG;AACH,8FANW,MAAM,GAIL,MAAM,CA8FjB;mBAxGkB,qBAAqB"}
1
+ {"version":3,"file":"makeOrbitalCameraController.d.ts","sourceRoot":"","sources":["../../../../../src/engine/graphics/camera/makeOrbitalCameraController.js"],"names":[],"mappings":"AAOA;;;;;;;GAOG;AACH,8FANW,MAAM,GAIL,MAAM,CA8FjB;mBA1GkB,qBAAqB"}
@@ -1,9 +1,9 @@
1
- import TopDownCameraController, { rotate_from_view } from "../ecs/camera/topdown/TopDownCameraController.js";
2
- import InputController from "../../input/ecs/components/InputController.js";
3
- import { decodeMouseEventButtons } from "../../input/devices/PointerDevice.js";
1
+ import { clamp } from "../../../core/math/clamp.js";
4
2
  import Entity from "../../ecs/Entity.js";
3
+ import { decodeMouseEventButtons } from "../../input/devices/mouse/decodeMouseEventButtons.js";
4
+ import InputController from "../../input/ecs/components/InputController.js";
5
5
  import { Camera } from "../ecs/camera/Camera.js";
6
- import { clamp } from "../../../core/math/clamp.js";
6
+ import TopDownCameraController, { rotate_from_view } from "../ecs/camera/topdown/TopDownCameraController.js";
7
7
 
8
8
  /**
9
9
  *
@@ -1 +1 @@
1
- {"version":3,"file":"VertexDataSpec.d.ts","sourceRoot":"","sources":["../../../../../src/engine/graphics/geometry/VertexDataSpec.js"],"names":[],"mappings":"AAYA;;;GAGG;AACH;IAeI;;;;OAIG;IACH,2BAHW,aAAa,GACX,cAAc,CAQ1B;IAxBD;;;OAGG;IACH,YAFU,aAAa,EAAE,CAET;IAsBhB;;;;OAIG;IACH,yBAHW,MAAM,GACL,aAAa,GAAC,SAAS,CAgBlC;IAED;;;OAGG;IACH,8BAFW,MAAM,GADJ,MAAM,CAiBlB;IAED;;;OAGG;IACH,oBAFW,aAAa,EAAE,QAOzB;IAED;;;;OAIG;IACH,eAHW,aAAa,GACZ,cAAc,CAkBzB;IAED;;;OAGG;IACH,0BAFW,aAAa,EAAE,QAYzB;IAED,cAKC;IAED;;;;OAIG;IACH,cAHW,cAAc,GACZ,OAAO,CAQnB;IAED,sBAEC;IAED,eAMC;IAED;;MAIC;IAED;;aAkBC;IAED;;;OAGG;IACH,eAFa,MAAM,CAelB;IAIL;;;OAGG;IACH,2BAFU,OAAO,CAEwB;;CAPxC;8BA/M6B,oBAAoB"}
1
+ {"version":3,"file":"VertexDataSpec.d.ts","sourceRoot":"","sources":["../../../../../src/engine/graphics/geometry/VertexDataSpec.js"],"names":[],"mappings":"AAYA;;;GAGG;AACH;IAeI;;;;OAIG;IACH,2BAHW,aAAa,GACX,cAAc,CAQ1B;IAxBD;;;OAGG;IACH,YAFU,aAAa,EAAE,CAET;IAsBhB;;;;OAIG;IACH,yBAHW,MAAM,GACL,aAAa,GAAC,SAAS,CAgBlC;IAED;;;OAGG;IACH,8BAFW,MAAM,GADJ,MAAM,CAiBlB;IAED;;;OAGG;IACH,oBAFW,aAAa,EAAE,QAOzB;IAED;;;;OAIG;IACH,eAHW,aAAa,GACZ,cAAc,CAkBzB;IAED;;;OAGG;IACH,0BAFW,aAAa,EAAE,QAQzB;IAED,cAMC;IAED;;;;OAIG;IACH,cAHW,cAAc,GACZ,OAAO,CAQnB;IAED,sBAEC;IAED,eAMC;IAED;;MAIC;IAED;;aAkBC;IAED;;;OAGG;IACH,eAFa,MAAM,CAelB;IAIL;;;OAGG;IACH,2BAFU,OAAO,CAEwB;;CAPxC;8BA5M6B,oBAAoB"}
@@ -118,23 +118,20 @@ export class VertexDataSpec {
118
118
  }
119
119
 
120
120
  /**
121
- *
121
+ * Replace existing attributes
122
122
  * @param {AttributeSpec[]} attributes
123
123
  */
124
124
  setAttributes(attributes) {
125
125
 
126
126
  this.clear();
127
127
 
128
- const n = attributes.length;
129
-
130
- for (let i = 0; i < n; i++) {
131
- this.add(attributes[i]);
132
- }
128
+ this.addMany(attributes);
133
129
 
134
130
  }
135
131
 
136
132
  clear() {
137
- this.attributes.splice(0, this.attributes.length);
133
+ const count = this.attributes.length;
134
+ this.attributes.splice(0, count);
138
135
 
139
136
  // reset hash to trigger hash update
140
137
  this.#hash = DEFAULT_HASH;
@@ -24,6 +24,13 @@ const float lpv_max_thickness = 0.50; // in Meters
24
24
  #define SEARCH_STEP_LIMIT 32u
25
25
  #define INVALID_TET 1073741823u
26
26
 
27
+
28
+ /** Slightly bump the location of the shadow test point away from the shadow casting surface.
29
+ The shadow casting surface is the boundary for shadow, so the nearer an imprecise value is
30
+ to it the more the light leaks.
31
+ */
32
+ #define LPV_NORMAL_BIAS 0.0001f
33
+
27
34
  ivec2 lpv_index_to_256_coordinate(uint index) {
28
35
 
29
36
  uint pixel_x = index % 256u;
@@ -160,18 +167,15 @@ vec2 lpv_probe_getDepthTriangular(uint probe_index, vec3 direction) {
160
167
  frame1 += tile_offset;
161
168
  frame2 += tile_offset;
162
169
 
163
- float samp0 = texelFetch(lpv_t_probe_depth, ivec2(frame0), 0).r;
164
- float samp1 = texelFetch(lpv_t_probe_depth, ivec2(frame1), 0).r;
165
- float samp2 = texelFetch(lpv_t_probe_depth, ivec2(frame2), 0).r;
170
+ vec2 samp0 = texelFetch(lpv_t_probe_depth, ivec2(frame0), 0).rg;
171
+ vec2 samp1 = texelFetch(lpv_t_probe_depth, ivec2(frame1), 0).rg;
172
+ vec2 samp2 = texelFetch(lpv_t_probe_depth, ivec2(frame2), 0).rg;
166
173
 
167
- float d0 = samp0 * weights.x;
168
- float d1 = samp1 * weights.y;
169
- float d2 = samp2 * weights.z;
174
+ vec2 d0 = samp0 * weights.x;
175
+ vec2 d1 = samp1 * weights.y;
176
+ vec2 d2 = samp2 * weights.z;
170
177
 
171
- float mean = d0 + d1 + d2;
172
- float mean2 = samp0 * d0 + samp1 * d1 + samp2 * d2;
173
-
174
- return vec2(mean, mean2);
178
+ return (d0 + d1 + d2);
175
179
  }
176
180
 
177
181
  float lpv_bilinear_lerp(float v00, float v01, float v10, float v11, vec2 fraction) {
@@ -182,6 +186,14 @@ float lpv_bilinear_lerp(float v00, float v01, float v10, float v11, vec2 fractio
182
186
  return mix(x0, x1, fraction.y);
183
187
  }
184
188
 
189
+ vec2 lpv_bilinear_lerp(vec2 v00, vec2 v01, vec2 v10, vec2 v11, vec2 fraction) {
190
+
191
+ vec2 x0 = mix(v00, v01, fraction.x);
192
+ vec2 x1 = mix(v10, v11, fraction.x);
193
+
194
+ return mix(x0, x1, fraction.y);
195
+ }
196
+
185
197
  vec2 lpv_sample_bilinear(sampler2D tex, ivec2 texel_position, vec2 fraction) {
186
198
 
187
199
  float texel_00 = texelFetch(tex, texel_position, 0).r;
@@ -191,13 +203,13 @@ vec2 lpv_sample_bilinear(sampler2D tex, ivec2 texel_position, vec2 fraction) {
191
203
 
192
204
  return vec2(
193
205
  lpv_bilinear_lerp(
194
- texel_00, texel_01,
195
- texel_10, texel_11,
196
- fraction
197
- ),
206
+ texel_00, texel_01,
207
+ texel_10, texel_11,
208
+ fraction
209
+ ),
198
210
  lpv_bilinear_lerp(
199
- texel_00*texel_00, texel_01*texel_01,
200
- texel_10*texel_10, texel_11*texel_11,
211
+ texel_00 * texel_00, texel_01 * texel_01,
212
+ texel_10 * texel_10, texel_11 * texel_11,
201
213
  fraction
202
214
  )
203
215
  );
@@ -246,27 +258,20 @@ vec2 lpv_probe_getDepthBilinear(uint probe_index, vec3 direction) {
246
258
  ivec2 tile_p_10;
247
259
  ivec2 tile_p_11;
248
260
 
249
- tile_p_00 = wrapOctahedralTexelCoordinates(texel_position , depth_tile_resolution);
261
+ tile_p_00 = wrapOctahedralTexelCoordinates(texel_position, depth_tile_resolution);
250
262
  tile_p_01 = wrapOctahedralTexelCoordinates(texel_position + ivec2(1, 0), depth_tile_resolution);
251
263
  tile_p_10 = wrapOctahedralTexelCoordinates(texel_position + ivec2(0, 1), depth_tile_resolution);
252
264
  tile_p_11 = wrapOctahedralTexelCoordinates(texel_position + ivec2(1, 1), depth_tile_resolution);
253
265
 
254
- float texel_00 = texelFetch(lpv_t_probe_depth, tile_offset + tile_p_00, 0).r;
255
- float texel_01 = texelFetch(lpv_t_probe_depth, tile_offset + tile_p_01, 0).r;
256
- float texel_10 = texelFetch(lpv_t_probe_depth, tile_offset + tile_p_10, 0).r;
257
- float texel_11 = texelFetch(lpv_t_probe_depth, tile_offset + tile_p_11, 0).r;
266
+ vec2 texel_00 = texelFetch(lpv_t_probe_depth, tile_offset + tile_p_00, 0).rg;
267
+ vec2 texel_01 = texelFetch(lpv_t_probe_depth, tile_offset + tile_p_01, 0).rg;
268
+ vec2 texel_10 = texelFetch(lpv_t_probe_depth, tile_offset + tile_p_10, 0).rg;
269
+ vec2 texel_11 = texelFetch(lpv_t_probe_depth, tile_offset + tile_p_11, 0).rg;
258
270
 
259
- return vec2(
260
- lpv_bilinear_lerp(
261
- texel_00, texel_01,
262
- texel_10, texel_11,
263
- gridFrac
264
- ),
265
- lpv_bilinear_lerp(
266
- texel_00 * texel_00, texel_01 * texel_01,
267
- texel_10 * texel_10, texel_11 * texel_11,
268
- gridFrac
269
- )
271
+ return lpv_bilinear_lerp(
272
+ texel_00, texel_01,
273
+ texel_10, texel_11,
274
+ gridFrac
270
275
  );
271
276
  }
272
277
 
@@ -353,7 +358,9 @@ float lpv_probe_getVisibilityMask(vec3 position, uint probe_index) {
353
358
  vec2 temp = lpv_probe_getDepthBilinear(probe_index, direction);
354
359
 
355
360
  float mean = temp.x;
356
- float variance = abs(mean * mean - temp.y);
361
+ float mean2 = temp.y; // mean of squared distances
362
+
363
+ float variance = abs(mean * mean - mean2);
357
364
 
358
365
  // http://www.punkuser.net/vsm/vsm_paper.pdf; equation 5
359
366
  // Need the max in the denominator because biasing can cause a negative displacement
@@ -400,12 +407,6 @@ vec4 lvp_mask_weights_by_visibility_by_normal(vec3 position, vec3 normal, uint t
400
407
  }
401
408
 
402
409
 
403
- /** Slightly bump the location of the shadow test point away from the shadow casting surface.
404
- The shadow casting surface is the boundary for shadow, so the nearer an imprecise value is
405
- to it the more the light leaks.
406
- */
407
- #define LPV_NORMAL_BIAS 0.01f
408
-
409
410
  vec4 lvp_mask_weights_by_visibility(in vec3 position, in vec3 normal, in vec3 view_direction, in uint tet_index, in vec4 barycentric) {
410
411
 
411
412
  uvec4 vertices = lpv_mesh_getVertices(tet_index);
@@ -451,7 +452,7 @@ vec4 lvp_mask_weights_by_visibility(in vec3 position, in vec3 normal, in vec3 vi
451
452
  // The small offset at the end reduces the "going to zero" impact
452
453
  // where this is really close to exactly opposite
453
454
  float backface_term = max(0.0001, (dot(direction_to_probe, normal) + 1.0) * 0.5);
454
- weight *= backface_term * backface_term + 0.2;
455
+ weight *= backface_term * backface_term + 0.05;
455
456
 
456
457
  }
457
458
 
@@ -559,30 +560,20 @@ vec4 lpv_renormalize_weights(in vec4 source) {
559
560
 
560
561
  vec3 lpv_sample_irradiance(vec3 position, vec3 normal, vec3 view_direction) {
561
562
 
562
- // Bias the position at which visibility is computed; this
563
- // avoids performing a shadow test *at* a surface, which is a
564
- // dangerous location because that is exactly the line between
565
- // shadowed and unshadowed. If the normal bias is too small,
566
- // there will be light and dark leaks. If it is too large,
567
- // then samples can pass through thin occluders to the other
568
- // side (this can only happen if there are MULTIPLE occluders
569
- // near each other, a wall surface won't pass through itself.)
570
- vec3 lookup_position = position + (normal + view_direction * 3.0) * LPV_NORMAL_BIAS;
571
-
572
563
  // lookup nearby tet
573
564
  vec3 lpv_mesh_bounds_min = lpv_v3_bounds_min;
574
565
  vec3 lpv_mesh_bounds_max = lpv_v3_bounds_max;
575
- vec3 lookup_coordinates = (lookup_position - lpv_mesh_bounds_min) / (lpv_mesh_bounds_max - lpv_mesh_bounds_min);
566
+ vec3 lookup_coordinates = (position - lpv_mesh_bounds_min) / (lpv_mesh_bounds_max - lpv_mesh_bounds_min);
576
567
 
577
568
 
578
- uint nearest_tet = lpv_guess_initial_tet(lookup_position);
569
+ uint nearest_tet = lpv_guess_initial_tet(position);
579
570
 
580
571
  uint tet;
581
572
  vec4 barycentric_coordinates;
582
- lpv_walk_to_tetrahedron(lookup_position, nearest_tet, tet, barycentric_coordinates);
573
+ lpv_walk_to_tetrahedron(position, nearest_tet, tet, barycentric_coordinates);
583
574
 
584
575
  // apply visibility term
585
- vec4 weights = lvp_mask_weights_by_visibility(lookup_position, normal, view_direction, tet, barycentric_coordinates);
576
+ vec4 weights = lvp_mask_weights_by_visibility(position, normal, view_direction, tet, barycentric_coordinates);
586
577
 
587
578
  if (tet == INVALID_TET) {
588
579
  // do nothing
@@ -1 +1 @@
1
- {"version":3,"file":"makeOctahedralDepthAtlas.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/gi/material/makeOctahedralDepthAtlas.js"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,sDAHW,MAAM,GACJ,WAAW,CAsBvB;4BA3BqF,OAAO"}
1
+ {"version":3,"file":"makeOctahedralDepthAtlas.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/gi/material/makeOctahedralDepthAtlas.js"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,sDAHW,MAAM,GACJ,WAAW,CAwBvB;4BA7BoF,OAAO"}
@@ -1,4 +1,4 @@
1
- import { ClampToEdgeWrapping, DataTexture, FloatType, NearestFilter, RedFormat } from "three";
1
+ import { ClampToEdgeWrapping, DataTexture, FloatType, NearestFilter, RGFormat } from "three";
2
2
 
3
3
  /**
4
4
  *
@@ -7,10 +7,10 @@ import { ClampToEdgeWrapping, DataTexture, FloatType, NearestFilter, RedFormat }
7
7
  */
8
8
  export function makeOctahedralDepthAtlas(resolution = 4096) {
9
9
  const texture = new DataTexture(
10
- new Float32Array(resolution * resolution),
10
+ new Float32Array(resolution * resolution * 2),
11
11
  resolution,
12
12
  resolution,
13
- RedFormat,
13
+ RGFormat,
14
14
  FloatType
15
15
  );
16
16
 
@@ -24,5 +24,7 @@ export function makeOctahedralDepthAtlas(resolution = 4096) {
24
24
 
25
25
  texture.needsUpdate = true;
26
26
 
27
+ texture.internalFormat = "RG32F";
28
+
27
29
  return texture;
28
30
  }
@@ -35,10 +35,10 @@ export class LightProbeVolume {
35
35
  * Depth map is stored as a 2d texture of size RESOLUTION x RESOLUTION
36
36
  * @type {number}
37
37
  */
38
- #probe_depth_resolution = 64;
38
+ #probe_depth_resolution = 16;
39
39
 
40
40
  /**
41
- * Octahedral-encoded depth map for each probe
41
+ * Octahedral-encoded depth map for each probe, 2 channels for mean and mean squared for variance recovery in the shader
42
42
  * @type {number[]}
43
43
  */
44
44
  #probe_depth = [];
@@ -90,7 +90,7 @@ export class LightProbeVolumeBaker {
90
90
  depth_resolution,
91
91
  max_depth,
92
92
  lpv.points, position_offset,
93
- lpv.depth, probe_index * probe_element_count
93
+ lpv.depth, probe_index * probe_element_count * 2
94
94
  );
95
95
  }
96
96
  }
@@ -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,qBAAoB;IACpB,qBAAyB;IAEzB,uBAA6B;IAE7B;;;;;;;;OAQG;IACH,kCAPW,MAAM,aACN,MAAM,YACN,MAAM,EAAE,mBACR,MAAM,UACN,MAAM,EAAE,iBACR,MAAM,QAahB;IAED,iFAuCC;IAKD,mBACC;IAED,4BAKC;CACJ;8BA5F6B,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;IAErB,qBAAoB;IACpB,qBAAyB;IAEzB,uBAA6B;IAE7B;;;;;;;;OAQG;IACH,kCAPW,MAAM,aACN,MAAM,YACN,MAAM,EAAE,mBACR,MAAM,UACN,MAAM,EAAE,iBACR,MAAM,QAahB;IAED,iFAuCC;IAKD,mBACC;IAED,4BAKC;CACJ;8BA7F6B,oBAAoB;2BAHvB,8BAA8B;gCADzB,mCAAmC"}
@@ -23,8 +23,9 @@ const sampled_irradiance = new Float32Array(3);
23
23
 
24
24
  export class PathTracerProbeRenderer extends ProbeRenderer {
25
25
  tracer = new PathTracer();
26
- max_bounce_count = 7;
27
- sample_count = 1024;
26
+ max_bounce_count = 5;
27
+ // sample_count = 190;
28
+ sample_count = 4096;
28
29
  random = seededRandom(0);
29
30
 
30
31
  scene = new PathTracedScene()
@@ -1 +1 @@
1
- {"version":3,"file":"bake_octahedral_depth_map.d.ts","sourceRoot":"","sources":["../../../../../../../../src/engine/graphics/sh3/lpv/depth/octahedral/bake_octahedral_depth_map.js"],"names":[],"mappings":"AAiCA;;;;;;;;;GASG;AACH,kDARW,MAAM,EAAE,iBACR,MAAM,oCAEN,MAAM,EAAE,UAAQ,mBAChB,MAAM,cACN,MAAM,aACN,MAAM,QA4HhB"}
1
+ {"version":3,"file":"bake_octahedral_depth_map.d.ts","sourceRoot":"","sources":["../../../../../../../../src/engine/graphics/sh3/lpv/depth/octahedral/bake_octahedral_depth_map.js"],"names":[],"mappings":"AAkCA;;;;;;;;;GASG;AACH,kDARW,MAAM,EAAE,iBACR,MAAM,oCAEN,MAAM,EAAE,UAAQ,mBAChB,MAAM,cACN,MAAM,aACN,MAAM,QAkIhB"}
@@ -7,6 +7,7 @@ import {
7
7
  import { Ray3 } from "../../../../../../core/geom/3d/Ray3.js";
8
8
  import { v3_distance } from "../../../../../../core/geom/vec3/v3_distance.js";
9
9
  import { v3_dot_array_array } from "../../../../../../core/geom/vec3/v3_dot_array_array.js";
10
+ import { clamp } from "../../../../../../core/math/clamp.js";
10
11
  import { max2 } from "../../../../../../core/math/max2.js";
11
12
  import { generate_hammersley_jitter } from "../../../../../../core/math/statistics/generate_hammersley_jitter.js";
12
13
 
@@ -14,7 +15,7 @@ import { generate_hammersley_jitter } from "../../../../../../core/math/statisti
14
15
  * Weights of rays that are aligned with the probe direction get exponentially weighted by this exponent
15
16
  * @type {number}
16
17
  */
17
- const DEPTH_SHARPNESS = 40;
18
+ const DEPTH_SHARPNESS = 3;
18
19
 
19
20
  const scratch_ray = new Ray3();
20
21
 
@@ -28,7 +29,7 @@ const ray_hit = [];
28
29
  *
29
30
  * @type {number}
30
31
  */
31
- const SUB_SAMPLE_COUNT = 4;
32
+ const SUB_SAMPLE_COUNT = 16;
32
33
 
33
34
 
34
35
  /**
@@ -71,7 +72,9 @@ export function bake_octahedral_depth_map(
71
72
  */
72
73
  const RESOLUTION_BIAS = Math.sin(texel_angular_coverage) * Math.SQRT2 * 2;
73
74
 
74
- const NORMAL_BIAS = max2(0.01, max_depth * 0.01) + 1e-6;
75
+ // const NORMAL_BIAS = max2(1e-6, max_depth * 0.01);
76
+ const NORMAL_BIAS = 1e-6;
77
+ // const NORMAL_BIAS = clamp(max_depth * Math.sin(texel_angular_coverage),1e-6, max_depth*0.1);
75
78
 
76
79
  const ray_direction = scratch_ray.direction;
77
80
 
@@ -86,6 +89,7 @@ export function bake_octahedral_depth_map(
86
89
  for (let oct_y = 0; oct_y < resolution; oct_y++) {
87
90
 
88
91
  let distance_sum = 0;
92
+ let distance2_sum = 0;
89
93
  let weight_sum = 0;
90
94
 
91
95
  // offset position by half a pixel, as we are storing values for pixel centers
@@ -126,7 +130,7 @@ export function bake_octahedral_depth_map(
126
130
  const surface_position_y = ray_hit[1];
127
131
  const surface_position_z = ray_hit[2];
128
132
 
129
- const hit_normal_bias = -NORMAL_BIAS;
133
+ const hit_normal_bias = NORMAL_BIAS;
130
134
 
131
135
  // sink the contact into the surface along the hit normal
132
136
  const biased_hit_x = surface_position_x + surface_normal_x * hit_normal_bias;
@@ -150,16 +154,19 @@ export function bake_octahedral_depth_map(
150
154
  );
151
155
 
152
156
  distance_sum += distance * weight;
157
+ distance2_sum += distance * distance * weight;
153
158
  weight_sum += weight;
154
159
  }
155
160
 
156
161
  const pixel_index = oct_y * resolution + oct_x;
157
162
 
158
- const address = result_offset + pixel_index;
163
+ const address = result_offset + pixel_index * 2;
159
164
 
160
- const distance = distance_sum / weight_sum;
165
+ const mean = distance_sum / weight_sum;
166
+ const mean2 = distance2_sum / weight_sum;
161
167
 
162
- result[address] = distance;
168
+ result[address] = mean;
169
+ result[address + 1] = mean2;
163
170
  }
164
171
  }
165
172
 
@@ -168,6 +168,14 @@ float lpv_bilinear_lerp(float v00, float v01, float v10, float v11, vec2 fractio
168
168
  return mix(x0, x1, fraction.y);
169
169
  }
170
170
 
171
+ vec2 lpv_bilinear_lerp(vec2 v00, vec2 v01, vec2 v10, vec2 v11, vec2 fraction) {
172
+
173
+ vec2 x0 = mix(v00, v01, fraction.x);
174
+ vec2 x1 = mix(v10, v11, fraction.x);
175
+
176
+ return mix(x0, x1, fraction.y);
177
+ }
178
+
171
179
  vec2 lpv_sample_bilinear(sampler2D tex, ivec2 texel_position, vec2 fraction) {
172
180
 
173
181
  float texel_00 = texelFetch(tex, texel_position, 0).r;
@@ -264,22 +272,16 @@ vec2 lpv_probe_getDepthBilinear(uint probe_index, vec3 direction) {
264
272
  tile_p_10 = wrapOctahedralTexelCoordinates(texel_position + ivec2(0, 1), depth_tile_resolution);
265
273
  tile_p_11 = wrapOctahedralTexelCoordinates(texel_position + ivec2(1, 1), depth_tile_resolution);
266
274
 
267
- float texel_00 = texelFetch(lpv_t_probe_depth, tile_offset + tile_p_00, 0).r;
268
- float texel_01 = texelFetch(lpv_t_probe_depth, tile_offset + tile_p_01, 0).r;
269
- float texel_10 = texelFetch(lpv_t_probe_depth, tile_offset + tile_p_10, 0).r;
270
- float texel_11 = texelFetch(lpv_t_probe_depth, tile_offset + tile_p_11, 0).r;
271
275
 
272
- return vec2(
273
- lpv_bilinear_lerp(
274
- texel_00, texel_01,
275
- texel_10, texel_11,
276
- gridFrac
277
- ),
278
- lpv_bilinear_lerp(
279
- texel_00 * texel_00, texel_01 * texel_01,
280
- texel_10 * texel_10, texel_11 * texel_11,
281
- gridFrac
282
- )
276
+ vec2 texel_00 = texelFetch(lpv_t_probe_depth, tile_offset + tile_p_00, 0).rg;
277
+ vec2 texel_01 = texelFetch(lpv_t_probe_depth, tile_offset + tile_p_01, 0).rg;
278
+ vec2 texel_10 = texelFetch(lpv_t_probe_depth, tile_offset + tile_p_10, 0).rg;
279
+ vec2 texel_11 = texelFetch(lpv_t_probe_depth, tile_offset + tile_p_11, 0).rg;
280
+
281
+ return lpv_bilinear_lerp(
282
+ texel_00, texel_01,
283
+ texel_10, texel_11,
284
+ gridFrac
283
285
  );
284
286
  }
285
287