@woosh/meep-engine 2.109.2 → 2.109.4

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 (36) hide show
  1. package/build/meep.cjs +4 -0
  2. package/build/meep.module.js +4 -0
  3. package/package.json +1 -1
  4. package/src/core/bvh2/bvh3/query/bvh_query_leaves_ray_segment.d.ts +18 -0
  5. package/src/core/bvh2/bvh3/query/bvh_query_leaves_ray_segment.d.ts.map +1 -0
  6. package/src/core/bvh2/bvh3/query/bvh_query_leaves_ray_segment.js +94 -0
  7. package/src/core/bvh2/bvh3/query/bvh_query_user_data_ray_segment.d.ts +18 -0
  8. package/src/core/bvh2/bvh3/query/bvh_query_user_data_ray_segment.d.ts.map +1 -0
  9. package/src/core/bvh2/bvh3/query/bvh_query_user_data_ray_segment.js +100 -0
  10. package/src/core/collection/map/HashMap.js +2 -2
  11. package/src/core/geom/3d/aabb/aabb3_intersects_ray_segment.d.ts +21 -0
  12. package/src/core/geom/3d/aabb/aabb3_intersects_ray_segment.d.ts.map +1 -0
  13. package/src/core/geom/3d/aabb/aabb3_intersects_ray_segment.js +67 -0
  14. package/src/core/geom/3d/ray/ray3_interval_array_apply_matrix4.d.ts +11 -0
  15. package/src/core/geom/3d/ray/ray3_interval_array_apply_matrix4.d.ts.map +1 -0
  16. package/src/core/geom/3d/ray/ray3_interval_array_apply_matrix4.js +61 -0
  17. package/src/core/math/max4.d.ts +10 -0
  18. package/src/core/math/max4.d.ts.map +1 -0
  19. package/src/core/math/max4.js +24 -0
  20. package/src/core/math/min4.d.ts +10 -0
  21. package/src/core/math/min4.d.ts.map +1 -0
  22. package/src/core/math/min4.js +23 -0
  23. package/src/core/model/node-graph/node/NodeDescription.d.ts.map +1 -1
  24. package/src/core/model/node-graph/node/NodeDescription.js +23 -0
  25. package/src/engine/graphics/geometry/buffered/computeBufferAttributeHash.d.ts.map +1 -1
  26. package/src/engine/graphics/geometry/buffered/computeBufferAttributeHash.js +9 -5
  27. package/src/engine/graphics/impostors/octahedral/prototypeBaker.js +6 -5
  28. package/src/engine/graphics/sh3/path_tracer/BufferedGeometryBVH.d.ts.map +1 -1
  29. package/src/engine/graphics/sh3/path_tracer/BufferedGeometryBVH.js +6 -31
  30. package/src/engine/graphics/sh3/path_tracer/PathTracedMesh.js +1 -1
  31. package/src/engine/graphics/sh3/path_tracer/PathTracedScene.d.ts.map +1 -1
  32. package/src/engine/graphics/sh3/path_tracer/PathTracedScene.js +6 -29
  33. package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +6 -6
  34. package/src/core/geom/3d/aabb/aabb3_overlaps_ray_segment.d.ts +0 -11
  35. package/src/core/geom/3d/aabb/aabb3_overlaps_ray_segment.d.ts.map +0 -1
  36. package/src/core/geom/3d/aabb/aabb3_overlaps_ray_segment.js +0 -61
package/build/meep.cjs CHANGED
@@ -60141,8 +60141,12 @@ class HashMap {
60141
60141
  return true;
60142
60142
  }
60143
60143
 
60144
+ // assert.equal(record.hash, this.#build_key_hash(record.key), `Key hash has diverged for key ${record.key}, likely key was mutated or hash function is unstable`);
60145
+
60144
60146
  const result = this.keyEqualityFunction(record.key, key);
60145
60147
 
60148
+ // assert.isBoolean(result, `result(a=${record.key},b=${key})`);
60149
+
60146
60150
  return result;
60147
60151
  }
60148
60152
 
@@ -60139,8 +60139,12 @@ class HashMap {
60139
60139
  return true;
60140
60140
  }
60141
60141
 
60142
+ // assert.equal(record.hash, this.#build_key_hash(record.key), `Key hash has diverged for key ${record.key}, likely key was mutated or hash function is unstable`);
60143
+
60142
60144
  const result = this.keyEqualityFunction(record.key, key);
60143
60145
 
60146
+ // assert.isBoolean(result, `result(a=${record.key},b=${key})`);
60147
+
60144
60148
  return result;
60145
60149
  }
