@woosh/meep-engine 2.97.0 → 2.98.1

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.
Files changed (163) hide show
  1. package/build/bundle-worker-terrain.js +1 -1
  2. package/build/meep.cjs +861 -670
  3. package/build/meep.min.js +1 -1
  4. package/build/meep.module.js +861 -670
  5. package/package.json +1 -1
  6. package/src/core/bvh2/bvh3/query/bvh_query_leaves_ray.js +1 -1
  7. package/src/core/bvh2/bvh3/query/bvh_query_user_data_generic.js +1 -1
  8. package/src/core/bvh2/bvh3/query/bvh_query_user_data_ray.d.ts.map +1 -1
  9. package/src/core/bvh2/bvh3/query/bvh_query_user_data_ray.js +3 -2
  10. package/src/core/collection/array/arrayQuickSort.js +2 -2
  11. package/src/core/collection/array/array_compute_max.d.ts +9 -0
  12. package/src/core/collection/array/array_compute_max.d.ts.map +1 -0
  13. package/src/core/collection/array/{computeArrayMax.js → array_compute_max.js} +1 -1
  14. package/src/core/collection/array/array_compute_min.d.ts +9 -0
  15. package/src/core/collection/array/array_compute_min.d.ts.map +1 -0
  16. package/src/core/collection/array/{computeArrayMin.js → array_compute_min.js} +1 -1
  17. package/src/core/collection/array/array_compute_min_max.d.ts.map +1 -1
  18. package/src/core/collection/array/array_compute_min_max.js +1 -0
  19. package/src/core/collection/array/array_swap.d.ts.map +1 -1
  20. package/src/core/collection/array/array_swap.js +11 -8
  21. package/src/core/collection/array/array_swap_one.d.ts +8 -0
  22. package/src/core/collection/array/array_swap_one.d.ts.map +1 -0
  23. package/src/core/collection/array/{arraySwapElements.js → array_swap_one.js} +1 -1
  24. package/src/core/collection/array/iterator/AbstractArrayIterator.d.ts.map +1 -0
  25. package/src/core/collection/array/iterator/ArrayIteratorRandom.d.ts.map +1 -0
  26. package/src/core/collection/array/{ArrayIteratorRandom.js → iterator/ArrayIteratorRandom.js} +2 -2
  27. package/src/core/collection/array/iterator/ArrayIteratorSequential.d.ts.map +1 -0
  28. package/src/core/collection/array/randomizeArrayElementOrder.js +2 -2
  29. package/src/core/collection/map/HashMap.js +10 -10
  30. package/src/core/collection/map/ObservedMap.d.ts +7 -4
  31. package/src/core/collection/map/ObservedMap.d.ts.map +1 -1
  32. package/src/core/collection/map/ObservedMap.js +4 -1
  33. package/src/core/collection/queue/Deque.d.ts.map +1 -1
  34. package/src/core/collection/queue/Deque.js +82 -36
  35. package/src/core/collection/set/compute_set_difference.d.ts.map +1 -1
  36. package/src/core/collection/set/compute_set_difference.js +8 -0
  37. package/src/core/collection/set/compute_set_difference.spec.d.ts +2 -0
  38. package/src/core/collection/set/compute_set_difference.spec.d.ts.map +1 -0
  39. package/src/core/collection/set/compute_set_difference.spec.js +45 -0
  40. package/src/core/collection/set/compute_set_intersection.d.ts +1 -0
  41. package/src/core/collection/set/compute_set_intersection.d.ts.map +1 -1
  42. package/src/core/collection/set/compute_set_intersection.js +9 -0
  43. package/src/core/collection/set/compute_set_intersection.spec.d.ts +2 -0
  44. package/src/core/collection/set/compute_set_intersection.spec.d.ts.map +1 -0
  45. package/src/core/collection/set/compute_set_intersection.spec.js +45 -0
  46. package/src/core/collection/set/set_remove.d.ts +2 -0
  47. package/src/core/collection/set/set_remove.d.ts.map +1 -1
  48. package/src/core/collection/set/set_remove.js +2 -0
  49. package/src/core/color/oklab/XYZ.spec.d.ts +2 -0
  50. package/src/core/color/oklab/XYZ.spec.d.ts.map +1 -0
  51. package/src/core/color/oklab/XYZ.spec.js +17 -0
  52. package/src/core/color/oklab/oklab_to_xyz.d.ts +9 -0
  53. package/src/core/color/oklab/oklab_to_xyz.d.ts.map +1 -0
  54. package/src/core/color/oklab/oklab_to_xyz.js +32 -0
  55. package/src/core/color/oklab/oklab_to_xyz.spec.d.ts +2 -0
  56. package/src/core/color/oklab/oklab_to_xyz.spec.d.ts.map +1 -0
  57. package/src/core/color/oklab/oklab_to_xyz.spec.js +31 -0
  58. package/src/core/color/oklab/xyz_to_oklab.d.ts +8 -0
  59. package/src/core/color/oklab/xyz_to_oklab.d.ts.map +1 -0
  60. package/src/core/color/oklab/xyz_to_oklab.js +29 -0
  61. package/src/core/color/oklab/xyz_to_oklab.spec.d.ts +2 -0
  62. package/src/core/color/oklab/xyz_to_oklab.spec.d.ts.map +1 -0
  63. package/src/core/color/oklab/xyz_to_oklab.spec.js +31 -0
  64. package/src/core/color/sRGB/linear_to_sRGB.d.ts.map +1 -1
  65. package/src/core/color/sRGB/linear_to_sRGB.js +16 -5
  66. package/src/core/color/sRGB/sRGB_to_linear.d.ts.map +1 -1
  67. package/src/core/color/sRGB/sRGB_to_linear.js +17 -5
  68. package/src/core/color/xyz/rgb_to_xyz.d.ts +1 -0
  69. package/src/core/color/xyz/rgb_to_xyz.d.ts.map +1 -1
  70. package/src/core/color/xyz/rgb_to_xyz.js +4 -3
  71. package/src/core/color/xyz/xyz_to_rgb.d.ts +1 -1
  72. package/src/core/color/xyz/xyz_to_rgb.js +4 -4
  73. package/src/core/geom/3d/aabb/aabb3_intersects_ray.js +10 -10
  74. package/src/core/parser/simple/ParserError.d.ts +11 -6
  75. package/src/core/parser/simple/ParserError.d.ts.map +1 -1
  76. package/src/core/parser/simple/ParserError.js +51 -4
  77. package/src/core/parser/simple/Token.d.ts.map +1 -1
  78. package/src/core/parser/simple/Token.js +8 -2
  79. package/src/core/parser/simple/TokenType.d.ts +1 -5
  80. package/src/core/parser/simple/TokenType.d.ts.map +1 -1
  81. package/src/core/parser/simple/TokenType.js +1 -1
  82. package/src/core/parser/simple/readBooleanToken.d.ts.map +1 -1
  83. package/src/core/parser/simple/readBooleanToken.js +6 -1
  84. package/src/core/parser/simple/readHexToken.d.ts.map +1 -1
  85. package/src/core/parser/simple/readHexToken.js +7 -2
  86. package/src/core/parser/simple/readIdentifierToken.d.ts.map +1 -1
  87. package/src/core/parser/simple/readIdentifierToken.js +6 -1
  88. package/src/core/parser/simple/readLiteralToken.d.ts.map +1 -1
  89. package/src/core/parser/simple/readLiteralToken.js +8 -3
  90. package/src/core/parser/simple/readNumberToken.d.ts.map +1 -1
  91. package/src/core/parser/simple/readNumberToken.js +7 -2
  92. package/src/core/parser/simple/readReferenceToken.d.ts.map +1 -1
  93. package/src/core/parser/simple/readReferenceToken.js +6 -1
  94. package/src/core/parser/simple/readStringToken.d.ts.map +1 -1
  95. package/src/core/parser/simple/readStringToken.js +6 -1
  96. package/src/core/parser/simple/readUnsignedIntegerToken.d.ts.map +1 -1
  97. package/src/core/parser/simple/readUnsignedIntegerToken.js +7 -2
  98. package/src/core/parser/simple/skipWhitespace.d.ts.map +1 -1
  99. package/src/core/parser/simple/skipWhitespace.js +8 -0
  100. package/src/core/primitives/strings/string_repeat.d.ts +9 -0
  101. package/src/core/primitives/strings/string_repeat.d.ts.map +1 -0
  102. package/src/core/primitives/strings/string_repeat.js +26 -0
  103. package/src/engine/asset/AssetManager.d.ts.map +1 -1
  104. package/src/engine/development/performance/RingBufferMetric.d.ts.map +1 -1
  105. package/src/engine/development/performance/RingBufferMetric.js +5 -5
  106. package/src/engine/ecs/terrain/ecs/BuildLightTexture.d.ts.map +1 -1
  107. package/src/engine/ecs/terrain/ecs/BuildLightTexture.js +15 -22
  108. package/src/engine/graphics/ecs/camera/Camera.d.ts.map +1 -1
  109. package/src/engine/graphics/ecs/camera/Camera.js +23 -16
  110. package/src/engine/graphics/filter/ImageFilter.d.ts +2 -2
  111. package/src/engine/graphics/filter/ImageFilter.d.ts.map +1 -1
  112. package/src/engine/graphics/filter/ImageFilter.js +3 -3
  113. package/src/engine/graphics/render/RendererPool.d.ts +14 -1
  114. package/src/engine/graphics/render/RendererPool.d.ts.map +1 -1
  115. package/src/engine/graphics/render/RendererPool.js +43 -1
  116. package/src/engine/graphics/render/forward_plus/LightManager.js +2 -2
  117. package/src/engine/graphics/sh3/path_tracer/PathTracer.d.ts +2 -1
  118. package/src/engine/graphics/sh3/path_tracer/PathTracer.d.ts.map +1 -1
  119. package/src/engine/graphics/sh3/path_tracer/PathTracer.js +23 -50
  120. package/src/engine/graphics/sh3/path_tracer/getBiasedNormalSample.d.ts +9 -0
  121. package/src/engine/graphics/sh3/path_tracer/getBiasedNormalSample.d.ts.map +1 -1
  122. package/src/engine/graphics/sh3/path_tracer/getBiasedNormalSample.js +53 -3
  123. package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +3 -3
  124. package/src/engine/graphics/texture/sampler/convertTexture2Sampler2D.d.ts +1 -1
  125. package/src/engine/graphics/texture/sampler/convertTexture2Sampler2D.d.ts.map +1 -1
  126. package/src/engine/graphics/texture/sampler/convertTexture2Sampler2D.js +42 -36
  127. package/src/engine/graphics/texture/sampler/debug/debug_draw_sampler.d.ts +3 -0
  128. package/src/engine/graphics/texture/sampler/debug/debug_draw_sampler.d.ts.map +1 -0
  129. package/src/engine/graphics/texture/sampler/debug/debug_draw_sampler.js +34 -0
  130. package/src/engine/graphics/texture/sampler/debug/debug_draw_sampler_grid.d.ts +10 -0
  131. package/src/engine/graphics/texture/sampler/debug/debug_draw_sampler_grid.d.ts.map +1 -0
  132. package/src/engine/graphics/texture/sampler/debug/debug_draw_sampler_grid.js +89 -0
  133. package/src/engine/graphics/texture/sampler/debug/prototypeSamplerFiltering.d.ts.map +1 -0
  134. package/src/engine/graphics/texture/sampler/{prototypeSamplerFiltering.js → debug/prototypeSamplerFiltering.js} +105 -113
  135. package/src/generation/grid/generation/GridTaskDensityMarkerDistribution.d.ts.map +1 -1
  136. package/src/generation/grid/generation/GridTaskDensityMarkerDistribution.js +8 -8
  137. package/src/generation/markers/GridActionRuleSet.d.ts.map +1 -1
  138. package/src/generation/markers/GridActionRuleSet.js +5 -5
  139. package/src/core/binary/byteArrayToString.d.ts +0 -9
  140. package/src/core/binary/byteArrayToString.d.ts.map +0 -1
  141. package/src/core/binary/byteArrayToString.js +0 -28
  142. package/src/core/collection/array/AbstractArrayIterator.d.ts.map +0 -1
  143. package/src/core/collection/array/ArrayIteratorRandom.d.ts.map +0 -1
  144. package/src/core/collection/array/ArrayIteratorSequential.d.ts.map +0 -1
  145. package/src/core/collection/array/arrayPickMinElement.d.ts +0 -8
  146. package/src/core/collection/array/arrayPickMinElement.d.ts.map +0 -1
  147. package/src/core/collection/array/arrayPickMinElement.js +0 -43
  148. package/src/core/collection/array/arraySwapElements.d.ts +0 -8
  149. package/src/core/collection/array/arraySwapElements.d.ts.map +0 -1
  150. package/src/core/collection/array/computeArrayMax.d.ts +0 -9
  151. package/src/core/collection/array/computeArrayMax.d.ts.map +0 -1
  152. package/src/core/collection/array/computeArrayMin.d.ts +0 -9
  153. package/src/core/collection/array/computeArrayMin.d.ts.map +0 -1
  154. package/src/core/color/hsluv/HSLuv.d.ts +0 -13
  155. package/src/core/color/hsluv/HSLuv.d.ts.map +0 -1
  156. package/src/core/color/hsluv/HSLuv.js +0 -187
  157. package/src/engine/graphics/texture/sampler/prototypeSamplerFiltering.d.ts.map +0 -1
  158. /package/src/core/collection/array/{AbstractArrayIterator.d.ts → iterator/AbstractArrayIterator.d.ts} +0 -0
  159. /package/src/core/collection/array/{AbstractArrayIterator.js → iterator/AbstractArrayIterator.js} +0 -0
  160. /package/src/core/collection/array/{ArrayIteratorRandom.d.ts → iterator/ArrayIteratorRandom.d.ts} +0 -0
  161. /package/src/core/collection/array/{ArrayIteratorSequential.d.ts → iterator/ArrayIteratorSequential.d.ts} +0 -0
  162. /package/src/core/collection/array/{ArrayIteratorSequential.js → iterator/ArrayIteratorSequential.js} +0 -0
  163. /package/src/engine/graphics/texture/sampler/{prototypeSamplerFiltering.d.ts → debug/prototypeSamplerFiltering.d.ts} +0 -0
