@woosh/meep-engine 2.86.4 → 2.86.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/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sampler2d_blur_gaussian.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/texture/sampler/filter/sampler2d_blur_gaussian.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sampler2d_blur_gaussian.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/texture/sampler/filter/sampler2d_blur_gaussian.js"],"names":[],"mappings":"AA+BA;;;;;;GAMG;AACH,gDALW,SAAS,SACT,SAAS,QACT,MAAM,YACN,MAAM,QAkFhB;0BAnHyB,iBAAiB"}
|
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
import { gaussian } from "../../../../../core/math/gaussian.js";
|
|
2
2
|
import { makeNextOdd } from "../../../../../core/math/makeNextOdd.js";
|
|
3
3
|
import { max2 } from "../../../../../core/math/max2.js";
|
|
4
|
+
import { Sampler2D } from "../Sampler2D.js";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
let temp_data = new Float64Array(1);
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @param {number} sample_count
|
|
12
|
+
* @param {Float32Array} kernel
|
|
13
|
+
*/
|
|
14
|
+
function build_kernel(sample_count, kernel) {
|
|
15
|
+
const sigma = 10;
|
|
16
|
+
|
|
17
|
+
let kernel_power_sum = 0;
|
|
18
|
+
for (let i = 0; i < sample_count; i++) {
|
|
19
|
+
const local = i - sample_count * 0.5;
|
|
20
|
+
|
|
21
|
+
const power = gaussian(sigma, local);
|
|
22
|
+
kernel[i] = power;
|
|
23
|
+
kernel_power_sum += power;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// normalize kernel
|
|
27
|
+
for (let i = 0; i < sample_count; i++) {
|
|
28
|
+
kernel[i] /= kernel_power_sum;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
4
31
|
|
|
5
32
|
/**
|
|
6
33
|
*
|
|
@@ -13,28 +40,26 @@ export function sampler2d_blur_gaussian(output, input, size, quality = 1) {
|
|
|
13
40
|
|
|
14
41
|
const sample_count = max2(3, makeNextOdd(Math.round(size * quality)));
|
|
15
42
|
|
|
16
|
-
|
|
17
43
|
const kernel = new Float32Array(sample_count);
|
|
18
44
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
for (let i = 0; i < sample_count; i++) {
|
|
22
|
-
const local = i - sample_count * 0.5;
|
|
23
|
-
|
|
24
|
-
kernel[i] = gaussian(sigma, local);
|
|
25
|
-
}
|
|
45
|
+
build_kernel(sample_count, kernel);
|
|
26
46
|
|
|
27
47
|
const width = input.width;
|
|
28
48
|
const height = input.height;
|
|
49
|
+
const channel_count = input.itemSize;
|
|
50
|
+
|
|
51
|
+
const total_value_count = width * height * channel_count;
|
|
52
|
+
if (temp_data.length < total_value_count) {
|
|
53
|
+
temp_data = new Float64Array(total_value_count);
|
|
54
|
+
}
|
|
29
55
|
|
|
30
56
|
let source = input;
|
|
31
|
-
let target =
|
|
57
|
+
let target = new Sampler2D(temp_data, channel_count, width, height);
|
|
32
58
|
|
|
33
59
|
const half_samples = (sample_count - 1) * 0.5;
|
|
34
60
|
const local_u_scale = width / (sample_count - 1);
|
|
35
61
|
const local_v_scale = height / (sample_count - 1);
|
|
36
62
|
|
|
37
|
-
const channel_count = input.itemSize;
|
|
38
63
|
const sample = new Float64Array(channel_count);
|
|
39
64
|
|
|
40
65
|
// horizonal pass
|
|
@@ -63,6 +88,7 @@ export function sampler2d_blur_gaussian(output, input, size, quality = 1) {
|
|
|
63
88
|
}
|
|
64
89
|
|
|
65
90
|
source = target;
|
|
91
|
+
target = output;
|
|
66
92
|
|
|
67
93
|
// vertical pass
|
|
68
94
|
for (let y = 0; y < height; y++) {
|