60146
60150
 
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.109.2",
8
+ "version": "2.109.4",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -0,0 +1,18 @@
1
+ /**
2
+ *
3
+ * @param {BVH} bvh
4
+ * @param {number} root
5
+ * @param {number[]} result
6
+ * @param {number} result_offset
7
+ * @param {number} origin_x
8
+ * @param {number} origin_y
9
+ * @param {number} origin_z
10
+ * @param {number} direction_x
11
+ * @param {number} direction_y
12
+ * @param {number} direction_z
13
+ * @param {number} t_min
14
+ * @param {number} t_max
15
+ * @returns {number}
16
+ */
17
+ export function bvh_query_leaves_ray_segment(bvh: BVH, root: number, result: number[], result_offset: number, origin_x: number, origin_y: number, origin_z: number, direction_x: number, direction_y: number, direction_z: number, t_min: number, t_max: number): number;
18
+ //# sourceMappingURL=bvh_query_leaves_ray_segment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bvh_query_leaves_ray_segment.d.ts","sourceRoot":"","sources":["../../../../../../src/core/bvh2/bvh3/query/bvh_query_leaves_ray_segment.js"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;GAeG;AACH,6DAbW,MAAM,UACN,MAAM,EAAE,iBACR,MAAM,YACN,MAAM,YACN,MAAM,YACN,MAAM,eACN,MAAM,eACN,MAAM,eACN,MAAM,SACN,MAAM,SACN,MAAM,GACJ,MAAM,CAwElB"}
@@ -0,0 +1,94 @@
1
+ import { SCRATCH_UINT32_TRAVERSAL_STACK } from "../../../collection/SCRATCH_UINT32_TRAVERSAL_STACK.js";
2
+ import { aabb3_intersects_ray_segment } from "../../../geom/3d/aabb/aabb3_intersects_ray_segment.js";
3
+ import { COLUMN_CHILD_1, COLUMN_CHILD_2, ELEMENT_WORD_COUNT, NULL_NODE } from "../BVH.js";
4
+
5
+ const stack = SCRATCH_UINT32_TRAVERSAL_STACK;
6
+
7
+
8
+ /**
9
+ *
10
+ * @param {BVH} bvh
11
+ * @param {number} root
12
+ * @param {number[]} result
13
+ * @param {number} result_offset
14
+ * @param {number} origin_x
15
+ * @param {number} origin_y
16
+ * @param {number} origin_z
17
+ * @param {number} direction_x
18
+ * @param {number} direction_y
19
+ * @param {number} direction_z
20
+ * @param {number} t_min
21
+ * @param {number} t_max
22
+ * @returns {number}
23
+ */
24
+ export function bvh_query_leaves_ray_segment(
25
+ bvh, root,
26
+ result, result_offset,
27
+ origin_x, origin_y, origin_z,
28
+ direction_x, direction_y, direction_z,
29
+ t_min, t_max
30
+ ) {
31
+
32
+ if (root === NULL_NODE) {
33
+ return 0;
34
+ }
35
+
36
+
37
+ /**
38
+ *
39
+ * @type {number}
40
+ */
41
+ const stack_top = stack.pointer++;
42
+
43
+ stack[stack_top] = root;
44
+
45
+ let result_cursor = result_offset;
46
+
47
+ /*
48
+ For performance, we bind data directly to avoid extra copies required to read out AABB
49
+ */
50
+ const float32 = bvh.__data_float32;
51
+ const uint32 = bvh.__data_uint32;
52
+
53
+ do {
54
+ stack.pointer--;
55
+
56
+ /**
57
+ *
58
+ * @type {number}
59
+ */
60
+ const node = stack[stack.pointer];
61
+
62
+ const address = node * ELEMENT_WORD_COUNT;
63
+
64
+ // test node against the ray
65
+ const intersects = aabb3_intersects_ray_segment(
66
+ float32[address], float32[address + 1], float32[address + 2],
67
+ float32[address + 3], float32[address + 4], float32[address + 5],
68
+ origin_x, origin_y, origin_z,
69
+ direction_x, direction_y, direction_z,
70
+ t_min, t_max
71
+ );
72
+
73
+ if (!intersects) {
74
+ continue;
75
+ }
76
+
77
+ // get fist child to check if this is a leaf node or not
78
+ const child_1 = uint32[address + COLUMN_CHILD_1];
79
+
80
+ if (child_1 !== NULL_NODE) {
81
+
82
+ // this is not a leaf node, push children onto traversal stack
83
+ stack[stack.pointer++] = uint32[address + COLUMN_CHILD_2];
84
+ stack[stack.pointer++] = child_1;
85
+
86
+ } else {
87
+ // leaf node
88
+
89
+ result[result_cursor++] = node;
90
+ }
91
+ } while (stack.pointer > stack_top);
92
+
93
+ return result_cursor - result_offset;
94
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ *
3
+ * @param {BVH} bvh
4
+ * @param {number} root
5
+ * @param {number[]} result
6
+ * @param {number} result_offset
7
+ * @param {number} origin_x
8
+ * @param {number} origin_y
9
+ * @param {number} origin_z
10
+ * @param {number} direction_x
11
+ * @param {number} direction_y
12
+ * @param {number} direction_z
13
+ * @param {number} t_min
14
+ * @param {number} t_max
15
+ * @returns {number}
16
+ */
17
+ export function bvh_query_user_data_ray_segment(bvh: BVH, root: number, result: number[], result_offset: number, origin_x: number, origin_y: number, origin_z: number, direction_x: number, direction_y: number, direction_z: number, t_min: number, t_max: number): number;
18
+ //# sourceMappingURL=bvh_query_user_data_ray_segment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bvh_query_user_data_ray_segment.d.ts","sourceRoot":"","sources":["../../../../../../src/core/bvh2/bvh3/query/bvh_query_user_data_ray_segment.js"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;GAeG;AACH,gEAbW,MAAM,UACN,MAAM,EAAE,iBACR,MAAM,YACN,MAAM,YACN,MAAM,YACN,MAAM,eACN,MAAM,eACN,MAAM,eACN,MAAM,SACN,MAAM,SACN,MAAM,GACJ,MAAM,CA+ElB"}
@@ -0,0 +1,100 @@
1
+ import { SCRATCH_UINT32_TRAVERSAL_STACK } from "../../../collection/SCRATCH_UINT32_TRAVERSAL_STACK.js";
2
+ import { aabb3_intersects_ray_segment } from "../../../geom/3d/aabb/aabb3_intersects_ray_segment.js";
3
+ import { COLUMN_CHILD_1, COLUMN_CHILD_2, COLUMN_USER_DATA, ELEMENT_WORD_COUNT, NULL_NODE } from "../BVH.js";
4
+
5
+ const stack = SCRATCH_UINT32_TRAVERSAL_STACK;
6
+
7
+ /**
8
+ *
9
+ * @param {BVH} bvh
10
+ * @param {number} root
11
+ * @param {number[]} result
12
+ * @param {number} result_offset
13
+ * @param {number} origin_x
14
+ * @param {number} origin_y
15
+ * @param {number} origin_z
16
+ * @param {number} direction_x
17
+ * @param {number} direction_y
18
+ * @param {number} direction_z
19
+ * @param {number} t_min
20
+ * @param {number} t_max
21
+ * @returns {number}
22
+ */
23
+ export function bvh_query_user_data_ray_segment(
24
+ bvh, root,
25
+ result, result_offset,
26
+ origin_x, origin_y, origin_z,
27
+ direction_x, direction_y, direction_z,
28
+ t_min, t_max
29
+ ) {
30
+
31
+ if (root === NULL_NODE) {
32
+ return 0;
33
+ }
34
+
35
+ /**
36
+ * Move stack pointer to local variable scope to avoid de-referencing inside the loop
37
+ * @type {number}
38
+ */
39
+ let pointer = stack.pointer;
40
+
41
+ /**
42
+ *
43
+ * @type {number}
44
+ */
45
+ const stack_top = pointer;
46
+
47
+ stack[pointer++] = root;
48
+
49
+ let result_cursor = result_offset;
50
+
51
+ /*
52
+ For performance, we bind data directly to avoid extra copies required to read out AABB
53
+ */
54
+ const float32 = bvh.__data_float32;
55
+ const uint32 = bvh.__data_uint32;
56
+
57
+ do {
58
+ --pointer;
59
+
60
+ /**
61
+ *
62
+ * @type {number}
63
+ */
64
+ const node = stack[pointer];
65
+
66
+ const address = node * ELEMENT_WORD_COUNT;
67
+
68
+ // test node against the ray
69
+ const intersects = aabb3_intersects_ray_segment(
70
+ float32[address], float32[address + 1], float32[address + 2],
71
+ float32[address + 3], float32[address + 4], float32[address + 5],
72
+ origin_x, origin_y, origin_z,
73
+ direction_x, direction_y, direction_z,
74
+ t_min, t_max
75
+ );
76
+
77
+ if (!intersects) {
78
+ continue;
79
+ }
80
+
81
+ // get fist child to check if this is a leaf node or not
82
+ const child_1 = uint32[address + COLUMN_CHILD_1];
83
+
84
+ if (child_1 !== NULL_NODE) {
85
+
86
+ // this is not a leaf node, push children onto traversal stack
87
+ const child_2 = uint32[address + COLUMN_CHILD_2];
88
+
89
+ stack[pointer++] = child_2;
90
+ stack[pointer++] = child_1;
91
+
92
+ } else {
93
+ // leaf node
94
+
95
+ result[result_cursor++] = uint32[address + COLUMN_USER_DATA];
96
+ }
97
+ } while (pointer > stack_top);
98
+
99
+ return result_cursor - result_offset;
100
+ }
@@ -337,11 +337,11 @@ export class HashMap {
337
337
  return true;
338
338
  }
339
339
 
340
- assert.equal(record.hash, this.#build_key_hash(record.key), `Key hash has diverged for key ${record.key}, likely key was mutated or hash function is unstable`);
340
+ // assert.equal(record.hash, this.#build_key_hash(record.key), `Key hash has diverged for key ${record.key}, likely key was mutated or hash function is unstable`);
341
341
 
342
342
  const result = this.keyEqualityFunction(record.key, key);
343
343
 
344
- assert.isBoolean(result, `result(a=${record.key},b=${key})`);
344
+ // assert.isBoolean(result, `result(a=${record.key},b=${key})`);
345
345
 
346
346
  return result;
347
347
  }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @see Ray Tracing Gems II, Chapter 2 "RAY AXIS-ALIGNED BOUNDING BOX INTERSECTION"
3
+ * @param {number} x0
4
+ * @param {number} y0
5
+ * @param {number} z0
6
+ * @param {number} x1
7
+ * @param {number} y1
8
+ * @param {number} z1
9
+ * @param {number} origin_x
10
+ * @param {number} origin_y
11
+ * @param {number} origin_z
12
+ * @param {number} direction_x
13
+ * @param {number} direction_y
14
+ * @param {number} direction_z
15
+ * @param {number} min_distance
16
+ * @param {number} max_distance
17
+ * @returns {boolean}
18
+ * @returns {boolean}
19
+ */
20
+ export function aabb3_intersects_ray_segment(x0: number, y0: number, z0: number, x1: number, y1: number, z1: number, origin_x: number, origin_y: number, origin_z: number, direction_x: number, direction_y: number, direction_z: number, min_distance: number, max_distance: number): boolean;
21
+ //# sourceMappingURL=aabb3_intersects_ray_segment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aabb3_intersects_ray_segment.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/aabb/aabb3_intersects_ray_segment.js"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;GAkBG;AACH,iDAjBW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,YACN,MAAM,YACN,MAAM,YACN,MAAM,eACN,MAAM,eACN,MAAM,eACN,MAAM,gBACN,MAAM,gBACN,MAAM,GACJ,OAAO,CA+CnB"}
@@ -0,0 +1,67 @@
1
+ import { max2 } from "../../../math/max2.js";
2
+ import { min2 } from "../../../math/min2.js";
3
+
4
+ /**
5
+ * @see Ray Tracing Gems II, Chapter 2 "RAY AXIS-ALIGNED BOUNDING BOX INTERSECTION"
6
+ * @param {number} x0
7
+ * @param {number} y0
8
+ * @param {number} z0
9
+ * @param {number} x1
10
+ * @param {number} y1
11
+ * @param {number} z1
12
+ * @param {number} origin_x
13
+ * @param {number} origin_y
14
+ * @param {number} origin_z
15
+ * @param {number} direction_x
16
+ * @param {number} direction_y
17
+ * @param {number} direction_z
18
+ * @param {number} min_distance
19
+ * @param {number} max_distance
20
+ * @returns {boolean}
21
+ * @returns {boolean}
22
+ */
23
+ export function aabb3_intersects_ray_segment(
24
+ x0, y0, z0,
25
+ x1, y1, z1,
26
+ origin_x, origin_y, origin_z,
27
+ direction_x, direction_y, direction_z,
28
+ min_distance, max_distance
29
+ ) {
30
+
31
+ // move aabb into ray space
32
+ const _x0 = x0 - origin_x;
33
+ const _y0 = y0 - origin_y;
34
+ const _z0 = z0 - origin_z;
35
+
36
+ const _x1 = x1 - origin_x;
37
+ const _y1 = y1 - origin_y;
38
+ const _z1 = z1 - origin_z;
39
+
40
+ const inv_direction_x = 1 / direction_x;
41
+ const inv_direction_y = 1 / direction_y;
42
+ const inv_direction_z = 1 / direction_z;
43
+
44
+ // Absolute distances to lower and upper box coordinates
45
+ const t_lower_x = _x0 * inv_direction_x;
46
+ const t_lower_y = _y0 * inv_direction_y;
47
+ const t_lower_z = _z0 * inv_direction_z;
48
+
49
+ const t_upper_x = _x1 * inv_direction_x;
50
+ const t_upper_y = _y1 * inv_direction_y;
51
+ const t_upper_z = _z1 * inv_direction_z;
52
+
53
+ // The four t-intervals (for x-/y-/z-slabs, and ray p(t))
54
+ const t_min_x = min2(t_lower_x, t_upper_x);
55
+ const t_min_y = min2(t_lower_y, t_upper_y);
56
+ const t_min_z = min2(t_lower_z, t_upper_z);
57
+
58
+ const t_max_x = max2(t_lower_x, t_upper_x);
59
+ const t_max_y = max2(t_lower_y, t_upper_y);
60
+ const t_max_z = max2(t_lower_z, t_upper_z);
61
+
62
+ // Easy to remember: ``max of mins, and min of maxes''
63
+ const t_box_min = Math.max(t_min_x, t_min_y, t_min_z, min_distance);
64
+ const t_box_max = Math.min(t_max_x, t_max_y, t_max_z, max_distance);
65
+
66
+ return t_box_min <= t_box_max;
67
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ *
3
+ * @param {number[]|ArrayLike<number>|Float32Array} output 8 component vector, [origin_x, origin_y, origin_z, direction_x, direction_y, direction_z, tMin, tMax]
4
+ * @param {number} output_offset
5
+ * @param {number[]|ArrayLike<number>|Float32Array} input 8 component vector, [origin_x, origin_y, origin_z, direction_x, direction_y, direction_z, tMin, tMax]
6
+ * @param {number} input_offset
7
+ * @param {number[]|ArrayLike<number>|Float32Array} m4 4x4 matrix
8
+ * @returns {boolean} false if matrix transformation is impossible, such as when scale of the matrix is 0
9
+ */
10
+ export function ray3_interval_array_apply_matrix4(output: number[] | ArrayLike<number> | Float32Array, output_offset: number, input: number[] | ArrayLike<number> | Float32Array, input_offset: number, m4: number[] | ArrayLike<number> | Float32Array): boolean;
11
+ //# sourceMappingURL=ray3_interval_array_apply_matrix4.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ray3_interval_array_apply_matrix4.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/ray/ray3_interval_array_apply_matrix4.js"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,0DAPW,MAAM,EAAE,GAAC,UAAU,MAAM,CAAC,GAAC,YAAY,iBACvC,MAAM,SACN,MAAM,EAAE,GAAC,UAAU,MAAM,CAAC,GAAC,YAAY,gBACvC,MAAM,MACN,MAAM,EAAE,GAAC,UAAU,MAAM,CAAC,GAAC,YAAY,GACrC,OAAO,CAqDnB"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ *
3
+ * @param {number[]|ArrayLike<number>|Float32Array} output 8 component vector, [origin_x, origin_y, origin_z, direction_x, direction_y, direction_z, tMin, tMax]
4
+ * @param {number} output_offset
5
+ * @param {number[]|ArrayLike<number>|Float32Array} input 8 component vector, [origin_x, origin_y, origin_z, direction_x, direction_y, direction_z, tMin, tMax]
6
+ * @param {number} input_offset
7
+ * @param {number[]|ArrayLike<number>|Float32Array} m4 4x4 matrix
8
+ * @returns {boolean} false if matrix transformation is impossible, such as when scale of the matrix is 0
9
+ */
10
+ export function ray3_interval_array_apply_matrix4(output, output_offset, input, input_offset, m4) {
11
+ const origin_x = input[input_offset + 0];
12
+ const origin_y = input[input_offset + 1];
13
+ const origin_z = input[input_offset + 2];
14
+
15
+ const direction_x = input[input_offset + 3];
16
+ const direction_y = input[input_offset + 4];
17
+ const direction_z = input[input_offset + 5];
18
+
19
+ // transform ray to local space (inlined for speed)
20
+ const det = m4[3] * origin_x + m4[7] * origin_y + m4[11] * origin_z + m4[15];
21
+
22
+ if (det === 0) {
23
+ return false;
24
+ }
25
+
26
+ const inv_w = 1 / det;
27
+
28
+ const out_origin_x = (m4[0] * origin_x + m4[4] * origin_y + m4[8] * origin_z + m4[12]) * inv_w;
29
+ const out_origin_y = (m4[1] * origin_x + m4[5] * origin_y + m4[9] * origin_z + m4[13]) * inv_w;
30
+ const out_origin_z = (m4[2] * origin_x + m4[6] * origin_y + m4[10] * origin_z + m4[14]) * inv_w;
31
+
32
+ const out_direction_x = m4[0] * direction_x + m4[4] * direction_y + m4[8] * direction_z;
33
+ const out_direction_y = m4[1] * direction_x + m4[5] * direction_y + m4[9] * direction_z;
34
+ const out_direction_z = m4[2] * direction_x + m4[6] * direction_y + m4[10] * direction_z;
35
+
36
+ // normalize direction
37
+ const out_direction_magnitude = Math.hypot(out_direction_x, out_direction_y, out_direction_z);
38
+
39
+ if (out_direction_magnitude === 0) {
40
+ return false;
41
+ }
42
+
43
+ const out_direction_magnitude_inverse = 1 / out_direction_magnitude;
44
+
45
+ const out_direction_normalized_x = out_direction_x * out_direction_magnitude_inverse;
46
+ const out_direction_normalized_y = out_direction_y * out_direction_magnitude_inverse;
47
+ const out_direction_normalized_z = out_direction_z * out_direction_magnitude_inverse;
48
+
49
+ output[output_offset + 0] = out_origin_x;
50
+ output[output_offset + 1] = out_origin_y;
51
+ output[output_offset + 2] = out_origin_z;
52
+
53
+ output[output_offset + 3] = out_direction_normalized_x;
54
+ output[output_offset + 4] = out_direction_normalized_y;
55
+ output[output_offset + 5] = out_direction_normalized_z;
56
+
57
+ // TODO implement
58
+ throw new Error("Not Implemented")
59
+
60
+ return true;
61
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ *
3
+ * @param {number} a
4
+ * @param {number} b
5
+ * @param {number} c
6
+ * @param {number} d
7
+ * @returns {number}
8
+ */
9
+ export function max4(a: number, b: number, c: number, d: number): number;
10
+ //# sourceMappingURL=max4.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"max4.d.ts","sourceRoot":"","sources":["../../../../src/core/math/max4.js"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBANW,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,GACJ,MAAM,CAgBlB"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ *
3
+ * @param {number} a
4
+ * @param {number} b
5
+ * @param {number} c
6
+ * @param {number} d
7
+ * @returns {number}
8
+ */
9
+ export function max4(a, b, c, d) {
10
+ let v = a;
11
+
12
+ if (b > v) {
13
+ v = b;
14
+ }
15
+ if (c > v) {
16
+ v = c;
17
+ }
18
+ if (d > v) {
19
+ v = d;
20
+ }
21
+
22
+ return v;
23
+ }
24
+
@@ -0,0 +1,10 @@
1
+ /**
2
+ *
3
+ * @param {number} a
4
+ * @param {number} b
5
+ * @param {number} c
6
+ * @param {number} d
7
+ * @returns {number}
8
+ */
9
+ export function min4(a: number, b: number, c: number, d: number): number;
10
+ //# sourceMappingURL=min4.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"min4.d.ts","sourceRoot":"","sources":["../../../../src/core/math/min4.js"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBANW,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,GACJ,MAAM,CAgBlB"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ *
3
+ * @param {number} a
4
+ * @param {number} b
5
+ * @param {number} c
6
+ * @param {number} d
7
+ * @returns {number}
8
+ */
9
+ export function min4(a, b, c, d) {
10
+ let v = a;
11
+
12
+ if (b < v) {
13
+ v = b;
14
+ }
15
+ if (c < v) {
16
+ v = c;
17
+ }
18
+ if (d < v) {
19
+ v = d;
20
+ }
21
+
22
+ return v;
23
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"NodeDescription.d.ts","sourceRoot":"","sources":["../../../../../../src/core/model/node-graph/node/NodeDescription.js"],"names":[],"mappings":"AAwCA;IACI;;;OAGG;IACH,MAFU,MAAM,CAEN;IAEV;;;;;;OAMG;IACH,IAFU,MAAM,CAEO;IAEvB;;;OAGG;IACH,iBAFU,IAAI,EAAE,CAEL;IAEX;;;OAGG;IACH,YAFU,wBAAwB,EAAE,CAEpB;IAEhB;;OAEG;IACH;QACI;;;WAGG;4BADO,OAAO,IAAI,CAAC;QAGtB;;;WAGG;8BADO,OAAO,IAAI,CAAC;MAGxB;IAEF;;;;OAIG;IACH,4CAEC;IAED;;;OAGG;IACH,uBAEC;IAED;;;OAGG;IACH,sBAEC;IAED;;;;;;OAMG;IACH,sBALW,MAAM,QACN,qBAAqB,iBACrB,MAAM,GAAC,OAAO,GAAC,MAAM,GACnB,MAAM,CA0ClB;IAED;;;;OAIG;IACH,iBAHW,MAAM,GACJ,wBAAwB,CAiBpC;IAGD;;;;;;OAMG;IACH,oDAHW,aAAa,GACX,MAAM,CA2BlB;IAED;;;;OAIG;IACH,eAHW,MAAM,GACJ,OAAO,CAuBnB;IAED;;;;OAIG;IACH,gBAHW,MAAM,GACJ,IAAI,GAAC,IAAI,CAgBrB;IAED;;;;OAIG;IACH,qBAHW,MAAM,GACL,IAAI,EAAE,CAwBjB;IAED;;;;OAIG;IACH,+BAHW,aAAa,GACZ,IAAI,EAAE,CAuBjB;IAED;;;;;OAKG;IACH,iCAJW,MAAM,aACN,aAAa,GACZ,IAAI,GAAC,SAAS,CAmBzB;IAED;;;OAGG;IACH,YAFa,IAAI,EAAE,CAIlB;IAED;;;;OAIG;IACH,cAHW,eAAe,GACb,OAAO,CAYnB;IAED,mBAEC;IAED;;;;MAMC;IAED;;;;;;OAMG;IACH,8BALW,EAAE,gCAaZ;IAKL;;;OAGG;IACH,4BAFU,OAAO,CAE0B;CAR1C;;;;qBAxYoB,WAAW;yCADS,yCAAyC;mBAH/D,kCAAkC;sCAEf,sCAAsC;8BAG9C,oBAAoB"}
1
+ {"version":3,"file":"NodeDescription.d.ts","sourceRoot":"","sources":["../../../../../../src/core/model/node-graph/node/NodeDescription.js"],"names":[],"mappings":"AAwCA;IACI;;;OAGG;IACH,MAFU,MAAM,CAEN;IAEV;;;;;;OAMG;IACH,IAFU,MAAM,CAEO;IAEvB;;;OAGG;IACH,iBAFU,IAAI,EAAE,CAEL;IAEX;;;OAGG;IACH,YAFU,wBAAwB,EAAE,CAEpB;IAEhB;;OAEG;IACH;QACI;;;WAGG;4BADO,OAAO,IAAI,CAAC;QAGtB;;;WAGG;8BADO,OAAO,IAAI,CAAC;MAGxB;IAEF;;;;OAIG;IACH,4CAEC;IAED;;;OAGG;IACH,uBAEC;IAED;;;OAGG;IACH,sBAEC;IAED;;;;;;OAMG;IACH,sBALW,MAAM,QACN,qBAAqB,iBACrB,MAAM,GAAC,OAAO,GAAC,MAAM,GACnB,MAAM,CA0ClB;IAED;;;;OAIG;IACH,iBAHW,MAAM,GACJ,wBAAwB,CAiBpC;IAGD;;;;;;OAMG;IACH,oDAHW,aAAa,GACX,MAAM,CA2BlB;IAED;;;;OAIG;IACH,eAHW,MAAM,GACJ,OAAO,CAuBnB;IAED;;;;OAIG;IACH,gBAHW,MAAM,GACJ,IAAI,GAAC,IAAI,CAgBrB;IAED;;;;OAIG;IACH,qBAHW,MAAM,GACL,IAAI,EAAE,CAwBjB;IAED;;;;;OAKG;IACH,+BAHW,aAAa,GACZ,OAAO,CAiBlB;IAED;;;;OAIG;IACH,+BAHW,aAAa,GACZ,IAAI,EAAE,CAuBjB;IAED;;;;;OAKG;IACH,iCAJW,MAAM,aACN,aAAa,GACZ,IAAI,GAAC,SAAS,CAmBzB;IAED;;;OAGG;IACH,YAFa,IAAI,EAAE,CAIlB;IAED;;;;OAIG;IACH,cAHW,eAAe,GACb,OAAO,CAYnB;IAED,mBAEC;IAED;;;;MAMC;IAED;;;;;;OAMG;IACH,8BALW,EAAE,gCAaZ;IAKL;;;OAGG;IACH,4BAFU,OAAO,CAE0B;CAR1C;;;;qBA/ZoB,WAAW;yCADS,yCAAyC;mBAH/D,kCAAkC;sCAEf,sCAAsC;8BAG9C,oBAAoB"}
@@ -291,6 +291,29 @@ export class NodeDescription {
291
291
  return result;
292
292
  }
293
293
 
294
+ /**
295
+ * Useful for checking if a node has inputs/outputs
296
+ * Does not allocate and terminates early, so performance characteristics are very good
297
+ * @param {PortDirection} direction
298
+ * @return {boolean}
299
+ */
300
+ hasPortsByDirection(direction) {
301
+ assert.enum(direction, PortDirection, 'direction');
302
+
303
+ const ports = this.ports;
304
+ const port_count = ports.length;
305
+
306
+ for (let i = 0; i < port_count; i++) {
307
+ const port = ports[i];
308
+
309
+ if (port.direction === direction) {
310
+ return true;
311
+ }
312
+ }
313
+
314
+ return false;
315
+ }
316
+
294
317
  /**
295
318
  *
296
319
  * @param {PortDirection} direction
@@ -1 +1 @@
1
- {"version":3,"file":"computeBufferAttributeHash.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/geometry/buffered/computeBufferAttributeHash.js"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,sDAHW,MAAM,eAAe,GACnB,MAAM,CAmBlB"}
1
+ {"version":3,"file":"computeBufferAttributeHash.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/geometry/buffered/computeBufferAttributeHash.js"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,sDAHW,MAAM,eAAe,GACnB,MAAM,CAsBlB"}
@@ -1,3 +1,4 @@
1
+ import { min2 } from "../../../../core/math/min2.js";
1
2
  import { computeStridedIntegerArrayHash } from "../../../../core/primitives/array/computeStridedIntegerArrayHash.js";
2
3
 
3
4
  /**
@@ -9,15 +10,18 @@ export function computeBufferAttributeHash(attribute) {
9
10
  let result = 0;
10
11
 
11
12
  if (attribute !== null) {
12
- const index_data = attribute.array;
13
- const index_data_size = index_data.length;
13
+ const data = attribute.array;
14
+ const data_size = data.length;
14
15
 
15
- result += index_data_size;
16
+ result += data_size;
17
+
18
+ // limit hash evaluation to first 1k of the data to random memory access and keep CPU cache usage more coherent
19
+ const hash_evaluation_length = min2(data_size, 1024);
16
20
 
17
21
  // compute stride so that we don't have to iterate over the entire buffer, instead picking at most X(509) values to consider
18
- const stride = Math.max(1, Math.ceil(index_data_size / 509));
22
+ const stride = Math.max(1, Math.ceil(hash_evaluation_length / 31));
19
23
 
20
- result ^= computeStridedIntegerArrayHash(index_data, 0, index_data_size, stride);
24
+ result ^= computeStridedIntegerArrayHash(data, 0, hash_evaluation_length, stride);
21
25
 
22
26
  }
23
27
 
@@ -37,7 +37,8 @@ async function main(engine) {
37
37
  await EngineHarness.buildBasics({
38
38
  engine,
39
39
  enableWater: false,
40
- cameraFieldOfView: 45
40
+ cameraFieldOfView: 45,
41
+ showFps: false
41
42
  });
42
43
 
43
44
  const ecd = engine.entityManager.dataset;
@@ -47,12 +48,12 @@ async function main(engine) {
47
48
  baker.renderer = renderer;
48
49
 
49
50
 
50
- const path = 'data/models/LowPolyTownshipSet/Small_house/Small_house.gltf';
51
+ // const path = 'data/models/LowPolyTownshipSet/Small_house/Small_house.gltf';
51
52
  // const path = 'data/models/road_bike/road_bike.gltf'; //large CAD-type model
52
53
  // const path = 'data/models/LowPolyTownshipSet/Barrel/model.gltf';
53
54
  // const path = 'data/models/LowPolyTownshipSet/Town_Hall/model.gltf';
54
55
  // const path = 'data/models/RTS_Buildings_Humans/18/Building_R_18_out/Building_R_18.gltf';
55
- // const path = 'data/models/MOBA and Tower Defense/Tree_01.gltf';
56
+ const path = 'data/models/MOBA and Tower Defense/Tree_01.gltf';
56
57
  // const path = 'data/models/samples/transform-hierarchy.glb';
57
58
  // const path = 'data/models/sponza-pbr/gltf/sponza.glb';
58
59
  // const path = 'data/models/snaps/cube_blue.gltf';
@@ -67,7 +68,7 @@ async function main(engine) {
67
68
  objects,
68
69
  frames: 12,
69
70
  resolution: 1024,
70
- type: ImpostorCaptureType.FullSphere
71
+ type: ImpostorCaptureType.Hemisphere
71
72
  });
72
73
  // console.profileEnd('bake');
73
74
 
@@ -76,7 +77,7 @@ async function main(engine) {
76
77
  const ctrl = makeImpostorAtlasPreview({
77
78
  impostor: id,
78
79
  renderer,
79
- mode: 'normal'
80
+ mode: 'diffuse'
80
81
  });
81
82
 
82
83
  ctrl.scale.setScalar(0.5);
@@ -1 +1 @@
1
- {"version":3,"file":"BufferedGeometryBVH.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/BufferedGeometryBVH.js"],"names":[],"mappings":"AA2BA;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,gBAFW,MAAM,cAAc,QAsC9B;IAGD;;;;;;;OAOG;IACH,gBANW,MAAM,EAAE,OACR,MAAM,EAAE,gBACR,MAAM,gBACN,MAAM,GACJ,MAAM,CA+FlB;;CACJ;sBAlOqB,wCAAwC"}
1
+ {"version":3,"file":"BufferedGeometryBVH.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/BufferedGeometryBVH.js"],"names":[],"mappings":"AAwBA;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,gBAFW,MAAM,cAAc,QAsC9B;IAGD;;;;;;;OAOG;IACH,gBANW,MAAM,EAAE,OACR,MAAM,EAAE,gBACR,MAAM,gBACN,MAAM,GACJ,MAAM,CAyElB;;CACJ;sBAzMqB,wCAAwC"}
@@ -1,11 +1,8 @@
1
- import { BVH, ELEMENT_WORD_COUNT } from "../../../../core/bvh2/bvh3/BVH.js";
1
+ import { BVH } from "../../../../core/bvh2/bvh3/BVH.js";
2
2
  import { ebvh_build_for_geometry_morton } from "../../../../core/bvh2/bvh3/ebvh_build_for_geometry_morton.js";
3
- import { bvh_query_leaves_ray } from "../../../../core/bvh2/bvh3/query/bvh_query_leaves_ray.js";
3
+ import { bvh_query_user_data_ray_segment } from "../../../../core/bvh2/bvh3/query/bvh_query_user_data_ray_segment.js";
4
4
  import { array_copy } from "../../../../core/collection/array/array_copy.js";
5
5
  import { AABB3 } from "../../../../core/geom/3d/aabb/AABB3.js";
6
- import {
7
- aabb3_unsigned_distance_sqr_to_point
8
- } from "../../../../core/geom/3d/aabb/aabb3_unsigned_distance_sqr_to_point.js";
9
6
 
10
7
  import {
11
8
  computeTriangleRayIntersectionBarycentricGeometry
@@ -136,7 +133,6 @@ export class BufferedGeometryBVH {
136
133
  */
137
134
  raycast(output, ray, min_distance, max_distance) {
138
135
 
139
-
140
136
  const indices = this.__geometry_index;
141
137
  const positions = this.__geometry_positions;
142
138
 
@@ -150,11 +146,12 @@ export class BufferedGeometryBVH {
150
146
 
151
147
  const bvh = this.#bvh;
152
148
 
153
- const count = bvh_query_leaves_ray(
149
+ const count = bvh_query_user_data_ray_segment(
154
150
  bvh, bvh.root,
155
151
  scratch_uint32_array, 0,
156
152
  origin_x, origin_y, origin_z,
157
- direction_x, direction_y, direction_z
153
+ direction_x, direction_y, direction_z,
154
+ min_distance, max_distance
158
155
  );
159
156
 
160
157
  if (count === 0) {
@@ -168,31 +165,10 @@ export class BufferedGeometryBVH {
168
165
  let best_index = -1;
169
166
  let best_u = 0;
170
167
  let best_v = 0;
171
- let best_node = -1;
172
-
173
-
174
- /*
175
- For performance, we bind data directly to avoid extra copies required to read out AABB
176
- */
177
- const float32 = bvh.__data_float32;
178
168
 
179
169
  // check triangles found via BVH
180
170
  for (let i = 0; i < count; i++) {
181
- const node = scratch_uint32_array[i];
182
-
183
- const node_address = node * ELEMENT_WORD_COUNT;
184
-
185
- if (aabb3_unsigned_distance_sqr_to_point(
186
- float32[node_address], float32[node_address + 1], float32[node_address + 2],
187
- float32[node_address + 3], float32[node_address + 4], float32[node_address + 5],
188
-
189
- origin_x, origin_y, origin_z
190
- ) > nearest_hit_distance * nearest_hit_distance) {
191
- // bounds of the mesh are too far
192
- continue;
193
- }
194
-
195
- const triangle_index = bvh.node_get_user_data(node);
171
+ const triangle_index = scratch_uint32_array[i];
196
172
 
197
173
  const intersection_found = computeTriangleRayIntersectionBarycentricGeometry(
198
174
  v3_scratch_0,
@@ -215,7 +191,6 @@ export class BufferedGeometryBVH {
215
191
  best_u = v3_scratch_0[1];
216
192
  best_v = v3_scratch_0[2];
217
193
 
218
- best_node = node;
219
194
  }
220
195
  }
221
196
 
@@ -121,7 +121,7 @@ export class PathTracedMesh {
121
121
  scratch_v3, 0,
122
122
  ray[0], ray[1], ray[2],
123
123
  ray[3], ray[4], ray[5],
124
- max_distance
124
+ max_distance-min_distance
125
125
  );
126
126
 
127
127
  // move far point into local coordinate space
@@ -1 +1 @@
1
- {"version":3,"file":"PathTracedScene.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/PathTracedScene.js"],"names":[],"mappings":"AAgDA;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;IAiF7C,iBAOC;IAED,uBAEC;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;;;;;OAKG;IACH,qBAJW,MAAM,cAAc,YACpB,MAAM,QAAQ,aACd,OAAK,MAAM,EAAE,QAavB;IAED;;;;OAIG;IACH,qBAHW,MAAM,EAAE,OACR,MAAM,EAAE,QAyBlB;IAED;;;;;;;OAOG;IACH,WANW,MAAM,EAAE,OACR,MAAM,EAAE,OAAK,gBACb,MAAM,gBACN,MAAM,GACL,MAAM,CAkEjB;IAED;;;;;;OAMG;IACH,uBALW,MAAM,EAAE,cACR,MAAM,aACN,MAAM,EAAE,oBACR,MAAM,QAIhB;IAED;;;;;;;OAOG;IACH,mBANW,MAAM,EAAE,cACR,MAAM,OACN,MAAM,EAAE,eACR,MAAM,GACJ,OAAO,CAmEnB;;CACJ;oBArfkD,mCAAmC;+BAoBvD,qBAAqB;8BAJtB,kDAAkD;oCAC5C,0BAA0B"}
1
+ {"version":3,"file":"PathTracedScene.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/PathTracedScene.js"],"names":[],"mappings":"AA6CA;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;IAiF7C,iBAOC;IAED,uBAEC;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;;;;;OAKG;IACH,qBAJW,MAAM,cAAc,YACpB,MAAM,QAAQ,aACd,OAAK,MAAM,EAAE,QAavB;IAED;;;;OAIG;IACH,qBAHW,MAAM,EAAE,OACR,MAAM,EAAE,QAyBlB;IAED;;;;;;;OAOG;IACH,WANW,MAAM,EAAE,OACR,MAAM,EAAE,OAAK,gBACb,MAAM,gBACN,MAAM,GACL,MAAM,CA8CjB;IAED;;;;;;OAMG;IACH,uBALW,MAAM,EAAE,cACR,MAAM,aACN,MAAM,EAAE,oBACR,MAAM,QAIhB;IAED;;;;;;;OAOG;IACH,mBANW,MAAM,EAAE,cACR,MAAM,OACN,MAAM,EAAE,eACR,MAAM,GACJ,OAAO,CAmEnB;;CACJ;oBA9d8B,mCAAmC;+BAiBnC,qBAAqB;8BAJtB,kDAAkD;oCAC5C,0BAA0B"}
@@ -1,15 +1,12 @@
1
1
  import { assert } from "../../../../core/assert.js";
2
- import { BVH, ELEMENT_WORD_COUNT, NULL_NODE } from "../../../../core/bvh2/bvh3/BVH.js";
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 { bvh_query_leaves_ray } from "../../../../core/bvh2/bvh3/query/bvh_query_leaves_ray.js";
4
+ import { bvh_query_user_data_ray_segment } from "../../../../core/bvh2/bvh3/query/bvh_query_user_data_ray_segment.js";
5
5
  import { Cache } from "../../../../core/cache/Cache.js";
6
6
  import { array_copy } from "../../../../core/collection/array/array_copy.js";
7
7
  import { array_quick_sort_by_lookup_map } from "../../../../core/collection/array/array_quick_sort_by_lookup_map.js";
8
8
  import { strictEquals } from "../../../../core/function/strictEquals.js";
9
9
  import { AABB3 } from "../../../../core/geom/3d/aabb/AABB3.js";
10
- import {
11
- aabb3_unsigned_distance_sqr_to_point
12
- } from "../../../../core/geom/3d/aabb/aabb3_unsigned_distance_sqr_to_point.js";
13
10
  import { v3_morton_encode_bounded } from "../../../../core/geom/3d/morton/v3_morton_encode_bounded.js";
14
11
  import { ray3_array_compose } from "../../../../core/geom/3d/ray/ray3_array_compose.js";
15
12
  import { v3_dot } from "../../../../core/geom/vec3/v3_dot.js";
@@ -362,38 +359,19 @@ export class PathTracedScene {
362
359
  const ray_direction_z = ray[5];
363
360
 
364
361
 
365
- const hit_count = bvh_query_leaves_ray(
362
+ const hit_count = bvh_query_user_data_ray_segment(
366
363
  bvh, bvh.root,
367
364
  scratch_uint32_array, 0,
368
365
  ray_origin_x, ray_origin_y, ray_origin_z,
369
- ray_direction_x, ray_direction_y, ray_direction_z
366
+ ray_direction_x, ray_direction_y, ray_direction_z,
367
+ min_distance, max_distance
370
368
  );
371
369
 
372
370
  let nearest_hit_distance = max_distance;
373
371
 
374
- /*
375
- For performance, we bind data directly to avoid extra copies required to read out AABB
376
- */
377
- const float32 = bvh.__data_float32;
378
- let best_node;
379
-
380
372
  for (let i = 0; i < hit_count; i++) {
381
373
 
382
- const node = scratch_uint32_array[i];
383
-
384
- const node_address = node * ELEMENT_WORD_COUNT;
385
-
386
- if (aabb3_unsigned_distance_sqr_to_point(
387
- float32[node_address], float32[node_address + 1], float32[node_address + 2],
388
- float32[node_address + 3], float32[node_address + 4], float32[node_address + 5],
389
-
390
- ray_origin_x, ray_origin_y, ray_origin_z
391
- ) > nearest_hit_distance * nearest_hit_distance ) {
392
- // bounds of the mesh are too far
393
- continue;
394
- }
395
-
396
- const node_user_data = bvh.node_get_user_data(node);
374
+ const node_user_data = scratch_uint32_array[i];
397
375
 
398
376
  const mesh = this.meshes.get(node_user_data);
399
377
 
@@ -402,7 +380,6 @@ export class PathTracedScene {
402
380
  if (distance_to_hit >= 0) {
403
381
  // since raycast in leaf nodes is already bound by maximum distance, any hit we get is necessarily a closer hit than before
404
382
  nearest_hit_distance = distance_to_hit;
405
- best_node = node;
406
383
  }
407
384
  }
408
385
 
@@ -76,7 +76,7 @@ vCanvas.css({
76
76
  * How many rays to use per-pixel
77
77
  * @type {number}
78
78
  */
79
- const PIXEL_SAMPLE_COUNT = 32;
79
+ const PIXEL_SAMPLE_COUNT = 1;
80
80
 
81
81
  const scene = new PathTracedScene();
82
82
  const pt = new PathTracer();
@@ -558,7 +558,7 @@ function* render(target, pt, camera, scene, progress = { current: 0, total: 0 })
558
558
  pixel_accummulation[1] /= pixel_sample_count
559
559
  pixel_accummulation[2] /= pixel_sample_count
560
560
 
561
- linear_to_sRGB(pixel_accummulation, 0, pixel_accummulation, 0);
561
+ // linear_to_sRGB(pixel_accummulation, 0, pixel_accummulation, 0);
562
562
 
563
563
  output_data[pixel_address] = float_to_uint8(pixel_accummulation[0]);
564
564
  output_data[pixel_address + 1] = float_to_uint8(pixel_accummulation[1]);
@@ -605,15 +605,15 @@ async function start_renderer(camera) {
605
605
  // await prepare_scene_lucy(scene, camera);
606
606
  // await prepare_scene_rtiow(pt, camera);
607
607
  // await prepare_scene_sphere_01(pt, camera);
608
- await prepare_gi_box_scene(scene, camera);
609
- // await prepare_sponza(scene, camera);
610
- // await prepare_scene_gltf(scene, camera, path);
608
+ // await prepare_gi_box_scene(scene, camera);
609
+ await prepare_sponza(scene, camera);
610
+ // await prepare_scene_gltf({scene, camera, path, url: path});
611
611
 
612
612
 
613
613
  await scene.build();
614
614
  // pt.optimize();
615
615
 
616
- const pixelRatio = 1;
616
+ const pixelRatio = 0.5;
617
617
 
618
618
  const rt = Sampler2D.uint8(4, vCanvas.size.x, vCanvas.size.y);
619
619
 
@@ -1,11 +0,0 @@
1
- /**
2
- *
3
- * @param {number[]} aabb
4
- * @param {number} aabb_offset
5
- * @param {number[]} ray
6
- * @param {number} min_distance
7
- * @param {number} max_distance
8
- * @returns {boolean}
9
- */
10
- export function aabb3_overlaps_ray_segment(aabb: number[], aabb_offset: number, ray: number[], min_distance: number, max_distance: number): boolean;
11
- //# sourceMappingURL=aabb3_overlaps_ray_segment.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"aabb3_overlaps_ray_segment.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/aabb/aabb3_overlaps_ray_segment.js"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,iDAPW,MAAM,EAAE,eACR,MAAM,OACN,MAAM,EAAE,gBACR,MAAM,gBACN,MAAM,GACJ,OAAO,CAmDnB"}
@@ -1,61 +0,0 @@
1
- import { v3_dot } from "../../vec3/v3_dot.js";
2
-
3
- /**
4
- *
5
- * @param {number[]} aabb
6
- * @param {number} aabb_offset
7
- * @param {number[]} ray
8
- * @param {number} min_distance
9
- * @param {number} max_distance
10
- * @returns {boolean}
11
- */
12
- export function aabb3_overlaps_ray_segment(
13
- aabb, aabb_offset, ray,
14
- min_distance, max_distance
15
- ) {
16
-
17
- const dir_x = ray[3];
18
- const dir_y = ray[4];
19
- const dir_z = ray[5];
20
-
21
- const plane_offset = v3_dot(
22
- ray[0], ray[1], ray[2],
23
- dir_x, dir_y, dir_z
24
- );
25
-
26
- let x0, y0, z0, x1, y1, z1;
27
-
28
- if (dir_x > 0) {
29
- x0 = aabb[0];
30
- x1 = aabb[3];
31
- } else {
32
- x1 = aabb[0];
33
- x0 = aabb[3];
34
- }
35
-
36
- if (dir_y > 0) {
37
- y0 = aabb[1];
38
- y1 = aabb[4];
39
- } else {
40
- y1 = aabb[1];
41
- y0 = aabb[4];
42
- }
43
-
44
- if (dir_z > 0) {
45
- z0 = aabb[2];
46
- z1 = aabb[5];
47
- } else {
48
- z1 = aabb[2];
49
- z0 = aabb[5];
50
- }
51
-
52
- const min = plane_offset + dir_x * x0 + dir_y * y0 + dir_z * z0;
53
-
54
- if (min >= max_distance) {
55
- return false;
56
- }
57
-
58
- const max = plane_offset + dir_x * x1 + dir_y * y1 + dir_z * z1;
59
-
60
- return max > min_distance;
61
- }