@woosh/meep-engine 2.109.13 → 2.109.15
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/package.json +1 -1
- package/src/core/geom/3d/Ray3.d.ts +23 -6
- package/src/core/geom/3d/Ray3.d.ts.map +1 -1
- package/src/core/geom/3d/Ray3.js +91 -12
- package/src/core/geom/vec3/v3_normalize_array.d.ts +3 -3
- package/src/core/geom/vec3/v3_normalize_array.d.ts.map +1 -1
- package/src/core/geom/vec3/v3_normalize_array.js +2 -2
- package/src/core/math/random/generate_halton_jitter.js +2 -2
- package/src/engine/graphics/sh3/gi/material/makeOctahedralDepthAtlas.d.ts.map +1 -1
- package/src/engine/graphics/sh3/gi/material/makeOctahedralDepthAtlas.js +3 -3
- package/src/engine/graphics/sh3/lpv/LightProbeVolumeBaker.d.ts.map +1 -1
- package/src/engine/graphics/sh3/lpv/LightProbeVolumeBaker.js +4 -2
- package/src/engine/graphics/sh3/lpv/depth/octahedral/bake_octahedral_depth_map.d.ts.map +1 -1
- package/src/engine/graphics/sh3/lpv/depth/octahedral/bake_octahedral_depth_map.js +78 -41
- package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.d.ts.map +1 -1
- package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.js +6 -2
- package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +6 -13
- package/src/engine/graphics/sh3/prototypeSH3Probe.js +4 -4
package/package.json
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 3D ray
|
|
3
|
+
* Oprimized representation for faster memory access
|
|
3
4
|
*/
|
|
4
5
|
export class Ray3 extends Float32Array {
|
|
5
6
|
constructor();
|
|
6
7
|
set tMax(arg: any);
|
|
7
8
|
get tMax(): any;
|
|
8
9
|
6: any;
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
* @param {number[]|Float32Array} v
|
|
12
|
-
*/
|
|
13
|
-
set direction(arg: number[] | Float32Array);
|
|
14
|
-
get direction(): number[] | Float32Array;
|
|
15
10
|
/**
|
|
16
11
|
*
|
|
17
12
|
* @param {number[]|Float32Array} v
|
|
18
13
|
*/
|
|
19
14
|
set origin(arg: number[] | Float32Array);
|
|
20
15
|
get origin(): number[] | Float32Array;
|
|
16
|
+
get origin_x(): number;
|
|
17
|
+
get origin_y(): number;
|
|
18
|
+
get origin_z(): number;
|
|
21
19
|
/**
|
|
22
20
|
*
|
|
23
21
|
* @param {number} x
|
|
@@ -28,6 +26,15 @@ export class Ray3 extends Float32Array {
|
|
|
28
26
|
0: number;
|
|
29
27
|
1: number;
|
|
30
28
|
2: number;
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* @param {number[]|Float32Array} v
|
|
32
|
+
*/
|
|
33
|
+
set direction(arg: number[] | Float32Array);
|
|
34
|
+
get direction(): number[] | Float32Array;
|
|
35
|
+
get direction_x(): number;
|
|
36
|
+
get direction_y(): number;
|
|
37
|
+
get direction_z(): number;
|
|
31
38
|
/**
|
|
32
39
|
*
|
|
33
40
|
* @param {number} x
|
|
@@ -38,6 +45,16 @@ export class Ray3 extends Float32Array {
|
|
|
38
45
|
3: number;
|
|
39
46
|
4: number;
|
|
40
47
|
5: number;
|
|
48
|
+
normalizeDirection(): void;
|
|
49
|
+
/**
|
|
50
|
+
*
|
|
51
|
+
* @param {number} x normalized coordinates in -1,1 range
|
|
52
|
+
* @param {number} y normalized coordinates in -1,1 range
|
|
53
|
+
* @param {number} z normalized coordinates in -1,1 range, typically 0.5
|
|
54
|
+
* @param {number[]|Float32Array|mat4} transform
|
|
55
|
+
* @param {number[]|Float32Array|mat4} projection_inverse
|
|
56
|
+
*/
|
|
57
|
+
projectFromCamera(x: number, y: number, z: number, transform: number[] | Float32Array | mat4, projection_inverse: number[] | Float32Array | mat4): void;
|
|
41
58
|
/**
|
|
42
59
|
*
|
|
43
60
|
* @param {number} distance
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Ray3.d.ts","sourceRoot":"","sources":["../../../../../src/core/geom/3d/Ray3.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Ray3.d.ts","sourceRoot":"","sources":["../../../../../src/core/geom/3d/Ray3.js"],"names":[],"mappings":"AASA;;;GAGG;AACH;IACI,cAKC;IAMD,mBAEC;IAND,gBAEC;IAGG,OAAW;IAOf;;;OAGG;IACH,yCAEC;IAVD,sCAEC;IAUD,uBAEC;IAED,uBAEC;IAED,uBAEC;IAGD;;;;;OAKG;IACH,aAJW,MAAM,KACN,MAAM,KACN,MAAM,QAUhB;IAHG,UAAW;IACX,UAAW;IACX,UAAW;IAQf;;;OAGG;IACH,4CAEC;IAVD,yCAEC;IAWD,0BAEC;IAED,0BAEC;IAED,0BAEC;IAED;;;;;OAKG;IACH,gBAJW,MAAM,KACN,MAAM,KACN,MAAM,QAUhB;IAHG,UAAW;IACX,UAAW;IACX,UAAW;IAGf,2BAEC;IAED;;;;;;;OAOG;IACH,qBANW,MAAM,KACN,MAAM,KACN,MAAM,aACN,MAAM,EAAE,GAAC,YAAY,OAAK,sBAC1B,MAAM,EAAE,GAAC,YAAY,OAAK,QA6BpC;IAED;;;OAGG;IACH,uBAFW,MAAM,QAMhB;IAED;;;OAGG;IACH,iBAFW,MAAM,EAAE,UAAM,YAAY,QAepC;IAED;;;OAGG;IACH,SAFa,IAAI,CAQhB;IAED;;;OAGG;IACH,YAFW,IAAI,QAId;IAED,eAEC;IAED;;;;OAIG;IACH,cAHW,IAAI,GACF,OAAO,CAInB;CACJ"}
|
package/src/core/geom/3d/Ray3.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import { assert } from "../../assert.js";
|
|
1
2
|
import { array_copy } from "../../collection/array/array_copy.js";
|
|
2
3
|
import { array_range_equal_strict } from "../../collection/array/array_range_equal_strict.js";
|
|
3
4
|
import { computeHashFloatArray } from "../../math/hash/computeHashFloatArray.js";
|
|
4
5
|
import { v3_matrix4_multiply } from "../vec3/v3_matrix4_multiply.js";
|
|
5
6
|
import { v3_matrix4_rotate } from "../vec3/v3_matrix4_rotate.js";
|
|
7
|
+
import { v3_normalize_array } from "../vec3/v3_normalize_array.js";
|
|
6
8
|
import { ray3_interval_array_apply_matrix4 } from "./ray/ray3_interval_array_apply_matrix4.js";
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* 3D ray
|
|
12
|
+
* Oprimized representation for faster memory access
|
|
10
13
|
*/
|
|
11
14
|
export class Ray3 extends Float32Array {
|
|
12
15
|
constructor() {
|
|
@@ -24,18 +27,6 @@ export class Ray3 extends Float32Array {
|
|
|
24
27
|
this[6] = v;
|
|
25
28
|
}
|
|
26
29
|
|
|
27
|
-
get direction() {
|
|
28
|
-
return new Float32Array(this.buffer, this.byteOffset + 3 * 4, 3);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
*
|
|
33
|
-
* @param {number[]|Float32Array} v
|
|
34
|
-
*/
|
|
35
|
-
set direction(v) {
|
|
36
|
-
array_copy(v, 0, this, 3, 3);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
30
|
get origin() {
|
|
40
31
|
return new Float32Array(this.buffer, this.byteOffset, 3);
|
|
41
32
|
}
|
|
@@ -48,6 +39,19 @@ export class Ray3 extends Float32Array {
|
|
|
48
39
|
array_copy(v, 0, this, 0, 3);
|
|
49
40
|
}
|
|
50
41
|
|
|
42
|
+
get origin_x() {
|
|
43
|
+
return this[0];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
get origin_y() {
|
|
47
|
+
return this[1];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
get origin_z() {
|
|
51
|
+
return this[2];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
51
55
|
/**
|
|
52
56
|
*
|
|
53
57
|
* @param {number} x
|
|
@@ -55,11 +59,41 @@ export class Ray3 extends Float32Array {
|
|
|
55
59
|
* @param {number} z
|
|
56
60
|
*/
|
|
57
61
|
setOrigin(x, y, z) {
|
|
62
|
+
assert.isNumber(x, 'x');
|
|
63
|
+
assert.isNumber(y, 'y');
|
|
64
|
+
assert.isNumber(z, 'z');
|
|
65
|
+
|
|
58
66
|
this[0] = x;
|
|
59
67
|
this[1] = y;
|
|
60
68
|
this[2] = z;
|
|
61
69
|
}
|
|
62
70
|
|
|
71
|
+
|
|
72
|
+
get direction() {
|
|
73
|
+
return new Float32Array(this.buffer, this.byteOffset + 3 * 4, 3);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
*
|
|
78
|
+
* @param {number[]|Float32Array} v
|
|
79
|
+
*/
|
|
80
|
+
set direction(v) {
|
|
81
|
+
array_copy(v, 0, this, 3, 3);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
get direction_x() {
|
|
86
|
+
return this[3];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
get direction_y() {
|
|
90
|
+
return this[4];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
get direction_z() {
|
|
94
|
+
return this[5];
|
|
95
|
+
}
|
|
96
|
+
|
|
63
97
|
/**
|
|
64
98
|
*
|
|
65
99
|
* @param {number} x
|
|
@@ -67,11 +101,56 @@ export class Ray3 extends Float32Array {
|
|
|
67
101
|
* @param {number} z
|
|
68
102
|
*/
|
|
69
103
|
setDirection(x, y, z) {
|
|
104
|
+
assert.isNumber(x, 'x');
|
|
105
|
+
assert.isNumber(y, 'y');
|
|
106
|
+
assert.isNumber(z, 'z');
|
|
107
|
+
|
|
70
108
|
this[3] = x;
|
|
71
109
|
this[4] = y;
|
|
72
110
|
this[5] = z;
|
|
73
111
|
}
|
|
74
112
|
|
|
113
|
+
normalizeDirection() {
|
|
114
|
+
v3_normalize_array(this, 3, this, 3);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
*
|
|
119
|
+
* @param {number} x normalized coordinates in -1,1 range
|
|
120
|
+
* @param {number} y normalized coordinates in -1,1 range
|
|
121
|
+
* @param {number} z normalized coordinates in -1,1 range, typically 0.5
|
|
122
|
+
* @param {number[]|Float32Array|mat4} transform
|
|
123
|
+
* @param {number[]|Float32Array|mat4} projection_inverse
|
|
124
|
+
*/
|
|
125
|
+
projectFromCamera(
|
|
126
|
+
x, y, z,
|
|
127
|
+
transform,
|
|
128
|
+
projection_inverse
|
|
129
|
+
) {
|
|
130
|
+
assert.isNumber(x, 'x');
|
|
131
|
+
assert.isNumber(y, 'y');
|
|
132
|
+
assert.isNumber(z, 'z');
|
|
133
|
+
|
|
134
|
+
// extract position from transform matrix
|
|
135
|
+
const origin_x = transform[12];
|
|
136
|
+
const origin_y = transform[13];
|
|
137
|
+
const origin_z = transform[14];
|
|
138
|
+
|
|
139
|
+
this.setOrigin(origin_x, origin_y, origin_z);
|
|
140
|
+
|
|
141
|
+
this.setDirection(x, y, z);
|
|
142
|
+
v3_matrix4_multiply(this, 3, this, 3, projection_inverse);
|
|
143
|
+
v3_matrix4_multiply(this, 3, this, 3, transform);
|
|
144
|
+
|
|
145
|
+
// subtract origin
|
|
146
|
+
this[3] -= origin_x;
|
|
147
|
+
this[4] -= origin_y;
|
|
148
|
+
this[5] -= origin_z;
|
|
149
|
+
|
|
150
|
+
// normalize
|
|
151
|
+
this.normalizeDirection();
|
|
152
|
+
}
|
|
153
|
+
|
|
75
154
|
/**
|
|
76
155
|
*
|
|
77
156
|
* @param {number} distance
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
*
|
|
3
|
-
* @param {number[]} input
|
|
3
|
+
* @param {number[]|Float32Array} input
|
|
4
4
|
* @param {number} input_offset
|
|
5
|
-
* @param {number[]} output
|
|
5
|
+
* @param {number[]|Float32Array} output
|
|
6
6
|
* @param {number} output_offset
|
|
7
7
|
*/
|
|
8
|
-
export function v3_normalize_array(input: number[], input_offset: number, output: number[], output_offset: number): void;
|
|
8
|
+
export function v3_normalize_array(input: number[] | Float32Array, input_offset: number, output: number[] | Float32Array, output_offset: number): void;
|
|
9
9
|
//# sourceMappingURL=v3_normalize_array.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"v3_normalize_array.d.ts","sourceRoot":"","sources":["../../../../../src/core/geom/vec3/v3_normalize_array.js"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,0CALW,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"v3_normalize_array.d.ts","sourceRoot":"","sources":["../../../../../src/core/geom/vec3/v3_normalize_array.js"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,0CALW,MAAM,EAAE,GAAC,YAAY,gBACrB,MAAM,UACN,MAAM,EAAE,GAAC,YAAY,iBACrB,MAAM,QAqBhB"}
|
|
@@ -13,8 +13,8 @@ export function generate_halton_jitter(point_count) {
|
|
|
13
13
|
|
|
14
14
|
for (let i = 0; i < point_count; i++) {
|
|
15
15
|
const i2 = i * 2;
|
|
16
|
-
result[i2] = halton_sequence(2, i) * 2
|
|
17
|
-
result[i2 + 1] = halton_sequence(3, i) * 2
|
|
16
|
+
result[i2] = 1 - halton_sequence(2, i) * 2;
|
|
17
|
+
result[i2 + 1] = 1 - halton_sequence(3, i) * 2;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
return result;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"makeOctahedralDepthAtlas.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/gi/material/makeOctahedralDepthAtlas.js"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,sDAHW,MAAM,GACJ,WAAW,CAsBvB;
|
|
1
|
+
{"version":3,"file":"makeOctahedralDepthAtlas.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/gi/material/makeOctahedralDepthAtlas.js"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,sDAHW,MAAM,GACJ,WAAW,CAsBvB;4BA3BoF,OAAO"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ClampToEdgeWrapping, DataTexture, FloatType, NearestFilter,
|
|
1
|
+
import { ClampToEdgeWrapping, DataTexture, FloatType, NearestFilter, RGFormat } from "three";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
*
|
|
@@ -7,10 +7,10 @@ import { ClampToEdgeWrapping, DataTexture, FloatType, NearestFilter, RedFormat }
|
|
|
7
7
|
*/
|
|
8
8
|
export function makeOctahedralDepthAtlas(resolution = 4096) {
|
|
9
9
|
const texture = new DataTexture(
|
|
10
|
-
new Float32Array(resolution * resolution),
|
|
10
|
+
new Float32Array(resolution * resolution * 2),
|
|
11
11
|
resolution,
|
|
12
12
|
resolution,
|
|
13
|
-
|
|
13
|
+
RGFormat, // 2 channels
|
|
14
14
|
FloatType
|
|
15
15
|
);
|
|
16
16
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LightProbeVolumeBaker.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/LightProbeVolumeBaker.js"],"names":[],"mappings":"AAOA;IAEI,8BAAqC;IAGrC;;;;;OAKG;IACH,0DAJa,SAAS,
|
|
1
|
+
{"version":3,"file":"LightProbeVolumeBaker.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/LightProbeVolumeBaker.js"],"names":[],"mappings":"AAOA;IAEI,8BAAqC;IAGrC;;;;;OAKG;IACH,0DAJa,SAAS,CAkErB;CACJ;wCA5EuC,8BAA8B;sBALhD,4CAA4C"}
|
|
@@ -42,15 +42,17 @@ export class LightProbeVolumeBaker {
|
|
|
42
42
|
const max_distance = find_max_depth_radius_for_point(i, lpv.mesh, lpv.points);
|
|
43
43
|
|
|
44
44
|
// bias a little to ensure we capture everything
|
|
45
|
-
const max_depth = max_distance * 1.01 +
|
|
45
|
+
const max_depth = max_distance * 1.01 + 1e-6;
|
|
46
46
|
|
|
47
47
|
const depth_resolution = lpv.depth_map_resolution;
|
|
48
48
|
|
|
49
|
+
const probe_element_count = depth_resolution * depth_resolution * 2;
|
|
50
|
+
|
|
49
51
|
renderer.bake_depth_octahedral(
|
|
50
52
|
depth_resolution,
|
|
51
53
|
max_depth,
|
|
52
54
|
lpv.points, i * 3,
|
|
53
|
-
lpv.depth, i *
|
|
55
|
+
lpv.depth, i * probe_element_count
|
|
54
56
|
);
|
|
55
57
|
|
|
56
58
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bake_octahedral_depth_map.d.ts","sourceRoot":"","sources":["../../../../../../../../src/engine/graphics/sh3/lpv/depth/octahedral/bake_octahedral_depth_map.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bake_octahedral_depth_map.d.ts","sourceRoot":"","sources":["../../../../../../../../src/engine/graphics/sh3/lpv/depth/octahedral/bake_octahedral_depth_map.js"],"names":[],"mappings":"AA2BA;;;;;;;;;GASG;AACH,kDARW,MAAM,EAAE,iBACR,MAAM,oCAEN,MAAM,EAAE,UAAQ,mBAChB,MAAM,cACN,MAAM,aACN,MAAM,QA+GhB"}
|
|
@@ -5,8 +5,9 @@ import {
|
|
|
5
5
|
import { Ray3 } from "../../../../../../core/geom/3d/Ray3.js";
|
|
6
6
|
import { v3_distance } from "../../../../../../core/geom/vec3/v3_distance.js";
|
|
7
7
|
import { v3_dot } from "../../../../../../core/geom/vec3/v3_dot.js";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { v3_dot_array_array } from "../../../../../../core/geom/vec3/v3_dot_array_array.js";
|
|
9
|
+
import { max2 } from "../../../../../../core/math/max2.js";
|
|
10
|
+
import { generate_halton_jitter } from "../../../../../../core/math/random/generate_halton_jitter.js";
|
|
10
11
|
|
|
11
12
|
const scratch_ray = new Ray3();
|
|
12
13
|
|
|
@@ -16,6 +17,14 @@ const scratch_ray = new Ray3();
|
|
|
16
17
|
*/
|
|
17
18
|
const ray_hit = [];
|
|
18
19
|
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @type {number}
|
|
23
|
+
*/
|
|
24
|
+
const SUB_SAMPLE_COUNT = 7;
|
|
25
|
+
|
|
26
|
+
const DEPTH_SHARPNESS = 1;
|
|
27
|
+
|
|
19
28
|
/**
|
|
20
29
|
*
|
|
21
30
|
* @param {number[]} result
|
|
@@ -37,73 +46,101 @@ export function bake_octahedral_depth_map(
|
|
|
37
46
|
scratch_ray.tMax = max_depth;
|
|
38
47
|
array_copy(position, position_offset, scratch_ray, 0, 3);
|
|
39
48
|
|
|
49
|
+
const CONSTANT_NORMAL_BIAS = max_depth * 0.01 + 1e-6;
|
|
40
50
|
|
|
41
|
-
|
|
42
|
-
* Resolution bias is to compensate for discontinuities between samples
|
|
43
|
-
* The lower the resolution - the higher the discontinuities
|
|
44
|
-
* This is heights of an arch on a unit sphere, where arch spans 1/resolution angle
|
|
45
|
-
* Half-PI is to get the height at midpoint of the arch
|
|
46
|
-
* x2 is to get error over the entire circle, as the previous term only gets us to semicircle (we can skip this to get half the max rise, or mean)
|
|
47
|
-
* xMath.SQRT2 is to allow for diagonals between pixels
|
|
48
|
-
* @type {number}
|
|
49
|
-
*/
|
|
50
|
-
const RESOLUTION_BIAS = Math.sin(PI_HALF / resolution) * Math.SQRT2;
|
|
51
|
+
const ray_direction = scratch_ray.direction;
|
|
51
52
|
|
|
52
|
-
const
|
|
53
|
+
const probe_direction = new Float32Array(3);
|
|
54
|
+
|
|
55
|
+
const texel_uv_scale = 0.5 / (resolution - 1);
|
|
56
|
+
|
|
57
|
+
const jittered_sub_samples = generate_halton_jitter(SUB_SAMPLE_COUNT);
|
|
53
58
|
|
|
54
|
-
const ray_direction = scratch_ray.direction;
|
|
55
59
|
|
|
56
60
|
for (let oct_x = 0; oct_x < resolution; oct_x++) {
|
|
57
61
|
for (let oct_y = 0; oct_y < resolution; oct_y++) {
|
|
58
62
|
|
|
63
|
+
let distance_sum = 0;
|
|
64
|
+
let distance2_sum = 0;
|
|
65
|
+
let weight_sum = 0;
|
|
66
|
+
|
|
59
67
|
const u = (oct_x) / (resolution - 1);
|
|
60
68
|
const v = (oct_y) / (resolution - 1);
|
|
61
69
|
|
|
62
70
|
decode_octahedron_to_unit(
|
|
63
|
-
|
|
71
|
+
probe_direction, 0,
|
|
64
72
|
u * 2 - 1, v * 2 - 1
|
|
65
73
|
);
|
|
66
74
|
|
|
67
|
-
let
|
|
75
|
+
for (let sub_sample_index = 0; sub_sample_index < SUB_SAMPLE_COUNT; sub_sample_index++) {
|
|
68
76
|
|
|
69
|
-
|
|
70
|
-
// no hit
|
|
71
|
-
distance = max_depth;
|
|
72
|
-
} else {
|
|
73
|
-
const surface_normal_x = ray_hit[3];
|
|
74
|
-
const surface_normal_y = ray_hit[4];
|
|
75
|
-
const surface_normal_z = ray_hit[5];
|
|
77
|
+
const sample_index2 = sub_sample_index * 2;
|
|
76
78
|
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
const surface_position_z = ray_hit[2];
|
|
79
|
+
const ray_u = u + jittered_sub_samples[sample_index2] * texel_uv_scale;
|
|
80
|
+
const ray_v = v + jittered_sub_samples[sample_index2 + 1] * texel_uv_scale;
|
|
80
81
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
ray_direction[0], ray_direction[1], ray_direction[2]
|
|
82
|
+
decode_octahedron_to_unit(
|
|
83
|
+
ray_direction, 0,
|
|
84
|
+
ray_u * 2 - 1, ray_v * 2 - 1
|
|
85
85
|
);
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
let distance = scene.trace(ray_hit, scratch_ray);
|
|
88
|
+
|
|
89
|
+
if (distance < 0) {
|
|
90
|
+
// no hit
|
|
91
|
+
distance = max_depth;
|
|
92
|
+
} else {
|
|
93
|
+
const surface_normal_x = ray_hit[3];
|
|
94
|
+
const surface_normal_y = ray_hit[4];
|
|
95
|
+
const surface_normal_z = ray_hit[5];
|
|
96
|
+
|
|
97
|
+
const surface_position_x = ray_hit[0];
|
|
98
|
+
const surface_position_y = ray_hit[1];
|
|
99
|
+
const surface_position_z = ray_hit[2];
|
|
100
|
+
|
|
101
|
+
// check for possible miss
|
|
102
|
+
const hit_angle_cos = -v3_dot(
|
|
103
|
+
surface_normal_x, surface_normal_y, surface_normal_z,
|
|
104
|
+
ray_direction[0], ray_direction[1], ray_direction[2]
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
const resolution_bias_offset = max_depth * texel_uv_scale;
|
|
88
108
|
|
|
89
|
-
|
|
109
|
+
const hit_normal_bias = CONSTANT_NORMAL_BIAS;
|
|
90
110
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
111
|
+
// sink the contact into the surface along the hit normal
|
|
112
|
+
const biased_hit_x = surface_position_x + surface_normal_x * hit_normal_bias;
|
|
113
|
+
const biased_hit_y = surface_position_y + surface_normal_y * hit_normal_bias;
|
|
114
|
+
const biased_hit_z = surface_position_z + surface_normal_z * hit_normal_bias;
|
|
95
115
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
116
|
+
distance = v3_distance(
|
|
117
|
+
scratch_ray[0], scratch_ray[1], scratch_ray[2],
|
|
118
|
+
biased_hit_x, biased_hit_y, biased_hit_z
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
// distance += resolution_bias_offset;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const direction_dot_product = v3_dot_array_array(ray_direction, 0, probe_direction, 0);
|
|
125
|
+
|
|
126
|
+
const weight = Math.pow(
|
|
127
|
+
max2(0,
|
|
128
|
+
direction_dot_product
|
|
129
|
+
),
|
|
130
|
+
DEPTH_SHARPNESS
|
|
99
131
|
);
|
|
100
132
|
|
|
101
|
-
|
|
133
|
+
distance_sum += distance * weight;
|
|
134
|
+
distance2_sum += distance * distance * weight;
|
|
135
|
+
weight_sum += weight;
|
|
102
136
|
}
|
|
103
137
|
|
|
104
138
|
const pixel_index = oct_y * resolution + oct_x;
|
|
105
139
|
|
|
106
|
-
|
|
140
|
+
const address = result_offset + pixel_index * 2;
|
|
141
|
+
|
|
142
|
+
result[address] = distance_sum / weight_sum;
|
|
143
|
+
result[address + 1] = distance2_sum / weight_sum;
|
|
107
144
|
}
|
|
108
145
|
}
|
|
109
146
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"probe_volume_to_textures.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/probe_volume_to_textures.js"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,6EAHW,MAAM,EAAE,eACR,MAAM,
|
|
1
|
+
{"version":3,"file":"probe_volume_to_textures.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/probe_volume_to_textures.js"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,6EAHW,MAAM,EAAE,eACR,MAAM,QAqChB;AAGD;;;;;;GAMG;AACH,2DALW,oBAAoB,UACpB,MAAM,EAAE,eACR,MAAM,eACN,MAAM,QAiBhB;qCApEoC,uCAAuC"}
|
|
@@ -27,14 +27,18 @@ export function octahedral_depth_to_atlas(lpv, atlas_data, atlas_width) {
|
|
|
27
27
|
|
|
28
28
|
const tile_pixel_index = pixel_y * tile_resolution + pixel_x;
|
|
29
29
|
|
|
30
|
-
const
|
|
30
|
+
const source_pixel_index = source_offset + tile_pixel_index;
|
|
31
|
+
const source_pixel_address = source_pixel_index * 2;
|
|
31
32
|
|
|
32
33
|
const target_pixel_x = tile_x * tile_resolution + pixel_x;
|
|
33
34
|
const target_pixel_y = tile_y * tile_resolution + pixel_y;
|
|
34
35
|
|
|
35
36
|
const target_pixel_index = target_pixel_y * atlas_width + target_pixel_x;
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
const target_pixel_address = target_pixel_index * 2;
|
|
39
|
+
|
|
40
|
+
atlas_data[target_pixel_address] = probe_depth[source_pixel_address];
|
|
41
|
+
atlas_data[target_pixel_address + 1] = probe_depth[source_pixel_address + 1];
|
|
38
42
|
}
|
|
39
43
|
}
|
|
40
44
|
}
|
|
@@ -411,9 +411,6 @@ function* render(target, pt, camera, scene, progress = { current: 0, total: 0 })
|
|
|
411
411
|
const pixel_accummulation = [];
|
|
412
412
|
const ray = new Ray3();
|
|
413
413
|
|
|
414
|
-
const ray_origin = new Vector3();
|
|
415
|
-
const ray_direction = new Vector3();
|
|
416
|
-
|
|
417
414
|
const width = target.width;
|
|
418
415
|
const height = target.height;
|
|
419
416
|
|
|
@@ -467,16 +464,12 @@ function* render(target, pt, camera, scene, progress = { current: 0, total: 0 })
|
|
|
467
464
|
|
|
468
465
|
for (let i = 0; i < pixel_sample_count; i++) {
|
|
469
466
|
|
|
470
|
-
|
|
467
|
+
ray.projectFromCamera(
|
|
471
468
|
_x + random() * pixel_scale_x * 2,
|
|
472
469
|
_y + random() * pixel_scale_y * 2,
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
ray3_array_compose(
|
|
477
|
-
ray,
|
|
478
|
-
ray_origin.x, ray_origin.y, ray_origin.z,
|
|
479
|
-
ray_direction.x, ray_direction.y, ray_direction.z
|
|
470
|
+
0.5,
|
|
471
|
+
camera.matrixWorld.elements,
|
|
472
|
+
camera.projectionMatrixInverse.elements
|
|
480
473
|
);
|
|
481
474
|
|
|
482
475
|
ray.tMax = Infinity;
|
|
@@ -542,8 +535,8 @@ async function start_renderer(camera) {
|
|
|
542
535
|
// await prepare_scene_rtiow(pt, camera);
|
|
543
536
|
// await prepare_scene_sphere_01(pt, camera);
|
|
544
537
|
// await prepare_gi_box_scene(scene, camera);
|
|
545
|
-
|
|
546
|
-
await prepare_attic_scene(scene, camera);
|
|
538
|
+
await prepare_sponza(scene, camera);
|
|
539
|
+
// await prepare_attic_scene(scene, camera);
|
|
547
540
|
// await prepare_scene_gltf({scene, camera, path, url: path});
|
|
548
541
|
|
|
549
542
|
|
|
@@ -245,7 +245,7 @@ async function getVolume({
|
|
|
245
245
|
engine,
|
|
246
246
|
ecd,
|
|
247
247
|
bounds: mesh_bounds,
|
|
248
|
-
density:
|
|
248
|
+
density: 500
|
|
249
249
|
});
|
|
250
250
|
|
|
251
251
|
const buffer = new BinaryBuffer();
|
|
@@ -385,10 +385,10 @@ async function main(engine) {
|
|
|
385
385
|
// const path = 'data/models/sibenik/3-window-less/model.gltf';
|
|
386
386
|
// const path = 'data/models/samples/gi_box_01/model.glb';
|
|
387
387
|
// const path = 'data/models/sponza-pbr/gltf/sponza.glb';
|
|
388
|
-
|
|
388
|
+
const path = 'data/models/pica_pica/pica_pica.gltf';
|
|
389
389
|
// const path = 'data/models/samples/susanne.glb';
|
|
390
390
|
// const path = 'data/models/samples/teapot.gltf';
|
|
391
|
-
const path = 'data/models/samples/salle_de_bain/model.glb';
|
|
391
|
+
// const path = 'data/models/samples/salle_de_bain/model.glb';
|
|
392
392
|
// const path = 'data/models/samples/conference/model-no-curtains.glb';
|
|
393
393
|
|
|
394
394
|
const mesh_asset = await engine.assetManager.promise(path, 'model/gltf+json');
|
|
@@ -449,7 +449,7 @@ async function main(engine) {
|
|
|
449
449
|
|
|
450
450
|
|
|
451
451
|
const camera = ecd.getAnyComponent(Camera);
|
|
452
|
-
camera.component.clip_far = max2(100, model_footprint);
|
|
452
|
+
camera.component.clip_far = max2(100, model_footprint * 3);
|
|
453
453
|
const camera_controller = ecd.getComponent(camera.entity, TopDownCameraController);
|
|
454
454
|
camera_controller.distanceMax = model_footprint * 2;
|
|
455
455
|
camera_controller.distanceMin = min2(camera_controller.distanceMin, model_footprint * 0.01);
|