@woosh/meep-engine 2.108.0 → 2.108.3

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 (216) hide show
  1. package/build/bundle-worker-terrain.js +1 -1
  2. package/build/meep.cjs +650 -308
  3. package/build/meep.min.js +1 -1
  4. package/build/meep.module.js +650 -308
  5. package/editor/tools/paint/TerrainHeightPaintTool.js +5 -5
  6. package/package.json +1 -1
  7. package/src/core/binary/float_to_uint8.d.ts +7 -0
  8. package/src/core/binary/float_to_uint8.d.ts.map +1 -0
  9. package/src/core/binary/{float2uint8.js → float_to_uint8.js} +1 -1
  10. package/src/core/binary/uint8_to_float.d.ts +7 -0
  11. package/src/core/binary/uint8_to_float.d.ts.map +1 -0
  12. package/src/core/binary/{uint82float.js → uint8_to_float.js} +1 -1
  13. package/src/core/binary/uint8_to_float.spec.d.ts +2 -0
  14. package/src/core/binary/uint8_to_float.spec.d.ts.map +1 -0
  15. package/src/core/binary/uint8_to_float.spec.js +7 -0
  16. package/src/core/bvh2/binary/2/BinaryUint32BVH.d.ts +6 -0
  17. package/src/core/bvh2/binary/2/BinaryUint32BVH.d.ts.map +1 -1
  18. package/src/core/bvh2/binary/2/BinaryUint32BVH.js +15 -3
  19. package/src/core/bvh2/bvh3/build_triangle_morton_codes.js +3 -3
  20. package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.d.ts.map +1 -1
  21. package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.js +25 -14
  22. package/src/core/codegen/codeToBlob.d.ts +8 -0
  23. package/src/core/codegen/codeToBlob.d.ts.map +1 -0
  24. package/src/core/codegen/codeToBlob.js +36 -0
  25. package/src/core/codegen/codeToURL.d.ts +8 -0
  26. package/src/core/codegen/codeToURL.d.ts.map +1 -0
  27. package/src/core/codegen/codeToURL.js +22 -0
  28. package/src/core/collection/array/arrayQuickSort.d.ts +0 -9
  29. package/src/core/collection/array/arrayQuickSort.d.ts.map +1 -1
  30. package/src/core/collection/array/arrayQuickSort.js +0 -73
  31. package/src/core/collection/array/array_quick_sort_by_comparator.d.ts +10 -0
  32. package/src/core/collection/array/array_quick_sort_by_comparator.d.ts.map +1 -0
  33. package/src/core/collection/array/array_quick_sort_by_comparator.js +75 -0
  34. package/src/core/collection/array/array_quick_sort_by_lookup.d.ts +8 -0
  35. package/src/core/collection/array/array_quick_sort_by_lookup.d.ts.map +1 -0
  36. package/src/core/collection/array/array_quick_sort_by_lookup.js +78 -0
  37. package/src/core/collection/array/array_shuffle.d.ts +8 -0
  38. package/src/core/collection/array/array_shuffle.d.ts.map +1 -0
  39. package/src/core/collection/array/array_shuffle.js +22 -0
  40. package/src/core/collection/array/array_shuffle.spec.d.ts +2 -0
  41. package/src/core/collection/array/array_shuffle.spec.d.ts.map +1 -0
  42. package/src/core/collection/array/{randomizeArrayElementOrder.spec.js → array_shuffle.spec.js} +4 -4
  43. package/src/core/collection/array/iterator/ArrayIteratorRandom.js +2 -2
  44. package/src/core/collection/array/randomMultipleFromArray.js +2 -2
  45. package/src/core/color/Color.js +9 -9
  46. package/src/core/color/hsv/hsv2rgb.js +4 -4
  47. package/src/core/color/rgb2uint24.js +4 -4
  48. package/src/core/color/sRGB/linear_to_sRGB.d.ts +1 -0
  49. package/src/core/color/sRGB/linear_to_sRGB.d.ts.map +1 -1
  50. package/src/core/color/sRGB/linear_to_sRGB.js +4 -4
  51. package/src/core/geom/2d/triangle2d_get_barycentric.d.ts +15 -0
  52. package/src/core/geom/2d/triangle2d_get_barycentric.d.ts.map +1 -0
  53. package/src/core/geom/2d/triangle2d_get_barycentric.js +48 -0
  54. package/src/core/geom/3d/aabb/AABB3.d.ts.map +1 -1
  55. package/src/core/geom/3d/aabb/AABB3.js +4 -1
  56. package/src/core/geom/3d/aabb/aabb3_from_v3_array.d.ts.map +1 -1
  57. package/src/core/geom/3d/aabb/aabb3_from_v3_array.js +2 -7
  58. package/src/core/geom/3d/aabb/aabb3_intersects_ray.js +3 -3
  59. package/src/core/geom/3d/aabb3_compute_from_triangle.d.ts +11 -0
  60. package/src/core/geom/3d/aabb3_compute_from_triangle.d.ts.map +1 -0
  61. package/src/core/geom/3d/aabb3_compute_from_triangle.js +43 -0
  62. package/src/core/geom/3d/shape/UnitSphereShape3D.d.ts.map +1 -1
  63. package/src/core/geom/3d/shape/UnitSphereShape3D.js +14 -14
  64. package/src/core/geom/3d/sphere/harmonics/SH3_COEFFICIENTS.d.ts.map +1 -1
  65. package/src/core/geom/3d/sphere/harmonics/SH3_COEFFICIENTS.js +2 -0
  66. package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.js +5 -5
  67. package/src/core/geom/3d/sphere/harmonics/sh_compute_K.d.ts +9 -0
  68. package/src/core/geom/3d/sphere/harmonics/sh_compute_K.d.ts.map +1 -0
  69. package/src/core/geom/3d/sphere/harmonics/sh_compute_K.js +17 -0
  70. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.d.ts +6 -3
  71. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.d.ts.map +1 -1
  72. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.js +56 -18
  73. package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_walk_towards_containing_tetrahedron.d.ts +1 -1
  74. package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_walk_towards_containing_tetrahedron.d.ts.map +1 -1
  75. package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_walk_towards_containing_tetrahedron.js +11 -4
  76. package/src/core/geom/3d/tetrahedra/{GetDepthForTetrahedronProbe.glsl → triangle/GetDepthForTetrahedronProbe.glsl} +17 -10
  77. package/src/core/geom/3d/tetrahedra/triangle/prototype.d.ts +2 -0
  78. package/src/core/geom/3d/tetrahedra/triangle/prototype.d.ts.map +1 -0
  79. package/src/core/geom/3d/tetrahedra/triangle/prototype.js +128 -0
  80. package/src/core/geom/3d/tetrahedra/triangle/trace_triangular_depth_map.d.ts +13 -0
  81. package/src/core/geom/3d/tetrahedra/triangle/trace_triangular_depth_map.d.ts.map +1 -0
  82. package/src/core/geom/3d/tetrahedra/triangle/trace_triangular_depth_map.js +120 -0
  83. package/src/core/geom/3d/tetrahedra/triangle/triangle_encode_rasterized_depth.d.ts +3 -0
  84. package/src/core/geom/3d/tetrahedra/triangle/triangle_encode_rasterized_depth.d.ts.map +1 -0
  85. package/src/core/geom/3d/tetrahedra/triangle/triangle_encode_rasterized_depth.js +106 -0
  86. package/src/core/geom/Vector3.js +3 -3
  87. package/src/core/geom/random/randomPointInSphere.d.ts +1 -1
  88. package/src/core/geom/random/randomPointInSphere.js +2 -2
  89. package/src/core/geom/random/randomPointOnSphere.d.ts +3 -3
  90. package/src/core/geom/random/randomPointOnSphere.d.ts.map +1 -1
  91. package/src/core/geom/random/randomPointOnSphere.js +5 -9
  92. package/src/core/math/factorial.d.ts +7 -0
  93. package/src/core/math/factorial.d.ts.map +1 -0
  94. package/src/core/math/factorial.js +15 -0
  95. package/src/core/math/factorial.spec.d.ts +2 -0
  96. package/src/core/math/factorial.spec.d.ts.map +1 -0
  97. package/src/core/math/factorial.spec.js +9 -0
  98. package/src/core/model/DebouncedObservedBoolean.d.ts +1 -1
  99. package/src/core/model/DebouncedObservedBoolean.d.ts.map +1 -1
  100. package/src/core/model/node-graph/node/NodeDescription.d.ts +6 -4
  101. package/src/core/process/task/util/randomCountTask.js +3 -3
  102. package/src/core/process/worker/WorkerBuilder.d.ts.map +1 -1
  103. package/src/core/process/worker/WorkerBuilder.js +5 -35
  104. package/src/engine/EngineHarness.d.ts.map +1 -1
  105. package/src/engine/EngineHarness.js +7 -1
  106. package/src/engine/asset/loaders/ArrayBufferLoader.d.ts.map +1 -1
  107. package/src/engine/asset/loaders/ArrayBufferLoader.js +17 -10
  108. package/src/engine/asset/loaders/material/TextureAttachmensByMaterialType.d.ts.map +1 -1
  109. package/src/engine/asset/loaders/material/TextureAttachmensByMaterialType.js +3 -0
  110. package/src/engine/asset/loaders/material/computeTextureEquality.d.ts.map +1 -1
  111. package/src/engine/asset/loaders/material/computeTextureEquality.js +8 -1
  112. package/src/engine/ecs/terrain/overlay/TerrainOverlay.js +4 -4
  113. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraController.d.ts.map +1 -1
  114. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraController.js +4 -0
  115. package/src/engine/graphics/ecs/mesh-v2/render/adapters/AbstractRenderAdapter.d.ts.map +1 -1
  116. package/src/engine/graphics/ecs/mesh-v2/render/adapters/AbstractRenderAdapter.js +3 -1
  117. package/src/engine/graphics/ecs/sprite/SpriteSystemPE.d.ts.map +1 -1
  118. package/src/engine/graphics/ecs/sprite/SpriteSystemPE.js +7 -7
  119. package/src/engine/graphics/filter/sampler2d_flipY_in_place.d.ts +8 -0
  120. package/src/engine/graphics/filter/sampler2d_flipY_in_place.d.ts.map +1 -0
  121. package/src/engine/graphics/filter/{FlipArrayInPlace.js → sampler2d_flipY_in_place.js} +1 -1
  122. package/src/engine/graphics/geometry/bvh/buffered/bvh32_set_leaf_from_triangle.d.ts.map +1 -1
  123. package/src/engine/graphics/geometry/bvh/buffered/bvh32_set_leaf_from_triangle.js +5 -27
  124. package/src/engine/graphics/impostors/octahedral/bake/prepare_bake_material.js +3 -3
  125. package/src/engine/graphics/render/Lines.d.ts.map +1 -1
  126. package/src/engine/graphics/render/Lines.js +10 -2
  127. package/src/engine/graphics/sh3/SH3VisualisationMaterial.d.ts.map +1 -1
  128. package/src/engine/graphics/sh3/SH3VisualisationMaterial.js +9 -6
  129. package/src/engine/graphics/sh3/gi/material/MaterialTransformer.d.ts +24 -0
  130. package/src/engine/graphics/sh3/gi/material/MaterialTransformer.d.ts.map +1 -0
  131. package/src/engine/graphics/sh3/gi/material/MaterialTransformer.js +293 -0
  132. package/src/engine/graphics/sh3/gi/material/build_fragment_shader.d.ts +6 -0
  133. package/src/engine/graphics/sh3/gi/material/build_fragment_shader.d.ts.map +1 -0
  134. package/src/engine/graphics/sh3/gi/material/build_fragment_shader.js +71 -0
  135. package/src/engine/graphics/sh3/gi/material/build_vertex_shader.d.ts +6 -0
  136. package/src/engine/graphics/sh3/gi/material/build_vertex_shader.d.ts.map +1 -0
  137. package/src/engine/graphics/sh3/gi/material/build_vertex_shader.js +256 -0
  138. package/src/engine/graphics/sh3/gi/tetrahedral_mesh_to_texture.js +4 -4
  139. package/src/engine/graphics/sh3/lpv/LightProbeVolume.d.ts +3 -1
  140. package/src/engine/graphics/sh3/lpv/LightProbeVolume.d.ts.map +1 -1
  141. package/src/engine/graphics/sh3/lpv/LightProbeVolume.js +12 -1
  142. package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.d.ts.map +1 -1
  143. package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.js +4 -5
  144. package/src/engine/graphics/sh3/lpv/build_probes_for_scene.d.ts +2 -1
  145. package/src/engine/graphics/sh3/lpv/build_probes_for_scene.d.ts.map +1 -1
  146. package/src/engine/graphics/sh3/lpv/build_probes_for_scene.js +6 -6
  147. package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.d.ts +8 -0
  148. package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.d.ts.map +1 -1
  149. package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.js +3 -2
  150. package/src/engine/graphics/sh3/path_tracer/PathTracedScene.d.ts.map +1 -1
  151. package/src/engine/graphics/sh3/path_tracer/PathTracedScene.js +9 -4
  152. package/src/engine/graphics/sh3/path_tracer/PathTracer.d.ts +3 -3
  153. package/src/engine/graphics/sh3/path_tracer/PathTracer.d.ts.map +1 -1
  154. package/src/engine/graphics/sh3/path_tracer/PathTracer.js +2 -2
  155. package/src/engine/graphics/sh3/path_tracer/compute_triangle_group_aabb3.d.ts +2 -2
  156. package/src/engine/graphics/sh3/path_tracer/compute_triangle_group_aabb3.d.ts.map +1 -1
  157. package/src/engine/graphics/sh3/path_tracer/compute_triangle_group_aabb3.js +18 -8
  158. package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +14 -6
  159. package/src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples.d.ts +10 -0
  160. package/src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples.d.ts.map +1 -0
  161. package/src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples.js +20 -0
  162. package/src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples_2d.d.ts +10 -0
  163. package/src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples_2d.d.ts.map +1 -0
  164. package/src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples_2d.js +31 -0
  165. package/src/engine/graphics/sh3/path_tracer/sampling/make_stratified_sample.d.ts +9 -0
  166. package/src/engine/graphics/sh3/path_tracer/sampling/make_stratified_sample.d.ts.map +1 -0
  167. package/src/engine/graphics/sh3/path_tracer/sampling/make_stratified_sample.js +21 -0
  168. package/src/engine/graphics/sh3/path_tracer/texture/sample_material.js +1 -1
  169. package/src/engine/graphics/sh3/path_tracer/texture/sample_texture.d.ts.map +1 -1
  170. package/src/engine/graphics/sh3/path_tracer/texture/sample_texture.js +2 -3
  171. package/src/engine/graphics/sh3/path_tracer/vec3_uint8_to_float.js +4 -4
  172. package/src/engine/graphics/sh3/prototypeSH3Probe.js +116 -19
  173. package/src/engine/graphics/texture/AttributeDataTexture.d.ts.map +1 -1
  174. package/src/engine/graphics/texture/AttributeDataTexture.js +8 -2
  175. package/src/engine/graphics/texture/computeThreeTextureFormat.js +2 -1
  176. package/src/engine/graphics/texture/computeThreeTextureFormatFromDataType.d.ts +7 -0
  177. package/src/engine/graphics/texture/computeThreeTextureFormatFromDataType.d.ts.map +1 -0
  178. package/src/engine/graphics/texture/computeThreeTextureFormatFromDataType.js +13 -0
  179. package/src/engine/graphics/texture/numericTypeFromBinaryDataType.d.ts +9 -0
  180. package/src/engine/graphics/texture/numericTypeFromBinaryDataType.d.ts.map +1 -0
  181. package/src/engine/graphics/texture/numericTypeFromBinaryDataType.js +31 -0
  182. package/src/engine/graphics/texture/sampler/Sampler2D.d.ts.map +1 -1
  183. package/src/engine/graphics/texture/sampler/Sampler2D.js +4 -4
  184. package/src/engine/graphics/texture/sampler/convertTexture2Sampler2D.d.ts.map +1 -1
  185. package/src/engine/graphics/texture/sampler/convertTexture2Sampler2D.js +47 -19
  186. package/src/engine/graphics/texture/sampler/debug/prototypeSamplerFiltering.js +5 -33
  187. package/src/engine/graphics/texture/sampler/sampler2d_copy_rectangle.d.ts +11 -0
  188. package/src/engine/graphics/texture/sampler/sampler2d_copy_rectangle.d.ts.map +1 -0
  189. package/src/engine/graphics/texture/sampler/sampler2d_copy_rectangle.js +41 -0
  190. package/src/engine/graphics/texture/virtual/VirtualTextureUsage.d.ts +0 -4
  191. package/src/engine/graphics/texture/virtual/VirtualTextureUsage.d.ts.map +1 -1
  192. package/src/engine/graphics/texture/virtual/VirtualTextureUsage.js +19 -30
  193. package/src/engine/network/convertPathToURL.d.ts +3 -1
  194. package/src/engine/network/convertPathToURL.d.ts.map +1 -1
  195. package/src/engine/network/convertPathToURL.js +68 -51
  196. package/src/engine/physics/fluid/SliceVisualiser.d.ts.map +1 -1
  197. package/src/engine/physics/fluid/SliceVisualiser.js +4 -4
  198. package/src/generation/filtering/numeric/CellFilterCache.d.ts.map +1 -1
  199. package/src/generation/filtering/numeric/CellFilterCache.js +1 -0
  200. package/src/core/binary/float2uint8.d.ts +0 -7
  201. package/src/core/binary/float2uint8.d.ts.map +0 -1
  202. package/src/core/binary/uint82float.d.ts +0 -7
  203. package/src/core/binary/uint82float.d.ts.map +0 -1
  204. package/src/core/binary/uint82float.spec.d.ts +0 -2
  205. package/src/core/binary/uint82float.spec.d.ts.map +0 -1
  206. package/src/core/binary/uint82float.spec.js +0 -7
  207. package/src/core/collection/array/randomizeArrayElementOrder.d.ts +0 -8
  208. package/src/core/collection/array/randomizeArrayElementOrder.d.ts.map +0 -1
  209. package/src/core/collection/array/randomizeArrayElementOrder.js +0 -24
  210. package/src/core/collection/array/randomizeArrayElementOrder.spec.d.ts +0 -2
  211. package/src/core/collection/array/randomizeArrayElementOrder.spec.d.ts.map +0 -1
  212. package/src/engine/graphics/filter/FlipArrayInPlace.d.ts +0 -8
  213. package/src/engine/graphics/filter/FlipArrayInPlace.d.ts.map +0 -1
  214. package/src/engine/graphics/sh3/path_tracer/texture/SoftwareTextureCache.d.ts +0 -3
  215. package/src/engine/graphics/sh3/path_tracer/texture/SoftwareTextureCache.d.ts.map +0 -1
  216. package/src/engine/graphics/sh3/path_tracer/texture/SoftwareTextureCache.js +0 -3
