@woosh/meep-engine 2.109.4 → 2.109.6
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 +115 -17
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +115 -17
- package/package.json +1 -1
- package/src/core/collection/queue/Deque.d.ts.map +1 -1
- package/src/core/collection/queue/Deque.js +58 -4
- 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/texture/virtual/prototype.js +4 -3
- 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
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { vec3 } from "gl-matrix";
|
|
2
|
+
import { Box3, MeshStandardMaterial, PlaneBufferGeometry, Sphere } from "three";
|
|
3
|
+
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
4
|
+
import { Color } from "../../../../core/color/Color.js";
|
|
5
|
+
import { kelvin_to_rgb } from "../../../../core/color/kelvin/kelvin_to_rgb.js";
|
|
6
|
+
import { noop } from "../../../../core/function/noop.js";
|
|
7
|
+
import Quaternion from "../../../../core/geom/Quaternion.js";
|
|
8
|
+
import Vector3 from "../../../../core/geom/Vector3.js";
|
|
9
|
+
import { Transform } from "../../../ecs/transform/Transform.js";
|
|
10
|
+
import { DirectionalLight } from "../../render/forward_plus/model/DirectionalLight.js";
|
|
11
|
+
import { three_object_replace_materials } from "../../three/three_object_replace_materials.js";
|
|
12
|
+
import { three_object_to_path_traced_scene } from "./three_object_to_path_traced_scene.js";
|
|
13
|
+
|
|
14
|
+
export function make_sun({
|
|
15
|
+
temperature = 5000, // around clear-sky day
|
|
16
|
+
color = '#FFFFFF',
|
|
17
|
+
intensity = 1,
|
|
18
|
+
direction = new Vector3(-0.5, -1, -0.05)
|
|
19
|
+
} = {}) {
|
|
20
|
+
|
|
21
|
+
const temp_c = new Color();
|
|
22
|
+
|
|
23
|
+
kelvin_to_rgb(temp_c, 0, temperature);
|
|
24
|
+
|
|
25
|
+
const light = new DirectionalLight();
|
|
26
|
+
|
|
27
|
+
light.color.parse(color);
|
|
28
|
+
vec3.multiply(light.color, light.color, temp_c);
|
|
29
|
+
|
|
30
|
+
const n = vec3.length(light.color);
|
|
31
|
+
vec3.scale(light.color, light.color, 1 / n); // normalize color vector
|
|
32
|
+
|
|
33
|
+
light.intensity.set(intensity * n);
|
|
34
|
+
light.direction.copy(direction);
|
|
35
|
+
light.direction.normalize();
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
return light;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
*
|
|
43
|
+
* @param {string} url
|
|
44
|
+
* @return {Promise<GLTF>}
|
|
45
|
+
*/
|
|
46
|
+
function promise_gltf(url) {
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
new GLTFLoader().load(url, resolve, noop, reject);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
*
|
|
54
|
+
* @param {PathTracedScene} scene
|
|
55
|
+
* @param {THREE.Camera} camera
|
|
56
|
+
* @param {string} url
|
|
57
|
+
* @param {number} [zoom]
|
|
58
|
+
* @param {number} [floor_level]
|
|
59
|
+
* @param {Object} [sun]
|
|
60
|
+
* @param {boolean} [no_materials]
|
|
61
|
+
* @return {Promise<void>}
|
|
62
|
+
*/
|
|
63
|
+
export async function prepare_scene_gltf({
|
|
64
|
+
scene,
|
|
65
|
+
camera,
|
|
66
|
+
url,
|
|
67
|
+
zoom = 1,
|
|
68
|
+
floor_level = 0,
|
|
69
|
+
sun,
|
|
70
|
+
no_materials = false
|
|
71
|
+
}) {
|
|
72
|
+
const gltf = await promise_gltf(url);
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
const ground_material = new MeshStandardMaterial({
|
|
76
|
+
color: '#ffceae'
|
|
77
|
+
});
|
|
78
|
+
scene.createMesh(new PlaneBufferGeometry(), ground_material, Transform.fromJSON({
|
|
79
|
+
position: new Vector3(0, floor_level, 0),
|
|
80
|
+
scale: 5000,
|
|
81
|
+
rotation: Quaternion.fromEulerAngles(-Math.PI / 2, 0, 0)
|
|
82
|
+
}).matrix);
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
const gltf_scene = gltf.scene;
|
|
86
|
+
|
|
87
|
+
if (no_materials) {
|
|
88
|
+
three_object_replace_materials(gltf_scene, new MeshStandardMaterial({ color: 'white' }));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
three_object_to_path_traced_scene(gltf_scene, scene);
|
|
92
|
+
|
|
93
|
+
const box3 = new Box3();
|
|
94
|
+
box3.setFromObject(gltf_scene);
|
|
95
|
+
|
|
96
|
+
const sphere = new Sphere();
|
|
97
|
+
|
|
98
|
+
box3.getBoundingSphere(sphere);
|
|
99
|
+
|
|
100
|
+
scene.addLight(make_sun(sun));
|
|
101
|
+
|
|
102
|
+
camera.position.set(1, 1.3, 1)
|
|
103
|
+
.normalize()
|
|
104
|
+
.multiplyScalar(sphere.radius * 2.6 * (1 / zoom));
|
|
105
|
+
|
|
106
|
+
camera.lookAt(sphere.center);
|
|
107
|
+
}
|
|
@@ -1,23 +1,15 @@
|
|
|
1
|
-
import { mat4
|
|
2
|
-
import {
|
|
3
|
-
Box3,
|
|
4
|
-
MeshStandardMaterial,
|
|
5
|
-
OctahedronBufferGeometry,
|
|
6
|
-
PerspectiveCamera,
|
|
7
|
-
PlaneBufferGeometry,
|
|
8
|
-
Sphere
|
|
9
|
-
} from "three";
|
|
10
|
-
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
1
|
+
import { mat4 } from "gl-matrix";
|
|
2
|
+
import { MeshStandardMaterial, OctahedronBufferGeometry, PerspectiveCamera, PlaneBufferGeometry } from "three";
|
|
11
3
|
import { PLYLoader } from "three/examples/jsm/loaders/PLYLoader.js";
|
|
12
4
|
|
|
13
5
|
import '../../../../../../../../css/game.scss';
|
|
14
6
|
import { float_to_uint8 } from "../../../../core/binary/float_to_uint8.js";
|
|
15
7
|
import { Color } from "../../../../core/color/Color.js";
|
|
16
|
-
import { kelvin_to_rgb } from "../../../../core/color/kelvin/kelvin_to_rgb.js";
|
|
17
8
|
import { linear_to_sRGB } from "../../../../core/color/sRGB/linear_to_sRGB.js";
|
|
18
9
|
|
|
19
10
|
import { noop } from "../../../../core/function/noop.js";
|
|
20
11
|
import { ray3_array_compose } from "../../../../core/geom/3d/ray/ray3_array_compose.js";
|
|
12
|
+
import { Ray3 } from "../../../../core/geom/3d/Ray3.js";
|
|
21
13
|
import Quaternion from "../../../../core/geom/Quaternion.js";
|
|
22
14
|
import { v3_distance } from "../../../../core/geom/vec3/v3_distance.js";
|
|
23
15
|
import Vector3 from "../../../../core/geom/Vector3.js";
|
|
@@ -40,10 +32,9 @@ import { DirectionalLight } from "../../render/forward_plus/model/DirectionalLig
|
|
|
40
32
|
import { sampler2d_scale } from "../../texture/sampler/resize/sampler2d_scale.js";
|
|
41
33
|
import { Sampler2D } from "../../texture/sampler/Sampler2D.js";
|
|
42
34
|
import sampler2D2Canvas from "../../texture/sampler/Sampler2D2Canvas.js";
|
|
43
|
-
import { three_object_replace_materials } from "../../three/three_object_replace_materials.js";
|
|
44
35
|
import { PathTracedScene } from "./PathTracedScene.js";
|
|
45
36
|
import { PathTracer } from "./PathTracer.js";
|
|
46
|
-
import {
|
|
37
|
+
import { make_sun, prepare_scene_gltf } from "./prepare_scene_gltf.js";
|
|
47
38
|
|
|
48
39
|
document.body.style.margin = 0;
|
|
49
40
|
document.body.style.overflow = "hidden";
|
|
@@ -76,40 +67,14 @@ vCanvas.css({
|
|
|
76
67
|
* How many rays to use per-pixel
|
|
77
68
|
* @type {number}
|
|
78
69
|
*/
|
|
79
|
-
const PIXEL_SAMPLE_COUNT =
|
|
70
|
+
const PIXEL_SAMPLE_COUNT = 256;
|
|
71
|
+
const PIXEL_RENDER_RATIO = 1;
|
|
80
72
|
|
|
81
73
|
const scene = new PathTracedScene();
|
|
82
74
|
const pt = new PathTracer();
|
|
83
75
|
|
|
84
76
|
window.scene = scene;
|
|
85
77
|
|
|
86
|
-
function make_sun({
|
|
87
|
-
temperature = 5000, // around clear-sky day
|
|
88
|
-
color = '#FFFFFF',
|
|
89
|
-
intensity = 1,
|
|
90
|
-
direction = new Vector3(-0.5, -1, -0.05)
|
|
91
|
-
} = {}) {
|
|
92
|
-
|
|
93
|
-
const temp_c = new Color();
|
|
94
|
-
|
|
95
|
-
kelvin_to_rgb(temp_c, 0, temperature);
|
|
96
|
-
|
|
97
|
-
const light = new DirectionalLight();
|
|
98
|
-
|
|
99
|
-
light.color.parse(color);
|
|
100
|
-
vec3.multiply(light.color, light.color, temp_c);
|
|
101
|
-
|
|
102
|
-
const n = vec3.length(light.color);
|
|
103
|
-
vec3.scale(light.color, light.color, 1 / n); // normalize color vector
|
|
104
|
-
|
|
105
|
-
light.intensity.set(intensity * n);
|
|
106
|
-
light.direction.copy(direction);
|
|
107
|
-
light.direction.normalize();
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
return light;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
78
|
function prepare_scene_sphere_01(pt, camera) {
|
|
114
79
|
camera.position.set(0, 0, -2.1);
|
|
115
80
|
camera.lookAt(0, 0, 0);
|
|
@@ -153,74 +118,6 @@ function promise_ply(url) {
|
|
|
153
118
|
});
|
|
154
119
|
}
|
|
155
120
|
|
|
156
|
-
/**
|
|
157
|
-
*
|
|
158
|
-
* @param {string} url
|
|
159
|
-
* @return {Promise<GLTF>}
|
|
160
|
-
*/
|
|
161
|
-
function promise_gltf(url) {
|
|
162
|
-
return new Promise((resolve, reject) => {
|
|
163
|
-
new GLTFLoader().load(url, resolve, noop, reject);
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
*
|
|
169
|
-
* @param {PathTracedScene} scene
|
|
170
|
-
* @param {THREE.Camera} camera
|
|
171
|
-
* @param {string} url
|
|
172
|
-
* @param {number} [zoom]
|
|
173
|
-
* @param {number} [floor_level]
|
|
174
|
-
* @param {Object} [sun]
|
|
175
|
-
* @param {boolean} [no_materials]
|
|
176
|
-
* @return {Promise<void>}
|
|
177
|
-
*/
|
|
178
|
-
async function prepare_scene_gltf({
|
|
179
|
-
scene,
|
|
180
|
-
camera,
|
|
181
|
-
url,
|
|
182
|
-
zoom = 1,
|
|
183
|
-
floor_level = 0,
|
|
184
|
-
sun,
|
|
185
|
-
no_materials = false
|
|
186
|
-
}) {
|
|
187
|
-
const gltf = await promise_gltf(url);
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
const ground_material = new MeshStandardMaterial({
|
|
191
|
-
color: '#ffceae'
|
|
192
|
-
});
|
|
193
|
-
scene.createMesh(new PlaneBufferGeometry(), ground_material, Transform.fromJSON({
|
|
194
|
-
position: new Vector3(0, floor_level, 0),
|
|
195
|
-
scale: 5000,
|
|
196
|
-
rotation: Quaternion.fromEulerAngles(-Math.PI / 2, 0, 0)
|
|
197
|
-
}).matrix);
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
const gltf_scene = gltf.scene;
|
|
201
|
-
|
|
202
|
-
if (no_materials) {
|
|
203
|
-
three_object_replace_materials(gltf_scene, new MeshStandardMaterial({ color: 'white' }));
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
three_object_to_path_traced_scene(gltf_scene, scene);
|
|
207
|
-
|
|
208
|
-
const box3 = new Box3();
|
|
209
|
-
box3.setFromObject(gltf_scene);
|
|
210
|
-
|
|
211
|
-
const sphere = new Sphere();
|
|
212
|
-
|
|
213
|
-
box3.getBoundingSphere(sphere);
|
|
214
|
-
|
|
215
|
-
scene.addLight(make_sun(sun));
|
|
216
|
-
|
|
217
|
-
camera.position.set(1, 1.3, 1)
|
|
218
|
-
.normalize()
|
|
219
|
-
.multiplyScalar(sphere.radius * 2.6 * (1 / zoom));
|
|
220
|
-
|
|
221
|
-
camera.lookAt(sphere.center);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
121
|
/**
|
|
225
122
|
*
|
|
226
123
|
* @param {PathTracedScene} scene
|
|
@@ -316,8 +213,10 @@ async function prepare_sponza(scene, camera) {
|
|
|
316
213
|
scene: scene,
|
|
317
214
|
camera: camera,
|
|
318
215
|
url: path,
|
|
216
|
+
no_materials: false,
|
|
319
217
|
sun: {
|
|
320
|
-
direction: new Vector3(0.2, -1, 0.2)
|
|
218
|
+
direction: new Vector3(0.2, -1, 0.2),
|
|
219
|
+
intensity: 3
|
|
321
220
|
}
|
|
322
221
|
});
|
|
323
222
|
|
|
@@ -474,7 +373,7 @@ function* render(target, pt, camera, scene, progress = { current: 0, total: 0 })
|
|
|
474
373
|
|
|
475
374
|
const pixel_color = [];
|
|
476
375
|
const pixel_accummulation = [];
|
|
477
|
-
const ray =
|
|
376
|
+
const ray = new Ray3();
|
|
478
377
|
|
|
479
378
|
const ray_origin = new Vector3();
|
|
480
379
|
const ray_direction = new Vector3();
|
|
@@ -544,7 +443,8 @@ function* render(target, pt, camera, scene, progress = { current: 0, total: 0 })
|
|
|
544
443
|
ray_direction.x, ray_direction.y, ray_direction.z
|
|
545
444
|
);
|
|
546
445
|
|
|
547
|
-
|
|
446
|
+
ray.tMax = Infinity;
|
|
447
|
+
pt.path_trace(pixel_color, ray, 1, 7, random, scene);
|
|
548
448
|
|
|
549
449
|
pixel_accummulation[0] += pixel_color[0];
|
|
550
450
|
pixel_accummulation[1] += pixel_color[1];
|
|
@@ -558,7 +458,7 @@ function* render(target, pt, camera, scene, progress = { current: 0, total: 0 })
|
|
|
558
458
|
pixel_accummulation[1] /= pixel_sample_count
|
|
559
459
|
pixel_accummulation[2] /= pixel_sample_count
|
|
560
460
|
|
|
561
|
-
|
|
461
|
+
linear_to_sRGB(pixel_accummulation, 0, pixel_accummulation, 0);
|
|
562
462
|
|
|
563
463
|
output_data[pixel_address] = float_to_uint8(pixel_accummulation[0]);
|
|
564
464
|
output_data[pixel_address + 1] = float_to_uint8(pixel_accummulation[1]);
|
|
@@ -605,21 +505,19 @@ async function start_renderer(camera) {
|
|
|
605
505
|
// await prepare_scene_lucy(scene, camera);
|
|
606
506
|
// await prepare_scene_rtiow(pt, camera);
|
|
607
507
|
// await prepare_scene_sphere_01(pt, camera);
|
|
608
|
-
|
|
609
|
-
await prepare_sponza(scene, camera);
|
|
508
|
+
await prepare_gi_box_scene(scene, camera);
|
|
509
|
+
// await prepare_sponza(scene, camera);
|
|
610
510
|
// await prepare_scene_gltf({scene, camera, path, url: path});
|
|
611
511
|
|
|
612
512
|
|
|
613
|
-
await scene.build();
|
|
614
513
|
// pt.optimize();
|
|
615
514
|
|
|
616
|
-
const pixelRatio = 0.5;
|
|
617
515
|
|
|
618
|
-
const rt = Sampler2D.
|
|
516
|
+
const rt = Sampler2D.uint8clamped(4, vCanvas.size.x, vCanvas.size.y);
|
|
619
517
|
|
|
620
518
|
let scaled_rt = rt;
|
|
621
|
-
if (
|
|
622
|
-
scaled_rt = Sampler2D.uint8clamped(4, Math.ceil(rt.width *
|
|
519
|
+
if (PIXEL_RENDER_RATIO !== 1) {
|
|
520
|
+
scaled_rt = Sampler2D.uint8clamped(4, Math.ceil(rt.width * PIXEL_RENDER_RATIO), Math.ceil(rt.height * PIXEL_RENDER_RATIO));
|
|
623
521
|
}
|
|
624
522
|
|
|
625
523
|
function make_render_task() {
|
|
@@ -685,7 +583,7 @@ async function start_renderer(camera) {
|
|
|
685
583
|
start_renderer(camera);
|
|
686
584
|
|
|
687
585
|
vCanvas.el.addEventListener(MouseEvents.Click, (evt) => {
|
|
688
|
-
const ray =
|
|
586
|
+
const ray = new Ray3();
|
|
689
587
|
|
|
690
588
|
const ray_origin = new Vector3();
|
|
691
589
|
const ray_direction = new Vector3();
|
|
@@ -706,10 +604,12 @@ vCanvas.el.addEventListener(MouseEvents.Click, (evt) => {
|
|
|
706
604
|
ray_origin.x, ray_origin.y, ray_origin.z,
|
|
707
605
|
ray_direction.x, ray_direction.y, ray_direction.z
|
|
708
606
|
);
|
|
607
|
+
ray.tMin = 0;
|
|
608
|
+
ray.tMax = Infinity;
|
|
709
609
|
|
|
710
610
|
const out = [];
|
|
711
611
|
|
|
712
|
-
scene.trace(out, ray
|
|
612
|
+
scene.trace(out, ray);
|
|
713
613
|
|
|
714
614
|
console.log(pointer, out, ray, pt);
|
|
715
615
|
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @param {number[]} output
|
|
4
|
-
* @param {number} output_offset
|
|
5
|
-
* @param {number[]} normal
|
|
6
|
-
* @param {number} normal_offset
|
|
7
|
-
* @param {number[]} m 4x4 matrix
|
|
8
|
-
*/
|
|
9
|
-
export function transform_normal_m4(output: number[], output_offset: number, normal: number[], normal_offset: number, m: number[]): void;
|
|
10
1
|
/**
|
|
11
2
|
*
|
|
12
3
|
* @param {number[]} output
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ray_hit_apply_transform.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/ray_hit_apply_transform.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ray_hit_apply_transform.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/ray_hit_apply_transform.js"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,gDAJW,MAAM,EAAE,OACR,MAAM,EAAE,KACR,MAAM,EAAE,GAAC,YAAY,QAuB/B"}
|
|
@@ -1,31 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { v3_matrix4_rotate } from "../../../../core/geom/vec3/v3_matrix4_rotate.js";
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
* @param {number[]} output
|
|
6
|
-
* @param {number} output_offset
|
|
7
|
-
* @param {number[]} normal
|
|
8
|
-
* @param {number} normal_offset
|
|
9
|
-
* @param {number[]} m 4x4 matrix
|
|
10
|
-
*/
|
|
11
|
-
export function transform_normal_m4(output, output_offset, normal, normal_offset, m) {
|
|
12
|
-
|
|
13
|
-
const n_x = normal[normal_offset];
|
|
14
|
-
const n_y = normal[normal_offset + 1];
|
|
15
|
-
const n_z = normal[normal_offset + 2];
|
|
16
|
-
|
|
17
|
-
const result_n_x = m[0] * n_x + m[4] * n_y + m[8] * n_z;
|
|
18
|
-
const result_n_y = m[1] * n_x + m[5] * n_y + m[9] * n_z;
|
|
19
|
-
const result_n_z = m[2] * n_x + m[6] * n_y + m[10] * n_z;
|
|
20
|
-
|
|
21
|
-
const vec_length = v3_length(result_n_x, result_n_y, result_n_z);
|
|
22
|
-
|
|
23
|
-
const normal_multiplier = vec_length === 0 ? 0 : 1 / vec_length;
|
|
24
|
-
|
|
25
|
-
output[output_offset] = result_n_x * normal_multiplier;
|
|
26
|
-
output[output_offset + 1] = result_n_y * normal_multiplier;
|
|
27
|
-
output[output_offset + 2] = result_n_z * normal_multiplier;
|
|
28
|
-
}
|
|
29
3
|
|
|
30
4
|
/**
|
|
31
5
|
*
|
|
@@ -52,6 +26,6 @@ export function ray_hit_apply_transform(output, hit, m) {
|
|
|
52
26
|
output[2] = result_p_z;
|
|
53
27
|
|
|
54
28
|
// transform normal
|
|
55
|
-
|
|
29
|
+
v3_matrix4_rotate(output, 3, hit, 3, m);
|
|
56
30
|
|
|
57
31
|
}
|
|
@@ -9,13 +9,4 @@
|
|
|
9
9
|
* @param {function():number} random
|
|
10
10
|
*/
|
|
11
11
|
export function getBiasedNormalSample(out: number[], out_offset: number, normal: number[], normal_offset: number, power: number, random: () => number): void;
|
|
12
|
-
/**
|
|
13
|
-
* @see https://www.shadertoy.com/view/stVfWc
|
|
14
|
-
* @param {number[]} out
|
|
15
|
-
* @param {number} out_offset
|
|
16
|
-
* @param {number[]} normal
|
|
17
|
-
* @param {number} normal_offset
|
|
18
|
-
* @param {function():number} random
|
|
19
|
-
*/
|
|
20
|
-
export function getCosineDirection(out: number[], out_offset: number, normal: number[], normal_offset: number, random: () => number): void;
|
|
21
12
|
//# sourceMappingURL=getBiasedNormalSample.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBiasedNormalSample.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/path_tracer/sampling/getBiasedNormalSample.js"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,2CAPW,MAAM,EAAE,cACR,MAAM,UACN,MAAM,EAAE,iBACR,MAAM,SACN,MAAM,gBACK,MAAM,QAsD3B
|
|
1
|
+
{"version":3,"file":"getBiasedNormalSample.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/path_tracer/sampling/getBiasedNormalSample.js"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,2CAPW,MAAM,EAAE,cACR,MAAM,UACN,MAAM,EAAE,iBACR,MAAM,SACN,MAAM,gBACK,MAAM,QAsD3B"}
|
|
@@ -64,42 +64,3 @@ export function getBiasedNormalSample(
|
|
|
64
64
|
out[out_offset + 2] = k0 * o1_z + k1 * o2_z + r_y * dir_z;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
/**
|
|
68
|
-
* @see https://www.shadertoy.com/view/stVfWc
|
|
69
|
-
* @param {number[]} out
|
|
70
|
-
* @param {number} out_offset
|
|
71
|
-
* @param {number[]} normal
|
|
72
|
-
* @param {number} normal_offset
|
|
73
|
-
* @param {function():number} random
|
|
74
|
-
*/
|
|
75
|
-
export function getCosineDirection(
|
|
76
|
-
out,
|
|
77
|
-
out_offset,
|
|
78
|
-
normal,
|
|
79
|
-
normal_offset,
|
|
80
|
-
random
|
|
81
|
-
) {
|
|
82
|
-
|
|
83
|
-
const dir_x = normal[normal_offset];
|
|
84
|
-
const dir_y = normal[normal_offset + 1];
|
|
85
|
-
const dir_z = normal[normal_offset + 2];
|
|
86
|
-
|
|
87
|
-
const r_x = random() * PI2;
|
|
88
|
-
const r_y = 2 * random() - 1;
|
|
89
|
-
|
|
90
|
-
const oneminus = Math.sqrt(1.0 - r_y * r_y);
|
|
91
|
-
|
|
92
|
-
const k0 = Math.cos(r_x) * oneminus;
|
|
93
|
-
const k1 = Math.sin(r_x) * oneminus;
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
let out_dir_x = dir_x + k0;
|
|
97
|
-
let out_dir_y = dir_y + k1;
|
|
98
|
-
let out_dir_z = dir_z + r_y;
|
|
99
|
-
|
|
100
|
-
const len2 = 1 / Math.hypot(out_dir_x, out_dir_y, out_dir_z);
|
|
101
|
-
|
|
102
|
-
out[out_offset] = out_dir_x * len2;
|
|
103
|
-
out[out_offset + 1] = out_dir_y * len2;
|
|
104
|
-
out[out_offset + 2] = out_dir_z * len2;
|
|
105
|
-
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @see https://www.shadertoy.com/view/stVfWc
|
|
3
|
+
* @param {number[]} out
|
|
4
|
+
* @param {number} out_offset
|
|
5
|
+
* @param {number[]} normal
|
|
6
|
+
* @param {number} normal_offset
|
|
7
|
+
* @param {function():number} random
|
|
8
|
+
*/
|
|
9
|
+
export function getCosineDirection(out: number[], out_offset: number, normal: number[], normal_offset: number, random: () => number): void;
|
|
10
|
+
//# sourceMappingURL=getCosineDirection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCosineDirection.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/path_tracer/sampling/getCosineDirection.js"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,wCANW,MAAM,EAAE,cACR,MAAM,UACN,MAAM,EAAE,iBACR,MAAM,gBACK,MAAM,QAgC3B"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { PI2 } from "../../../../../core/math/PI2.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @see https://www.shadertoy.com/view/stVfWc
|
|
5
|
+
* @param {number[]} out
|
|
6
|
+
* @param {number} out_offset
|
|
7
|
+
* @param {number[]} normal
|
|
8
|
+
* @param {number} normal_offset
|
|
9
|
+
* @param {function():number} random
|
|
10
|
+
*/
|
|
11
|
+
export function getCosineDirection(
|
|
12
|
+
out,
|
|
13
|
+
out_offset,
|
|
14
|
+
normal,
|
|
15
|
+
normal_offset,
|
|
16
|
+
random
|
|
17
|
+
) {
|
|
18
|
+
|
|
19
|
+
const dir_x = normal[normal_offset];
|
|
20
|
+
const dir_y = normal[normal_offset + 1];
|
|
21
|
+
const dir_z = normal[normal_offset + 2];
|
|
22
|
+
|
|
23
|
+
const r_x = random() * PI2;
|
|
24
|
+
const r_y = 2 * random() - 1;
|
|
25
|
+
|
|
26
|
+
const oneminus = Math.sqrt(1.0 - r_y * r_y);
|
|
27
|
+
|
|
28
|
+
const k0 = Math.cos(r_x) * oneminus;
|
|
29
|
+
const k1 = Math.sin(r_x) * oneminus;
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
let out_dir_x = dir_x + k0;
|
|
33
|
+
let out_dir_y = dir_y + k1;
|
|
34
|
+
let out_dir_z = dir_z + r_y;
|
|
35
|
+
|
|
36
|
+
const len2 = 1 / Math.hypot(out_dir_x, out_dir_y, out_dir_z);
|
|
37
|
+
|
|
38
|
+
out[out_offset] = out_dir_x * len2;
|
|
39
|
+
out[out_offset + 1] = out_dir_y * len2;
|
|
40
|
+
out[out_offset + 2] = out_dir_z * len2;
|
|
41
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build orthonormal matrix from direction vector
|
|
3
|
+
* @param {number[]} out
|
|
4
|
+
* @param {number} out_offset
|
|
5
|
+
* @param {number} dir_x
|
|
6
|
+
* @param {number} dir_y
|
|
7
|
+
* @param {number} dir_z
|
|
8
|
+
*/
|
|
9
|
+
export function v3_orthonormal_matrix_from_normal(out: number[], out_offset: number, dir_x: number, dir_y: number, dir_z: number): void;
|
|
10
|
+
//# sourceMappingURL=v3_orthonormal_matrix_from_normal.d.ts.map
|
package/src/engine/graphics/sh3/path_tracer/sampling/v3_orthonormal_matrix_from_normal.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v3_orthonormal_matrix_from_normal.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/path_tracer/sampling/v3_orthonormal_matrix_from_normal.js"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,uDANW,MAAM,EAAE,cACR,MAAM,SACN,MAAM,SACN,MAAM,SACN,MAAM,QAsChB"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build orthonormal matrix from direction vector
|
|
3
|
+
* @param {number[]} out
|
|
4
|
+
* @param {number} out_offset
|
|
5
|
+
* @param {number} dir_x
|
|
6
|
+
* @param {number} dir_y
|
|
7
|
+
* @param {number} dir_z
|
|
8
|
+
*/
|
|
9
|
+
export function v3_orthonormal_matrix_from_normal(out, out_offset, dir_x, dir_y, dir_z) {
|
|
10
|
+
// we build orthonormal vectors with respect to the direction vector
|
|
11
|
+
let o1_x, o1_y, o1_z;
|
|
12
|
+
|
|
13
|
+
if (Math.abs(dir_x) > Math.abs(dir_z)) {
|
|
14
|
+
o1_x = -dir_y;
|
|
15
|
+
o1_y = dir_x;
|
|
16
|
+
o1_z = 0;
|
|
17
|
+
} else {
|
|
18
|
+
o1_x = 0;
|
|
19
|
+
o1_y = -dir_z;
|
|
20
|
+
o1_z = dir_y;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// normalize orthonormal vector
|
|
24
|
+
const o1_norm = 1 / Math.hypot(o1_x, o1_y, o1_z);
|
|
25
|
+
|
|
26
|
+
o1_x *= o1_norm;
|
|
27
|
+
o1_y *= o1_norm;
|
|
28
|
+
o1_z *= o1_norm;
|
|
29
|
+
|
|
30
|
+
const o2_x = dir_y * o1_z - dir_z * o1_y;
|
|
31
|
+
const o2_y = dir_z * o1_x - dir_x * o1_z;
|
|
32
|
+
const o2_z = dir_x * o1_y - dir_y * o1_x;
|
|
33
|
+
|
|
34
|
+
out[out_offset] = o1_x;
|
|
35
|
+
out[out_offset + 1] = o1_y;
|
|
36
|
+
out[out_offset + 2] = o1_z;
|
|
37
|
+
|
|
38
|
+
out[out_offset + 3] = o2_x;
|
|
39
|
+
out[out_offset + 4] = o2_y;
|
|
40
|
+
out[out_offset + 5] = o2_z;
|
|
41
|
+
|
|
42
|
+
out[out_offset + 6] = dir_x;
|
|
43
|
+
out[out_offset + 7] = dir_y;
|
|
44
|
+
out[out_offset + 8] = dir_z;
|
|
45
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sample_material.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/path_tracer/texture/sample_material.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sample_material.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/path_tracer/texture/sample_material.js"],"names":[],"mappings":"AA4CA;;;;;;;GAOG;AACH,qCANW,MAAM,EAAE,sCAER,MAAM,KACN,MAAM,KACN,MAAM,QAkFhB"}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { vec3 } from "gl-matrix";
|
|
2
2
|
import { dataTypeFromTypedArray } from "../../../../../core/binary/type/dataTypeFromTypedArray.js";
|
|
3
|
+
import { v3_distance_sqr } from "../../../../../core/geom/vec3/v3_distance_sqr.js";
|
|
4
|
+
import { v3_matrix4_rotate } from "../../../../../core/geom/vec3/v3_matrix4_rotate.js";
|
|
3
5
|
import { decode_attribute_value } from "../../../geometry/decode_attribute_value.js";
|
|
4
6
|
import { geometry_construct_triangle_normal } from "../../../geometry/geometry_construct_triangle_normal.js";
|
|
5
7
|
import { sample_triangle_attribute } from "../geometry/sample_triangle_attribute.js";
|
|
6
|
-
|
|
8
|
+
|
|
9
|
+
import { v3_orthonormal_matrix_from_normal } from "../sampling/v3_orthonormal_matrix_from_normal.js";
|
|
7
10
|
|
|
8
11
|
const texture_uv = [0, 0];
|
|
9
|
-
const color = new Float64Array(
|
|
12
|
+
const color = new Float64Array(3);
|
|
13
|
+
const normal = new Float32Array(3);
|
|
14
|
+
const scratch_m3 = new Float32Array(9);
|
|
10
15
|
|
|
11
16
|
/**
|
|
12
17
|
*
|
|
@@ -52,6 +57,7 @@ export function sample_material(
|
|
|
52
57
|
u, v
|
|
53
58
|
) {
|
|
54
59
|
|
|
60
|
+
const material = mesh.material;
|
|
55
61
|
const geometry = mesh.geometry;
|
|
56
62
|
const index_attribute = geometry.getIndex();
|
|
57
63
|
const index_array = index_attribute.array;
|
|
@@ -80,8 +86,25 @@ export function sample_material(
|
|
|
80
86
|
}
|
|
81
87
|
|
|
82
88
|
// apply transform
|
|
83
|
-
|
|
89
|
+
v3_matrix4_rotate(out, 3, out, 3, mesh.transform);
|
|
90
|
+
|
|
91
|
+
material.normal.sample(normal, texture_uv[0], texture_uv[1]);
|
|
84
92
|
|
|
93
|
+
if (v3_distance_sqr(normal[0], normal[1], normal[2], 0.5, 0.5, 1) > 0.01) {
|
|
94
|
+
//
|
|
95
|
+
normal[0] = normal[0] * 2 - 1;
|
|
96
|
+
normal[1] = normal[1] * 2 - 1;
|
|
97
|
+
normal[2] = normal[2] * 2 - 1;
|
|
98
|
+
|
|
99
|
+
vec3.normalize(normal, normal);
|
|
100
|
+
|
|
101
|
+
// needs transform
|
|
102
|
+
v3_orthonormal_matrix_from_normal(scratch_m3, 0, out[3], out[4], out[5]);
|
|
103
|
+
|
|
104
|
+
out[3] = scratch_m3[0] * normal[0] + scratch_m3[3] * normal[1] + scratch_m3[6] * normal[2];
|
|
105
|
+
out[4] = scratch_m3[1] * normal[0] + scratch_m3[4] * normal[1] + scratch_m3[7] * normal[2];
|
|
106
|
+
out[5] = scratch_m3[2] * normal[0] + scratch_m3[5] * normal[1] + scratch_m3[8] * normal[2];
|
|
107
|
+
}
|
|
85
108
|
|
|
86
109
|
const uv_attribute = geometry.getAttribute('uv');
|
|
87
110
|
|
|
@@ -102,12 +125,9 @@ export function sample_material(
|
|
|
102
125
|
vec3.multiply(out, out, color);
|
|
103
126
|
}
|
|
104
127
|
|
|
105
|
-
const material = mesh.material;
|
|
106
|
-
|
|
107
128
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
tex_diffuse.sample(color, texture_uv[0], texture_uv[1]);
|
|
129
|
+
material.diffuse.sample(color, texture_uv[0], texture_uv[1]);
|
|
111
130
|
|
|
112
131
|
vec3.multiply(out, out, color);
|
|
132
|
+
|
|
113
133
|
}
|