@@ -4,8 +4,8 @@
4
4
 
5
5
 
6
6
  import { DoubleSide, LinearFilter, Mesh, OrthographicCamera, Scene, ShaderMaterial, WebGLRenderTarget } from 'three';
7
- import { FULL_SCREEN_TRIANGLE_GEOMETRY } from "../geometry/FULL_SCREEN_TRIANGLE_GEOMETRY.js";
8
7
  import { FULL_SCREEN_QUAD_VERTEX_SHADER } from "../FULL_SCREEN_QUAD_VERTEX_SHADER.js";
8
+ import { FULL_SCREEN_TRIANGLE_GEOMETRY } from "../geometry/FULL_SCREEN_TRIANGLE_GEOMETRY.js";
9
9
 
10
10
  /**
11
11
  *
@@ -13,7 +13,7 @@ import { FULL_SCREEN_QUAD_VERTEX_SHADER } from "../FULL_SCREEN_QUAD_VERTEX_SHADE
13
13
  * @param {number} width
14
14
  * @param {number} height
15
15
  * @param {{vertexShader?:string,fragmentShader:string, uniforms?:Object, defines?:Object}} processShader
16
- * @param {Uint8Array} [destination]
16
+ * @param {Uint8Array|Uint8ClampedArray} [destination]
17
17
  * @return {{array: Uint8Array, renderer: WebGLRenderer}}
18
18
  */
