@woosh/meep-engine 2.96.0 → 2.98.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/bundle-worker-terrain.js +1 -1
- package/build/meep.cjs +892 -687
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +892 -687
- package/package.json +1 -1
- package/src/core/binary/BitSet.d.ts +2 -2
- package/src/core/binary/BitSet.d.ts.map +1 -1
- package/src/core/binary/BitSet.js +8 -5
- package/src/core/bvh2/bvh3/query/bvh_query_leaves_ray.js +1 -1
- package/src/core/bvh2/bvh3/query/bvh_query_user_data_generic.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 +3 -2
- package/src/core/collection/array/arrayQuickSort.js +2 -2
- package/src/core/collection/array/array_compute_max.d.ts +9 -0
- package/src/core/collection/array/array_compute_max.d.ts.map +1 -0
- package/src/core/collection/array/{computeArrayMax.js → array_compute_max.js} +1 -1
- package/src/core/collection/array/array_compute_min.d.ts +9 -0
- package/src/core/collection/array/array_compute_min.d.ts.map +1 -0
- package/src/core/collection/array/{computeArrayMin.js → array_compute_min.js} +1 -1
- package/src/core/collection/array/array_compute_min_max.d.ts.map +1 -1
- package/src/core/collection/array/array_compute_min_max.js +1 -0
- package/src/core/collection/array/array_swap.d.ts.map +1 -1
- package/src/core/collection/array/array_swap.js +11 -8
- package/src/core/collection/array/array_swap_one.d.ts +8 -0
- package/src/core/collection/array/array_swap_one.d.ts.map +1 -0
- package/src/core/collection/array/{arraySwapElements.js → array_swap_one.js} +1 -1
- package/src/core/collection/array/iterator/AbstractArrayIterator.d.ts.map +1 -0
- package/src/core/collection/array/iterator/ArrayIteratorRandom.d.ts.map +1 -0
- package/src/core/collection/array/{ArrayIteratorRandom.js → iterator/ArrayIteratorRandom.js} +2 -2
- package/src/core/collection/array/iterator/ArrayIteratorSequential.d.ts.map +1 -0
- package/src/core/collection/array/randomizeArrayElementOrder.js +2 -2
- package/src/core/collection/map/HashMap.js +10 -10
- package/src/core/collection/map/ObservedMap.d.ts +7 -4
- package/src/core/collection/map/ObservedMap.d.ts.map +1 -1
- package/src/core/collection/map/ObservedMap.js +4 -1
- package/src/core/collection/queue/Deque.d.ts.map +1 -1
- package/src/core/collection/queue/Deque.js +82 -36
- package/src/core/geom/3d/aabb/aabb3_intersects_ray.js +10 -10
- package/src/core/graph/v2/Graph.d.ts.map +1 -1
- package/src/core/graph/v2/Graph.js +9 -0
- package/src/core/math/spline/computeNonuniformCaltmullRomSplineDerivative.d.ts +16 -0
- package/src/core/math/spline/computeNonuniformCaltmullRomSplineDerivative.d.ts.map +1 -0
- package/src/core/math/spline/computeNonuniformCaltmullRomSplineDerivative.js +90 -0
- package/src/core/parser/simple/ParserError.d.ts +11 -6
- package/src/core/parser/simple/ParserError.d.ts.map +1 -1
- package/src/core/parser/simple/ParserError.js +51 -4
- package/src/core/parser/simple/Token.d.ts.map +1 -1
- package/src/core/parser/simple/Token.js +8 -2
- package/src/core/parser/simple/TokenType.d.ts +1 -5
- package/src/core/parser/simple/TokenType.d.ts.map +1 -1
- package/src/core/parser/simple/TokenType.js +1 -1
- package/src/core/parser/simple/readBooleanToken.d.ts.map +1 -1
- package/src/core/parser/simple/readBooleanToken.js +6 -1
- package/src/core/parser/simple/readHexToken.d.ts.map +1 -1
- package/src/core/parser/simple/readHexToken.js +7 -2
- package/src/core/parser/simple/readIdentifierToken.d.ts.map +1 -1
- package/src/core/parser/simple/readIdentifierToken.js +6 -1
- package/src/core/parser/simple/readLiteralToken.d.ts.map +1 -1
- package/src/core/parser/simple/readLiteralToken.js +8 -3
- package/src/core/parser/simple/readNumberToken.d.ts.map +1 -1
- package/src/core/parser/simple/readNumberToken.js +7 -2
- package/src/core/parser/simple/readReferenceToken.d.ts.map +1 -1
- package/src/core/parser/simple/readReferenceToken.js +6 -1
- package/src/core/parser/simple/readStringToken.d.ts.map +1 -1
- package/src/core/parser/simple/readStringToken.js +6 -1
- package/src/core/parser/simple/readUnsignedIntegerToken.d.ts.map +1 -1
- package/src/core/parser/simple/readUnsignedIntegerToken.js +7 -2
- package/src/core/parser/simple/skipWhitespace.d.ts.map +1 -1
- package/src/core/parser/simple/skipWhitespace.js +8 -0
- package/src/core/primitives/strings/string_jaro_distance.d.ts +10 -0
- package/src/core/primitives/strings/string_jaro_distance.d.ts.map +1 -0
- package/src/core/primitives/strings/string_jaro_distance.js +127 -0
- package/src/core/primitives/strings/string_jaro_winkler.d.ts.map +1 -1
- package/src/core/primitives/strings/string_jaro_winkler.js +5 -105
- package/src/core/primitives/strings/string_repeat.d.ts +9 -0
- package/src/core/primitives/strings/string_repeat.d.ts.map +1 -0
- package/src/core/primitives/strings/string_repeat.js +26 -0
- package/src/engine/asset/AssetManager.d.ts.map +1 -1
- package/src/engine/development/performance/RingBufferMetric.d.ts.map +1 -1
- package/src/engine/development/performance/RingBufferMetric.js +5 -5
- package/src/engine/ecs/terrain/ecs/BuildLightTexture.d.ts.map +1 -1
- package/src/engine/ecs/terrain/ecs/BuildLightTexture.js +15 -22
- package/src/engine/graphics/ecs/camera/Camera.d.ts.map +1 -1
- package/src/engine/graphics/ecs/camera/Camera.js +23 -16
- package/src/engine/graphics/ecs/path/testPathDisplaySystem.js +142 -10
- package/src/engine/graphics/ecs/path/tube/build/TubePathBuilder.d.ts.map +1 -1
- package/src/engine/graphics/ecs/path/tube/build/TubePathBuilder.js +9 -9
- package/src/engine/graphics/ecs/path/tube/build/build_geometry_catmullrom.d.ts.map +1 -1
- package/src/engine/graphics/ecs/path/tube/build/build_geometry_catmullrom.js +173 -23
- package/src/engine/graphics/ecs/path/tube/prototypeAnimatedPathMask.js +16 -2
- package/src/engine/graphics/filter/ImageFilter.d.ts +2 -2
- package/src/engine/graphics/filter/ImageFilter.d.ts.map +1 -1
- package/src/engine/graphics/filter/ImageFilter.js +3 -3
- package/src/engine/graphics/render/RendererPool.d.ts +14 -1
- package/src/engine/graphics/render/RendererPool.d.ts.map +1 -1
- package/src/engine/graphics/render/RendererPool.js +43 -1
- package/src/engine/graphics/render/forward_plus/LightManager.js +2 -2
- package/src/engine/graphics/sh3/path_tracer/PathTracer.d.ts +2 -1
- package/src/engine/graphics/sh3/path_tracer/PathTracer.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/PathTracer.js +23 -50
- package/src/engine/graphics/sh3/path_tracer/getBiasedNormalSample.d.ts +9 -0
- package/src/engine/graphics/sh3/path_tracer/getBiasedNormalSample.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/getBiasedNormalSample.js +53 -3
- package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +3 -3
- package/src/engine/graphics/texture/sampler/convertTexture2Sampler2D.d.ts +1 -1
- package/src/engine/graphics/texture/sampler/convertTexture2Sampler2D.d.ts.map +1 -1
- package/src/engine/graphics/texture/sampler/convertTexture2Sampler2D.js +42 -36
- package/src/engine/graphics/texture/sampler/debug/debug_draw_sampler.d.ts +3 -0
- package/src/engine/graphics/texture/sampler/debug/debug_draw_sampler.d.ts.map +1 -0
- package/src/engine/graphics/texture/sampler/debug/debug_draw_sampler.js +34 -0
- package/src/engine/graphics/texture/sampler/debug/debug_draw_sampler_grid.d.ts +10 -0
- package/src/engine/graphics/texture/sampler/debug/debug_draw_sampler_grid.d.ts.map +1 -0
- package/src/engine/graphics/texture/sampler/debug/debug_draw_sampler_grid.js +89 -0
- package/src/engine/graphics/texture/sampler/debug/prototypeSamplerFiltering.d.ts.map +1 -0
- package/src/engine/graphics/texture/sampler/{prototypeSamplerFiltering.js → debug/prototypeSamplerFiltering.js} +105 -113
- package/src/generation/grid/generation/GridTaskDensityMarkerDistribution.d.ts.map +1 -1
- package/src/generation/grid/generation/GridTaskDensityMarkerDistribution.js +8 -8
- package/src/generation/markers/GridActionRuleSet.d.ts.map +1 -1
- package/src/generation/markers/GridActionRuleSet.js +5 -5
- package/src/core/binary/byteArrayToString.d.ts +0 -9
- package/src/core/binary/byteArrayToString.d.ts.map +0 -1
- package/src/core/binary/byteArrayToString.js +0 -28
- package/src/core/collection/array/AbstractArrayIterator.d.ts.map +0 -1
- package/src/core/collection/array/ArrayIteratorRandom.d.ts.map +0 -1
- package/src/core/collection/array/ArrayIteratorSequential.d.ts.map +0 -1
- package/src/core/collection/array/arrayPickMinElement.d.ts +0 -8
- package/src/core/collection/array/arrayPickMinElement.d.ts.map +0 -1
- package/src/core/collection/array/arrayPickMinElement.js +0 -43
- package/src/core/collection/array/arraySwapElements.d.ts +0 -8
- package/src/core/collection/array/arraySwapElements.d.ts.map +0 -1
- package/src/core/collection/array/computeArrayMax.d.ts +0 -9
- package/src/core/collection/array/computeArrayMax.d.ts.map +0 -1
- package/src/core/collection/array/computeArrayMin.d.ts +0 -9
- package/src/core/collection/array/computeArrayMin.d.ts.map +0 -1
- package/src/engine/graphics/texture/sampler/prototypeSamplerFiltering.d.ts.map +0 -1
- /package/src/core/collection/array/{AbstractArrayIterator.d.ts → iterator/AbstractArrayIterator.d.ts} +0 -0
- /package/src/core/collection/array/{AbstractArrayIterator.js → iterator/AbstractArrayIterator.js} +0 -0
- /package/src/core/collection/array/{ArrayIteratorRandom.d.ts → iterator/ArrayIteratorRandom.d.ts} +0 -0
- /package/src/core/collection/array/{ArrayIteratorSequential.d.ts → iterator/ArrayIteratorSequential.d.ts} +0 -0
- /package/src/core/collection/array/{ArrayIteratorSequential.js → iterator/ArrayIteratorSequential.js} +0 -0
- /package/src/engine/graphics/texture/sampler/{prototypeSamplerFiltering.d.ts → debug/prototypeSamplerFiltering.d.ts} +0 -0
|
@@ -5,7 +5,7 @@ export class WebGLRendererPool {
|
|
|
5
5
|
|
|
6
6
|
used = new Set();
|
|
7
7
|
|
|
8
|
-
get(
|
|
8
|
+
get() {
|
|
9
9
|
const canvas = document.createElement('canvas');
|
|
10
10
|
const context = canvas.getContext('webgl2', { antialias: true });
|
|
11
11
|
|
|
@@ -40,5 +40,47 @@ export class WebGLRendererPool {
|
|
|
40
40
|
return true;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
/**
|
|
44
|
+
* After callback returns, renderer is released back into the pool
|
|
45
|
+
* @template T
|
|
46
|
+
* @param {function(renderer:WebGLRenderer):T} callback
|
|
47
|
+
* @param {*} [thisArg]
|
|
48
|
+
*/
|
|
49
|
+
use(callback, thisArg) {
|
|
50
|
+
|
|
51
|
+
const renderer = this.get();
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
const result = callback.call(thisArg, renderer);
|
|
55
|
+
|
|
56
|
+
if (result instanceof Promise) {
|
|
57
|
+
console.warn("callback returned a promise, if you need async behavior - use 'useAsync' method instead");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return result;
|
|
61
|
+
|
|
62
|
+
} finally {
|
|
63
|
+
|
|
64
|
+
this.release(renderer);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @template T
|
|
71
|
+
* @param {function(renderer:WebGLRenderer):Promise<T>} callback
|
|
72
|
+
* @param {*} [thisArg]
|
|
73
|
+
*/
|
|
74
|
+
async useAsync(callback, thisArg) {
|
|
75
|
+
|
|
76
|
+
const renderer = this.get();
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
await callback.call(thisArg, renderer);
|
|
80
|
+
} finally {
|
|
81
|
+
this.release(renderer);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
43
85
|
static global = new WebGLRendererPool();
|
|
44
86
|
}
|
|
@@ -23,8 +23,8 @@ import {
|
|
|
23
23
|
bvh_query_user_data_overlaps_frustum
|
|
24
24
|
} from "../../../../core/bvh2/bvh3/query/bvh_query_user_data_overlaps_frustum.js";
|
|
25
25
|
import { array_copy } from "../../../../core/collection/array/array_copy.js";
|
|
26
|
+
import { array_swap_one } from "../../../../core/collection/array/array_swap_one.js";
|
|
26
27
|
import { arrayQuickSort } from "../../../../core/collection/array/arrayQuickSort.js";
|
|
27
|
-
import { arraySwapElements } from "../../../../core/collection/array/arraySwapElements.js";
|
|
28
28
|
import { read_cluster_frustum_corners } from "../../../../core/geom/3d/frustum/read_cluster_frustum_corners.js";
|
|
29
29
|
import { read_three_planes_to_array } from "../../../../core/geom/3d/frustum/read_three_planes_to_array.js";
|
|
30
30
|
import { slice_frustum_linear_to_points } from "../../../../core/geom/3d/frustum/slice_frustum_linear_to_points.js";
|
|
@@ -706,7 +706,7 @@ export class LightManager {
|
|
|
706
706
|
__build_view_frustum(camera) {
|
|
707
707
|
frustum_from_camera(camera, this.__view_frustum, false);
|
|
708
708
|
|
|
709
|
-
|
|
709
|
+
array_swap_one(this.__view_frustum.planes, 4, 5);
|
|
710
710
|
|
|
711
711
|
this.__build_view_frustum_points();
|
|
712
712
|
}
|
|
@@ -61,7 +61,7 @@ export class PathTracer {
|
|
|
61
61
|
sample_texture(out: number[], texture: Texture, u: number, v: number): void;
|
|
62
62
|
/**
|
|
63
63
|
*
|
|
64
|
-
* @param {number[]} out
|
|
64
|
+
* @param {number[]} out [color_r, color_g, color_b, normal_x, normal_y, normal_z]
|
|
65
65
|
* @param {number[]} hit
|
|
66
66
|
*/
|
|
67
67
|
sample_material(out: number[], hit: number[]): void;
|
|
@@ -88,6 +88,7 @@ export class PathTracer {
|
|
|
88
88
|
* @param {number} out_offset
|
|
89
89
|
* @param {number[]} ray
|
|
90
90
|
* @param {number} ray_address
|
|
91
|
+
* @returns {boolean}
|
|
91
92
|
*/
|
|
92
93
|
sample_lights(out: number[], out_offset: number, ray: number[], ray_address: number): boolean;
|
|
93
94
|
path_trace(out: any, ray: any, max_distance: any, max_bounce: any, random?: () => number): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PathTracer.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/PathTracer.js"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"PathTracer.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/PathTracer.js"],"names":[],"mappings":";AA2DA;IAGQ;;;OAGG;IACH,eAFU,GAAG,CAEiB;IAE9B;;;OAGG;IACH,QAFU,IAAI,MAAM,EAAE,cAAc,CAAC,CAEd;IAEvB;;;OAGG;IACH,UAFU,eAAe,CAEP;IAElB;;;OAGG;IACH,WAFU,IAAI,MAAM,cAAc,EAAE,kBAAkB,CAAC,CAE7B;IAE1B;;;OAGG;IACH,UAFU,IAAI,MAAM,YAAY,CAEP;IAEzB;;;;OAIG;IACH,6BAA8C;IAGlD;;;;OAIG;IACH,uBAHW,MAAM,cAAc,GACnB,kBAAkB,CAgB7B;IAED,iBAGC;IAED,uBAoCC;IAED;;;OAGG;IACH,qCAEC;IAED;;;;;OAKG;IACH,aAJW,MAAM,cAAc,YACpB,MAAM,QAAQ,aACd,IAAI,GAAC,MAAM,EAAE,QA6CvB;IAED;;;;;;OAMG;IACH,oBALW,MAAM,EAAE,uBAER,MAAM,KACN,MAAM,QA+ChB;IAED;;;;OAIG;IACH,qBAHW,MAAM,EAAE,OACR,MAAM,EAAE,QAmFlB;IAED;;;;;;;OAOG;IACH,WANW,MAAM,EAAE,OACR,MAAM,EAAE,gBACR,MAAM,gBACN,MAAM,GACL,MAAM,CAwCjB;IAED;;;;;;OAMG;IACH,uBALW,MAAM,EAAE,cACR,MAAM,aACN,MAAM,EAAE,oBACR,MAAM,QAIhB;IAED;;;;;;;OAOG;IACH,mBANW,MAAM,EAAE,cACR,MAAM,OACN,MAAM,EAAE,eACR,MAAM,GACJ,OAAO,CAmEnB;IAED,gGAqDC;CACJ;oBA/hBmB,mCAAmC;+BAexB,qBAAqB;mCAHjB,yBAAyB;qBAtBjC,WAAW"}
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from "three";
|
|
11
11
|
import { BVH } from "../../../../core/bvh2/bvh3/BVH.js";
|
|
12
12
|
import { ebvh_sort_for_traversal_depth_first } from "../../../../core/bvh2/bvh3/ebvh_sort_for_traversal_depth_first.js";
|
|
13
|
-
import {
|
|
13
|
+
import { bvh_query_user_data_ray } from "../../../../core/bvh2/bvh3/query/bvh_query_user_data_ray.js";
|
|
14
14
|
import { array_copy } from "../../../../core/collection/array/array_copy.js";
|
|
15
15
|
import { linear_to_sRGB } from "../../../../core/color/sRGB/linear_to_sRGB.js";
|
|
16
16
|
import { aabb3_matrix4_project } from "../../../../core/geom/3d/aabb/aabb3_matrix4_project.js";
|
|
@@ -46,11 +46,6 @@ const color = [];
|
|
|
46
46
|
|
|
47
47
|
const irradiance = [0, 0, 0];
|
|
48
48
|
|
|
49
|
-
/**
|
|
50
|
-
*
|
|
51
|
-
* @type {number[]|vec3}
|
|
52
|
-
*/
|
|
53
|
-
const throughputColor = [1, 1, 1];
|
|
54
49
|
const trace_result = [];
|
|
55
50
|
|
|
56
51
|
const _ray_0 = [];
|
|
@@ -282,7 +277,7 @@ export class PathTracer {
|
|
|
282
277
|
|
|
283
278
|
/**
|
|
284
279
|
*
|
|
285
|
-
* @param {number[]} out
|
|
280
|
+
* @param {number[]} out [color_r, color_g, color_b, normal_x, normal_y, normal_z]
|
|
286
281
|
* @param {number[]} hit
|
|
287
282
|
*/
|
|
288
283
|
sample_material(out, hit) {
|
|
@@ -379,10 +374,11 @@ export class PathTracer {
|
|
|
379
374
|
trace(out, ray, min_distance, max_distance) {
|
|
380
375
|
const bvh = this.bvh_top_level;
|
|
381
376
|
|
|
382
|
-
const hit_count =
|
|
377
|
+
const hit_count = bvh_query_user_data_ray(
|
|
383
378
|
bvh, bvh.root,
|
|
384
379
|
temp_ray_results, 0,
|
|
385
|
-
ray[0], ray[1], ray[2],
|
|
380
|
+
ray[0], ray[1], ray[2],
|
|
381
|
+
ray[3], ray[4], ray[5]
|
|
386
382
|
);
|
|
387
383
|
|
|
388
384
|
let nearest_hit_distance = max_distance;
|
|
@@ -390,9 +386,7 @@ export class PathTracer {
|
|
|
390
386
|
|
|
391
387
|
|
|
392
388
|
for (let i = 0; i < hit_count; i++) {
|
|
393
|
-
const
|
|
394
|
-
|
|
395
|
-
const node_user_data = bvh.node_get_user_data(node_id);
|
|
389
|
+
const node_user_data = temp_ray_results[i];
|
|
396
390
|
|
|
397
391
|
const mesh = this.meshes.get(node_user_data);
|
|
398
392
|
|
|
@@ -434,6 +428,7 @@ export class PathTracer {
|
|
|
434
428
|
* @param {number} out_offset
|
|
435
429
|
* @param {number[]} ray
|
|
436
430
|
* @param {number} ray_address
|
|
431
|
+
* @returns {boolean}
|
|
437
432
|
*/
|
|
438
433
|
sample_lights(out, out_offset, ray, ray_address) {
|
|
439
434
|
let lights_sampled = false;
|
|
@@ -462,7 +457,10 @@ export class PathTracer {
|
|
|
462
457
|
const light_dir_inv_y = -dir.y;
|
|
463
458
|
const light_dir_inv_z = -dir.z;
|
|
464
459
|
|
|
465
|
-
const dotNL = v3_dot(
|
|
460
|
+
const dotNL = v3_dot(
|
|
461
|
+
ray_direction_x, ray_direction_y, ray_direction_z,
|
|
462
|
+
light_dir_inv_x, light_dir_inv_y, light_dir_inv_z
|
|
463
|
+
);
|
|
466
464
|
|
|
467
465
|
if (dotNL <= 0) {
|
|
468
466
|
// no contribution, facing away from the light
|
|
@@ -508,8 +506,6 @@ export class PathTracer {
|
|
|
508
506
|
irradiance[1] = 1;
|
|
509
507
|
irradiance[2] = 1;
|
|
510
508
|
|
|
511
|
-
let got_emission = false;
|
|
512
|
-
|
|
513
509
|
let i;
|
|
514
510
|
for (i = 0; i < max_bounce; i++) {
|
|
515
511
|
|
|
@@ -520,14 +516,9 @@ export class PathTracer {
|
|
|
520
516
|
// ray didn't hit anything
|
|
521
517
|
|
|
522
518
|
// sample "environment" and terminate path as there is nothing to reflect off of
|
|
523
|
-
|
|
524
519
|
this.sample_background(tmp_0, 0, _ray_0, 3);
|
|
525
|
-
|
|
526
520
|
vec3.multiply(irradiance, irradiance, tmp_0);
|
|
527
521
|
|
|
528
|
-
|
|
529
|
-
got_emission = true;
|
|
530
|
-
|
|
531
522
|
break;
|
|
532
523
|
}
|
|
533
524
|
|
|
@@ -535,47 +526,29 @@ export class PathTracer {
|
|
|
535
526
|
|
|
536
527
|
// adjust normal on the hit
|
|
537
528
|
array_copy(tmp_0, 3, trace_result, 3, 3);
|
|
529
|
+
array_copy(trace_result, 0, _ray_0, 0, 3);
|
|
538
530
|
|
|
531
|
+
// accumulate irradiance
|
|
532
|
+
vec3.multiply(irradiance, irradiance, tmp_0);
|
|
539
533
|
|
|
540
534
|
// reflect ray
|
|
541
|
-
array_copy(trace_result, 0, _ray_0, 0, 3);
|
|
542
|
-
|
|
543
535
|
getBiasedNormalSample(_ray_0, 3, tmp_0, 3, 1, random);
|
|
544
536
|
|
|
545
|
-
// accumulate
|
|
546
|
-
vec3.multiply(irradiance, irradiance, tmp_0);
|
|
547
537
|
}
|
|
548
538
|
|
|
549
|
-
|
|
550
539
|
if (i > 0) {
|
|
551
|
-
|
|
552
|
-
// directly sample light at the end of the path
|
|
540
|
+
// direct lighting
|
|
553
541
|
this.sample_lights(tmp_1, 0, trace_result, 0);
|
|
554
542
|
|
|
555
|
-
|
|
543
|
+
irradiance[0] *= tmp_1[0];
|
|
544
|
+
irradiance[1] *= tmp_1[1];
|
|
545
|
+
irradiance[2] *= tmp_1[2];
|
|
556
546
|
}
|
|
557
547
|
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
548
|
+
out[0] = irradiance[0]
|
|
549
|
+
out[1] = irradiance[1]
|
|
550
|
+
out[2] = irradiance[2]
|
|
561
551
|
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
* @param {number} material
|
|
565
|
-
* @param {number} hit
|
|
566
|
-
*/
|
|
567
|
-
function compute_hit_reaction_standard_material(material, hit) {
|
|
568
|
-
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
/**
|
|
573
|
-
*
|
|
574
|
-
* @param {number[]|vec3} out
|
|
575
|
-
* @param {number} value
|
|
576
|
-
*/
|
|
577
|
-
function vec3_set_scalar(out, value) {
|
|
578
|
-
out[0] = value;
|
|
579
|
-
out[1] = value;
|
|
580
|
-
out[2] = value;
|
|
552
|
+
// array_copy(irradiance, 0, out, 0, 3);
|
|
553
|
+
}
|
|
581
554
|
}
|
|
@@ -9,4 +9,13 @@
|
|
|
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;
|
|
12
21
|
//# sourceMappingURL=getBiasedNormalSample.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBiasedNormalSample.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/getBiasedNormalSample.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getBiasedNormalSample.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/getBiasedNormalSample.js"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,2CAPW,MAAM,EAAE,cACR,MAAM,UACN,MAAM,EAAE,iBACR,MAAM,SACN,MAAM,gBACK,MAAM,QAsD3B;AAED;;;;;;;GAOG;AACH,wCANW,MAAM,EAAE,cACR,MAAM,UACN,MAAM,EAAE,iBACR,MAAM,gBACK,MAAM,QAgC3B"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { PI2 } from "../../../../core/math/PI2.js";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* @see 2003 "Global Illumination Compendium" by Philip Dutré (equation 36)
|
|
3
5
|
* @see http://blog.hvidtfeldts.net/index.php/2015/01/path-tracing-3d-fractals/
|
|
@@ -8,7 +10,15 @@
|
|
|
8
10
|
* @param {number} power
|
|
9
11
|
* @param {function():number} random
|
|
10
12
|
*/
|
|
11
|
-
export function getBiasedNormalSample(
|
|
13
|
+
export function getBiasedNormalSample(
|
|
14
|
+
out,
|
|
15
|
+
out_offset,
|
|
16
|
+
normal,
|
|
17
|
+
normal_offset,
|
|
18
|
+
power,
|
|
19
|
+
random
|
|
20
|
+
) {
|
|
21
|
+
|
|
12
22
|
const dir_x = normal[normal_offset];
|
|
13
23
|
const dir_y = normal[normal_offset + 1];
|
|
14
24
|
const dir_z = normal[normal_offset + 2];
|
|
@@ -40,8 +50,8 @@ export function getBiasedNormalSample(out, out_offset, normal, normal_offset, po
|
|
|
40
50
|
// we can skip normalizing second orthonormal vector, as it will be guaranteed to be unit length already
|
|
41
51
|
// for explanation, see https://math.stackexchange.com/questions/23259/is-the-cross-product-of-two-unit-vectors-itself-a-unit-vector#:~:text=If%20you%20know%20that%20the,(a%20length%20of%20one).
|
|
42
52
|
|
|
43
|
-
const r_x =
|
|
44
|
-
const r_y = Math.pow(
|
|
53
|
+
const r_x = random() * PI2;
|
|
54
|
+
const r_y = Math.pow(random(), 1 / (power + 1));
|
|
45
55
|
|
|
46
56
|
const oneminus = Math.sqrt(1.0 - r_y * r_y);
|
|
47
57
|
|
|
@@ -53,3 +63,43 @@ export function getBiasedNormalSample(out, out_offset, normal, normal_offset, po
|
|
|
53
63
|
out[out_offset + 1] = k0 * o1_y + k1 * o2_y + r_y * dir_y;
|
|
54
64
|
out[out_offset + 2] = k0 * o1_z + k1 * o2_z + r_y * dir_z;
|
|
55
65
|
}
|
|
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
|
+
}
|
|
@@ -71,7 +71,7 @@ vCanvas.css({
|
|
|
71
71
|
* How many rays to use per-pixel
|
|
72
72
|
* @type {number}
|
|
73
73
|
*/
|
|
74
|
-
const PIXEL_SAMPLE_COUNT =
|
|
74
|
+
const PIXEL_SAMPLE_COUNT = 64;
|
|
75
75
|
|
|
76
76
|
const pt = new PathTracer();
|
|
77
77
|
|
|
@@ -476,7 +476,7 @@ function* render(target, pt, camera, progress = { current: 0, total: 0 }) {
|
|
|
476
476
|
ray_direction.x, ray_direction.y, ray_direction.z
|
|
477
477
|
);
|
|
478
478
|
|
|
479
|
-
pt.path_trace(pixel_color, ray, Infinity,
|
|
479
|
+
pt.path_trace(pixel_color, ray, Infinity, 3, random);
|
|
480
480
|
|
|
481
481
|
pixel_accummulation[0] += pixel_color[0];
|
|
482
482
|
pixel_accummulation[1] += pixel_color[1];
|
|
@@ -533,7 +533,7 @@ async function start_renderer(camera) {
|
|
|
533
533
|
// await prepare_scene_sphere_01(pt, camera);
|
|
534
534
|
await prepare_scene_gltf(pt, camera, path);
|
|
535
535
|
|
|
536
|
-
pt.build();
|
|
536
|
+
await pt.build();
|
|
537
537
|
// pt.optimize();
|
|
538
538
|
|
|
539
539
|
const pixelRatio = 1;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @param {Texture} texture
|
|
4
4
|
* @param {number} [width]
|
|
5
5
|
* @param {number} [height]
|
|
6
|
-
* @param {boolean} flipY
|
|
6
|
+
* @param {boolean} [flipY]
|
|
7
7
|
* @return {Sampler2D}
|
|
8
8
|
*/
|
|
9
9
|
export function convertTexture2Sampler2D(texture: Texture, width?: number, height?: number, flipY?: boolean): Sampler2D;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convertTexture2Sampler2D.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/texture/sampler/convertTexture2Sampler2D.js"],"names":[],"mappings":"AAUA;;;;;;;GAOG;AACH,mEALW,MAAM,WACN,MAAM,UACN,OAAO,GACN,SAAS,
|
|
1
|
+
{"version":3,"file":"convertTexture2Sampler2D.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/texture/sampler/convertTexture2Sampler2D.js"],"names":[],"mappings":"AAUA;;;;;;;GAOG;AACH,mEALW,MAAM,WACN,MAAM,UACN,OAAO,GACN,SAAS,CAyEpB;0BArFyB,gBAAgB"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { flipArrayInPlace } from "../../filter/FlipArrayInPlace.js";
|
|
2
2
|
import ImageFilter from "../../filter/ImageFilter.js";
|
|
3
|
-
import { Sampler2D } from "./Sampler2D.js";
|
|
4
3
|
import CopyShader from "../../postprocess/threejs/shaders/CopyShader.js";
|
|
5
|
-
import {
|
|
4
|
+
import { WebGLRendererPool } from "../../render/RendererPool.js";
|
|
5
|
+
import { Sampler2D } from "./Sampler2D.js";
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
const DEFAULT_TEXTURE_WIDTH = 512;
|
|
@@ -13,39 +13,47 @@ const DEFAULT_TEXTURE_HEIGHT = 512;
|
|
|
13
13
|
* @param {Texture} texture
|
|
14
14
|
* @param {number} [width]
|
|
15
15
|
* @param {number} [height]
|
|
16
|
-
* @param {boolean} flipY
|
|
16
|
+
* @param {boolean} [flipY]
|
|
17
17
|
* @return {Sampler2D}
|
|
18
18
|
*/
|
|
19
|
-
export function convertTexture2Sampler2D(
|
|
19
|
+
export function convertTexture2Sampler2D(
|
|
20
|
+
texture,
|
|
21
|
+
width,
|
|
22
|
+
height,
|
|
23
|
+
flipY = true
|
|
24
|
+
) {
|
|
25
|
+
let _height = height;
|
|
26
|
+
let _width = width;
|
|
27
|
+
|
|
20
28
|
// TODO take channel count into account
|
|
21
29
|
|
|
22
|
-
if (
|
|
30
|
+
if (_width === undefined || _height === undefined) {
|
|
23
31
|
|
|
24
32
|
//figure out texture size
|
|
25
33
|
const image = texture.image;
|
|
26
34
|
|
|
27
35
|
if (image !== undefined && image !== null) {
|
|
28
|
-
if (
|
|
36
|
+
if (_width === undefined) {
|
|
29
37
|
if (typeof image.width === "number") {
|
|
30
|
-
|
|
38
|
+
_width = image.width;
|
|
31
39
|
} else {
|
|
32
|
-
|
|
40
|
+
_width = DEFAULT_TEXTURE_WIDTH;
|
|
33
41
|
}
|
|
34
42
|
}
|
|
35
|
-
if (
|
|
43
|
+
if (_height === undefined) {
|
|
36
44
|
if (typeof image.height === "number") {
|
|
37
|
-
|
|
45
|
+
_height = image.height;
|
|
38
46
|
} else {
|
|
39
|
-
|
|
47
|
+
_height = DEFAULT_TEXTURE_HEIGHT;
|
|
40
48
|
}
|
|
41
49
|
}
|
|
42
50
|
} else {
|
|
43
|
-
if (
|
|
44
|
-
|
|
51
|
+
if (_width === undefined) {
|
|
52
|
+
_width = DEFAULT_TEXTURE_WIDTH;
|
|
45
53
|
}
|
|
46
54
|
|
|
47
|
-
if (
|
|
48
|
-
|
|
55
|
+
if (_height === undefined) {
|
|
56
|
+
_height = DEFAULT_TEXTURE_HEIGHT;
|
|
49
57
|
}
|
|
50
58
|
}
|
|
51
59
|
|
|
@@ -53,32 +61,30 @@ export function convertTexture2Sampler2D(texture, width, height, flipY = true) {
|
|
|
53
61
|
|
|
54
62
|
// TODO add special case for DataTexture
|
|
55
63
|
|
|
56
|
-
const
|
|
64
|
+
const built = WebGLRendererPool.global.use(renderer => {
|
|
57
65
|
|
|
58
|
-
|
|
66
|
+
const ctx = renderer.getContext();
|
|
59
67
|
|
|
60
|
-
|
|
61
|
-
|
|
68
|
+
//support for compressed textures
|
|
69
|
+
ctx.getExtension("WEBGL_compressed_texture_s3tc");
|
|
62
70
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
return ImageFilter(renderer, _width, _height, {
|
|
72
|
+
vertexShader: CopyShader.vertexShader,
|
|
73
|
+
fragmentShader: CopyShader.fragmentShader,
|
|
74
|
+
uniforms: {
|
|
75
|
+
tDiffuse: {
|
|
76
|
+
value: texture,
|
|
77
|
+
type: 't'
|
|
78
|
+
},
|
|
79
|
+
opacity: { value: 1.0 }
|
|
80
|
+
}
|
|
81
|
+
});
|
|
74
82
|
|
|
75
|
-
|
|
83
|
+
});
|
|
76
84
|
|
|
77
85
|
if (flipY) {
|
|
78
|
-
flipArrayInPlace(built.array,
|
|
86
|
+
flipArrayInPlace(built.array, _width, _height);
|
|
79
87
|
}
|
|
80
88
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return sampler;
|
|
89
|
+
return new Sampler2D(built.array, 4, _width, _height);
|
|
84
90
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug_draw_sampler.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/texture/sampler/debug/debug_draw_sampler.js"],"names":[],"mappings":"AAIA,iGA6BC;sBAhCqB,2CAA2C"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { CanvasView } from "../../../../../view/elements/CanvasView.js";
|
|
2
|
+
import EmptyView from "../../../../../view/elements/EmptyView.js";
|
|
3
|
+
import sampler2D2Canvas from "../Sampler2D2Canvas.js";
|
|
4
|
+
|
|
5
|
+
export function debug_draw_sampler(engine, sampler, x = 0, y = 0) {
|
|
6
|
+
|
|
7
|
+
const view = new CanvasView();
|
|
8
|
+
view.size.set(sampler.width, sampler.height);
|
|
9
|
+
sampler2D2Canvas(sampler, 1, 0, view.el);
|
|
10
|
+
|
|
11
|
+
view.css({
|
|
12
|
+
position: 'absolute',
|
|
13
|
+
top: "0",
|
|
14
|
+
left: "0"
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const container = new EmptyView({
|
|
18
|
+
css: {
|
|
19
|
+
position: 'absolute',
|
|
20
|
+
top: `${y}px`,
|
|
21
|
+
left: `${x}px`
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
container.size.set(sampler.width, sampler.height);
|
|
25
|
+
container.addChild(view);
|
|
26
|
+
|
|
27
|
+
engine.gameView.addChild(container);
|
|
28
|
+
|
|
29
|
+
container.$redraw = () => {
|
|
30
|
+
sampler2D2Canvas(sampler, 1, 0, view.el);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
return container;
|
|
34
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {Engine} engine
|
|
4
|
+
* @param {Sampler2D} input
|
|
5
|
+
* @param {function(Sampler2D,Sampler2D,{label:string, skip:boolean})[]} transforms
|
|
6
|
+
* @param {Vector2} size
|
|
7
|
+
* @param {boolean} display_labels
|
|
8
|
+
*/
|
|
9
|
+
export function debug_draw_sampler_grid({ engine, input, transforms, size, display_labels }: Engine): void;
|
|
10
|
+
//# sourceMappingURL=debug_draw_sampler_grid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug_draw_sampler_grid.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/texture/sampler/debug/debug_draw_sampler_grid.js"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,2GA0EC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import Vector2 from "../../../../../core/geom/Vector2.js";
|
|
2
|
+
import { max2 } from "../../../../../core/math/max2.js";
|
|
3
|
+
import LabelView from "../../../../../view/common/LabelView.js";
|
|
4
|
+
import { debug_draw_sampler } from "./debug_draw_sampler.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param {Engine} engine
|
|
9
|
+
* @param {Sampler2D} input
|
|
10
|
+
* @param {function(Sampler2D,Sampler2D,{label:string, skip:boolean})[]} transforms
|
|
11
|
+
* @param {Vector2} size
|
|
12
|
+
* @param {boolean} display_labels
|
|
13
|
+
*/
|
|
14
|
+
export function debug_draw_sampler_grid({
|
|
15
|
+
engine,
|
|
16
|
+
input,
|
|
17
|
+
transforms,
|
|
18
|
+
size = new Vector2(input.width, input.height),
|
|
19
|
+
display_labels = true
|
|
20
|
+
}) {
|
|
21
|
+
|
|
22
|
+
const GAP_SIZE = 4;
|
|
23
|
+
|
|
24
|
+
let draw_index = 0;
|
|
25
|
+
|
|
26
|
+
const viewport_width = window.innerWidth;
|
|
27
|
+
const tiles_x = max2(1, Math.floor(viewport_width / (size.x + GAP_SIZE)));
|
|
28
|
+
|
|
29
|
+
for (let i = 0; i < transforms.length; i++) {
|
|
30
|
+
const out = input.clone();
|
|
31
|
+
|
|
32
|
+
out.resize(size.x, size.y);
|
|
33
|
+
|
|
34
|
+
const params = {
|
|
35
|
+
label: '',
|
|
36
|
+
skip: false
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const t0 = performance.now();
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
transforms[i](out, input, params);
|
|
43
|
+
} catch (e) {
|
|
44
|
+
// error, skip
|
|
45
|
+
console.error(`Failed '${params.label}'. Reason: ${e.message}`)
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const t1 = performance.now();
|
|
50
|
+
|
|
51
|
+
if (params.skip) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const t_duration = t1 - t0;
|
|
56
|
+
|
|
57
|
+
console.log(`Executed ${params.label} in ${t_duration}ms`);
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
const draw_x = (draw_index % tiles_x) * (size.x + GAP_SIZE);
|
|
61
|
+
const draw_y = Math.floor(draw_index / tiles_x) * (size.y + GAP_SIZE);
|
|
62
|
+
|
|
63
|
+
const view = debug_draw_sampler(engine, out, draw_x, draw_y);
|
|
64
|
+
|
|
65
|
+
if (params.label.length > 0 && display_labels) {
|
|
66
|
+
const vLabel = new LabelView(params.label, {
|
|
67
|
+
css: {
|
|
68
|
+
position: 'absolute',
|
|
69
|
+
fontFamily: 'sans-serif',
|
|
70
|
+
fontWeight: 'bold',
|
|
71
|
+
top: 0,
|
|
72
|
+
left: 0,
|
|
73
|
+
zIndex: 1,
|
|
74
|
+
color: '#000000',
|
|
75
|
+
textShadow: '1px 1px 1px white',
|
|
76
|
+
background: 'rgba(255,255,255,0.7)',
|
|
77
|
+
padding: '2px'
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
view.addChild(vLabel);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
draw_index++;
|
|
85
|
+
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|