@woosh/meep-engine 2.109.4 → 2.109.5
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/meep.cjs +109 -14
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +109 -14
- package/package.json +1 -1
- package/src/core/collection/queue/Deque.d.ts.map +1 -1
- package/src/core/collection/queue/Deque.js +52 -1
- package/src/core/collection/queue/Deque.spec.js +29 -0
- package/src/core/geom/3d/Ray3.d.ts +23 -10
- package/src/core/geom/3d/Ray3.d.ts.map +1 -1
- package/src/core/geom/3d/Ray3.js +59 -20
- package/src/core/geom/3d/ray/ray3_interval_array_apply_matrix4.d.ts +2 -2
- package/src/core/geom/3d/ray/ray3_interval_array_apply_matrix4.d.ts.map +1 -1
- package/src/core/geom/3d/ray/ray3_interval_array_apply_matrix4.js +42 -27
- package/src/core/geom/3d/tetrahedra/triangle/prototype.js +0 -2
- package/src/core/geom/3d/tetrahedra/triangle/trace_triangular_depth_map.d.ts.map +1 -1
- package/src/core/geom/3d/tetrahedra/triangle/trace_triangular_depth_map.js +5 -2
- package/src/core/geom/vec3/v3_matrix4_rotate.d.ts +10 -0
- package/src/core/geom/vec3/v3_matrix4_rotate.d.ts.map +1 -0
- package/src/core/geom/vec3/v3_matrix4_rotate.js +27 -0
- package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.d.ts +1 -0
- package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.d.ts.map +1 -1
- package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.js +5 -3
- package/src/engine/graphics/sh3/lpv/sh3_bake_depth.d.ts.map +1 -1
- package/src/engine/graphics/sh3/lpv/sh3_bake_depth.js +2 -1
- package/src/engine/graphics/sh3/path_tracer/BufferedGeometryBVH.d.ts +9 -4
- package/src/engine/graphics/sh3/path_tracer/BufferedGeometryBVH.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/BufferedGeometryBVH.js +61 -6
- package/src/engine/graphics/sh3/path_tracer/PathTracedMesh.d.ts +11 -4
- package/src/engine/graphics/sh3/path_tracer/PathTracedMesh.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/PathTracedMesh.js +28 -36
- package/src/engine/graphics/sh3/path_tracer/PathTracedScene.d.ts +17 -8
- package/src/engine/graphics/sh3/path_tracer/PathTracedScene.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/PathTracedScene.js +83 -44
- package/src/engine/graphics/sh3/path_tracer/PathTracer.d.ts +3 -3
- package/src/engine/graphics/sh3/path_tracer/PathTracer.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/PathTracer.js +40 -33
- package/src/engine/graphics/sh3/path_tracer/material/MaterialConverter.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/material/MaterialConverter.js +43 -40
- package/src/engine/graphics/sh3/path_tracer/material/StandardMaterial.d.ts +14 -0
- package/src/engine/graphics/sh3/path_tracer/material/StandardMaterial.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/material/StandardMaterial.js +34 -1
- package/src/engine/graphics/sh3/path_tracer/prepare_scene_gltf.d.ts +21 -0
- package/src/engine/graphics/sh3/path_tracer/prepare_scene_gltf.d.ts.map +1 -0
- package/src/engine/graphics/sh3/path_tracer/prepare_scene_gltf.js +107 -0
- package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +22 -122
- package/src/engine/graphics/sh3/path_tracer/ray_hit_apply_transform.d.ts +0 -9
- package/src/engine/graphics/sh3/path_tracer/ray_hit_apply_transform.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/ray_hit_apply_transform.js +2 -28
- package/src/engine/graphics/sh3/path_tracer/sampling/getBiasedNormalSample.d.ts +0 -9
- package/src/engine/graphics/sh3/path_tracer/sampling/getBiasedNormalSample.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/sampling/getBiasedNormalSample.js +0 -39
- package/src/engine/graphics/sh3/path_tracer/sampling/getCosineDirection.d.ts +10 -0
- package/src/engine/graphics/sh3/path_tracer/sampling/getCosineDirection.d.ts.map +1 -0
- package/src/engine/graphics/sh3/path_tracer/sampling/getCosineDirection.js +41 -0
- package/src/engine/graphics/sh3/path_tracer/sampling/v3_orthonormal_matrix_from_normal.d.ts +10 -0
- package/src/engine/graphics/sh3/path_tracer/sampling/v3_orthonormal_matrix_from_normal.d.ts.map +1 -0
- package/src/engine/graphics/sh3/path_tracer/sampling/v3_orthonormal_matrix_from_normal.js +45 -0
- package/src/engine/graphics/sh3/path_tracer/texture/sample_material.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/texture/sample_material.js +28 -8
- package/src/engine/graphics/sh3/prototypeSH3Probe.js +7 -5
- package/src/engine/graphics/texture/sampler/convertTexture2Sampler2D.d.ts.map +1 -1
- package/src/engine/graphics/texture/sampler/convertTexture2Sampler2D.js +62 -13
- package/src/engine/graphics/three/material/iterate_three_material_textures.d.ts +10 -0
- package/src/engine/graphics/three/material/iterate_three_material_textures.d.ts.map +1 -0
- package/src/engine/graphics/three/material/iterate_three_material_textures.js +33 -0
- package/src/core/math/max4.d.ts +0 -10
- package/src/core/math/max4.d.ts.map +0 -1
- package/src/core/math/max4.js +0 -24
- package/src/core/math/min4.d.ts +0 -10
- package/src/core/math/min4.d.ts.map +0 -1
- package/src/core/math/min4.js +0 -23
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { array_copy } from "../../../../core/collection/array/array_copy.js";
|
|
2
|
+
import { Ray3 } from "../../../../core/geom/3d/Ray3.js";
|
|
2
3
|
import { sh3_basis_at } from "../../../../core/geom/3d/sphere/harmonics/sh3_basis_at.js";
|
|
3
4
|
import {
|
|
4
5
|
sh3_dering_optimize_positive
|
|
@@ -21,7 +22,7 @@ const __shared_buffer = new ArrayBuffer((27 + 9) * 8);
|
|
|
21
22
|
const sh_basis = new Float64Array(__shared_buffer, 0, 9);
|
|
22
23
|
const coefficients = new Float64Array(__shared_buffer, 9 * 8, 27);
|
|
23
24
|
|
|
24
|
-
const ray = new
|
|
25
|
+
const ray = new Ray3();
|
|
25
26
|
const sampled_irradiance = new Float32Array(3);
|
|
26
27
|
|
|
27
28
|
export class PathTracerProbeRenderer extends ProbeRenderer {
|
|
@@ -67,8 +68,10 @@ export class PathTracerProbeRenderer extends ProbeRenderer {
|
|
|
67
68
|
for (let i = 0; i < this.sample_count; i++) {
|
|
68
69
|
|
|
69
70
|
randomPointOnSphere(this.random, ray, 3);
|
|
71
|
+
ray.tMax = Infinity;
|
|
72
|
+
ray.tMin = 0;
|
|
70
73
|
|
|
71
|
-
tracer.path_trace(sampled_irradiance, ray,
|
|
74
|
+
tracer.path_trace(sampled_irradiance, ray, 1, 7, this.random, this.scene);
|
|
72
75
|
|
|
73
76
|
sh3_basis_at(ray[3], ray[4], ray[5], sh_basis);
|
|
74
77
|
|
|
@@ -94,7 +97,6 @@ export class PathTracerProbeRenderer extends ProbeRenderer {
|
|
|
94
97
|
}
|
|
95
98
|
|
|
96
99
|
bake_start() {
|
|
97
|
-
return this.scene.build();
|
|
98
100
|
}
|
|
99
101
|
|
|
100
102
|
build_scene(ecd) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sh3_bake_depth.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/sh3_bake_depth.js"],"names":[],"mappings":"AAQA;;;;;;;;;;GAUG;AACH,uCATW,MAAM,EAAE,iBACR,MAAM,sCAEN,MAAM,cACN,MAAM,cACN,MAAM,cACN,MAAM,eACN,MAAM,
|
|
1
|
+
{"version":3,"file":"sh3_bake_depth.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/sh3_bake_depth.js"],"names":[],"mappings":"AAQA;;;;;;;;;;GAUG;AACH,uCATW,MAAM,EAAE,iBACR,MAAM,sCAEN,MAAM,cACN,MAAM,cACN,MAAM,cACN,MAAM,eACN,MAAM,QAsDhB"}
|
|
@@ -32,6 +32,7 @@ export function sh3_bake_depth(
|
|
|
32
32
|
const sh = new Float32Array(9);
|
|
33
33
|
|
|
34
34
|
ray.origin.set(position_x, position_y, position_z);
|
|
35
|
+
ray.tMax = max_depth;
|
|
35
36
|
|
|
36
37
|
const encoder = new OctahedralUvEncoder();
|
|
37
38
|
|
|
@@ -42,7 +43,7 @@ export function sh3_bake_depth(
|
|
|
42
43
|
|
|
43
44
|
encoder.uv_to_unit(ray.direction, [u, v])
|
|
44
45
|
|
|
45
|
-
let distance = scene.trace(ray_hit, ray
|
|
46
|
+
let distance = scene.trace(ray_hit, ray);
|
|
46
47
|
|
|
47
48
|
if (distance < 0) {
|
|
48
49
|
distance = 100;
|
|
@@ -33,15 +33,20 @@ export class BufferedGeometryBVH {
|
|
|
33
33
|
* @param {THREE.BufferGeometry} geometry
|
|
34
34
|
*/
|
|
35
35
|
build(geometry: THREE.BufferGeometry): void;
|
|
36
|
+
/**
|
|
37
|
+
* Tests ray for occlusion
|
|
38
|
+
* Returns true if ray hits anything at all
|
|
39
|
+
* @param {Ray3} ray
|
|
40
|
+
* @returns {boolean}
|
|
41
|
+
*/
|
|
42
|
+
occluded(ray: Ray3): boolean;
|
|
36
43
|
/**
|
|
37
44
|
* NOTE: raycast is performed in local coordinate space
|
|
38
45
|
* @param {number[]} output
|
|
39
|
-
* @param {number[]} ray
|
|
40
|
-
* @param {number} min_distance
|
|
41
|
-
* @param {number} max_distance
|
|
46
|
+
* @param {number[]|Ray3} ray
|
|
42
47
|
* @returns {number} distance along the ray, negative if no hit
|
|
43
48
|
*/
|
|
44
|
-
raycast(output: number[], ray: number[]
|
|
49
|
+
raycast(output: number[], ray: number[] | Ray3): number;
|
|
45
50
|
#private;
|
|
46
51
|
}
|
|
47
52
|
import { AABB3 } from "../../../../core/geom/3d/aabb/AABB3.js";
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;IAED;;;;;OAKG;IACH,qBAFa,OAAO,CAkDnB;IAED;;;;;OAKG;IACH,gBAJW,MAAM,EAAE,OACR,MAAM,EAAE,OAAK,GACX,MAAM,CA2ElB;;CACJ;sBAhQqB,wCAAwC"}
|
|
@@ -122,16 +122,69 @@ export class BufferedGeometryBVH {
|
|
|
122
122
|
r.toArray(this.#bounds_sphere);
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
+
/**
|
|
126
|
+
* Tests ray for occlusion
|
|
127
|
+
* Returns true if ray hits anything at all
|
|
128
|
+
* @param {Ray3} ray
|
|
129
|
+
* @returns {boolean}
|
|
130
|
+
*/
|
|
131
|
+
occluded(ray) {
|
|
132
|
+
const indices = this.__geometry_index;
|
|
133
|
+
const positions = this.__geometry_positions;
|
|
134
|
+
|
|
135
|
+
const origin_x = ray[0];
|
|
136
|
+
const origin_y = ray[1];
|
|
137
|
+
const origin_z = ray[2];
|
|
138
|
+
|
|
139
|
+
const direction_x = ray[3];
|
|
140
|
+
const direction_y = ray[4];
|
|
141
|
+
const direction_z = ray[5];
|
|
142
|
+
|
|
143
|
+
const max_distance = ray[6];
|
|
144
|
+
|
|
145
|
+
const bvh = this.#bvh;
|
|
146
|
+
|
|
147
|
+
const count = bvh_query_user_data_ray_segment(
|
|
148
|
+
bvh, bvh.root,
|
|
149
|
+
scratch_uint32_array, 0,
|
|
150
|
+
origin_x, origin_y, origin_z,
|
|
151
|
+
direction_x, direction_y, direction_z,
|
|
152
|
+
0, max_distance
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
// check triangles found via BVH
|
|
156
|
+
for (let i = 0; i < count; i++) {
|
|
157
|
+
const triangle_index = scratch_uint32_array[i];
|
|
158
|
+
|
|
159
|
+
const intersection_found = computeTriangleRayIntersectionBarycentricGeometry(
|
|
160
|
+
v3_scratch_0,
|
|
161
|
+
origin_x, origin_y, origin_z,
|
|
162
|
+
direction_x, direction_y, direction_z,
|
|
163
|
+
indices, triangle_index,
|
|
164
|
+
positions
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
if (!intersection_found) {
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const t = v3_scratch_0[0];
|
|
172
|
+
|
|
173
|
+
if (t < max_distance && t > 0) {
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
125
180
|
|
|
126
181
|
/**
|
|
127
182
|
* NOTE: raycast is performed in local coordinate space
|
|
128
183
|
* @param {number[]} output
|
|
129
|
-
* @param {number[]} ray
|
|
130
|
-
* @param {number} min_distance
|
|
131
|
-
* @param {number} max_distance
|
|
184
|
+
* @param {number[]|Ray3} ray
|
|
132
185
|
* @returns {number} distance along the ray, negative if no hit
|
|
133
186
|
*/
|
|
134
|
-
raycast(output, ray
|
|
187
|
+
raycast(output, ray) {
|
|
135
188
|
|
|
136
189
|
const indices = this.__geometry_index;
|
|
137
190
|
const positions = this.__geometry_positions;
|
|
@@ -144,6 +197,8 @@ export class BufferedGeometryBVH {
|
|
|
144
197
|
const direction_y = ray[4];
|
|
145
198
|
const direction_z = ray[5];
|
|
146
199
|
|
|
200
|
+
const max_distance = ray[6];
|
|
201
|
+
|
|
147
202
|
const bvh = this.#bvh;
|
|
148
203
|
|
|
149
204
|
const count = bvh_query_user_data_ray_segment(
|
|
@@ -151,7 +206,7 @@ export class BufferedGeometryBVH {
|
|
|
151
206
|
scratch_uint32_array, 0,
|
|
152
207
|
origin_x, origin_y, origin_z,
|
|
153
208
|
direction_x, direction_y, direction_z,
|
|
154
|
-
|
|
209
|
+
0, max_distance
|
|
155
210
|
);
|
|
156
211
|
|
|
157
212
|
if (count === 0) {
|
|
@@ -184,7 +239,7 @@ export class BufferedGeometryBVH {
|
|
|
184
239
|
|
|
185
240
|
const t = v3_scratch_0[0];
|
|
186
241
|
|
|
187
|
-
if (t < nearest_hit_distance && t >
|
|
242
|
+
if (t < nearest_hit_distance && t > 0) {
|
|
188
243
|
nearest_hit_distance = t;
|
|
189
244
|
|
|
190
245
|
best_index = triangle_index;
|
|
@@ -24,20 +24,27 @@ export class PathTracedMesh {
|
|
|
24
24
|
* @type {StandardMaterial|null}
|
|
25
25
|
*/
|
|
26
26
|
material: StandardMaterial | null;
|
|
27
|
+
get transform_inverse(): Float32Array;
|
|
27
28
|
build_tight_bounds(): void;
|
|
28
29
|
update_bounds(): void;
|
|
29
30
|
set transform(arg: Float32Array);
|
|
30
31
|
get transform(): Float32Array;
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
* @param {Ray3} ray
|
|
35
|
+
* @returns {boolean}
|
|
36
|
+
*/
|
|
37
|
+
occluded(ray: Ray3): boolean;
|
|
31
38
|
/**
|
|
32
39
|
*
|
|
33
40
|
* @param {number[]} out
|
|
34
|
-
* @param {number[]} ray
|
|
35
|
-
* @param {number}
|
|
36
|
-
* @param {number} max_distance
|
|
41
|
+
* @param {number[]|Ray3} ray
|
|
42
|
+
* @param {number} ray_limit overrides Ray.tMax
|
|
37
43
|
* @returns {number} distance along the ray to contact
|
|
38
44
|
*/
|
|
39
|
-
hit(out: number[], ray: number[]
|
|
45
|
+
hit(out: number[], ray: number[] | Ray3, ray_limit: number): number;
|
|
40
46
|
#private;
|
|
41
47
|
}
|
|
42
48
|
import { AABB3 } from "../../../../core/geom/3d/aabb/AABB3.js";
|
|
49
|
+
import { Ray3 } from "../../../../core/geom/3d/Ray3.js";
|
|
43
50
|
//# sourceMappingURL=PathTracedMesh.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PathTracedMesh.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/PathTracedMesh.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PathTracedMesh.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/PathTracedMesh.js"],"names":[],"mappings":"AAeA;IACI;;;OAGG;IACH,IAFU,MAAM,CAEO;IAEvB;;;OAGG;IACH,MAFU,KAAK,CAEI;IAEnB;;;OAGG;IACH,KAFU,sBAAoB,IAAI,CAEvB;IAGX;;;OAGG;IACH,UAFU,MAAM,cAAc,GAAC,IAAI,CAEnB;IAEhB;;;OAGG;IACH,UAFU,mBAAiB,IAAI,CAEf;IAKhB,sCAEC;IAED,2BAqBC;IAED,sBAGC;IAED,iCAQC;IAED,8BAEC;IAED;;;;OAIG;IACH,cAHW,IAAI,GACF,OAAO,CAWnB;IAED;;;;;;OAMG;IACH,SALW,MAAM,EAAE,OACR,MAAM,EAAE,GAAC,IAAI,aACb,MAAM,GACJ,MAAM,CA4BlB;;CACJ;sBAhJqB,wCAAwC;qBAIzC,kCAAkC"}
|
|
@@ -4,17 +4,13 @@ import { AABB3 } from "../../../../core/geom/3d/aabb/AABB3.js";
|
|
|
4
4
|
import { aabb3_from_v3_array_transformed } from "../../../../core/geom/3d/aabb/aabb3_from_v3_array_transformed.js";
|
|
5
5
|
import { decompose_matrix_4_array } from "../../../../core/geom/3d/decompose_matrix_4_array.js";
|
|
6
6
|
import { allocate_m4 } from "../../../../core/geom/3d/mat4/allocate_m4.js";
|
|
7
|
-
import {
|
|
8
|
-
import { ray3_shift_origin_along_direction } from "../../../../core/geom/3d/ray/ray3_shift_origin_along_direction.js";
|
|
7
|
+
import { Ray3 } from "../../../../core/geom/3d/Ray3.js";
|
|
9
8
|
import Quaternion from "../../../../core/geom/Quaternion.js";
|
|
10
|
-
import { v3_array_displace_in_direction } from "../../../../core/geom/vec3/v3_array_displace_in_direction.js";
|
|
11
9
|
import { v3_distance } from "../../../../core/geom/vec3/v3_distance.js";
|
|
12
|
-
import { v3_matrix4_multiply } from "../../../../core/geom/vec3/v3_matrix4_multiply.js";
|
|
13
10
|
import Vector3 from "../../../../core/geom/Vector3.js";
|
|
14
11
|
import { ray_hit_apply_transform } from "./ray_hit_apply_transform.js";
|
|
15
12
|
|
|
16
|
-
const local_ray = new
|
|
17
|
-
const scratch_v3 = new Float32Array(3);
|
|
13
|
+
const local_ray = new Ray3();
|
|
18
14
|
let mesh_id_counter = 0;
|
|
19
15
|
|
|
20
16
|
export class PathTracedMesh {
|
|
@@ -52,6 +48,10 @@ export class PathTracedMesh {
|
|
|
52
48
|
#transform = allocate_m4();
|
|
53
49
|
#transform_inverse = allocate_m4();
|
|
54
50
|
|
|
51
|
+
get transform_inverse() {
|
|
52
|
+
return this.#transform_inverse;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
55
|
build_tight_bounds() {
|
|
56
56
|
const position = new Vector3();
|
|
57
57
|
const rotation = new Quaternion();
|
|
@@ -96,45 +96,37 @@ export class PathTracedMesh {
|
|
|
96
96
|
|
|
97
97
|
/**
|
|
98
98
|
*
|
|
99
|
-
* @param {
|
|
100
|
-
* @
|
|
101
|
-
* @param {number} min_distance
|
|
102
|
-
* @param {number} max_distance
|
|
103
|
-
* @returns {number} distance along the ray to contact
|
|
99
|
+
* @param {Ray3} ray
|
|
100
|
+
* @returns {boolean}
|
|
104
101
|
*/
|
|
105
|
-
|
|
106
|
-
//transform ray
|
|
107
|
-
const m4 = this.#transform_inverse;
|
|
108
|
-
|
|
109
|
-
// shift ray forward by "min distance"
|
|
110
|
-
ray3_shift_origin_along_direction(local_ray, 0, ray, 0, min_distance);
|
|
102
|
+
occluded(ray) {
|
|
111
103
|
|
|
104
|
+
const m4 = this.#transform_inverse;
|
|
112
105
|
|
|
113
|
-
|
|
106
|
+
local_ray.copy(ray);
|
|
107
|
+
local_ray.applyMatrix4(m4);
|
|
114
108
|
|
|
109
|
+
return this.bvh.occluded(local_ray);
|
|
115
110
|
|
|
116
|
-
|
|
111
|
+
}
|
|
117
112
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
113
|
+
/**
|
|
114
|
+
*
|
|
115
|
+
* @param {number[]} out
|
|
116
|
+
* @param {number[]|Ray3} ray
|
|
117
|
+
* @param {number} ray_limit overrides Ray.tMax
|
|
118
|
+
* @returns {number} distance along the ray to contact
|
|
119
|
+
*/
|
|
120
|
+
hit(out, ray, ray_limit) {
|
|
121
|
+
//transform ray
|
|
122
|
+
const m4 = this.#transform_inverse;
|
|
126
123
|
|
|
127
|
-
|
|
128
|
-
|
|
124
|
+
local_ray.copy(ray);
|
|
125
|
+
local_ray.tMax = ray_limit;
|
|
129
126
|
|
|
130
|
-
|
|
131
|
-
max_distance_local = v3_distance(
|
|
132
|
-
local_ray[0], local_ray[1], local_ray[2],
|
|
133
|
-
scratch_v3[0], scratch_v3[1], scratch_v3[2]
|
|
134
|
-
);
|
|
135
|
-
}
|
|
127
|
+
local_ray.applyMatrix4(m4);
|
|
136
128
|
|
|
137
|
-
let distance_to_hit = this.bvh.raycast(out, local_ray
|
|
129
|
+
let distance_to_hit = this.bvh.raycast(out, local_ray);
|
|
138
130
|
|
|
139
131
|
if (distance_to_hit >= 0) {
|
|
140
132
|
// transform output
|
|
@@ -26,7 +26,6 @@ export class PathTracedScene {
|
|
|
26
26
|
*/
|
|
27
27
|
private __background_sampler;
|
|
28
28
|
optimize(): void;
|
|
29
|
-
build(): Promise<void>;
|
|
30
29
|
/**
|
|
31
30
|
*
|
|
32
31
|
* @param {THREE.BufferGeometry} geo
|
|
@@ -56,6 +55,12 @@ export class PathTracedScene {
|
|
|
56
55
|
* @returns {boolean}
|
|
57
56
|
*/
|
|
58
57
|
removeMesh(mesh: PathTracedMesh): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Retrieves pre-cached material or build one from scratch, caches it and returns the result
|
|
60
|
+
* @param {THREE.Material} material
|
|
61
|
+
* @returns {StandardMaterial}
|
|
62
|
+
*/
|
|
63
|
+
obtainMaterial(material: THREE.Material): StandardMaterial;
|
|
59
64
|
/**
|
|
60
65
|
*
|
|
61
66
|
* @param {THREE.BufferGeometry} geometry
|
|
@@ -67,17 +72,22 @@ export class PathTracedScene {
|
|
|
67
72
|
*
|
|
68
73
|
* @param {number[]} out [color_r, color_g, color_b, normal_x, normal_y, normal_z]
|
|
69
74
|
* @param {number[]} hit
|
|
75
|
+
* @param {Ray3} incoming_ray
|
|
70
76
|
*/
|
|
71
|
-
sample_material(out: number[], hit: number[]): void;
|
|
77
|
+
sample_material(out: number[], hit: number[], incoming_ray: Ray3): void;
|
|
78
|
+
/**
|
|
79
|
+
* Tests ray for occlusion
|
|
80
|
+
* @param {Ray3} ray
|
|
81
|
+
* @returns {boolean}
|
|
82
|
+
*/
|
|
83
|
+
occluded(ray: Ray3): boolean;
|
|
72
84
|
/**
|
|
73
85
|
*
|
|
74
86
|
* @param {number[]} out
|
|
75
87
|
* @param {number[]|Ray3} ray
|
|
76
|
-
* @param {number} min_distance
|
|
77
|
-
* @param {number} max_distance
|
|
78
88
|
* @return {number} distance to contact, or -1 if no contact found
|
|
79
89
|
*/
|
|
80
|
-
trace(out: number[], ray: number[] | Ray3
|
|
90
|
+
trace(out: number[], ray: number[] | Ray3): number;
|
|
81
91
|
/**
|
|
82
92
|
*
|
|
83
93
|
* @param {number[]} out
|
|
@@ -91,14 +101,13 @@ export class PathTracedScene {
|
|
|
91
101
|
* @param {number[]} out
|
|
92
102
|
* @param {number} out_offset
|
|
93
103
|
* @param {number[]} ray
|
|
94
|
-
* @param {number} ray_address
|
|
95
|
-
* @returns {boolean}
|
|
96
104
|
*/
|
|
97
|
-
sample_lights(out: number[], out_offset: number, ray: number[]
|
|
105
|
+
sample_lights(out: number[], out_offset: number, ray: number[]): void;
|
|
98
106
|
#private;
|
|
99
107
|
}
|
|
100
108
|
import { BVH } from "../../../../core/bvh2/bvh3/BVH.js";
|
|
101
109
|
import { PathTracedMesh } from "./PathTracedMesh.js";
|
|
102
110
|
import { AbstractLight } from "../../render/forward_plus/model/AbstractLight.js";
|
|
103
111
|
import { BufferedGeometryBVH } from "./BufferedGeometryBVH.js";
|
|
112
|
+
import { Ray3 } from "../../../../core/geom/3d/Ray3.js";
|
|
104
113
|
//# sourceMappingURL=PathTracedScene.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PathTracedScene.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/PathTracedScene.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PathTracedScene.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/PathTracedScene.js"],"names":[],"mappings":"AAgCA;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;;;;OAIG;IACH,uBAHW,MAAM,cAAc,GACnB,mBAAmB,CAmB9B;IAED;;;OAGG;IACH,gBAFW,aAAa,QAMvB;IAED;;;;OAIG;IACH,cAHW,cAAc,GACZ,OAAO,CAInB;IAED;;;;OAIG;IACH,cAHW,cAAc,GACZ,OAAO,CAiCnB;IAED;;;;OAIG;IACH,iBAHW,cAAc,GACZ,OAAO,CAgBnB;IAED;;;;OAIG;IACH,yBAHW,MAAM,QAAQ,oBAKxB;IAED;;;;;OAKG;IACH,qBAJW,MAAM,cAAc,YACpB,MAAM,QAAQ,aACd,OAAK,MAAM,EAAE,QAavB;IAED;;;;;OAKG;IACH,qBAJW,MAAM,EAAE,OACR,MAAM,EAAE,gBACR,IAAI,QAgCd;IAED;;;;OAIG;IACH,cAHW,IAAI,GACF,OAAO,CAsCnB;IAED;;;;;OAKG;IACH,WAJW,MAAM,EAAE,OACR,MAAM,EAAE,GAAC,IAAI,GACZ,MAAM,CA+CjB;IAED;;;;;;OAMG;IACH,uBALW,MAAM,EAAE,cACR,MAAM,aACN,MAAM,EAAE,oBACR,MAAM,QAIhB;IAED;;;;;OAKG;IACH,mBAJW,MAAM,EAAE,cACR,MAAM,OACN,MAAM,EAAE,QAkElB;;CACJ;oBArgB8B,mCAAmC;+BAkBnC,qBAAqB;8BAJtB,kDAAkD;oCAC5C,0BAA0B;qBALzC,kCAAkC"}
|
|
@@ -9,6 +9,7 @@ import { strictEquals } from "../../../../core/function/strictEquals.js";
|
|
|
9
9
|
import { AABB3 } from "../../../../core/geom/3d/aabb/AABB3.js";
|
|
10
10
|
import { v3_morton_encode_bounded } from "../../../../core/geom/3d/morton/v3_morton_encode_bounded.js";
|
|
11
11
|
import { ray3_array_compose } from "../../../../core/geom/3d/ray/ray3_array_compose.js";
|
|
12
|
+
import { Ray3 } from "../../../../core/geom/3d/Ray3.js";
|
|
12
13
|
import { v3_dot } from "../../../../core/geom/vec3/v3_dot.js";
|
|
13
14
|
import { max2 } from "../../../../core/math/max2.js";
|
|
14
15
|
import { compute_geometry_polycount } from "../../geometry/compute_geometry_polycount.js";
|
|
@@ -25,24 +26,10 @@ import { sample_material } from "./texture/sample_material.js";
|
|
|
25
26
|
*/
|
|
26
27
|
const scratch_uint32_array = new Uint32Array(4096);
|
|
27
28
|
|
|
28
|
-
const _ray_1 =
|
|
29
|
-
const tmp_0 = new Float64Array(11);
|
|
30
|
-
const null_output = [];
|
|
29
|
+
const _ray_1 = new Ray3();
|
|
31
30
|
|
|
32
31
|
const DEFAULT_CONVERTER = new MaterialConverter();
|
|
33
32
|
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
*
|
|
37
|
-
* @param {Uint32Array} result
|
|
38
|
-
* @param {number} result_offset
|
|
39
|
-
* @param {number} count
|
|
40
|
-
* @param {BVH} bvh
|
|
41
|
-
*/
|
|
42
|
-
function bvh_build_query_cache(result, result_offset, count, bvh) {
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
33
|
export class PathTracedScene {
|
|
47
34
|
|
|
48
35
|
|
|
@@ -183,10 +170,6 @@ export class PathTracedScene {
|
|
|
183
170
|
this.#rebuild_bvh();
|
|
184
171
|
}
|
|
185
172
|
|
|
186
|
-
async build() {
|
|
187
|
-
|
|
188
|
-
}
|
|
189
|
-
|
|
190
173
|
/**
|
|
191
174
|
*
|
|
192
175
|
* @param {THREE.BufferGeometry} geo
|
|
@@ -289,6 +272,15 @@ export class PathTracedScene {
|
|
|
289
272
|
return true;
|
|
290
273
|
}
|
|
291
274
|
|
|
275
|
+
/**
|
|
276
|
+
* Retrieves pre-cached material or build one from scratch, caches it and returns the result
|
|
277
|
+
* @param {THREE.Material} material
|
|
278
|
+
* @returns {StandardMaterial}
|
|
279
|
+
*/
|
|
280
|
+
obtainMaterial(material) {
|
|
281
|
+
return this.#material_cache.getOrCompute(material, DEFAULT_CONVERTER.convert, DEFAULT_CONVERTER);
|
|
282
|
+
}
|
|
283
|
+
|
|
292
284
|
/**
|
|
293
285
|
*
|
|
294
286
|
* @param {THREE.BufferGeometry} geometry
|
|
@@ -296,7 +288,7 @@ export class PathTracedScene {
|
|
|
296
288
|
* @param {mat4|number[]} transform
|
|
297
289
|
*/
|
|
298
290
|
createMesh(geometry, material, transform) {
|
|
299
|
-
const standard_material = this
|
|
291
|
+
const standard_material = this.obtainMaterial(material);
|
|
300
292
|
|
|
301
293
|
const mesh = new PathTracedMesh();
|
|
302
294
|
mesh.geometry = geometry;
|
|
@@ -312,8 +304,9 @@ export class PathTracedScene {
|
|
|
312
304
|
*
|
|
313
305
|
* @param {number[]} out [color_r, color_g, color_b, normal_x, normal_y, normal_z]
|
|
314
306
|
* @param {number[]} hit
|
|
307
|
+
* @param {Ray3} incoming_ray
|
|
315
308
|
*/
|
|
316
|
-
sample_material(out, hit) {
|
|
309
|
+
sample_material(out, hit, incoming_ray) {
|
|
317
310
|
const primitive_id = hit[9];
|
|
318
311
|
const instance_id = hit[10];
|
|
319
312
|
const u = hit[7];
|
|
@@ -336,17 +329,65 @@ export class PathTracedScene {
|
|
|
336
329
|
|
|
337
330
|
sample_material(out, mesh, primitive_id, u, v);
|
|
338
331
|
|
|
332
|
+
// const pdf = mesh.material.scattering_pdf(
|
|
333
|
+
// incoming_ray[3],incoming_ray[4],incoming_ray[5],
|
|
334
|
+
// out[3],out[4],out[5],
|
|
335
|
+
// incoming_ray[3],incoming_ray[4],incoming_ray[5],
|
|
336
|
+
// );
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Tests ray for occlusion
|
|
343
|
+
* @param {Ray3} ray
|
|
344
|
+
* @returns {boolean}
|
|
345
|
+
*/
|
|
346
|
+
occluded(ray) {
|
|
347
|
+
|
|
348
|
+
const bvh = this.bvh_top_level;
|
|
349
|
+
|
|
350
|
+
const ray_origin_x = ray[0];
|
|
351
|
+
const ray_origin_y = ray[1];
|
|
352
|
+
const ray_origin_z = ray[2];
|
|
353
|
+
|
|
354
|
+
const ray_direction_x = ray[3];
|
|
355
|
+
const ray_direction_y = ray[4];
|
|
356
|
+
const ray_direction_z = ray[5];
|
|
357
|
+
|
|
358
|
+
const max_distance = ray[6];
|
|
359
|
+
|
|
360
|
+
const hit_count = bvh_query_user_data_ray_segment(
|
|
361
|
+
bvh, bvh.root,
|
|
362
|
+
scratch_uint32_array, 0,
|
|
363
|
+
ray_origin_x, ray_origin_y, ray_origin_z,
|
|
364
|
+
ray_direction_x, ray_direction_y, ray_direction_z,
|
|
365
|
+
0, max_distance
|
|
366
|
+
);
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
for (let i = 0; i < hit_count; i++) {
|
|
370
|
+
|
|
371
|
+
const node_user_data = scratch_uint32_array[i];
|
|
372
|
+
|
|
373
|
+
const mesh = this.meshes.get(node_user_data);
|
|
374
|
+
|
|
375
|
+
if (mesh.occluded(ray)) {
|
|
376
|
+
return true;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
return false;
|
|
339
382
|
}
|
|
340
383
|
|
|
341
384
|
/**
|
|
342
385
|
*
|
|
343
386
|
* @param {number[]} out
|
|
344
387
|
* @param {number[]|Ray3} ray
|
|
345
|
-
* @param {number} min_distance
|
|
346
|
-
* @param {number} max_distance
|
|
347
388
|
* @return {number} distance to contact, or -1 if no contact found
|
|
348
389
|
*/
|
|
349
|
-
trace(out, ray
|
|
390
|
+
trace(out, ray) {
|
|
350
391
|
|
|
351
392
|
const bvh = this.bvh_top_level;
|
|
352
393
|
|
|
@@ -358,13 +399,14 @@ export class PathTracedScene {
|
|
|
358
399
|
const ray_direction_y = ray[4];
|
|
359
400
|
const ray_direction_z = ray[5];
|
|
360
401
|
|
|
402
|
+
const max_distance = ray[6];
|
|
361
403
|
|
|
362
404
|
const hit_count = bvh_query_user_data_ray_segment(
|
|
363
405
|
bvh, bvh.root,
|
|
364
406
|
scratch_uint32_array, 0,
|
|
365
407
|
ray_origin_x, ray_origin_y, ray_origin_z,
|
|
366
408
|
ray_direction_x, ray_direction_y, ray_direction_z,
|
|
367
|
-
|
|
409
|
+
0, max_distance
|
|
368
410
|
);
|
|
369
411
|
|
|
370
412
|
let nearest_hit_distance = max_distance;
|
|
@@ -375,7 +417,7 @@ export class PathTracedScene {
|
|
|
375
417
|
|
|
376
418
|
const mesh = this.meshes.get(node_user_data);
|
|
377
419
|
|
|
378
|
-
const distance_to_hit = mesh.hit(out, ray,
|
|
420
|
+
const distance_to_hit = mesh.hit(out, ray, nearest_hit_distance);
|
|
379
421
|
|
|
380
422
|
if (distance_to_hit >= 0) {
|
|
381
423
|
// since raycast in leaf nodes is already bound by maximum distance, any hit we get is necessarily a closer hit than before
|
|
@@ -408,11 +450,8 @@ export class PathTracedScene {
|
|
|
408
450
|
* @param {number[]} out
|
|
409
451
|
* @param {number} out_offset
|
|
410
452
|
* @param {number[]} ray
|
|
411
|
-
* @param {number} ray_address
|
|
412
|
-
* @returns {boolean}
|
|
413
453
|
*/
|
|
414
|
-
sample_lights(out, out_offset, ray
|
|
415
|
-
let lights_sampled = false;
|
|
454
|
+
sample_lights(out, out_offset, ray) {
|
|
416
455
|
|
|
417
456
|
const lights = this.__lights;
|
|
418
457
|
const light_count = lights.length;
|
|
@@ -430,9 +469,9 @@ export class PathTracedScene {
|
|
|
430
469
|
|
|
431
470
|
// see https://github.com/mrdoob/three.js/blob/f0a9e0cf90a2f1ba5017fcb7fd46f02748b920cf/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js#L172
|
|
432
471
|
|
|
433
|
-
const ray_direction_x = ray[
|
|
434
|
-
const ray_direction_y = ray[
|
|
435
|
-
const ray_direction_z = ray[
|
|
472
|
+
const ray_direction_x = ray[3];
|
|
473
|
+
const ray_direction_y = ray[4];
|
|
474
|
+
const ray_direction_z = ray[5];
|
|
436
475
|
|
|
437
476
|
const light_dir_inv_x = -dir.x;
|
|
438
477
|
const light_dir_inv_y = -dir.y;
|
|
@@ -448,33 +487,33 @@ export class PathTracedScene {
|
|
|
448
487
|
continue;
|
|
449
488
|
}
|
|
450
489
|
|
|
451
|
-
const ray_origin_x = ray[
|
|
452
|
-
const ray_origin_y = ray[
|
|
453
|
-
const ray_origin_z = ray[
|
|
490
|
+
const ray_origin_x = ray[0];
|
|
491
|
+
const ray_origin_y = ray[1];
|
|
492
|
+
const ray_origin_z = ray[2];
|
|
454
493
|
|
|
455
494
|
ray3_array_compose(_ray_1,
|
|
456
495
|
ray_origin_x, ray_origin_y, ray_origin_z,
|
|
457
496
|
light_dir_inv_x, light_dir_inv_y, light_dir_inv_z
|
|
458
497
|
);
|
|
459
498
|
|
|
499
|
+
_ray_1.tMax = Infinity;
|
|
500
|
+
|
|
460
501
|
// check if there are any obstacles in the direction of the light
|
|
461
|
-
if (this.
|
|
502
|
+
if (this.occluded(_ray_1)) {
|
|
462
503
|
// light is occluded
|
|
463
504
|
continue;
|
|
464
505
|
}
|
|
465
506
|
|
|
466
507
|
|
|
467
508
|
const intensity = dotNL * light.intensity.getValue();
|
|
509
|
+
const light_color = light.color;
|
|
510
|
+
|
|
511
|
+
out[out_offset] += light_color.r * intensity;
|
|
512
|
+
out[out_offset + 1] += light_color.g * intensity;
|
|
513
|
+
out[out_offset + 2] += light_color.b * intensity;
|
|
468
514
|
|
|
469
|
-
for (let j = 0; j < 3; j++) {
|
|
470
|
-
// irradiance
|
|
471
|
-
out[out_offset + j] += light.color[j] * intensity;
|
|
472
|
-
}
|
|
473
515
|
|
|
474
|
-
lights_sampled = true;
|
|
475
516
|
}
|
|
476
517
|
}
|
|
477
|
-
|
|
478
|
-
return lights_sampled;
|
|
479
518
|
}
|
|
480
519
|
}
|
|
@@ -2,13 +2,13 @@ export class PathTracer {
|
|
|
2
2
|
/**
|
|
3
3
|
*
|
|
4
4
|
* @param {number[]|Float32Array} out
|
|
5
|
-
* @param {number[]|Float32Array} ray
|
|
6
|
-
* @param {number} max_distance
|
|
5
|
+
* @param {number[]|Float32Array|Ray3} ray
|
|
7
6
|
* @param {number} min_bounce
|
|
8
7
|
* @param {number} max_bounce
|
|
9
8
|
* @param {function} random
|
|
10
9
|
* @param {PathTracedScene} scene
|
|
11
10
|
*/
|
|
12
|
-
path_trace(out: number[] | Float32Array, ray: number[] | Float32Array
|
|
11
|
+
path_trace(out: number[] | Float32Array, ray: number[] | Float32Array | Ray3, min_bounce: number, max_bounce: number, random: Function, scene: PathTracedScene): void;
|
|
13
12
|
}
|
|
13
|
+
import { Ray3 } from "../../../../core/geom/3d/Ray3.js";
|
|
14
14
|
//# sourceMappingURL=PathTracer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PathTracer.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/PathTracer.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PathTracer.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/PathTracer.js"],"names":[],"mappings":"AAiCA;IAGI;;;;;;;;OAQG;IACH,gBAPW,MAAM,EAAE,GAAC,YAAY,OACrB,MAAM,EAAE,GAAC,YAAY,GAAC,IAAI,cAC1B,MAAM,cACN,MAAM,kDAkFhB;CACJ;qBA1HoB,kCAAkC"}
|