@woosh/meep-engine 2.109.19 → 2.109.21
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/build/bundle-worker-image-decoder.js +1 -1
- package/build/bundle-worker-terrain.js +1 -1
- package/build/meep.cjs +12 -8
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +12 -8
- package/package.json +1 -1
- package/src/core/bvh2/bvh3/query/bvh_query_leaves_ray_segment.js +1 -1
- package/src/core/bvh2/bvh3/query/bvh_query_user_data_ray_segment.js +1 -1
- package/src/core/collection/array/isArrayEqualStrict.d.ts.map +1 -1
- package/src/core/collection/array/isArrayEqualStrict.js +1 -3
- package/src/core/collection/array/typed/is_typed_array_equals.d.ts +1 -1
- package/src/core/collection/array/typed/is_typed_array_equals.d.ts.map +1 -1
- package/src/core/collection/array/typed/is_typed_array_equals.js +8 -2
- package/src/core/geom/3d/aabb/aabb3_array_near_distance_to_intersection_ray_segment.d.ts +16 -0
- package/src/core/geom/3d/aabb/aabb3_array_near_distance_to_intersection_ray_segment.d.ts.map +1 -0
- package/src/core/geom/3d/aabb/aabb3_array_near_distance_to_intersection_ray_segment.js +30 -0
- package/src/core/geom/3d/aabb/aabb3_intersects_ray_segment.d.ts +4 -5
- package/src/core/geom/3d/aabb/aabb3_intersects_ray_segment.d.ts.map +1 -1
- package/src/core/geom/3d/aabb/aabb3_intersects_ray_segment.js +6 -9
- package/src/core/geom/3d/aabb/aabb3_near_distance_to_intersection_ray_segment.d.ts +20 -0
- package/src/core/geom/3d/aabb/aabb3_near_distance_to_intersection_ray_segment.d.ts.map +1 -0
- package/src/core/geom/3d/aabb/aabb3_near_distance_to_intersection_ray_segment.js +67 -0
- package/src/core/geom/3d/line/line3_compute_nearest_point_to_point.d.ts.map +1 -1
- package/src/core/geom/3d/line/line3_compute_nearest_point_to_point.js +15 -1
- package/src/core/geom/3d/normal/octahedron/decode_octahedron_to_unit.d.ts +2 -1
- package/src/core/geom/3d/normal/octahedron/decode_octahedron_to_unit.d.ts.map +1 -1
- package/src/core/geom/3d/normal/octahedron/decode_octahedron_to_unit.js +6 -1
- package/src/core/geom/3d/triangle/computeTriangleClosestPointToPointBarycentric.d.ts +20 -0
- package/src/core/geom/3d/triangle/computeTriangleClosestPointToPointBarycentric.d.ts.map +1 -0
- package/src/core/geom/3d/triangle/computeTriangleClosestPointToPointBarycentric.js +147 -0
- package/src/core/geom/3d/triangle/computeTriangleClosestPointToPointBarycentric.spec.d.ts +2 -0
- package/src/core/geom/3d/triangle/computeTriangleClosestPointToPointBarycentric.spec.d.ts.map +1 -0
- package/src/core/geom/3d/triangle/computeTriangleClosestPointToPointBarycentric.spec.js +100 -0
- package/src/core/geom/octahedral_uv_crease_distance.d.ts +8 -0
- package/src/core/geom/octahedral_uv_crease_distance.d.ts.map +1 -0
- package/src/core/geom/octahedral_uv_crease_distance.js +26 -0
- package/src/core/math/random/generate_halton_jitter.js +2 -2
- package/src/core/math/statistics/generate_hammersley_jitter.d.ts +7 -0
- package/src/core/math/statistics/generate_hammersley_jitter.d.ts.map +1 -0
- package/src/core/math/statistics/generate_hammersley_jitter.js +16 -0
- package/src/core/math/statistics/hammersley_sequence_2d.js +2 -1
- package/src/engine/graphics/geometry/buffered/computeGeometryEquality.d.ts.map +1 -1
- package/src/engine/graphics/geometry/buffered/computeGeometryEquality.js +4 -0
- package/src/engine/graphics/sh3/gi/material/common.glsl +1 -1
- package/src/engine/graphics/sh3/lpv/LightProbeVolume.d.ts +0 -7
- package/src/engine/graphics/sh3/lpv/LightProbeVolume.d.ts.map +1 -1
- package/src/engine/graphics/sh3/lpv/LightProbeVolume.js +0 -11
- package/src/engine/graphics/sh3/lpv/LightProbeVolumeBaker.d.ts +7 -0
- package/src/engine/graphics/sh3/lpv/LightProbeVolumeBaker.d.ts.map +1 -1
- package/src/engine/graphics/sh3/lpv/LightProbeVolumeBaker.js +39 -25
- package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.js +1 -1
- package/src/engine/graphics/sh3/lpv/depth/octahedral/bake_octahedral_depth_map.d.ts.map +1 -1
- package/src/engine/graphics/sh3/lpv/depth/octahedral/bake_octahedral_depth_map.js +34 -35
- package/src/engine/graphics/sh3/path_tracer/BufferedGeometryBVH.d.ts +18 -0
- package/src/engine/graphics/sh3/path_tracer/BufferedGeometryBVH.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/BufferedGeometryBVH.js +421 -21
- package/src/engine/graphics/sh3/path_tracer/PathTracedMesh.js +1 -1
- package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +4 -4
- package/src/engine/graphics/sh3/prototypeSH3Probe.js +4 -2
- package/src/engine/graphics/texture/virtual/prototype.js +3 -1
- package/src/engine/input/devices/PointerDevice.d.ts.map +1 -1
- package/src/engine/input/devices/PointerDevice.js +3 -3
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { computeTriangleClosestPointToPointBarycentric } from "./computeTriangleClosestPointToPointBarycentric.js";
|
|
2
|
+
|
|
3
|
+
test("basics", () => {
|
|
4
|
+
|
|
5
|
+
const result = [];
|
|
6
|
+
|
|
7
|
+
// internal point
|
|
8
|
+
computeTriangleClosestPointToPointBarycentric(
|
|
9
|
+
result, 0,
|
|
10
|
+
0, 0.5, 0,
|
|
11
|
+
-1, 0, 0,
|
|
12
|
+
1, 0, 0,
|
|
13
|
+
0, 1, 0
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
expect(result).toEqual([0.25,0.25]);
|
|
17
|
+
|
|
18
|
+
// point lies on a vertex
|
|
19
|
+
computeTriangleClosestPointToPointBarycentric(
|
|
20
|
+
result, 0,
|
|
21
|
+
-1, 0, 0,
|
|
22
|
+
-1, 0, 0,
|
|
23
|
+
1, 0, 0,
|
|
24
|
+
0, 1, 0
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
expect(result).toEqual([1,0]);
|
|
28
|
+
|
|
29
|
+
computeTriangleClosestPointToPointBarycentric(
|
|
30
|
+
result, 0,
|
|
31
|
+
1, 0, 0,
|
|
32
|
+
-1, 0, 0,
|
|
33
|
+
1, 0, 0,
|
|
34
|
+
0, 1, 0
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
expect(result).toEqual([0,1]);
|
|
38
|
+
|
|
39
|
+
computeTriangleClosestPointToPointBarycentric(
|
|
40
|
+
result, 0,
|
|
41
|
+
0, 1, 0,
|
|
42
|
+
-1, 0, 0,
|
|
43
|
+
1, 0, 0,
|
|
44
|
+
0, 1, 0
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
expect(result).toEqual([0,0]);
|
|
48
|
+
|
|
49
|
+
// point lies on an edge
|
|
50
|
+
computeTriangleClosestPointToPointBarycentric(
|
|
51
|
+
result, 0,
|
|
52
|
+
0, 0, 0,
|
|
53
|
+
-1, 0, 0,
|
|
54
|
+
1, 0, 0,
|
|
55
|
+
0, 1, 0
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
expect(result).toEqual([0.5,0.5]);
|
|
59
|
+
|
|
60
|
+
// point lies outside the triangle
|
|
61
|
+
computeTriangleClosestPointToPointBarycentric(
|
|
62
|
+
result, 0,
|
|
63
|
+
- 2, 0, 0,
|
|
64
|
+
-1, 0, 0,
|
|
65
|
+
1, 0, 0,
|
|
66
|
+
0, 1, 0
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
expect(result).toEqual([1,0]);
|
|
70
|
+
|
|
71
|
+
computeTriangleClosestPointToPointBarycentric(
|
|
72
|
+
result, 0,
|
|
73
|
+
2, 0, 0 ,
|
|
74
|
+
-1, 0, 0,
|
|
75
|
+
1, 0, 0,
|
|
76
|
+
0, 1, 0
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
expect(result).toEqual([0,1]);
|
|
80
|
+
|
|
81
|
+
computeTriangleClosestPointToPointBarycentric(
|
|
82
|
+
result, 0,
|
|
83
|
+
0, 2, 0 ,
|
|
84
|
+
-1, 0, 0,
|
|
85
|
+
1, 0, 0,
|
|
86
|
+
0, 1, 0
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
expect(result).toEqual([0,0]);
|
|
90
|
+
|
|
91
|
+
computeTriangleClosestPointToPointBarycentric(
|
|
92
|
+
result, 0,
|
|
93
|
+
0, -2, 0 ,
|
|
94
|
+
-1, 0, 0,
|
|
95
|
+
1, 0, 0,
|
|
96
|
+
0, 1, 0
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
expect(result).toEqual([0.5,0.5]);
|
|
100
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Distance to the nearest crease
|
|
3
|
+
* @param {number} u from 0 to 1
|
|
4
|
+
* @param {number} v from 0 to 1
|
|
5
|
+
* @returns {number}
|
|
6
|
+
*/
|
|
7
|
+
export function octahedral_uv_crease_distance(u: number, v: number): number;
|
|
8
|
+
//# sourceMappingURL=octahedral_uv_crease_distance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"octahedral_uv_crease_distance.d.ts","sourceRoot":"","sources":["../../../../src/core/geom/octahedral_uv_crease_distance.js"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,iDAJW,MAAM,KACN,MAAM,GACJ,MAAM,CAqBlB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Distance to the nearest crease
|
|
3
|
+
* @param {number} u from 0 to 1
|
|
4
|
+
* @param {number} v from 0 to 1
|
|
5
|
+
* @returns {number}
|
|
6
|
+
*/
|
|
7
|
+
export function octahedral_uv_crease_distance(u, v) {
|
|
8
|
+
|
|
9
|
+
const cross_distance_u = Math.abs(u - 0.5);
|
|
10
|
+
const cross_distance_v = Math.abs(v - 0.5);
|
|
11
|
+
|
|
12
|
+
const cross_distance = Math.min(cross_distance_u, cross_distance_v);
|
|
13
|
+
|
|
14
|
+
const n_u = u * 2 - 1;
|
|
15
|
+
const n_v = v * 2 - 1;
|
|
16
|
+
|
|
17
|
+
// for the belt of the fold
|
|
18
|
+
const fold = 1 - Math.abs(n_u) - Math.abs(n_v);
|
|
19
|
+
|
|
20
|
+
const fold_distance = Math.abs(fold);
|
|
21
|
+
|
|
22
|
+
// distance to the edge of the map, which folds the welding crease
|
|
23
|
+
const welding_crease_distance = Math.min(Math.min(u, 1 - u), Math.min(v, 1 - v));
|
|
24
|
+
|
|
25
|
+
return Math.min(fold_distance, cross_distance, welding_crease_distance);
|
|
26
|
+
}
|
|
@@ -13,8 +13,8 @@ export function generate_halton_jitter(point_count) {
|
|
|
13
13
|
|
|
14
14
|
for (let i = 0; i < point_count; i++) {
|
|
15
15
|
const i2 = i * 2;
|
|
16
|
-
result[i2] =
|
|
17
|
-
result[i2 + 1] =
|
|
16
|
+
result[i2] = halton_sequence(2, i) * 2 - 1;
|
|
17
|
+
result[i2 + 1] = halton_sequence(3, i) * 2 - 1;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
return result;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate_hammersley_jitter.d.ts","sourceRoot":"","sources":["../../../../../src/core/math/statistics/generate_hammersley_jitter.js"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,yDAHW,MAAM,GACJ,YAAY,CAUxB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { hammersley_sequence_2d } from "./hammersley_sequence_2d.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {number} sample_count
|
|
6
|
+
* @returns {Float32Array}
|
|
7
|
+
*/
|
|
8
|
+
export function generate_hammersley_jitter(sample_count) {
|
|
9
|
+
const result = new Float32Array(sample_count * 2);
|
|
10
|
+
|
|
11
|
+
for (let i = 0; i < sample_count; i++) {
|
|
12
|
+
hammersley_sequence_2d(result, i * 2, i, sample_count);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"computeGeometryEquality.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/geometry/buffered/computeGeometryEquality.js"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,2CAJW,MAAM,cAAc,KACpB,MAAM,cAAc,GAClB,OAAO,
|
|
1
|
+
{"version":3,"file":"computeGeometryEquality.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/geometry/buffered/computeGeometryEquality.js"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,2CAJW,MAAM,cAAc,KACpB,MAAM,cAAc,GAClB,OAAO,CAmDnB"}
|
|
@@ -9,6 +9,10 @@ import { is_typed_array_equals } from "../../../../core/collection/array/typed/i
|
|
|
9
9
|
* @returns {boolean}
|
|
10
10
|
*/
|
|
11
11
|
export function computeGeometryEquality(a, b) {
|
|
12
|
+
if (a === b) {
|
|
13
|
+
// identity shortcut
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
12
16
|
|
|
13
17
|
const a_index = a.getIndex();
|
|
14
18
|
const b_index = b.getIndex();
|
|
@@ -362,7 +362,7 @@ float lpv_probe_getVisibilityMask(vec3 position, uint probe_index) {
|
|
|
362
362
|
float chebyshevWeight = variance / (variance + distance_delta * distance_delta);
|
|
363
363
|
|
|
364
364
|
// Increase contrast in the weight
|
|
365
|
-
chebyshevWeight = max(chebyshevWeight * chebyshevWeight * chebyshevWeight, 0.0);
|
|
365
|
+
// chebyshevWeight = max(chebyshevWeight * chebyshevWeight * chebyshevWeight, 0.0);
|
|
366
366
|
|
|
367
367
|
return (distToProbe <= mean) ? 1.0 : chebyshevWeight;
|
|
368
368
|
}
|
|
@@ -28,13 +28,6 @@ export class LightProbeVolume {
|
|
|
28
28
|
* @param {number} z
|
|
29
29
|
*/
|
|
30
30
|
add_point(x: number, y: number, z: number): void;
|
|
31
|
-
/**
|
|
32
|
-
*
|
|
33
|
-
* @param {number} index
|
|
34
|
-
* @param {number[]} source
|
|
35
|
-
* @param {number} source_offset
|
|
36
|
-
*/
|
|
37
|
-
write_probe(index: number, source: number[], source_offset: number): void;
|
|
38
31
|
/**
|
|
39
32
|
* Build tetrahedral mesh
|
|
40
33
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LightProbeVolume.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/LightProbeVolume.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"LightProbeVolume.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/LightProbeVolume.js"],"names":[],"mappings":"AAUA;;;GAGG;AACH;IAiCI,sBAEC;IAED,cAkBC;IAED;;;OAGG;IACH,4BAEC;IAED,uBAEC;IAED,0BAEC;IAMD;;;OAGG;IACH,sCAIC;IAZD,mCAEC;IAYD,sBAEC;IAMD,uBAEC;IAND,oBAEC;IAMD;;;;;OAKG;IACH,aAJW,MAAM,KACN,MAAM,KACN,MAAM,QAgBhB;IAED;;OAEG;IACH,mBAaC;IAGD;;;;;OAKG;IACH,mCAJW,MAAM,GAEJ,UAAU,CAsBtB;IAGD,yBAEC;;CAEJ;gCAvL+B,wDAAwD;2BAC7D,mCAAmC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { assert } from "../../../../core/assert.js";
|
|
2
|
-
import { array_copy } from "../../../../core/collection/array/array_copy.js";
|
|
3
2
|
import {
|
|
4
3
|
compute_delaunay_tetrahedral_mesh
|
|
5
4
|
} from "../../../../core/geom/3d/tetrahedra/delaunay/compute_delaunay_tetrahedral_mesh.js";
|
|
@@ -134,16 +133,6 @@ export class LightProbeVolume {
|
|
|
134
133
|
this.#probe_count++;
|
|
135
134
|
}
|
|
136
135
|
|
|
137
|
-
/**
|
|
138
|
-
*
|
|
139
|
-
* @param {number} index
|
|
140
|
-
* @param {number[]} source
|
|
141
|
-
* @param {number} source_offset
|
|
142
|
-
*/
|
|
143
|
-
write_probe(index, source, source_offset) {
|
|
144
|
-
array_copy(source, source_offset, this.#sh3_rgb, index * 9 * 3, 9 * 3);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
136
|
/**
|
|
148
137
|
* Build tetrahedral mesh
|
|
149
138
|
*/
|
|
@@ -7,6 +7,13 @@ export class LightProbeVolumeBaker {
|
|
|
7
7
|
* @param {EntityComponentDataset} ecd
|
|
8
8
|
*/
|
|
9
9
|
bake(lpv: LightProbeVolume, ecd: EntityComponentDataset): TaskGroup;
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* @param {PathTracerProbeRenderer} renderer
|
|
13
|
+
* @param {LightProbeVolume} lpv
|
|
14
|
+
* @param {number} probe_index
|
|
15
|
+
*/
|
|
16
|
+
bake_probe(renderer: PathTracerProbeRenderer, lpv: LightProbeVolume, probe_index: number): void;
|
|
10
17
|
}
|
|
11
18
|
import { PathTracerProbeRenderer } from "./PathTracerProbeRenderer.js";
|
|
12
19
|
import TaskGroup from "../../../../core/process/task/TaskGroup.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LightProbeVolumeBaker.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/LightProbeVolumeBaker.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"LightProbeVolumeBaker.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/LightProbeVolumeBaker.js"],"names":[],"mappings":"AAQA;IAEI,8BAAqC;IAGrC;;;;;OAKG;IACH,0DAJa,SAAS,CA2CrB;IAED;;;;;OAKG;IACH,qBAJW,uBAAuB,sCAEvB,MAAM,QA8BhB;CACJ;wCAzFuC,8BAA8B;sBALhD,4CAA4C"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assert } from "../../../../core/assert.js";
|
|
1
2
|
import TaskGroup from "../../../../core/process/task/TaskGroup.js";
|
|
2
3
|
import { actionTask } from "../../../../core/process/task/util/actionTask.js";
|
|
3
4
|
import { countTask } from "../../../../core/process/task/util/countTask.js";
|
|
@@ -29,31 +30,8 @@ export class LightProbeVolumeBaker {
|
|
|
29
30
|
|
|
30
31
|
const probe_count = lpv.count;
|
|
31
32
|
|
|
32
|
-
const tBakeIrradiance = countTask(0, probe_count, (
|
|
33
|
-
|
|
34
|
-
// Bake color
|
|
35
|
-
renderer.bake(
|
|
36
|
-
lpv.points, i * 3,
|
|
37
|
-
lpv.harmonics, i * 9 * 3
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
// Bake depth
|
|
42
|
-
const max_distance = find_max_depth_radius_for_point(i, lpv.mesh, lpv.points);
|
|
43
|
-
|
|
44
|
-
// bias a little to ensure we capture everything
|
|
45
|
-
const max_depth = max_distance * 1.01 + 1e-6;
|
|
46
|
-
|
|
47
|
-
const depth_resolution = lpv.depth_map_resolution;
|
|
48
|
-
|
|
49
|
-
const probe_element_count = depth_resolution * depth_resolution;
|
|
50
|
-
|
|
51
|
-
renderer.bake_depth_octahedral(
|
|
52
|
-
depth_resolution,
|
|
53
|
-
max_depth,
|
|
54
|
-
lpv.points, i * 3,
|
|
55
|
-
lpv.depth, i * probe_element_count
|
|
56
|
-
);
|
|
33
|
+
const tBakeIrradiance = countTask(0, probe_count, (probe_index) => {
|
|
34
|
+
this.bake_probe(renderer, lpv, probe_index);
|
|
57
35
|
|
|
58
36
|
});
|
|
59
37
|
tBakeIrradiance.estimatedDuration = probe_count;
|
|
@@ -79,4 +57,40 @@ export class LightProbeVolumeBaker {
|
|
|
79
57
|
tPrepare, tBakeIrradiance, tFinish
|
|
80
58
|
], "LightProbeVolume Bake");
|
|
81
59
|
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
*
|
|
63
|
+
* @param {PathTracerProbeRenderer} renderer
|
|
64
|
+
* @param {LightProbeVolume} lpv
|
|
65
|
+
* @param {number} probe_index
|
|
66
|
+
*/
|
|
67
|
+
bake_probe(renderer, lpv, probe_index) {
|
|
68
|
+
assert.isNonNegativeInteger(probe_index, 'probe_index');
|
|
69
|
+
|
|
70
|
+
const position_offset = probe_index * 3;
|
|
71
|
+
|
|
72
|
+
// Bake color
|
|
73
|
+
renderer.bake(
|
|
74
|
+
lpv.points, position_offset,
|
|
75
|
+
lpv.harmonics, probe_index * 9 * 3
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
// Bake depth
|
|
80
|
+
const max_distance = find_max_depth_radius_for_point(probe_index, lpv.mesh, lpv.points);
|
|
81
|
+
|
|
82
|
+
// bias a little to ensure we capture everything
|
|
83
|
+
const max_depth = max_distance * 1.01 + 1e-6;
|
|
84
|
+
|
|
85
|
+
const depth_resolution = lpv.depth_map_resolution;
|
|
86
|
+
|
|
87
|
+
const probe_element_count = depth_resolution * depth_resolution;
|
|
88
|
+
|
|
89
|
+
renderer.bake_depth_octahedral(
|
|
90
|
+
depth_resolution,
|
|
91
|
+
max_depth,
|
|
92
|
+
lpv.points, position_offset,
|
|
93
|
+
lpv.depth, probe_index * probe_element_count
|
|
94
|
+
);
|
|
95
|
+
}
|
|
82
96
|
}
|
|
@@ -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 = 7;
|
|
27
|
-
sample_count =
|
|
27
|
+
sample_count = 1024;
|
|
28
28
|
random = seededRandom(0);
|
|
29
29
|
|
|
30
30
|
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":"
|
|
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,QAuHhB"}
|
|
@@ -1,15 +1,20 @@
|
|
|
1
|
+
import { assert } from "../../../../../../core/assert.js";
|
|
2
|
+
import { UINT32_MAX } from "../../../../../../core/binary/UINT32_MAX.js";
|
|
1
3
|
import { array_copy } from "../../../../../../core/collection/array/array_copy.js";
|
|
2
4
|
import {
|
|
3
5
|
decode_octahedron_to_unit
|
|
4
6
|
} from "../../../../../../core/geom/3d/normal/octahedron/decode_octahedron_to_unit.js";
|
|
5
7
|
import { Ray3 } from "../../../../../../core/geom/3d/Ray3.js";
|
|
6
8
|
import { v3_distance } from "../../../../../../core/geom/vec3/v3_distance.js";
|
|
7
|
-
import { v3_dot } from "../../../../../../core/geom/vec3/v3_dot.js";
|
|
8
9
|
import { v3_dot_array_array } from "../../../../../../core/geom/vec3/v3_dot_array_array.js";
|
|
9
|
-
import { clamp01 } from "../../../../../../core/math/clamp01.js";
|
|
10
10
|
import { max2 } from "../../../../../../core/math/max2.js";
|
|
11
|
-
import {
|
|
12
|
-
|
|
11
|
+
import { generate_hammersley_jitter } from "../../../../../../core/math/statistics/generate_hammersley_jitter.js";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Weights of rays that are aligned with the probe direction get exponentially weighted by this exponent
|
|
15
|
+
* @type {number}
|
|
16
|
+
*/
|
|
17
|
+
const DEPTH_SHARPNESS = 40;
|
|
13
18
|
|
|
14
19
|
const scratch_ray = new Ray3();
|
|
15
20
|
|
|
@@ -23,9 +28,8 @@ const ray_hit = [];
|
|
|
23
28
|
*
|
|
24
29
|
* @type {number}
|
|
25
30
|
*/
|
|
26
|
-
const SUB_SAMPLE_COUNT =
|
|
31
|
+
const SUB_SAMPLE_COUNT = 4;
|
|
27
32
|
|
|
28
|
-
const DEPTH_SHARPNESS = 7;
|
|
29
33
|
|
|
30
34
|
/**
|
|
31
35
|
*
|
|
@@ -45,9 +49,16 @@ export function bake_octahedral_depth_map(
|
|
|
45
49
|
max_depth
|
|
46
50
|
) {
|
|
47
51
|
|
|
52
|
+
assert.lessThan(result_offset + resolution * resolution, UINT32_MAX, 'Result overflow');
|
|
53
|
+
|
|
48
54
|
scratch_ray.tMax = max_depth;
|
|
49
55
|
array_copy(position, position_offset, scratch_ray, 0, 3);
|
|
50
56
|
|
|
57
|
+
/**
|
|
58
|
+
* In radians, how wide of an arc does a single texel cover
|
|
59
|
+
* @type {number}
|
|
60
|
+
*/
|
|
61
|
+
const texel_angular_coverage = (Math.PI) / resolution;
|
|
51
62
|
|
|
52
63
|
/**
|
|
53
64
|
* Resolution bias is to compensate for discontinuities between samples
|
|
@@ -58,9 +69,9 @@ export function bake_octahedral_depth_map(
|
|
|
58
69
|
* xMath.SQRT2 is to allow for diagonals between pixels
|
|
59
70
|
* @type {number}
|
|
60
71
|
*/
|
|
61
|
-
const RESOLUTION_BIAS = Math.sin(
|
|
72
|
+
const RESOLUTION_BIAS = Math.sin(texel_angular_coverage) * Math.SQRT2 * 2;
|
|
62
73
|
|
|
63
|
-
const NORMAL_BIAS = max_depth * 0.01 + 1e-6;
|
|
74
|
+
const NORMAL_BIAS = max2(0.01, max_depth * 0.01) + 1e-6;
|
|
64
75
|
|
|
65
76
|
const ray_direction = scratch_ray.direction;
|
|
66
77
|
|
|
@@ -68,7 +79,7 @@ export function bake_octahedral_depth_map(
|
|
|
68
79
|
|
|
69
80
|
const texel_uv_scale = 0.5 / (resolution);
|
|
70
81
|
|
|
71
|
-
const jittered_sub_samples =
|
|
82
|
+
const jittered_sub_samples = generate_hammersley_jitter(SUB_SAMPLE_COUNT);
|
|
72
83
|
|
|
73
84
|
|
|
74
85
|
for (let oct_x = 0; oct_x < resolution; oct_x++) {
|
|
@@ -78,23 +89,18 @@ export function bake_octahedral_depth_map(
|
|
|
78
89
|
let weight_sum = 0;
|
|
79
90
|
|
|
80
91
|
// offset position by half a pixel, as we are storing values for pixel centers
|
|
81
|
-
const u = (oct_x ) / (resolution);
|
|
82
|
-
const v = (oct_y ) / (resolution);
|
|
83
|
-
|
|
84
|
-
// const u = (oct_x + 0.5) / (resolution - 1);
|
|
85
|
-
// const v = (oct_y + 0.5) / (resolution - 1);
|
|
86
|
-
|
|
87
|
-
decode_octahedron_to_unit(
|
|
88
|
-
probe_direction, 0,
|
|
89
|
-
u * 2 - 1, v * 2 - 1
|
|
90
|
-
);
|
|
92
|
+
const u = (oct_x + 0.5) / (resolution);
|
|
93
|
+
const v = (oct_y + 0.5) / (resolution);
|
|
91
94
|
|
|
92
95
|
for (let sub_sample_index = 0; sub_sample_index < SUB_SAMPLE_COUNT; sub_sample_index++) {
|
|
93
96
|
|
|
94
97
|
const sample_index2 = sub_sample_index * 2;
|
|
95
98
|
|
|
96
|
-
const
|
|
97
|
-
const
|
|
99
|
+
const sample_u = jittered_sub_samples[sample_index2];
|
|
100
|
+
const sample_v = jittered_sub_samples[sample_index2 + 1];
|
|
101
|
+
|
|
102
|
+
const ray_u = u + (sample_u * 2 - 1) * texel_uv_scale;
|
|
103
|
+
const ray_v = v + (sample_v * 2 - 1) * texel_uv_scale;
|
|
98
104
|
|
|
99
105
|
decode_octahedron_to_unit(
|
|
100
106
|
ray_direction, 0,
|
|
@@ -115,27 +121,18 @@ export function bake_octahedral_depth_map(
|
|
|
115
121
|
const surface_position_y = ray_hit[1];
|
|
116
122
|
const surface_position_z = ray_hit[2];
|
|
117
123
|
|
|
118
|
-
|
|
119
|
-
const hit_angle_cos = -v3_dot(
|
|
120
|
-
surface_normal_x, surface_normal_y, surface_normal_z,
|
|
121
|
-
ray_direction[0], ray_direction[1], ray_direction[2]
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
const resolution_bias_offset = max_depth * RESOLUTION_BIAS;
|
|
125
|
-
|
|
126
|
-
const hit_normal_bias = clamp01( 1-hit_angle_cos) * (resolution_bias_offset) + NORMAL_BIAS;
|
|
124
|
+
const hit_normal_bias = -NORMAL_BIAS;
|
|
127
125
|
|
|
128
126
|
// sink the contact into the surface along the hit normal
|
|
129
|
-
const biased_hit_x = surface_position_x
|
|
130
|
-
const biased_hit_y = surface_position_y
|
|
131
|
-
const biased_hit_z = surface_position_z
|
|
127
|
+
const biased_hit_x = surface_position_x + surface_normal_x * hit_normal_bias;
|
|
128
|
+
const biased_hit_y = surface_position_y + surface_normal_y * hit_normal_bias;
|
|
129
|
+
const biased_hit_z = surface_position_z + surface_normal_z * hit_normal_bias;
|
|
132
130
|
|
|
133
131
|
distance = v3_distance(
|
|
134
132
|
scratch_ray[0], scratch_ray[1], scratch_ray[2],
|
|
135
133
|
biased_hit_x, biased_hit_y, biased_hit_z
|
|
136
134
|
);
|
|
137
135
|
|
|
138
|
-
// distance += resolution_bias_offset;
|
|
139
136
|
}
|
|
140
137
|
|
|
141
138
|
const direction_dot_product = v3_dot_array_array(ray_direction, 0, probe_direction, 0);
|
|
@@ -155,7 +152,9 @@ export function bake_octahedral_depth_map(
|
|
|
155
152
|
|
|
156
153
|
const address = result_offset + pixel_index;
|
|
157
154
|
|
|
158
|
-
|
|
155
|
+
const distance = distance_sum / weight_sum;
|
|
156
|
+
|
|
157
|
+
result[address] = distance;
|
|
159
158
|
}
|
|
160
159
|
}
|
|
161
160
|
|
|
@@ -40,6 +40,23 @@ export class BufferedGeometryBVH {
|
|
|
40
40
|
* @returns {boolean}
|
|
41
41
|
*/
|
|
42
42
|
occluded(ray: Ray3): boolean;
|
|
43
|
+
/**
|
|
44
|
+
*
|
|
45
|
+
* @param {SurfacePoint3} result
|
|
46
|
+
* @param {number} x
|
|
47
|
+
* @param {number} y
|
|
48
|
+
* @param {number} z
|
|
49
|
+
* @returns {boolean} true if result is found, only false when geometry is empty
|
|
50
|
+
*/
|
|
51
|
+
nearestSurfacePoint(result: SurfacePoint3, x: number, y: number, z: number): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Code is largely inlined, to avoid extra checks
|
|
54
|
+
* NOTE: raycast is performed in local coordinate space
|
|
55
|
+
* @param {number[]} output
|
|
56
|
+
* @param {number[]|Ray3} ray
|
|
57
|
+
* @returns {number} distance along the ray, negative if no hit
|
|
58
|
+
*/
|
|
59
|
+
raycast2(output: number[], ray: number[] | Ray3): number;
|
|
43
60
|
/**
|
|
44
61
|
* NOTE: raycast is performed in local coordinate space
|
|
45
62
|
* @param {number[]} output
|
|
@@ -50,4 +67,5 @@ export class BufferedGeometryBVH {
|
|
|
50
67
|
#private;
|
|
51
68
|
}
|
|
52
69
|
import { AABB3 } from "../../../../core/geom/3d/aabb/AABB3.js";
|
|
70
|
+
import { SurfacePoint3 } from "../../../../core/geom/3d/SurfacePoint3.js";
|
|
53
71
|
//# sourceMappingURL=BufferedGeometryBVH.d.ts.map
|
|
@@ -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":"AA+CA;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,MAAM,cAAc,QAwC9B;IAED;;;;;OAKG;IACH,qBAFa,OAAO,CAmHnB;IAED;;;;;;;OAOG;IACH,4BANW,aAAa,KACb,MAAM,KACN,MAAM,KACN,MAAM,GACJ,OAAO,CAqKnB;IAGD;;;;;;OAMG;IACH,iBAJW,MAAM,EAAE,OACR,MAAM,EAAE,OAAK,GACX,MAAM,CAoIlB;IAED;;;;;OAKG;IACH,gBAJW,MAAM,EAAE,OACR,MAAM,EAAE,OAAK,GACX,MAAM,CA2ElB;;CACJ;sBA3oBqB,wCAAwC;8BAKhC,2CAA2C"}
|