@woosh/meep-engine 2.122.0 → 2.122.2
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 +1 -1
- package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.d.ts.map +1 -1
- package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.js +15 -0
- package/src/core/bvh2/bvh3/ebvh_nodes_sort_sah_local4.d.ts.map +1 -1
- package/src/core/bvh2/bvh3/ebvh_nodes_sort_sah_local4.js +4 -0
- package/src/core/bvh2/bvh3/ebvh_optimize_treelet.d.ts +2 -2
- package/src/core/bvh2/bvh3/ebvh_optimize_treelet.d.ts.map +1 -1
- package/src/core/bvh2/bvh3/ebvh_optimize_treelet.js +11 -8
- package/src/engine/graphics/sh3/path_tracer/BufferedGeometryBVH.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/BufferedGeometryBVH.js +4 -0
- package/src/engine/graphics/sh3/path_tracer/PathTracedScene.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/PathTracedScene.js +3 -4
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ebvh_build_for_geometry_morton.d.ts","sourceRoot":"","sources":["../../../../../src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ebvh_build_for_geometry_morton.d.ts","sourceRoot":"","sources":["../../../../../src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.js"],"names":[],"mappings":"AAYA;;;;;;;;;GASG;AACH,oDAPW,GAAG,eACH,MAAM,EAAE,GAAC,WAAW,GAAC,WAAW,kBAChC,MAAM,EAAE,GAAC,YAAY,GAAC,YAAY,iBAClC,WAAW,WACX,KAAK,YACL,MAAM,QAiIhB;sBAlJqB,6BAA6B"}
|
|
@@ -8,6 +8,7 @@ import { max2 } from "../../math/max2.js";
|
|
|
8
8
|
import { build_triangle_morton_codes } from "./build_triangle_morton_codes.js";
|
|
9
9
|
import { COLUMN_CHILD_1, COLUMN_HEIGHT, COLUMN_USER_DATA, ELEMENT_WORD_COUNT, NULL_NODE } from "./BVH.js";
|
|
10
10
|
import { ebvh_build_hierarchy } from "./ebvh_build_hierarchy.js";
|
|
11
|
+
import { ebvh_nodes_sort_sah_local4 } from "./ebvh_nodes_sort_sah_local4.js";
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Build the BVH bottom-up using spatial hash sorting
|
|
@@ -130,6 +131,20 @@ export function ebvh_build_for_geometry_morton(
|
|
|
130
131
|
|
|
131
132
|
typed_array_copy(nodes, unprocessed_nodes);
|
|
132
133
|
|
|
134
|
+
// do long-distance swaps, starting high and coming down
|
|
135
|
+
for (let power = 5; power > Math.max(5 - quality, 1); power--) {
|
|
136
|
+
|
|
137
|
+
ebvh_nodes_sort_sah_local4(
|
|
138
|
+
bvh,
|
|
139
|
+
unprocessed_nodes,
|
|
140
|
+
0,
|
|
141
|
+
1 << power,
|
|
142
|
+
tri_count
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
|
|
133
148
|
// assign root
|
|
134
149
|
bvh.root = ebvh_build_hierarchy(bvh, unprocessed_nodes, tri_count, nodes, tri_count, quality);
|
|
135
150
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ebvh_nodes_sort_sah_local4.d.ts","sourceRoot":"","sources":["../../../../../src/core/bvh2/bvh3/ebvh_nodes_sort_sah_local4.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ebvh_nodes_sort_sah_local4.d.ts","sourceRoot":"","sources":["../../../../../src/core/bvh2/bvh3/ebvh_nodes_sort_sah_local4.js"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,gDANW,GAAG,SACH,MAAM,EAAE,GAAC,WAAW,UACpB,MAAM,YACN,MAAM,SACN,MAAM,UAoFhB"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { assert } from "../../assert.js";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Sort consequent 4 nodes to reduce SAH among each consequent pair.
|
|
3
5
|
* Useful for optimizing topology for traversal.
|
|
@@ -14,6 +16,8 @@ export function ebvh_nodes_sort_sah_local4(
|
|
|
14
16
|
distance,
|
|
15
17
|
count
|
|
16
18
|
) {
|
|
19
|
+
assert.isNonNegativeInteger(offset, 'offset');
|
|
20
|
+
assert.isNonNegativeInteger(count, 'count');
|
|
17
21
|
|
|
18
22
|
const swap_pair_limit = Math.floor((count - (distance + 2)) / 2);
|
|
19
23
|
const end = offset + swap_pair_limit * 2;
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* Note that the root does not move, but everything below the root is subject to change
|
|
4
4
|
* @see "Fast Parallel Construction of High-Quality Bounding Volume Hierarchies" by Kerras, NVIDIA 2013
|
|
5
5
|
* @param {BVH} bvh
|
|
6
|
-
* @param {number} root where to start optimization, only nodes below this one will be considered
|
|
6
|
+
* @param {number} [root] where to start optimization, only nodes below this one will be considered
|
|
7
7
|
* @param {number} [treelet_size] the larger the size - the more optimization opportunities, but it gets exponentially slower
|
|
8
8
|
*/
|
|
9
|
-
export function ebvh_optimize_treelet(bvh: BVH, root
|
|
9
|
+
export function ebvh_optimize_treelet(bvh: BVH, root?: number, treelet_size?: number): void;
|
|
10
10
|
//# sourceMappingURL=ebvh_optimize_treelet.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ebvh_optimize_treelet.d.ts","sourceRoot":"","sources":["../../../../../src/core/bvh2/bvh3/ebvh_optimize_treelet.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ebvh_optimize_treelet.d.ts","sourceRoot":"","sources":["../../../../../src/core/bvh2/bvh3/ebvh_optimize_treelet.js"],"names":[],"mappings":"AAuNA;;;;;;;GAOG;AACH,2CAJW,GAAG,SACH,MAAM,iBACN,MAAM,QA8IhB"}
|
|
@@ -3,10 +3,13 @@ import { lsb_32 } from "../../binary/lsb_32.js";
|
|
|
3
3
|
import { bitCount } from "../../binary/operations/bitCount.js";
|
|
4
4
|
import { NULL_NODE } from "./BVH.js";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const
|
|
6
|
+
// Common continuous memory region for better cache performance
|
|
7
|
+
const scratch_memory = new ArrayBuffer((256 * 3 + 16) * 4);
|
|
8
|
+
|
|
9
|
+
const scratch_areas = new Float32Array(scratch_memory, 0, 256);
|
|
10
|
+
const scratch_cost = new Float32Array(scratch_memory, 1024, 256);
|
|
11
|
+
const scratch_partitions = new Uint32Array(scratch_memory, 2048, 256);
|
|
12
|
+
const scratch_treelet = new Uint32Array(scratch_memory, 3072, 16);
|
|
10
13
|
|
|
11
14
|
/**
|
|
12
15
|
*
|
|
@@ -87,7 +90,7 @@ function optimize_treelet(bvh, root, leaves, leaf_count) {
|
|
|
87
90
|
for (let i = 0; i < leaf_count; i++) {
|
|
88
91
|
const leaf = leaves[i];
|
|
89
92
|
|
|
90
|
-
scratch_cost[1 << i] = SAH_COST_TRIANGLE * bvh.node_get_surface_area(leaf)
|
|
93
|
+
scratch_cost[1 << i] = SAH_COST_TRIANGLE * bvh.node_get_surface_area(leaf);
|
|
91
94
|
}
|
|
92
95
|
|
|
93
96
|
// Optimize every subset of leaves
|
|
@@ -136,7 +139,7 @@ function optimize_treelet(bvh, root, leaves, leaf_count) {
|
|
|
136
139
|
* @param {number} treelet_max_size
|
|
137
140
|
*/
|
|
138
141
|
function optimize_at_node(bvh, root, treelet_max_size) {
|
|
139
|
-
if(root === NULL_NODE){
|
|
142
|
+
if (root === NULL_NODE) {
|
|
140
143
|
return;
|
|
141
144
|
}
|
|
142
145
|
|
|
@@ -215,12 +218,12 @@ const CAME_FROM_TYPE_CHILD_2 = 2;
|
|
|
215
218
|
* Note that the root does not move, but everything below the root is subject to change
|
|
216
219
|
* @see "Fast Parallel Construction of High-Quality Bounding Volume Hierarchies" by Kerras, NVIDIA 2013
|
|
217
220
|
* @param {BVH} bvh
|
|
218
|
-
* @param {number} root where to start optimization, only nodes below this one will be considered
|
|
221
|
+
* @param {number} [root] where to start optimization, only nodes below this one will be considered
|
|
219
222
|
* @param {number} [treelet_size] the larger the size - the more optimization opportunities, but it gets exponentially slower
|
|
220
223
|
*/
|
|
221
224
|
export function ebvh_optimize_treelet(
|
|
222
225
|
bvh,
|
|
223
|
-
root,
|
|
226
|
+
root = bvh.root,
|
|
224
227
|
treelet_size = 7
|
|
225
228
|
) {
|
|
226
229
|
assert.isNonNegativeInteger(treelet_size, 'treelet_size');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BufferedGeometryBVH.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/BufferedGeometryBVH.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BufferedGeometryBVH.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/BufferedGeometryBVH.js"],"names":[],"mappings":"AAwCA;IAkBI;;;OAGG;IACH,eAFW,KAAK,GAAC,MAAM,EAAE,QAIxB;IAIG;;;;OAIG;IACH,mBAAsB;IAEtB;;;;OAIG;IACH,yBAA4B;IAE5B;;;;OAIG;IACH,6BAAgC;IAGhC;;;;OAIG;IACH,yBAAyB;IAG7B;;;OAGG;IACH,WAFW,KAAK,CAAC,cAAc,QA8C9B;IAED;;;;;OAKG;IACH,cAHW,IAAI,GACF,OAAO,CAmHnB;IAED;;;;;;;OAOG;IACH,4BANW,aAAa,KACb,MAAM,KACN,MAAM,KACN,MAAM,GACJ,OAAO,CAUnB;IAGD;;;;;;OAMG;IACH,iBAJW,MAAM,EAAE,OACR,MAAM,EAAE,GAAC,IAAI,GACX,MAAM,CAoIlB;IAED;;;;;OAKG;IACH,gBAJW,MAAM,EAAE,OACR,MAAM,EAAE,GAAC,IAAI,GACX,MAAM,CA2ElB;;CACJ;sBA9eqB,wCAAwC;8BAGhC,2CAA2C"}
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
NULL_NODE
|
|
8
8
|
} from "../../../../core/bvh2/bvh3/BVH.js";
|
|
9
9
|
import { ebvh_build_for_geometry_morton } from "../../../../core/bvh2/bvh3/ebvh_build_for_geometry_morton.js";
|
|
10
|
+
import { ebvh_optimize_treelet } from "../../../../core/bvh2/bvh3/ebvh_optimize_treelet.js";
|
|
10
11
|
import { bvh_query_user_data_ray_segment } from "../../../../core/bvh2/bvh3/query/bvh_query_user_data_ray_segment.js";
|
|
11
12
|
import { array_copy } from "../../../../core/collection/array/array_copy.js";
|
|
12
13
|
import { SCRATCH_UINT32_TRAVERSAL_STACK } from "../../../../core/collection/SCRATCH_UINT32_TRAVERSAL_STACK.js";
|
|
@@ -130,6 +131,9 @@ export class BufferedGeometryBVH {
|
|
|
130
131
|
this.#bounds,
|
|
131
132
|
16
|
|
132
133
|
);
|
|
134
|
+
|
|
135
|
+
ebvh_optimize_treelet(bvh);
|
|
136
|
+
|
|
133
137
|
//
|
|
134
138
|
// ebvh_build_for_geometry_incremental(bvh, index_array, array_positions, 1);
|
|
135
139
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PathTracedScene.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/PathTracedScene.js"],"names":[],"mappings":"AAoDA;IAGI;;;OAGG;IACH,eAFU,GAAG,CAEa;IAG1B;;;OAGG;IACH,QAFU,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAElB;IAEnB;;;OAGG;IACH,UAFU,aAAa,EAAE,CAEX;IAEd;;;OAGG;IACH,WAFU,GAAG,CAAC,KAAK,CAAC,cAAc,EAAE,mBAAmB,CAAC,CAElC;IAmBtB;;;;OAIG;IACH,6BAA6C;
|
|
1
|
+
{"version":3,"file":"PathTracedScene.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/PathTracedScene.js"],"names":[],"mappings":"AAo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ert } from "../../../../core/assert.js";
|
|
2
2
|
import { BVH, NULL_NODE } from "../../../../core/bvh2/bvh3/BVH.js";
|
|
3
3
|
import { ebvh_build_hierarchy } from "../../../../core/bvh2/bvh3/ebvh_build_hierarchy.js";
|
|
4
|
-
import {
|
|
4
|
+
import { ebvh_optimize_treelet } from "../../../../core/bvh2/bvh3/ebvh_optimize_treelet.js";
|
|
5
5
|
import { bvh_query_user_data_ray_segment } from "../../../../core/bvh2/bvh3/query/bvh_query_user_data_ray_segment.js";
|
|
6
6
|
import { Cache } from "../../../../core/cache/Cache.js";
|
|
7
7
|
import { array_copy } from "../../../../core/collection/array/array_copy.js";
|
|
@@ -172,15 +172,14 @@ export class PathTracedScene {
|
|
|
172
172
|
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
-
ebvh_nodes_sort_sah_local4(bvh, nodes, 0, 2, node_leaf_count);
|
|
176
|
-
|
|
177
175
|
// record newly generated nodes as "unprocessed"
|
|
178
176
|
const unprocessed_nodes = new Uint32Array(node_leaf_count);
|
|
179
177
|
array_copy(nodes, 0, unprocessed_nodes, 0, node_leaf_count);
|
|
180
178
|
|
|
181
179
|
// assign root
|
|
182
|
-
bvh.__root = ebvh_build_hierarchy(bvh, unprocessed_nodes, node_leaf_count, nodes, node_leaf_count);
|
|
180
|
+
bvh.__root = ebvh_build_hierarchy(bvh, unprocessed_nodes, node_leaf_count, nodes, node_leaf_count,16);
|
|
183
181
|
|
|
182
|
+
ebvh_optimize_treelet(bvh);
|
|
184
183
|
}
|
|
185
184
|
|
|
186
185
|
optimize() {
|