@@ -0,0 +1,24 @@
1
+ export class MaterialTransformer extends AbstractMaterialTransformer {
2
+ /**
3
+ *
4
+ * @param {LightProbeVolume} volume
5
+ */
6
+ constructor({ volume }: LightProbeVolume);
7
+ /**
8
+ *
9
+ * @param {number} v
10
+ */
11
+ set intensity(arg: number);
12
+ /**
13
+ *
14
+ * @return {number}
15
+ */
16
+ get intensity(): number;
17
+ update_bounds(): void;
18
+ update_lookup(): void;
19
+ update(): void;
20
+ transform(source: any): any;
21
+ #private;
22
+ }
23
+ import { AbstractMaterialTransformer } from "../../../material/manager/AbstractMaterialTransformer.js";
24
+ //# sourceMappingURL=MaterialTransformer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MaterialTransformer.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/gi/material/MaterialTransformer.js"],"names":[],"mappings":"AA0CA;IAsHI;;;OAGG;IACH,0CAMC;IAlBD;;;OAGG;IACH,2BAEC;IAdD;;;OAGG;IACH,wBAEC;IAsBD,sBAIC;IAED,sBA2CC;IAED,eAuCC;IAED,4BA2BC;;CACJ;4CA9R2C,0DAA0D"}
@@ -0,0 +1,293 @@
1
+ import { DataTexture3D, NearestFilter, RedIntegerFormat, UnsignedIntType, Vector3 } from "three";
2
+ import { BinaryDataType } from "../../../../../core/binary/type/BinaryDataType.js";
3
+ import { AABB3 } from "../../../../../core/geom/3d/aabb/AABB3.js";
4
+ import { aabb3_from_v3_array } from "../../../../../core/geom/3d/aabb/aabb3_from_v3_array.js";
5
+ import { AttributeSpec } from "../../../geometry/AttributeSpec.js";
6
+ import { composeCompile } from "../../../material/composeCompile.js";
7
+ import { AbstractMaterialTransformer } from "../../../material/manager/AbstractMaterialTransformer.js";
8
+ import { isLitMaterial } from "../../../render/forward_plus/plugin/isLitMaterial.js";
9
+ import { AttributeDataTexture } from "../../../texture/AttributeDataTexture.js";
10
+ import { vector_buffer_to_attribute_texture } from "../../lpv/probe_volume_to_textures.js";
11
+ import { tetrahedral_mesh_to_texture } from "../tetrahedral_mesh_to_texture.js";
12
+ import { build_fragment_shader } from "./build_fragment_shader.js";
13
+ import { build_vertex_shader } from "./build_vertex_shader.js";
14
+
15
+ const PROPERTY_TRANSFORMER_MARKER = '@light-probe-volume-material-transformer';
16
+
17
+
18
+ function createLookupTexture(resolution) {
19
+
20
+ const lookup = new DataTexture3D(
21
+ new Uint32Array(resolution * resolution * resolution),
22
+ resolution,
23
+ resolution,
24
+ resolution
25
+ );
26
+
27
+ lookup.name = "Tetrahedron Lookup";
28
+
29
+ lookup.flipY = false;
30
+ lookup.generateMipmaps = false;
31
+ lookup.magFilter = NearestFilter;
32
+ lookup.minFilter = NearestFilter;
33
+
34
+ lookup.type = UnsignedIntType;
35
+ lookup.format = RedIntegerFormat;
36
+ lookup.internalFormat = "R32UI";
37
+
38
+ lookup.needsUpdate = true;
39
+
40
+ return lookup;
41
+ }
42
+
43
+ export class MaterialTransformer extends AbstractMaterialTransformer {
44
+
45
+ /**
46
+ *
47
+ * @type {LightProbeVolume|null}
48
+ */
49
+ #volume = null;
50
+
51
+ #mesh_lookup = createLookupTexture(32);
52
+ #mesh_bounds = new AABB3();
53
+
54
+ #textures = {
55
+ vertex: new AttributeDataTexture(
56
+ AttributeSpec.fromJSON({
57
+ name: "vertex",
58
+ type: BinaryDataType.Uint32,
59
+ itemSize: 4,
60
+ normalized: false
61
+ }),
62
+ 256, 1
63
+ ),
64
+ neighbour: new AttributeDataTexture(
65
+ AttributeSpec.fromJSON({
66
+ name: "neighbour",
67
+ type: BinaryDataType.Uint32,
68
+ itemSize: 4,
69
+ normalized: false
70
+ }),
71
+ 256, 1
72
+ ),
73
+ positions: new AttributeDataTexture(
74
+ AttributeSpec.fromJSON({
75
+ name: "positions",
76
+ type: BinaryDataType.Float32,
77
+ itemSize: 3,
78
+ normalized: false
79
+ }),
80
+ 256, 1
81
+ ),
82
+ harmonics: new AttributeDataTexture(
83
+ AttributeSpec.fromJSON({
84
+ name: "harmonics",
85
+ type: BinaryDataType.Float32,
86
+ itemSize: 3,
87
+ normalized: false
88
+ }),
89
+ 256, 9
90
+ )
91
+ };
92
+
93
+ #uniforms = {
94
+ lpv_t_mesh_vertices: {
95
+ type: "t",
96
+ value: this.#textures.vertex.texture
97
+ },
98
+ lpv_t_mesh_neighbours: {
99
+ type: "t",
100
+ value: this.#textures.neighbour.texture
101
+ },
102
+ lpv_t_probe_positions: {
103
+ type: "t",
104
+ value: this.#textures.positions.texture
105
+ },
106
+ lpv_t_probe_data: {
107
+ type: "t",
108
+ value: this.#textures.harmonics.texture
109
+ },
110
+ lpv_t_mesh_lookup: {
111
+ type: "t",
112
+ value: this.#mesh_lookup
113
+ },
114
+ lpv_v3_bounds_min: {
115
+ value: new Vector3(),
116
+ },
117
+ lpv_v3_bounds_max: {
118
+ value: new Vector3(),
119
+ },
120
+ lpv_u_mesh_tet_count: {
121
+ value: 0
122
+ },
123
+ lpv_f_intensity: {
124
+ value: 1
125
+ }
126
+ };
127
+
128
+ #uniform_version = -1;
129
+
130
+ /**
131
+ *
132
+ * @param {{uniforms, glslVersion, defines, vertexShader, fragmentShader}} shader
133
+ */
134
+ #onBeforeCompile = (shader) => {
135
+ Object.assign(shader.uniforms, this.#uniforms);
136
+
137
+ console.log(this.#uniforms)
138
+
139
+ shader.vertexShader = build_vertex_shader(shader.vertexShader);
140
+ shader.fragmentShader = build_fragment_shader(shader.fragmentShader);
141
+ };
142
+
143
+ #materials = [];
144
+
145
+ /**
146
+ *
147
+ * @return {number}
148
+ */
149
+ get intensity() {
150
+ return this.#uniforms.lpv_f_intensity.value;
151
+ }
152
+
153
+ /**
154
+ *
155
+ * @param {number} v
156
+ */
157
+ set intensity(v) {
158
+ this.#uniforms.lpv_f_intensity.value = v;
159
+ }
160
+
161
+ /**
162
+ *
163
+ * @param {LightProbeVolume} volume
164
+ */
165
+ constructor({
166
+ volume
167
+ }) {
168
+ super();
169
+
170
+ this.#volume = volume;
171
+ }
172
+
173
+ update_bounds() {
174
+
175
+ aabb3_from_v3_array(this.#mesh_bounds, this.#volume.points, this.#volume.count * 3);
176
+
177
+ }
178
+
179
+ update_lookup() {
180
+ this.update_bounds();
181
+
182
+ const bounds = this.#mesh_bounds;
183
+
184
+ const lookup = this.#mesh_lookup;
185
+
186
+ const image = lookup.image;
187
+
188
+ const res_z = image.depth;
189
+ const res_y = image.height;
190
+ const res_x = image.width;
191
+
192
+ const volume = this.#volume;
193
+
194
+ let last_tet = 0;
195
+
196
+ for (let z = 0; z < res_z; z++) {
197
+ for (let y = 0; y < res_y; y++) {
198
+ for (let x = 0; x < res_x; x++) {
199
+
200
+ // convert pixel position to world coordinate
201
+ const n_x = (x + 0.5) / res_x
202
+ const n_y = (y + 0.5) / res_y
203
+ const n_z = (z + 0.5) / res_z
204
+
205
+ const w_x = n_x * bounds.getExtentsX() + bounds.x0;
206
+ const w_y = n_y * bounds.getExtentsY() + bounds.y0;
207
+ const w_z = n_z * bounds.getExtentsZ() + bounds.z0;
208
+
209
+ const tet = volume.mesh.findTetraContainingPoint(w_x, w_y, w_z, volume.points, last_tet);
210
+
211
+ if (tet !== -1) {
212
+ last_tet = tet;
213
+ }
214
+
215
+ image.data[z * res_y * res_x + y * res_x + x] = last_tet;
216
+
217
+ }
218
+ }
219
+ }
220
+
221
+ lookup.needsUpdate = true;
222
+ }
223
+
224
+ update() {
225
+ const lpv = this.#volume;
226
+
227
+ if (lpv === null) {
228
+ return;
229
+ }
230
+
231
+ if (this.#uniform_version === lpv.version) {
232
+ return;
233
+ }
234
+
235
+ this.update_lookup();
236
+
237
+ this.#uniforms.lpv_u_mesh_tet_count.value = lpv.mesh.count;
238
+
239
+ this.#uniforms.lpv_v3_bounds_min.value.set(
240
+ this.#mesh_bounds.x0, this.#mesh_bounds.y0, this.#mesh_bounds.z0
241
+ );
242
+ this.#uniforms.lpv_v3_bounds_max.value.set(
243
+ this.#mesh_bounds.x1, this.#mesh_bounds.y1, this.#mesh_bounds.z1
244
+ );
245
+
246
+ this.#uniform_version = lpv.version;
247
+
248
+ console.time('prepareTextures');
249
+
250
+ vector_buffer_to_attribute_texture(this.#textures.positions, lpv.points, lpv.count, 3);
251
+ vector_buffer_to_attribute_texture(this.#textures.harmonics, lpv.harmonics, lpv.count * 9, 3);
252
+ tetrahedral_mesh_to_texture(
253
+ this.#textures.vertex, this.#textures.neighbour, lpv.mesh
254
+ );
255
+
256
+ console.timeEnd('prepareTextures');
257
+
258
+ for (let i = 0; i < this.#materials.length; i++) {
259
+ const material = this.#materials[i];
260
+
261
+ // material.uniformsNeedUpdate = true;
262
+ }
263
+ }
264
+
265
+ transform(source) {
266
+ if (source.hasOwnProperty(PROPERTY_TRANSFORMER_MARKER)) {
267
+ // already transformed
268
+
269
+ if (source[PROPERTY_TRANSFORMER_MARKER] !== this) {
270
+ throw new Error('The material is already transformed, but is associated with a different transformer instance');
271
+ } else {
272
+ return source;
273
+ }
274
+
275
+ }
276
+
277
+
278
+ let result = source;
279
+
280
+ if (isLitMaterial(source)) {
281
+
282
+ result.clone();
283
+
284
+ result.onBeforeCompile = composeCompile(source.onBeforeCompile, this.#onBeforeCompile);
285
+
286
+ result[PROPERTY_TRANSFORMER_MARKER] = this;
287
+
288
+ this.#materials.push(result);
289
+ }
290
+
291
+ return result;
292
+ }
293
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ *
3
+ * @param {string} source
4
+ */
5
+ export function build_fragment_shader(source: string): string;
6
+ //# sourceMappingURL=build_fragment_shader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build_fragment_shader.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/gi/material/build_fragment_shader.js"],"names":[],"mappings":"AAsDA;;;GAGG;AACH,8CAFW,MAAM,UAchB"}
@@ -0,0 +1,71 @@
1
+ import { insert_after } from "../../../../../core/primitives/strings/insert_after.js";
2
+
3
+ const PREAMBLE = `
4
+
5
+ uniform float lpv_f_intensity;
6
+
7
+ varying vec3[9] lpv_values;
8
+
9
+ // vec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {
10
+ // // normal is assumed to have unit length
11
+ // float x = normal.x, y = normal.y, z = normal.z;
12
+ //
13
+ // // band 0
14
+ // vec3 result = shCoefficients[ 0 ] * 0.886227;
15
+ //
16
+ // // band 1
17
+ // result -= shCoefficients[ 1 ] * 2.0 * 0.511664 * y;
18
+ // result += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;
19
+ // result -= shCoefficients[ 3 ] * 2.0 * 0.511664 * x;
20
+ //
21
+ // // band 2
22
+ // result += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;
23
+ // result -= shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;
24
+ // result += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );
25
+ // result -= shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;
26
+ // result += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );
27
+ //
28
+ // return result;
29
+ // }
30
+ //
31
+ // vec3 inverseTransformDirection( in vec3 normal, in mat4 matrix ) {
32
+ //
33
+ // // matrix is assumed to be orthogonal
34
+ //
35
+ // return normalize( ( vec4( normal, 0.0 ) * matrix ).xyz );
36
+ //
37
+ // }
38
+ //
39
+ // vec3 lpv_getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) {
40
+ //
41
+ // vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
42
+ //
43
+ // vec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );
44
+ //
45
+ // return irradiance;
46
+ //
47
+ // }
48
+ `;
49
+
50
+ const ACCUMULATION = `
51
+ irradiance += getLightProbeIrradiance(lpv_values, geometryNormal )* lpv_f_intensity;
52
+ `;
53
+
54
+
55
+ /**
56
+ *
57
+ * @param {string} source
58
+ */
59
+ export function build_fragment_shader(source) {
60
+
61
+ let result = PREAMBLE + source;
62
+
63
+
64
+ result = insert_after(
65
+ result,
66
+ '#include <lights_fragment_begin>',
67
+ ACCUMULATION
68
+ );
69
+
70
+ return result;
71
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ *
3
+ * @param {string} source
4
+ */
5
+ export function build_vertex_shader(source: string): string;
6
+ //# sourceMappingURL=build_vertex_shader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build_vertex_shader.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/gi/material/build_vertex_shader.js"],"names":[],"mappings":"AA+OA;;;GAGG;AACH,4CAFW,MAAM,UAchB"}
@@ -0,0 +1,256 @@
1
+ import { insert_after } from "../../../../../core/primitives/strings/insert_after.js";
2
+
3
+ const PREAMBLE = `
4
+ #ifndef LPV_SHADER_CHUNK_PREAMBLE
5
+ #define LPV_SHADER_CHUNK_PREAMBLE
6
+
7
+ precision highp usampler2D;
8
+ precision highp usampler3D;
9
+
10
+ uniform usampler2D lpv_t_mesh_vertices;
11
+ uniform usampler2D lpv_t_mesh_neighbours;
12
+ uniform usampler3D lpv_t_mesh_lookup;
13
+
14
+ uniform sampler2D lpv_t_probe_positions;
15
+ uniform sampler2D lpv_t_probe_data;
16
+
17
+ uniform uint lpv_u_mesh_tet_count;
18
+ uniform vec3 lpv_v3_bounds_min;
19
+ uniform vec3 lpv_v3_bounds_max;
20
+
21
+ varying vec3[9] lpv_values;
22
+
23
+ #define SEARCH_STEP_LIMIT 64u
24
+ #define INVALID_TET 1073741823u
25
+
26
+ ivec2 lpv_index_to_256_coordinate(uint index){
27
+
28
+ uint pixel_x = index % 256u;
29
+ uint pixel_y = index / 256u;
30
+
31
+ return ivec2(int(pixel_x), int(pixel_y));
32
+ }
33
+
34
+ uvec4 lpv_mesh_getVertices(uint tet_index){
35
+ ivec2 p = lpv_index_to_256_coordinate(tet_index);
36
+
37
+ return texelFetch(lpv_t_mesh_vertices, p, 0);
38
+
39
+ }
40
+
41
+ uvec4 lpv_mesh_getNeighbours(uint tet_index){
42
+ ivec2 p = lpv_index_to_256_coordinate(tet_index);
43
+
44
+ return texelFetch(lpv_t_mesh_neighbours, p, 0);
45
+ }
46
+
47
+ vec3[9] lpv_probe_getData(uint probe_index){
48
+
49
+
50
+ int slot = int( probe_index % 256u );
51
+ int column = int(probe_index / 256u);
52
+
53
+ int offset_x = int(slot * 9);
54
+
55
+ vec3[9] result;
56
+
57
+ for(int i=0; i<9; i++){
58
+ result[i] = texelFetch(lpv_t_probe_data, ivec2(offset_x + i, column),0).rgb;
59
+ }
60
+
61
+ return result;
62
+ }
63
+
64
+ vec3 lpv_probe_getPosition(uint probe_index){
65
+ return texelFetch(lpv_t_probe_positions, lpv_index_to_256_coordinate(probe_index), 0).rgb;
66
+ }
67
+
68
+ mat3 lpv_mesh_makeMatrix(vec3 p0, vec3 p1, vec3 p2, vec3 p3){
69
+
70
+ return inverse(
71
+ mat3(
72
+ p0 - p3,
73
+ p1 - p3,
74
+ p2 - p3
75
+ )
76
+ );
77
+
78
+ }
79
+
80
+ vec4 lpv_mesh_getBarycentricCoordinates(uint tet_index, vec3 position){
81
+ uvec4 vertices = lpv_mesh_getVertices(tet_index);
82
+
83
+ vec3 p0 = lpv_probe_getPosition(vertices[0]);
84
+ vec3 p1 = lpv_probe_getPosition(vertices[1]);
85
+ vec3 p2 = lpv_probe_getPosition(vertices[2]);
86
+ vec3 p3 = lpv_probe_getPosition(vertices[3]);
87
+
88
+ mat3 matrix = lpv_mesh_makeMatrix(p0, p1, p2, p3);
89
+
90
+ vec3 mult = matrix * (position - p3);
91
+
92
+ return vec4(mult, 1.0 - mult.x - mult.y - mult.z);
93
+ }
94
+
95
+ void lpv_getTetrahedron(
96
+ in vec3 position ,
97
+ in uint tet_guess,
98
+ out uint tet_index,
99
+ out vec4 weights
100
+ ){
101
+ uint came_from = 0u;
102
+
103
+ tet_index = tet_guess;
104
+
105
+ for(uint i=0u; i < SEARCH_STEP_LIMIT; i++){
106
+
107
+ weights = lpv_mesh_getBarycentricCoordinates(tet_index, position);
108
+
109
+ if(weights.x >= 0.0 && weights.y >= 0.0 && weights.z >= 0.0 && weights.w >= 0.0){
110
+ return;
111
+ }
112
+
113
+ uvec4 neighbors = lpv_mesh_getNeighbours(tet_index);
114
+
115
+ uint next_tet;
116
+
117
+ // Otherwise find the smallest barycentric coord and move in that direction
118
+ if (weights.x < weights.y && weights.x < weights.z && weights.x < weights.w) {
119
+ next_tet = neighbors[0];
120
+ } else if (weights.y < weights.z && weights.y < weights.w) {
121
+ next_tet = neighbors[1];
122
+ } else if (weights.z < weights.w) {
123
+ next_tet = neighbors[2];
124
+ } else {
125
+ next_tet = neighbors[3];
126
+ }
127
+
128
+ if(next_tet == came_from){
129
+ // numerical instability caused us to oscillate on the boundary
130
+ return;
131
+ }
132
+
133
+ came_from = tet_index;
134
+ tet_index = next_tet;
135
+ }
136
+
137
+ tet_index = INVALID_TET;
138
+ }
139
+
140
+ vec3[9] lpv_interpolate_probes(vec4 weights, uint tet_index){
141
+
142
+ uvec4 vertices = lpv_mesh_getVertices(tet_index);
143
+
144
+ vec3[9] probe0 = lpv_probe_getData(vertices[0]);
145
+ vec3[9] probe1 = lpv_probe_getData(vertices[1]);
146
+ vec3[9] probe2 = lpv_probe_getData(vertices[2]);
147
+ vec3[9] probe3 = lpv_probe_getData(vertices[3]);
148
+
149
+ vec3[9] result;
150
+
151
+ for(int i=0; i< 9; i++){
152
+
153
+ result[i] = probe0[i]* weights[0]
154
+ + probe1[i]* weights[1]
155
+ + probe2[i]* weights[2]
156
+ + probe3[i]* weights[3];
157
+
158
+ }
159
+
160
+ return result;
161
+ }
162
+
163
+ vec4 lpv_bias_weight_by_normal(const in vec3 position, const in vec3 normal, const in uint tet_index, const in vec4 weights){
164
+
165
+ uvec4 vertices = lpv_mesh_getVertices(tet_index);
166
+
167
+ vec4 result = weights;
168
+
169
+ for(int i = 0; i< 4; i++){
170
+ vec3 p = lpv_probe_getPosition(vertices[i]) - position;
171
+
172
+ if(dot(normal, p) <= 0.0){
173
+ // behind the surface, bias to 0
174
+ result[i] = 0.0;
175
+ }
176
+ }
177
+
178
+ float total_weight = result.x + result.y + result.z + result.w;
179
+
180
+ // needs to add up to 1
181
+ result = result / total_weight;
182
+
183
+ return result;
184
+ }
185
+
186
+ uint lpv_guess_initial_tet(vec3 position){
187
+
188
+ vec3 lpv_mesh_bounds_min = lpv_v3_bounds_min;
189
+ vec3 lpv_mesh_bounds_max = lpv_v3_bounds_max;
190
+
191
+ vec3 lookup_coordinates = (position - lpv_mesh_bounds_min) / (lpv_mesh_bounds_max - lpv_mesh_bounds_min) ;
192
+
193
+ return textureLod( lpv_t_mesh_lookup, lookup_coordinates, 0.0 ).r;
194
+
195
+ }
196
+
197
+ #endif
198
+ `;
199
+
200
+
201
+ const SHADER_CHUNK_ACCUMULATION = `
202
+ {
203
+ // lookup nearby tet
204
+ vec3 lpv_mesh_bounds_min = lpv_v3_bounds_min;
205
+ vec3 lpv_mesh_bounds_max = lpv_v3_bounds_max;
206
+ vec3 lookup_coordinates = (worldPosition.xyz - lpv_mesh_bounds_min) / (lpv_mesh_bounds_max - lpv_mesh_bounds_min) ;
207
+
208
+ uint nearest_tet = lpv_guess_initial_tet( worldPosition.xyz );
209
+
210
+ uint tet;
211
+ vec4 weights;
212
+ lpv_getTetrahedron(worldPosition.xyz, nearest_tet, tet, weights);
213
+
214
+
215
+ if(tet == INVALID_TET){
216
+ lpv_values = vec3[](
217
+ vec3(0.0, 0.0, 0.0),
218
+ vec3(0.0, 0.0, 0.0),
219
+ vec3(0.0, 0.0, 0.0),
220
+
221
+ vec3(0.0, 0.0, 0.0),
222
+ vec3(0.0, 0.0, 0.0),
223
+ vec3(0.0, 0.0, 0.0),
224
+
225
+ vec3(0.0, 0.0, 0.0),
226
+ vec3(0.0, 0.0, 0.0),
227
+ vec3(0.0, 0.0, 0.0)
228
+ );
229
+ }else{
230
+
231
+ vec3 worldNormal = normalize(inverseTransformDirection( normalize(normal), viewMatrix ));
232
+
233
+ //weights = lpv_bias_weight_by_normal(worldPosition.xyz, normal, tet, weights);
234
+
235
+ lpv_values = lpv_interpolate_probes(weights, tet);
236
+ }
237
+ }
238
+ `
239
+
240
+ /**
241
+ *
242
+ * @param {string} source
243
+ */
244
+ export function build_vertex_shader(source) {
245
+ let result = PREAMBLE + source;
246
+
247
+ result = insert_after(
248
+ result,
249
+ '#include <fog_vertex>',
250
+ SHADER_CHUNK_ACCUMULATION
251
+ );
252
+
253
+ // console.log(result)
254
+
255
+ return result;
256
+ }
@@ -31,9 +31,6 @@ export function tetrahedral_mesh_to_texture(
31
31
  vertices.resize(tetrahedron_count);
32
32
  neighbours.resize(tetrahedron_count);
33
33
 
34
- vertices.build()
35
- neighbours.build();
36
-
37
34
  const vertices_data = vertices.data;
38
35
  const neighbours_data = neighbours.data;
39
36
 
@@ -44,8 +41,11 @@ export function tetrahedral_mesh_to_texture(
44
41
  for (let j = 0; j < 4; j++) {
45
42
  vertices_data[i4 + j] = mesh.getVertexIndex(i, j);
46
43
 
47
- neighbours_data[i4 + j] = mesh.getNeighbour(i, j);
44
+ neighbours_data[i4 + j] = mesh.getNeighbour(i, j) >>> 2;
48
45
  }
49
46
 
50
47
  }
48
+
49
+ vertices.texture.needsUpdate = true;
50
+ neighbours.texture.needsUpdate = true;
51
51
  }