19
19
  function processTexture(
@@ -24,7 +24,7 @@ function processTexture(
24
24
  destination
25
25
  ) {
26
26
  if (destination === undefined) {
27
- destination = new Uint8Array(width * height * 4);
27
+ destination = new Uint8ClampedArray(width * height * 4);
28
28
  }
29
29
 
30
30
  //make a webgl renderer with orthographic camera
@@ -1,13 +1,26 @@
1
1
  export class WebGLRendererPool {
2
2
  static global: WebGLRendererPool;
3
3
  used: Set<any>;
4
- get(options: any): WebGLRenderer;
4
+ get(): WebGLRenderer;
5
5
  /**
6
6
  *
7
7
  * @param {THREE.WebGLRenderer} renderer
8
8
  * @returns {boolean}
9
9
  */
10
10
  release(renderer: THREE.WebGLRenderer): boolean;
11
+ /**
12
+ * After callback returns, renderer is released back into the pool
13
+ * @template T
14
+ * @param {function(renderer:WebGLRenderer):T} callback
15
+ * @param {*} [thisArg]
16
+ */
17
+ use<T>(callback: any, thisArg?: any): any;
18
+ /**
19
+ * @template T
20
+ * @param {function(renderer:WebGLRenderer):Promise<T>} callback
21
+ * @param {*} [thisArg]
22
+ */
23
+ useAsync<T_1>(callback: any, thisArg?: any): Promise<void>;
11
24
  }
12
25
  import { WebGLRenderer } from 'three';
13
26
  //# sourceMappingURL=RendererPool.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RendererPool.d.ts","sourceRoot":"","sources":["../../../../../src/engine/graphics/render/RendererPool.js"],"names":[],"mappings":"AAGA;IAuCI,iCAAwC;IArCxC,eAAiB;IAEjB,iCAcC;IAED;;;;OAIG;IACH,kBAHW,mBAAmB,GACjB,OAAO,CAcnB;CAGJ;8BA3C6B,OAAO"}
1
+ {"version":3,"file":"RendererPool.d.ts","sourceRoot":"","sources":["../../../../../src/engine/graphics/render/RendererPool.js"],"names":[],"mappings":"AAGA;IAiFI,iCAAwC;IA/ExC,eAAiB;IAEjB,qBAcC;IAED;;;;OAIG;IACH,kBAHW,mBAAmB,GACjB,OAAO,CAcnB;IAED;;;;;OAKG;IACH,0CAkBC;IAED;;;;OAIG;IACH,2DASC;CAGJ;8BArF6B,OAAO"}
@@ -5,7 +5,7 @@ export class WebGLRendererPool {
5
5
 
6
6
  used = new Set();
7
7
 
8
- get(options) {
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
- arraySwapElements(this.__view_frustum.planes, 4, 5);
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":";AAgEA;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,CAyCjB;IAED;;;;;;OAMG;IACH,uBALW,MAAM,EAAE,cACR,MAAM,aACN,MAAM,EAAE,oBACR,MAAM,QAIhB;IAED;;;;;;OAMG;IACH,mBALW,MAAM,EAAE,cACR,MAAM,OACN,MAAM,EAAE,eACR,MAAM,WAgEhB;IAED,gGAyDC;CACJ;oBAriBmB,mCAAmC;+BAexB,qBAAqB;mCAHjB,yBAAyB;qBAtBjC,WAAW"}
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 { bvh_query_leaves_ray } from "../../../../core/bvh2/bvh3/query/bvh_query_leaves_ray.js";
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 = bvh_query_leaves_ray(
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], ray[3], ray[4], ray[5]
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 node_id = temp_ray_results[i];
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(ray_direction_x, ray_direction_y, ray_direction_z, light_dir_inv_x, light_dir_inv_y, light_dir_inv_z);
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
- vec3.multiply(irradiance, irradiance, tmp_1);
543
+ irradiance[0] *= tmp_1[0];
544
+ irradiance[1] *= tmp_1[1];
545
+ irradiance[2] *= tmp_1[2];
556
546
  }
557
547
 
558
- array_copy(irradiance, 0, out, 0, 3);
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":"AAAA;;;;;;;;;GASG;AACH,2CAPW,MAAM,EAAE,cACR,MAAM,UACN,MAAM,EAAE,iBACR,MAAM,SACN,MAAM,gBACK,MAAM,QA8C3B"}
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(out, out_offset, normal, normal_offset, power, random) {
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 = (random()) * 2 * Math.PI;
44
- const r_y = Math.pow((random()), 1 / (power + 1));
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 = 4;
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, 4, random);
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,CAmEpB;0BAjFyB,gBAAgB"}
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 { WebGLRendererPool } from "../../render/RendererPool.js";
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 { flipArrayInPlace } from "../../filter/FlipArrayInPlace.js";
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(texture, width, height, flipY = true) {
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 (width === undefined || height === undefined) {
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 (width === undefined) {
36
+ if (_width === undefined) {
29
37
  if (typeof image.width === "number") {
30
- width = image.width;
38
+ _width = image.width;
31
39
  } else {
32
- width = DEFAULT_TEXTURE_WIDTH;
40
+ _width = DEFAULT_TEXTURE_WIDTH;
33
41
  }
34
42
  }
35
- if (height === undefined) {
43
+ if (_height === undefined) {
36
44
  if (typeof image.height === "number") {
37
- height = image.height;
45
+ _height = image.height;
38
46
  } else {
39
- height = DEFAULT_TEXTURE_HEIGHT;
47
+ _height = DEFAULT_TEXTURE_HEIGHT;
40
48
  }
41
49
  }
42
50
  } else {
43
- if (width === undefined) {
44
- width = DEFAULT_TEXTURE_WIDTH;
51
+ if (_width === undefined) {
52
+ _width = DEFAULT_TEXTURE_WIDTH;
45
53
  }
46
54
 
47
- if (height === undefined) {
48
- height = DEFAULT_TEXTURE_HEIGHT;
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 renderer = WebGLRendererPool.global.get({});
64
+ const built = WebGLRendererPool.global.use(renderer => {
57
65
 
58
- const ctx = renderer.getContext();
66
+ const ctx = renderer.getContext();
59
67
 
60
- //support for compressed textures
61
- ctx.getExtension("WEBGL_compressed_texture_s3tc");
68
+ //support for compressed textures
69
+ ctx.getExtension("WEBGL_compressed_texture_s3tc");
62
70
 
63
- const built = ImageFilter(renderer, width, height, {
64
- vertexShader: CopyShader.vertexShader,
65
- fragmentShader: CopyShader.fragmentShader,
66
- uniforms: {
67
- tDiffuse: {
68
- value: texture,
69
- type: 't'
70
- },
71
- opacity: { value: 1.0 }
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
- WebGLRendererPool.global.release(renderer);
83
+ });
76
84
 
77
85
  if (flipY) {
78
- flipArrayInPlace(built.array, width, height);
86
+ flipArrayInPlace(built.array, _width, _height);
79
87
  }
80
88
 
81
- const sampler = new Sampler2D(built.array, 4, width, height);
82
-
83
- return sampler;
89
+ return new Sampler2D(built.array, 4, _width, _height);
84
90
  }
@@ -0,0 +1,3 @@
1
+ export function debug_draw_sampler(engine: any, sampler: any, x?: number, y?: number): EmptyView;
2
+ import EmptyView from "../../../../../view/elements/EmptyView.js";
3
+ //# sourceMappingURL=debug_draw_sampler.d.ts.map
@@ -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"}