@woosh/meep-engine 2.108.4 → 2.109.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/meep.cjs +73 -48
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +73 -48
- package/package.json +1 -1
- package/src/core/assert.d.ts +2 -2
- package/src/core/assert.d.ts.map +1 -1
- package/src/core/assert.js +1 -1
- package/src/core/binary/align_4.spec.d.ts +2 -0
- package/src/core/binary/align_4.spec.d.ts.map +1 -0
- package/src/core/binary/align_4.spec.js +20 -0
- package/src/core/binary/{de_interleave_bits_by_2.d.ts → de_interleave_2_bits.d.ts} +1 -1
- package/src/core/binary/de_interleave_2_bits.d.ts.map +1 -0
- package/src/core/binary/de_interleave_2_bits.spec.js +1 -1
- package/src/core/binary/hex2dec.spec.d.ts +2 -0
- package/src/core/binary/hex2dec.spec.d.ts.map +1 -0
- package/src/core/binary/hex2dec.spec.js +22 -0
- package/src/core/binary/split_by_2.spec.d.ts +2 -0
- package/src/core/binary/split_by_2.spec.d.ts.map +1 -0
- package/src/core/binary/split_by_2.spec.js +22 -0
- package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.d.ts +4 -1
- package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.d.ts.map +1 -1
- package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.js +16 -7
- package/src/core/bvh2/bvh3/ebvh_build_hierarchy.js +1 -1
- package/src/core/bvh2/bvh3/query/bvh_query_user_data_ray.d.ts.map +1 -1
- package/src/core/bvh2/bvh3/query/bvh_query_user_data_ray.js +12 -7
- package/src/core/geom/2d/circle/circle_circumference.d.ts +7 -0
- package/src/core/geom/2d/circle/circle_circumference.d.ts.map +1 -0
- package/src/core/geom/2d/circle/circle_circumference.js +12 -0
- package/src/core/geom/2d/compute_polygon_area_2d.d.ts.map +1 -1
- package/src/core/geom/2d/compute_polygon_area_2d.js +6 -4
- package/src/core/geom/2d/lt-grid/LooseTightGrid.js +1 -1
- package/src/core/geom/2d/triangle2d_get_barycentric.d.ts +2 -2
- package/src/core/geom/2d/triangle2d_get_barycentric.js +2 -2
- package/src/core/geom/3d/Ray3.d.ts +19 -0
- package/src/core/geom/3d/Ray3.d.ts.map +1 -0
- package/src/core/geom/3d/Ray3.js +27 -0
- package/src/core/geom/3d/ray/ray3_shift_origin_along_direction.d.ts +10 -0
- package/src/core/geom/3d/ray/ray3_shift_origin_along_direction.d.ts.map +1 -0
- package/src/core/geom/3d/ray/ray3_shift_origin_along_direction.js +35 -0
- package/src/core/geom/3d/sphere/harmonics/compute_legendre_polynomial.d.ts +1 -0
- package/src/core/geom/3d/sphere/harmonics/compute_legendre_polynomial.d.ts.map +1 -0
- package/src/core/geom/3d/sphere/harmonics/compute_legendre_polynomial.js +0 -0
- package/src/core/geom/3d/sphere/harmonics/sh3_convolve_with_cosine_kernel.d.ts +9 -0
- package/src/core/geom/3d/sphere/harmonics/sh3_convolve_with_cosine_kernel.d.ts.map +1 -0
- package/src/core/geom/3d/sphere/harmonics/sh3_convolve_with_cosine_kernel.js +25 -0
- package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.d.ts.map +1 -1
- package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.js +2 -4
- package/src/core/geom/3d/sphere/harmonics/sh3_rotate_bl.d.ts +8 -0
- package/src/core/geom/3d/sphere/harmonics/sh3_rotate_bl.d.ts.map +1 -0
- package/src/core/geom/3d/sphere/harmonics/sh3_rotate_bl.js +94 -0
- package/src/core/geom/3d/sphere/harmonics/sh3_rotate_filament.d.ts +8 -0
- package/src/core/geom/3d/sphere/harmonics/sh3_rotate_filament.d.ts.map +1 -0
- package/src/core/geom/3d/sphere/harmonics/{sh3_rotate.js → sh3_rotate_filament.js} +5 -2
- package/src/core/geom/3d/sphere/harmonics/sh_compute_K.d.ts +3 -3
- package/src/core/geom/3d/sphere/harmonics/sh_compute_K.js +3 -3
- package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_build_from_grid.d.ts.map +1 -1
- package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_build_from_grid.js +29 -14
- package/src/core/geom/Quaternion.js +1 -1
- package/src/core/geom/vec3/v3_matrix4_multiply.d.ts +10 -0
- package/src/core/geom/vec3/v3_matrix4_multiply.d.ts.map +1 -0
- package/src/core/geom/vec3/v3_matrix4_multiply.js +27 -0
- package/src/core/geom/vec3/v3_shift_along_direction.d.ts +14 -0
- package/src/core/geom/vec3/v3_shift_along_direction.d.ts.map +1 -0
- package/src/core/geom/vec3/v3_shift_along_direction.js +23 -0
- package/src/core/math/compute_legendre_polynomial.d.ts +10 -0
- package/src/core/math/compute_legendre_polynomial.d.ts.map +1 -0
- package/src/core/math/compute_legendre_polynomial.js +46 -0
- package/src/core/math/statistics/softmax.d.ts +11 -0
- package/src/core/math/statistics/softmax.d.ts.map +1 -0
- package/src/core/math/statistics/softmax.js +24 -0
- package/src/core/math/statistics/softmax.spec.d.ts +2 -0
- package/src/core/math/statistics/softmax.spec.d.ts.map +1 -0
- package/src/core/math/statistics/softmax.spec.js +9 -0
- package/src/engine/ecs/transform/Transform.d.ts.map +1 -1
- package/src/engine/ecs/transform/Transform.js +19 -4
- package/src/engine/graphics/ecs/camera/CameraSystem.d.ts.map +1 -1
- package/src/engine/graphics/ecs/camera/CameraSystem.js +25 -13
- package/src/engine/graphics/geometry/decode_attribute_value.d.ts +10 -0
- package/src/engine/graphics/geometry/decode_attribute_value.d.ts.map +1 -0
- package/src/engine/graphics/geometry/decode_attribute_value.js +28 -0
- package/src/engine/graphics/geometry/geometry_construct_triangle_normal.d.ts +11 -0
- package/src/engine/graphics/geometry/geometry_construct_triangle_normal.d.ts.map +1 -0
- package/src/engine/graphics/geometry/geometry_construct_triangle_normal.js +31 -0
- package/src/engine/graphics/sh3/lpv/LightProbeVolume.d.ts.map +1 -1
- package/src/engine/graphics/sh3/lpv/LightProbeVolume.js +0 -86
- package/src/engine/graphics/sh3/lpv/WebGLCubeProbeRenderer.d.ts +1 -0
- package/src/engine/graphics/sh3/lpv/WebGLCubeProbeRenderer.d.ts.map +1 -1
- package/src/engine/graphics/sh3/lpv/WebGLCubeProbeRenderer.js +6 -2
- package/src/engine/graphics/sh3/path_tracer/{GeometryBVHBatched.d.ts → BufferedGeometryBVH.d.ts} +9 -2
- package/src/engine/graphics/sh3/path_tracer/BufferedGeometryBVH.d.ts.map +1 -0
- package/src/engine/graphics/sh3/path_tracer/{GeometryBVHBatched.js → BufferedGeometryBVH.js} +84 -5
- package/src/engine/graphics/sh3/path_tracer/PathTracedMesh.d.ts +6 -4
- package/src/engine/graphics/sh3/path_tracer/PathTracedMesh.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/PathTracedMesh.js +54 -8
- package/src/engine/graphics/sh3/path_tracer/PathTracedScene.d.ts +6 -10
- package/src/engine/graphics/sh3/path_tracer/PathTracedScene.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/PathTracedScene.js +41 -47
- package/src/engine/graphics/sh3/path_tracer/material/MaterialConverter.d.ts +11 -0
- package/src/engine/graphics/sh3/path_tracer/material/MaterialConverter.d.ts.map +1 -0
- package/src/engine/graphics/sh3/path_tracer/material/MaterialConverter.js +102 -0
- package/src/engine/graphics/sh3/path_tracer/material/StandardMaterial.d.ts +9 -0
- package/src/engine/graphics/sh3/path_tracer/material/StandardMaterial.d.ts.map +1 -0
- package/src/engine/graphics/sh3/path_tracer/material/StandardMaterial.js +17 -0
- package/src/engine/graphics/sh3/path_tracer/material/StandardTexture.d.ts +31 -0
- package/src/engine/graphics/sh3/path_tracer/material/StandardTexture.d.ts.map +1 -0
- package/src/engine/graphics/sh3/path_tracer/material/StandardTexture.js +85 -0
- package/src/engine/graphics/sh3/path_tracer/material/TextureFilter.d.ts +14 -0
- package/src/engine/graphics/sh3/path_tracer/material/TextureFilter.d.ts.map +1 -0
- package/src/engine/graphics/sh3/path_tracer/material/TextureFilter.js +17 -0
- package/src/engine/graphics/sh3/path_tracer/material/TextureWrapping.d.ts +7 -0
- package/src/engine/graphics/sh3/path_tracer/material/TextureWrapping.d.ts.map +1 -0
- package/src/engine/graphics/sh3/path_tracer/material/TextureWrapping.js +9 -0
- package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +104 -9
- package/src/engine/graphics/sh3/path_tracer/texture/sample_material.d.ts +1 -2
- 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 +50 -23
- package/src/engine/graphics/sh3/prototypeSH3Probe.js +62 -28
- package/src/engine/graphics/texture/sampler/one_pixel_sampler_uint8.d.ts +8 -0
- package/src/engine/graphics/texture/sampler/one_pixel_sampler_uint8.d.ts.map +1 -0
- package/src/engine/graphics/texture/sampler/one_pixel_sampler_uint8.js +10 -0
- package/src/engine/graphics/texture/sampler/sampler_multiply_vector.d.ts +8 -0
- package/src/engine/graphics/texture/sampler/sampler_multiply_vector.d.ts.map +1 -0
- package/src/engine/graphics/texture/sampler/sampler_multiply_vector.js +23 -0
- package/src/core/binary/de_interleave_bits_by_2.d.ts.map +0 -1
- package/src/core/geom/3d/sphere/harmonics/sh3_rotate.d.ts +0 -8
- package/src/core/geom/3d/sphere/harmonics/sh3_rotate.d.ts.map +0 -1
- package/src/engine/graphics/sh3/path_tracer/GeometryBVHBatched.d.ts.map +0 -1
- /package/src/core/binary/{de_interleave_bits_by_2.js → de_interleave_2_bits.js} +0 -0
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import { assert } from "../../../../core/assert.js";
|
|
2
2
|
import { BVH } from "../../../../core/bvh2/bvh3/BVH.js";
|
|
3
3
|
import { ebvh_sort_for_traversal_depth_first } from "../../../../core/bvh2/bvh3/ebvh_sort_for_traversal_depth_first.js";
|
|
4
|
-
import {
|
|
4
|
+
import { bvh_query_leaves_ray } from "../../../../core/bvh2/bvh3/query/bvh_query_leaves_ray.js";
|
|
5
|
+
import { Cache } from "../../../../core/cache/Cache.js";
|
|
5
6
|
import { array_copy } from "../../../../core/collection/array/array_copy.js";
|
|
7
|
+
import { strictEquals } from "../../../../core/function/strictEquals.js";
|
|
6
8
|
import { aabb3_matrix4_project } from "../../../../core/geom/3d/aabb/aabb3_matrix4_project.js";
|
|
9
|
+
import {
|
|
10
|
+
aabb3_unsigned_distance_sqr_to_point
|
|
11
|
+
} from "../../../../core/geom/3d/aabb/aabb3_unsigned_distance_sqr_to_point.js";
|
|
7
12
|
import { ray3_array_compose } from "../../../../core/geom/3d/ray/ray3_array_compose.js";
|
|
8
13
|
import { v3_dot } from "../../../../core/geom/vec3/v3_dot.js";
|
|
9
|
-
import { TextureAttachmentsByMaterialType } from "../../../asset/loaders/material/TextureAttachmensByMaterialType.js";
|
|
10
14
|
import { compute_geometry_polycount } from "../../geometry/compute_geometry_polycount.js";
|
|
11
15
|
import { AbstractLight } from "../../render/forward_plus/model/AbstractLight.js";
|
|
12
|
-
import { convertTexture2Sampler2D } from "../../texture/sampler/convertTexture2Sampler2D.js";
|
|
13
16
|
import { ensureGeometryBoundingBox } from "../../util/ensureGeometryBoundingBox.js";
|
|
14
|
-
import {
|
|
17
|
+
import { BufferedGeometryBVH } from "./BufferedGeometryBVH.js";
|
|
15
18
|
import { make_vector3 } from "./make_one_vector3.js";
|
|
19
|
+
import { MaterialConverter } from "./material/MaterialConverter.js";
|
|
16
20
|
import { PathTracedMesh } from "./PathTracedMesh.js";
|
|
17
21
|
import { sample_material } from "./texture/sample_material.js";
|
|
18
22
|
|
|
@@ -21,6 +25,9 @@ const _ray_1 = [];
|
|
|
21
25
|
const tmp_0 = [];
|
|
22
26
|
const null_output = [];
|
|
23
27
|
|
|
28
|
+
const DEFAULT_CONVERTER = new MaterialConverter();
|
|
29
|
+
|
|
30
|
+
|
|
24
31
|
export class PathTracedScene {
|
|
25
32
|
|
|
26
33
|
|
|
@@ -44,16 +51,20 @@ export class PathTracedScene {
|
|
|
44
51
|
|
|
45
52
|
/**
|
|
46
53
|
*
|
|
47
|
-
* @type {Map<THREE.BufferGeometry,
|
|
54
|
+
* @type {Map<THREE.BufferGeometry, BufferedGeometryBVH>}
|
|
48
55
|
*/
|
|
49
56
|
geo_cache = new Map();
|
|
50
57
|
|
|
51
58
|
/**
|
|
52
|
-
*
|
|
53
|
-
* @type {
|
|
59
|
+
*
|
|
60
|
+
* @type {Cache<THREE.Material, StandardMaterial>}
|
|
54
61
|
*/
|
|
55
|
-
|
|
56
|
-
|
|
62
|
+
#material_cache = new Cache({
|
|
63
|
+
keyEqualityFunction: strictEquals,
|
|
64
|
+
keyHashFunction(mat) {
|
|
65
|
+
return mat.id
|
|
66
|
+
}
|
|
67
|
+
});
|
|
57
68
|
|
|
58
69
|
/**
|
|
59
70
|
*
|
|
@@ -72,44 +83,13 @@ export class PathTracedScene {
|
|
|
72
83
|
for (const [id, mesh] of this.meshes) {
|
|
73
84
|
const material = mesh.material;
|
|
74
85
|
|
|
75
|
-
//patch textures
|
|
76
|
-
const materialType = material.type;
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
*
|
|
80
|
-
* @type {TextureAttachment[]}
|
|
81
|
-
*/
|
|
82
|
-
const attachments = TextureAttachmentsByMaterialType[materialType];
|
|
83
|
-
|
|
84
|
-
if (attachments === undefined) {
|
|
85
|
-
// unsupported
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
for (let i = 0; i < attachments.length; i++) {
|
|
90
|
-
const attachment = attachments[i];
|
|
91
|
-
|
|
92
|
-
const texture = attachment.read(material);
|
|
93
|
-
|
|
94
|
-
if (texture === undefined || texture === null) {
|
|
95
|
-
continue;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (this.textures.has(texture.id)) {
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const sampler2D = convertTexture2Sampler2D(texture, undefined, undefined, false);
|
|
103
|
-
|
|
104
|
-
this.textures.set(texture.id, sampler2D);
|
|
105
|
-
}
|
|
106
86
|
}
|
|
107
87
|
}
|
|
108
88
|
|
|
109
89
|
/**
|
|
110
90
|
*
|
|
111
91
|
* @param {THREE.BufferGeometry} geo
|
|
112
|
-
* @return {
|
|
92
|
+
* @return {BufferedGeometryBVH}
|
|
113
93
|
*/
|
|
114
94
|
obtainGeometryBVH(geo) {
|
|
115
95
|
const cached = this.geo_cache.get(geo);
|
|
@@ -118,7 +98,7 @@ export class PathTracedScene {
|
|
|
118
98
|
return cached;
|
|
119
99
|
}
|
|
120
100
|
|
|
121
|
-
const bvh = new
|
|
101
|
+
const bvh = new BufferedGeometryBVH();
|
|
122
102
|
|
|
123
103
|
const label = `bvh build ${compute_geometry_polycount(geo)}`;
|
|
124
104
|
console.time(label);
|
|
@@ -151,12 +131,13 @@ export class PathTracedScene {
|
|
|
151
131
|
|
|
152
132
|
const mesh = new PathTracedMesh();
|
|
153
133
|
mesh.geometry = geo;
|
|
154
|
-
mesh.material = material;
|
|
155
|
-
mesh.transform = transform;
|
|
156
134
|
|
|
135
|
+
mesh.material = this.#material_cache.getOrCompute(material, DEFAULT_CONVERTER.convert, DEFAULT_CONVERTER);
|
|
157
136
|
|
|
158
137
|
mesh.geo_bvh = this.obtainGeometryBVH(geo);
|
|
159
138
|
|
|
139
|
+
mesh.transform = transform;
|
|
140
|
+
|
|
160
141
|
const bvh = this.bvh_top_level;
|
|
161
142
|
|
|
162
143
|
const bvh_node_id = bvh.allocate_node();
|
|
@@ -217,7 +198,7 @@ export class PathTracedScene {
|
|
|
217
198
|
return;
|
|
218
199
|
}
|
|
219
200
|
|
|
220
|
-
sample_material(out, mesh,
|
|
201
|
+
sample_material(out, mesh, primitive_id, u, v);
|
|
221
202
|
|
|
222
203
|
}
|
|
223
204
|
|
|
@@ -232,7 +213,7 @@ export class PathTracedScene {
|
|
|
232
213
|
trace(out, ray, min_distance, max_distance) {
|
|
233
214
|
const bvh = this.bvh_top_level;
|
|
234
215
|
|
|
235
|
-
const hit_count =
|
|
216
|
+
const hit_count = bvh_query_leaves_ray(
|
|
236
217
|
bvh, bvh.root,
|
|
237
218
|
temp_ray_results, 0,
|
|
238
219
|
ray[0], ray[1], ray[2],
|
|
@@ -244,7 +225,20 @@ export class PathTracedScene {
|
|
|
244
225
|
|
|
245
226
|
|
|
246
227
|
for (let i = 0; i < hit_count; i++) {
|
|
247
|
-
const
|
|
228
|
+
const node = temp_ray_results[i];
|
|
229
|
+
|
|
230
|
+
bvh.node_get_aabb(node, tmp_0);
|
|
231
|
+
|
|
232
|
+
if (aabb3_unsigned_distance_sqr_to_point(
|
|
233
|
+
tmp_0[0], tmp_0[1], tmp_0[2],
|
|
234
|
+
tmp_0[3], tmp_0[4], tmp_0[5],
|
|
235
|
+
ray[0], ray[1], ray[2]
|
|
236
|
+
) > nearest_hit_distance * nearest_hit_distance) {
|
|
237
|
+
// bounds of the mesh are too far
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const node_user_data = bvh.node_get_user_data(node);
|
|
248
242
|
|
|
249
243
|
const mesh = this.meshes.get(node_user_data);
|
|
250
244
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export class MaterialConverter {
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param {THREE.Material} material
|
|
5
|
+
* @returns {StandardMaterial}
|
|
6
|
+
*/
|
|
7
|
+
convert(material: THREE.Material): StandardMaterial;
|
|
8
|
+
#private;
|
|
9
|
+
}
|
|
10
|
+
import { StandardMaterial } from "./StandardMaterial.js";
|
|
11
|
+
//# sourceMappingURL=MaterialConverter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MaterialConverter.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/path_tracer/material/MaterialConverter.js"],"names":[],"mappings":"AASA;IA4BI;;;;OAIG;IACH,kBAHW,MAAM,QAAQ,GACZ,gBAAgB,CA2D5B;;CAEJ;iCA/FgC,uBAAuB"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { Color } from "three";
|
|
2
|
+
import {
|
|
3
|
+
TextureAttachmentsByMaterialType
|
|
4
|
+
} from "../../../../asset/loaders/material/TextureAttachmensByMaterialType.js";
|
|
5
|
+
import { convertTexture2Sampler2D } from "../../../texture/sampler/convertTexture2Sampler2D.js";
|
|
6
|
+
import { sampler_multiply_vector } from "../../../texture/sampler/sampler_multiply_vector.js";
|
|
7
|
+
import { StandardMaterial } from "./StandardMaterial.js";
|
|
8
|
+
import { StandardTexture } from "./StandardTexture.js";
|
|
9
|
+
|
|
10
|
+
export class MaterialConverter {
|
|
11
|
+
/**
|
|
12
|
+
* Maps {@link Texture.id} to relevant sampler
|
|
13
|
+
* @type {Map<number, StandardTexture>}
|
|
14
|
+
*/
|
|
15
|
+
#textures = new Map();
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @param {THREE.Texture} texture
|
|
20
|
+
* @returns {StandardTexture}
|
|
21
|
+
*/
|
|
22
|
+
#ensure_texture(texture) {
|
|
23
|
+
const existing = this.#textures.get(texture.id);
|
|
24
|
+
|
|
25
|
+
if (existing !== undefined) {
|
|
26
|
+
return existing
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const sampler2D = convertTexture2Sampler2D(texture, undefined, undefined, false);
|
|
30
|
+
|
|
31
|
+
const st = StandardTexture.from(sampler2D);
|
|
32
|
+
|
|
33
|
+
this.#textures.set(texture.id, st);
|
|
34
|
+
|
|
35
|
+
return st;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @param {THREE.Material} material
|
|
41
|
+
* @returns {StandardMaterial}
|
|
42
|
+
*/
|
|
43
|
+
convert(material) {
|
|
44
|
+
|
|
45
|
+
const result = new StandardMaterial();
|
|
46
|
+
|
|
47
|
+
//patch textures
|
|
48
|
+
const materialType = material.type;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
*
|
|
52
|
+
* @type {TextureAttachment[]}
|
|
53
|
+
*/
|
|
54
|
+
const attachments = TextureAttachmentsByMaterialType[materialType];
|
|
55
|
+
|
|
56
|
+
if (attachments !== undefined) {
|
|
57
|
+
|
|
58
|
+
for (let i = 0; i < attachments.length; i++) {
|
|
59
|
+
const attachment = attachments[i];
|
|
60
|
+
|
|
61
|
+
const texture = attachment.read(material);
|
|
62
|
+
|
|
63
|
+
if (texture === undefined || texture === null) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const sampler = this.#ensure_texture(texture);
|
|
68
|
+
|
|
69
|
+
const name = attachment.name;
|
|
70
|
+
|
|
71
|
+
if (name === "diffuse") {
|
|
72
|
+
result.diffuse = sampler;
|
|
73
|
+
} else if (name === "normal") {
|
|
74
|
+
result.normal = sampler;
|
|
75
|
+
} else if (name === "metalness") {
|
|
76
|
+
result.metalness = sampler;
|
|
77
|
+
} else if (name === "roughness") {
|
|
78
|
+
result.roughness = sampler;
|
|
79
|
+
} else if (name === "emissive") {
|
|
80
|
+
result.emissive = sampler;
|
|
81
|
+
} else {
|
|
82
|
+
// unused
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (material.color !== undefined && !material.color.equals(new Color(1, 1, 1))) {
|
|
90
|
+
const tinted_diffuse = result.diffuse.clone();
|
|
91
|
+
|
|
92
|
+
tinted_diffuse.sampler = tinted_diffuse.sampler.clone();
|
|
93
|
+
|
|
94
|
+
sampler_multiply_vector(tinted_diffuse.sampler, result.diffuse.sampler, material.color.toArray());
|
|
95
|
+
|
|
96
|
+
result.diffuse = tinted_diffuse;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export class StandardMaterial {
|
|
2
|
+
diffuse: StandardTexture;
|
|
3
|
+
normal: StandardTexture;
|
|
4
|
+
emissive: StandardTexture;
|
|
5
|
+
roughness: StandardTexture;
|
|
6
|
+
metalness: StandardTexture;
|
|
7
|
+
}
|
|
8
|
+
import { StandardTexture } from "./StandardTexture.js";
|
|
9
|
+
//# sourceMappingURL=StandardMaterial.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StandardMaterial.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/path_tracer/material/StandardMaterial.js"],"names":[],"mappings":"AASA;IACI,yBAA+C;IAC/C,wBAA6C;IAC7C,0BAAiD;IACjD,2BAAmD;IACnD,2BAAmD;CACtD;gCAd+B,sBAAsB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { one_pixel_sampler_uint8 } from "../../../texture/sampler/one_pixel_sampler_uint8.js";
|
|
2
|
+
import { StandardTexture } from "./StandardTexture.js";
|
|
3
|
+
|
|
4
|
+
const DEFAULT_DIFFUSE = one_pixel_sampler_uint8([255, 255, 255, 255]);
|
|
5
|
+
const DEFAULT_NORMAL = one_pixel_sampler_uint8([0, 0, 255]);
|
|
6
|
+
const DEFAULT_EMISSIVE = one_pixel_sampler_uint8([0, 0, 0]);
|
|
7
|
+
const DEFAULT_ROUGHNESS = one_pixel_sampler_uint8([255]);
|
|
8
|
+
const DEFAULT_METALNESS = one_pixel_sampler_uint8([0]);
|
|
9
|
+
|
|
10
|
+
export class StandardMaterial {
|
|
11
|
+
diffuse = StandardTexture.from(DEFAULT_DIFFUSE)
|
|
12
|
+
normal = StandardTexture.from(DEFAULT_NORMAL)
|
|
13
|
+
emissive = StandardTexture.from(DEFAULT_EMISSIVE)
|
|
14
|
+
roughness = StandardTexture.from(DEFAULT_ROUGHNESS)
|
|
15
|
+
metalness = StandardTexture.from(DEFAULT_METALNESS)
|
|
16
|
+
}
|
|
17
|
+
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export class StandardTexture {
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param {Sampler2D} sampler
|
|
5
|
+
* @returns {StandardTexture}
|
|
6
|
+
*/
|
|
7
|
+
static from(sampler: Sampler2D): StandardTexture;
|
|
8
|
+
/**
|
|
9
|
+
* @type {Sampler2D}
|
|
10
|
+
*/
|
|
11
|
+
sampler: Sampler2D;
|
|
12
|
+
magFilter: number;
|
|
13
|
+
type: BinaryDataType;
|
|
14
|
+
wrapS: number;
|
|
15
|
+
wrapT: number;
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* @param {StandardTexture} other
|
|
19
|
+
*/
|
|
20
|
+
copy(other: StandardTexture): void;
|
|
21
|
+
clone(): StandardTexture;
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @param {number[]|Float32Array} out
|
|
25
|
+
* @param {number} u
|
|
26
|
+
* @param {number} v
|
|
27
|
+
*/
|
|
28
|
+
sample(out: number[] | Float32Array, u: number, v: number): void;
|
|
29
|
+
}
|
|
30
|
+
import { BinaryDataType } from "../../../../../core/binary/type/BinaryDataType.js";
|
|
31
|
+
//# sourceMappingURL=StandardTexture.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StandardTexture.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/path_tracer/material/StandardTexture.js"],"names":[],"mappings":"AAOA;IA8BI;;;;OAIG;IACH,iCAFa,eAAe,CAQ3B;IAxCD;;OAEG;IACH,mBAAO;IACP,kBAAsC;IACtC,qBAA2B;IAC3B,cAA2C;IAC3C,cAA2C;IAE3C;;;OAGG;IACH,YAFW,eAAe,QAQzB;IAED,yBAMC;IAeD;;;;;OAKG;IACH,YAJW,MAAM,EAAE,GAAC,YAAY,KACrB,MAAM,KACN,MAAM,QA6BhB;CACJ;+BAnF8B,mDAAmD"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { LinearFilter, LinearMipmapLinearFilter, NearestFilter, NearestMipMapLinearFilter } from "three";
|
|
2
|
+
import { BinaryDataType } from "../../../../../core/binary/type/BinaryDataType.js";
|
|
3
|
+
import { apply_texture_clamping_to_coordinate } from "../texture/apply_texture_clamping_to_coordinate.js";
|
|
4
|
+
import { vec3_uint8_to_float } from "../vec3_uint8_to_float.js";
|
|
5
|
+
import { TextureFilter } from "./TextureFilter.js";
|
|
6
|
+
import { TextureWrapping } from "./TextureWrapping.js";
|
|
7
|
+
|
|
8
|
+
export class StandardTexture {
|
|
9
|
+
/**
|
|
10
|
+
* @type {Sampler2D}
|
|
11
|
+
*/
|
|
12
|
+
sampler
|
|
13
|
+
magFilter = TextureFilter.LinearFilter
|
|
14
|
+
type = BinaryDataType.Uint8
|
|
15
|
+
wrapS = TextureWrapping.ClampToEdgeWrapping
|
|
16
|
+
wrapT = TextureWrapping.ClampToEdgeWrapping
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @param {StandardTexture} other
|
|
21
|
+
*/
|
|
22
|
+
copy(other) {
|
|
23
|
+
this.sampler = other.sampler
|
|
24
|
+
this.magFilter = other.magFilter
|
|
25
|
+
this.type = other.type
|
|
26
|
+
this.wrapS = other.wrapS
|
|
27
|
+
this.wrapT = other.wrapT
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
clone() {
|
|
31
|
+
const r = new StandardTexture();
|
|
32
|
+
|
|
33
|
+
r.copy(this);
|
|
34
|
+
|
|
35
|
+
return r;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @param {Sampler2D} sampler
|
|
41
|
+
* @returns {StandardTexture}
|
|
42
|
+
*/
|
|
43
|
+
static from(sampler) {
|
|
44
|
+
const texture = new StandardTexture();
|
|
45
|
+
|
|
46
|
+
texture.sampler = sampler;
|
|
47
|
+
|
|
48
|
+
return texture;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
*
|
|
53
|
+
* @param {number[]|Float32Array} out
|
|
54
|
+
* @param {number} u
|
|
55
|
+
* @param {number} v
|
|
56
|
+
*/
|
|
57
|
+
sample(out, u, v) {
|
|
58
|
+
|
|
59
|
+
const _u = apply_texture_clamping_to_coordinate(this.wrapS, u);
|
|
60
|
+
const _v = apply_texture_clamping_to_coordinate(this.wrapT, v);
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
const magFilter = this.magFilter;
|
|
64
|
+
|
|
65
|
+
const sampler = this.sampler;
|
|
66
|
+
|
|
67
|
+
switch (magFilter) {
|
|
68
|
+
default:
|
|
69
|
+
case NearestFilter:
|
|
70
|
+
case NearestMipMapLinearFilter:
|
|
71
|
+
sampler.sampleNearestUV(_u, _v, out);
|
|
72
|
+
break;
|
|
73
|
+
|
|
74
|
+
case LinearFilter:
|
|
75
|
+
case LinearMipmapLinearFilter:
|
|
76
|
+
|
|
77
|
+
sampler.sampleBilinearUV(_u, _v, out);
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (this.type === BinaryDataType.Uint8) {
|
|
82
|
+
vec3_uint8_to_float(out, out);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type TextureFilter = number;
|
|
2
|
+
export namespace TextureFilter {
|
|
3
|
+
let NearestFilter: number;
|
|
4
|
+
let NearestMipmapNearestFilter: number;
|
|
5
|
+
let NearestMipMapNearestFilter: number;
|
|
6
|
+
let NearestMipmapLinearFilter: number;
|
|
7
|
+
let NearestMipMapLinearFilter: number;
|
|
8
|
+
let LinearFilter: number;
|
|
9
|
+
let LinearMipmapNearestFilter: number;
|
|
10
|
+
let LinearMipMapNearestFilter: number;
|
|
11
|
+
let LinearMipmapLinearFilter: number;
|
|
12
|
+
let LinearMipMapLinearFilter: number;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=TextureFilter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextureFilter.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/path_tracer/material/TextureFilter.js"],"names":[],"mappings":"4BACU,MAAM"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @enum {number}
|
|
3
|
+
*/
|
|
4
|
+
export const TextureFilter = {
|
|
5
|
+
|
|
6
|
+
NearestFilter: 1003,
|
|
7
|
+
NearestMipmapNearestFilter: 1004,
|
|
8
|
+
NearestMipMapNearestFilter: 1004,
|
|
9
|
+
NearestMipmapLinearFilter: 1005,
|
|
10
|
+
NearestMipMapLinearFilter: 1005,
|
|
11
|
+
LinearFilter: 1006,
|
|
12
|
+
LinearMipmapNearestFilter: 1007,
|
|
13
|
+
LinearMipMapNearestFilter: 1007,
|
|
14
|
+
LinearMipmapLinearFilter: 1008,
|
|
15
|
+
LinearMipMapLinearFilter: 1008
|
|
16
|
+
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextureWrapping.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/path_tracer/material/TextureWrapping.js"],"names":[],"mappings":"8BACU,MAAM"}
|
|
@@ -34,6 +34,7 @@ import { Transform } from "../../../ecs/transform/Transform.js";
|
|
|
34
34
|
import { MouseEvents } from "../../../input/devices/events/MouseEvents.js";
|
|
35
35
|
import { makeSimpleTaskProgressView } from "../../../makeSimpleTaskProgressView.js";
|
|
36
36
|
import { Camera } from "../../ecs/camera/Camera.js";
|
|
37
|
+
import { three_camera_set_transform_rotation } from "../../ecs/camera/CameraSystem.js";
|
|
37
38
|
import { makeGeometryIndexed } from "../../geometry/buffered/makeGeometryIndexed.js";
|
|
38
39
|
import { DirectionalLight } from "../../render/forward_plus/model/DirectionalLight.js";
|
|
39
40
|
import { sampler2d_scale } from "../../texture/sampler/resize/sampler2d_scale.js";
|
|
@@ -73,7 +74,7 @@ vCanvas.css({
|
|
|
73
74
|
* How many rays to use per-pixel
|
|
74
75
|
* @type {number}
|
|
75
76
|
*/
|
|
76
|
-
const PIXEL_SAMPLE_COUNT =
|
|
77
|
+
const PIXEL_SAMPLE_COUNT = 256;
|
|
77
78
|
|
|
78
79
|
const scene = new PathTracedScene();
|
|
79
80
|
const pt = new PathTracer();
|
|
@@ -164,10 +165,19 @@ function promise_gltf(url) {
|
|
|
164
165
|
* @param {PathTracedScene} scene
|
|
165
166
|
* @param {THREE.Camera} camera
|
|
166
167
|
* @param {string} url
|
|
167
|
-
* @param zoom
|
|
168
|
+
* @param {number} [zoom]
|
|
169
|
+
* @param {number} [floor_level]
|
|
170
|
+
* @param {Object} [sun]
|
|
168
171
|
* @return {Promise<void>}
|
|
169
172
|
*/
|
|
170
|
-
async function prepare_scene_gltf(
|
|
173
|
+
async function prepare_scene_gltf({
|
|
174
|
+
scene,
|
|
175
|
+
camera,
|
|
176
|
+
url,
|
|
177
|
+
zoom = 1,
|
|
178
|
+
floor_level = 0,
|
|
179
|
+
sun
|
|
180
|
+
}) {
|
|
171
181
|
const gltf = await promise_gltf(url);
|
|
172
182
|
|
|
173
183
|
|
|
@@ -175,7 +185,7 @@ async function prepare_scene_gltf(scene, camera, url, zoom = 1) {
|
|
|
175
185
|
color: '#ffceae'
|
|
176
186
|
});
|
|
177
187
|
scene.addMesh(new PlaneBufferGeometry(), ground_material, Transform.fromJSON({
|
|
178
|
-
position: new Vector3(0,
|
|
188
|
+
position: new Vector3(0, floor_level, 0),
|
|
179
189
|
scale: 5000,
|
|
180
190
|
rotation: Quaternion.fromEulerAngles(-Math.PI / 2, 0, 0)
|
|
181
191
|
}).matrix);
|
|
@@ -196,7 +206,7 @@ async function prepare_scene_gltf(scene, camera, url, zoom = 1) {
|
|
|
196
206
|
|
|
197
207
|
box3.getBoundingSphere(sphere);
|
|
198
208
|
|
|
199
|
-
scene.addLight(make_sun());
|
|
209
|
+
scene.addLight(make_sun(sun));
|
|
200
210
|
|
|
201
211
|
camera.position.set(1, 1.3, 1)
|
|
202
212
|
.normalize()
|
|
@@ -241,6 +251,88 @@ async function prepare_scene_lucy(scene, camera) {
|
|
|
241
251
|
camera.lookAt(0, 0, 0);
|
|
242
252
|
}
|
|
243
253
|
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
*
|
|
257
|
+
* @param {THREE.Camera} camera
|
|
258
|
+
* @param {Transform} transform
|
|
259
|
+
*/
|
|
260
|
+
function set_camera_from_transform(camera, transform) {
|
|
261
|
+
camera.position.copy(transform.position);
|
|
262
|
+
three_camera_set_transform_rotation(camera, transform.rotation);
|
|
263
|
+
|
|
264
|
+
camera.updateMatrixWorld();
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
*
|
|
269
|
+
* @param {PathTracedScene} scene
|
|
270
|
+
* @param {THREE.Camera} camera
|
|
271
|
+
* @returns {Promise<void>}
|
|
272
|
+
*/
|
|
273
|
+
async function prepare_gi_box_scene(scene, camera) {
|
|
274
|
+
const path = 'data/models/samples/gi_box_01/model.glb';
|
|
275
|
+
await prepare_scene_gltf({
|
|
276
|
+
scene: scene,
|
|
277
|
+
camera: camera,
|
|
278
|
+
url: path,
|
|
279
|
+
sun: {
|
|
280
|
+
direction: new Vector3(1.2, -1, 0.2)
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
const transform = Transform.fromJSON({
|
|
285
|
+
"position": { "x": -2.320852352090763, "y": 4.765851637629835, "z": 5.154489928319274 },
|
|
286
|
+
"rotation": {
|
|
287
|
+
"x": 0.00480805808535541,
|
|
288
|
+
"y": 0.9797795216336188,
|
|
289
|
+
"z": -0.19861114162102378,
|
|
290
|
+
"w": 0.02371889518587569
|
|
291
|
+
},
|
|
292
|
+
"scale": {
|
|
293
|
+
"x": 1, "y": 1, "z": 1
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
set_camera_from_transform(camera, transform);
|
|
298
|
+
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
*
|
|
303
|
+
* @param {PathTracedScene} scene
|
|
304
|
+
* @param {THREE.Camera} camera
|
|
305
|
+
* @returns {Promise<void>}
|
|
306
|
+
*/
|
|
307
|
+
async function prepare_sponza(scene, camera) {
|
|
308
|
+
const path = 'data/models/sponza-pbr/gltf/sponza.glb';
|
|
309
|
+
await prepare_scene_gltf({
|
|
310
|
+
scene: scene,
|
|
311
|
+
camera: camera,
|
|
312
|
+
url: path,
|
|
313
|
+
sun: {
|
|
314
|
+
direction: new Vector3(0.2, -1, 0.2)
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
const transform = Transform.fromJSON({
|
|
319
|
+
"position": {
|
|
320
|
+
"x": -5.888122646477855,
|
|
321
|
+
"y": 4.631130854487186,
|
|
322
|
+
"z": -0.35698656745007035
|
|
323
|
+
},
|
|
324
|
+
"rotation": {
|
|
325
|
+
"x": 0.10780203229473442,
|
|
326
|
+
"y": 0.6847605545801206,
|
|
327
|
+
"z": -0.10349143573419042,
|
|
328
|
+
"w": 0.7132820111666399
|
|
329
|
+
},
|
|
330
|
+
"scale": { "x": 1, "y": 1, "z": 1 }
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
set_camera_from_transform(camera, transform);
|
|
334
|
+
}
|
|
335
|
+
|
|
244
336
|
/**
|
|
245
337
|
* Ray-Tracing In One Weekend test scene
|
|
246
338
|
* @param {PathTracer} pt
|
|
@@ -446,7 +538,7 @@ function* render(target, pt, camera, scene, progress = { current: 0, total: 0 })
|
|
|
446
538
|
ray_direction.x, ray_direction.y, ray_direction.z
|
|
447
539
|
);
|
|
448
540
|
|
|
449
|
-
pt.path_trace(pixel_color, ray, Infinity,
|
|
541
|
+
pt.path_trace(pixel_color, ray, Infinity, 1, 7, random, scene);
|
|
450
542
|
|
|
451
543
|
pixel_accummulation[0] += pixel_color[0];
|
|
452
544
|
pixel_accummulation[1] += pixel_color[1];
|
|
@@ -501,13 +593,16 @@ async function start_renderer(camera) {
|
|
|
501
593
|
camera.aspect = vCanvas.size.x / vCanvas.size.y;
|
|
502
594
|
|
|
503
595
|
// const path = 'data/models/LowPolyTownshipSet/Small_house/Small_house.gltf';
|
|
504
|
-
const path = 'data/models/pica_pica/pica_pica.gltf';
|
|
596
|
+
// const path = 'data/models/pica_pica/pica_pica.gltf';
|
|
505
597
|
// const path = 'data/models/road_bike/road_bike.gltf'; //large CAD-type model
|
|
506
598
|
|
|
507
599
|
// await prepare_scene_lucy(scene, camera);
|
|
508
|
-
|
|
600
|
+
await prepare_scene_rtiow(pt, camera);
|
|
509
601
|
// await prepare_scene_sphere_01(pt, camera);
|
|
510
|
-
await
|
|
602
|
+
// await prepare_gi_box_scene(scene, camera);
|
|
603
|
+
// await prepare_sponza(scene, camera);
|
|
604
|
+
// await prepare_scene_gltf(scene, camera, path);
|
|
605
|
+
|
|
511
606
|
|
|
512
607
|
await scene.build();
|
|
513
608
|
// pt.optimize();
|