@woosh/meep-engine 2.107.0 → 2.108.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.
Files changed (231) hide show
  1. package/build/bundle-worker-image-decoder.js +1 -1
  2. package/build/meep.cjs +78 -46
  3. package/build/meep.min.js +1 -1
  4. package/build/meep.module.js +78 -47
  5. package/package.json +1 -1
  6. package/src/core/binary/int32_to_binary_string.d.ts +3 -2
  7. package/src/core/binary/int32_to_binary_string.d.ts.map +1 -1
  8. package/src/core/binary/int32_to_binary_string.js +18 -14
  9. package/src/core/binary/split_by_3.spec.d.ts +2 -0
  10. package/src/core/binary/split_by_3.spec.d.ts.map +1 -0
  11. package/src/core/binary/split_by_3.spec.js +22 -0
  12. package/src/core/binary/to_half_float_uint16.d.ts.map +1 -1
  13. package/src/core/binary/to_half_float_uint16.js +7 -5
  14. package/src/core/collection/array/isArrayEqualStrict.d.ts.map +1 -1
  15. package/src/core/collection/array/isArrayEqualStrict.js +2 -2
  16. package/src/core/color/Color.d.ts.map +1 -1
  17. package/src/core/color/Color.js +7 -2
  18. package/src/core/color/hsv/rgb2hsv.d.ts +3 -3
  19. package/src/core/color/hsv/rgb2hsv.d.ts.map +1 -1
  20. package/src/core/color/hsv/rgb2hsv.js +11 -18
  21. package/src/core/color/rgb_to_luminance.d.ts +9 -0
  22. package/src/core/color/rgb_to_luminance.d.ts.map +1 -0
  23. package/src/core/color/rgb_to_luminance.js +10 -0
  24. package/src/core/geom/3d/sphere/harmonics/README.md +16 -2
  25. package/src/core/geom/3d/sphere/harmonics/SH3_COEFFICIENTS.d.ts +6 -0
  26. package/src/core/geom/3d/sphere/harmonics/SH3_COEFFICIENTS.d.ts.map +1 -0
  27. package/src/core/geom/3d/sphere/harmonics/SH3_COEFFICIENTS.js +15 -0
  28. package/src/core/geom/3d/sphere/harmonics/sh3_basis_at.d.ts.map +1 -1
  29. package/src/core/geom/3d/sphere/harmonics/sh3_basis_at.js +21 -9
  30. package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.d.ts +3 -3
  31. package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.d.ts.map +1 -1
  32. package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.js +35 -206
  33. package/src/core/geom/3d/sphere/harmonics/sh3_rotate.d.ts +8 -0
  34. package/src/core/geom/3d/sphere/harmonics/sh3_rotate.d.ts.map +1 -0
  35. package/src/core/geom/3d/sphere/harmonics/sh3_rotate.js +29 -0
  36. package/src/core/geom/3d/sphere/harmonics/sh3_sample_by_direction.js +10 -10
  37. package/src/core/geom/3d/sphere/harmonics/sh_index.d.ts +8 -0
  38. package/src/core/geom/3d/sphere/harmonics/sh_index.d.ts.map +1 -0
  39. package/src/core/geom/3d/sphere/harmonics/sh_index.js +9 -0
  40. package/src/core/geom/3d/sphere/harmonics/sh_rotate_band1.d.ts +8 -0
  41. package/src/core/geom/3d/sphere/harmonics/sh_rotate_band1.d.ts.map +1 -0
  42. package/src/core/geom/3d/sphere/harmonics/sh_rotate_band1.js +44 -0
  43. package/src/core/geom/3d/sphere/harmonics/sh_rotate_band2.d.ts +8 -0
  44. package/src/core/geom/3d/sphere/harmonics/sh_rotate_band2.d.ts.map +1 -0
  45. package/src/core/geom/3d/sphere/harmonics/sh_rotate_band2.js +86 -0
  46. package/src/core/geom/3d/sphere/in_sphere3d_robust.d.ts.map +1 -1
  47. package/src/core/geom/3d/sphere/in_sphere3d_robust.js +2 -1
  48. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.d.ts +20 -1
  49. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.d.ts.map +1 -1
  50. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.js +53 -7
  51. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.spec.js +2 -2
  52. package/src/core/geom/3d/tetrahedra/build_tetrahedral_mesh_buffer_geometry.d.ts +1 -1
  53. package/src/core/geom/3d/tetrahedra/build_tetrahedral_mesh_buffer_geometry.d.ts.map +1 -1
  54. package/src/core/geom/3d/tetrahedra/build_tetrahedral_mesh_buffer_geometry.js +12 -7
  55. package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_build_from_grid.d.ts +13 -0
  56. package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_build_from_grid.d.ts.map +1 -0
  57. package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_build_from_grid.js +135 -0
  58. package/src/core/geom/3d/tetrahedra/prototypeTetrahedraBuilder.js +38 -24
  59. package/src/core/geom/3d/tetrahedra/{compute_circumsphere.d.ts → tetrahedron_compute_circumsphere.d.ts} +3 -5
  60. package/src/core/geom/3d/tetrahedra/tetrahedron_compute_circumsphere.d.ts.map +1 -0
  61. package/src/core/geom/3d/tetrahedra/{compute_circumsphere.js → tetrahedron_compute_circumsphere.js} +2 -4
  62. package/src/core/geom/3d/tetrahedra/tetrahedron_compute_signed_volume.d.ts.map +1 -1
  63. package/src/core/geom/3d/tetrahedra/tetrahedron_compute_signed_volume.js +3 -1
  64. package/src/core/geom/Vector3.d.ts.map +1 -1
  65. package/src/core/geom/Vector3.js +1 -0
  66. package/src/core/geom/mat3/m3_multiply_vec3.d.ts +8 -0
  67. package/src/core/geom/mat3/m3_multiply_vec3.d.ts.map +1 -0
  68. package/src/core/geom/mat3/m3_multiply_vec3.js +21 -0
  69. package/src/core/geom/vec2/v2_cross_product.d.ts +15 -0
  70. package/src/core/geom/vec2/v2_cross_product.d.ts.map +1 -0
  71. package/src/core/geom/vec2/v2_cross_product.js +21 -0
  72. package/src/core/geom/vec3/v3_slerp.d.ts +1 -0
  73. package/src/core/geom/vec3/v3_slerp.d.ts.map +1 -1
  74. package/src/core/geom/vec3/v3_slerp.js +1 -0
  75. package/src/core/graph/MultiNode.d.ts +1 -1
  76. package/src/core/graph/MultiNode.js +1 -1
  77. package/src/core/graph/WeightedEdge.d.ts +6 -4
  78. package/src/core/graph/WeightedEdge.d.ts.map +1 -1
  79. package/src/core/graph/WeightedEdge.js +3 -0
  80. package/src/core/graph/coloring/colorizeGraph.js +19 -19
  81. package/src/core/graph/convert_graph_to_dot_string.d.ts +1 -1
  82. package/src/core/graph/convert_graph_to_dot_string.d.ts.map +1 -1
  83. package/src/core/graph/convert_graph_to_dot_string.js +10 -6
  84. package/src/core/graph/graph_compute_adjacency_matrix.d.ts +9 -0
  85. package/src/core/graph/graph_compute_adjacency_matrix.d.ts.map +1 -0
  86. package/src/core/graph/{graph_adjacency_matrix.js → graph_compute_adjacency_matrix.js} +1 -2
  87. package/src/core/graph/graph_compute_degree_matrix.d.ts +10 -0
  88. package/src/core/graph/graph_compute_degree_matrix.d.ts.map +1 -0
  89. package/src/core/graph/graph_compute_degree_matrix.js +23 -0
  90. package/src/core/graph/graph_compute_distance_matrix.d.ts +13 -0
  91. package/src/core/graph/graph_compute_distance_matrix.d.ts.map +1 -0
  92. package/src/core/graph/graph_compute_distance_matrix.js +103 -0
  93. package/src/core/graph/{graph_laplacian_matrix.d.ts → graph_compute_laplacian_matrix.d.ts} +2 -2
  94. package/src/core/graph/graph_compute_laplacian_matrix.d.ts.map +1 -0
  95. package/src/core/graph/{graph_laplacian_matrix.js → graph_compute_laplacian_matrix.js} +6 -6
  96. package/src/core/graph/graph_k_means_cluster.d.ts.map +1 -1
  97. package/src/core/graph/graph_k_means_cluster.js +4 -119
  98. package/src/core/graph/{coarsen_graph.d.ts → mn_graph_coarsen.d.ts} +2 -2
  99. package/src/core/graph/mn_graph_coarsen.d.ts.map +1 -0
  100. package/src/core/graph/{coarsen_graph.js → mn_graph_coarsen.js} +1 -1
  101. package/src/core/graph/mn_graph_coarsen.spec.d.ts +2 -0
  102. package/src/core/graph/mn_graph_coarsen.spec.d.ts.map +1 -0
  103. package/src/core/graph/{coarsen_graph.spec.js → mn_graph_coarsen.spec.js} +4 -4
  104. package/src/core/graph/mn_graph_collapse_weighted_edge.d.ts +1 -0
  105. package/src/core/graph/mn_graph_collapse_weighted_edge.d.ts.map +1 -1
  106. package/src/core/graph/mn_graph_collapse_weighted_edge.js +7 -1
  107. package/src/core/math/physics/brdf/brdf_burley.d.ts.map +1 -1
  108. package/src/core/math/physics/brdf/brdf_burley.js +9 -1
  109. package/src/core/math/physics/brdf/{D_GGX.d.ts → diffuse_GGX.d.ts} +2 -2
  110. package/src/core/math/physics/brdf/diffuse_GGX.d.ts.map +1 -0
  111. package/src/core/math/physics/brdf/{D_GGX.js → diffuse_GGX.js} +1 -1
  112. package/src/core/math/physics/brdf/fresnel_Schlick.d.ts +3 -0
  113. package/src/core/math/physics/brdf/fresnel_Schlick.d.ts.map +1 -0
  114. package/src/core/math/physics/brdf/fresnel_Schlick.js +3 -0
  115. package/src/core/math/physics/brdf/fresnel_Schlick_optimized.d.ts +9 -0
  116. package/src/core/math/physics/brdf/fresnel_Schlick_optimized.d.ts.map +1 -0
  117. package/src/core/math/physics/brdf/fresnel_Schlick_optimized.js +12 -0
  118. package/src/core/math/physics/brdf/fresnel_Schlick_original.d.ts +9 -0
  119. package/src/core/math/physics/brdf/fresnel_Schlick_original.d.ts.map +1 -0
  120. package/src/core/math/physics/brdf/fresnel_Schlick_original.js +10 -0
  121. package/src/core/math/physics/bsdf/bsdf_schlick.d.ts.map +1 -1
  122. package/src/core/math/physics/bsdf/bsdf_schlick.js +3 -11
  123. package/src/core/math/physics/ior_to_reflectivity.d.ts +7 -0
  124. package/src/core/math/physics/ior_to_reflectivity.d.ts.map +1 -0
  125. package/src/core/math/physics/ior_to_reflectivity.js +9 -0
  126. package/src/core/math/physics/pdf/README.md +1 -0
  127. package/src/core/math/physics/pdf/pdf_GGX.d.ts +16 -0
  128. package/src/core/math/physics/pdf/pdf_GGX.d.ts.map +1 -0
  129. package/src/core/math/physics/pdf/pdf_GGX.js +25 -0
  130. package/src/core/math/physics/reflectivity_to_ior.d.ts +7 -0
  131. package/src/core/math/physics/reflectivity_to_ior.d.ts.map +1 -0
  132. package/src/core/math/physics/reflectivity_to_ior.js +8 -0
  133. package/src/engine/EngineHarness.d.ts +10 -1
  134. package/src/engine/EngineHarness.d.ts.map +1 -1
  135. package/src/engine/EngineHarness.js +16 -11
  136. package/src/engine/asset/loaders/image/png/PNGReader.d.ts +25 -11
  137. package/src/engine/asset/loaders/image/png/PNGReader.d.ts.map +1 -1
  138. package/src/engine/asset/loaders/image/png/PNGReader.js +38 -24
  139. package/src/engine/asset/loaders/material/TextureAttachmensByMaterialType.js +2 -0
  140. package/src/engine/graphics/GraphicsEngine.js +1 -1
  141. package/src/engine/graphics/ecs/light/LightSystem.d.ts.map +1 -1
  142. package/src/engine/graphics/ecs/light/LightSystem.js +2 -3
  143. package/src/engine/graphics/ecs/light/binding/three/ThreeLightBinding.d.ts +6 -0
  144. package/src/engine/graphics/ecs/light/binding/three/ThreeLightBinding.d.ts.map +1 -1
  145. package/src/engine/graphics/ecs/light/binding/three/ThreeLightBinding.js +22 -11
  146. package/src/engine/graphics/render/forward_plus/model/DirectionalLight.d.ts.map +1 -1
  147. package/src/engine/graphics/render/forward_plus/model/DirectionalLight.js +25 -25
  148. package/src/engine/graphics/sh3/fromCubeRenderTarget.d.ts +9 -0
  149. package/src/engine/graphics/sh3/fromCubeRenderTarget.d.ts.map +1 -0
  150. package/src/engine/graphics/sh3/fromCubeRenderTarget.js +145 -0
  151. package/src/engine/graphics/sh3/gi/tetrahedral_mesh_to_texture.d.ts +8 -0
  152. package/src/engine/graphics/sh3/gi/tetrahedral_mesh_to_texture.d.ts.map +1 -0
  153. package/src/engine/graphics/sh3/gi/tetrahedral_mesh_to_texture.js +51 -0
  154. package/src/engine/graphics/sh3/{LightProbeVolume.d.ts → lpv/LightProbeVolume.d.ts} +18 -7
  155. package/src/engine/graphics/sh3/lpv/LightProbeVolume.d.ts.map +1 -0
  156. package/src/engine/graphics/sh3/lpv/LightProbeVolume.js +340 -0
  157. package/src/engine/graphics/sh3/lpv/LightProbeVolumeSerializationAdapter.d.ts +18 -0
  158. package/src/engine/graphics/sh3/lpv/LightProbeVolumeSerializationAdapter.d.ts.map +1 -0
  159. package/src/engine/graphics/sh3/lpv/LightProbeVolumeSerializationAdapter.js +44 -0
  160. package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.d.ts +12 -0
  161. package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.d.ts.map +1 -0
  162. package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.js +123 -0
  163. package/src/engine/graphics/sh3/lpv/ProbeRenderer.d.ts +29 -0
  164. package/src/engine/graphics/sh3/lpv/ProbeRenderer.d.ts.map +1 -0
  165. package/src/engine/graphics/sh3/lpv/ProbeRenderer.js +35 -0
  166. package/src/engine/graphics/sh3/lpv/WebGLCubeProbeRenderer.d.ts +27 -0
  167. package/src/engine/graphics/sh3/lpv/WebGLCubeProbeRenderer.d.ts.map +1 -0
  168. package/src/engine/graphics/sh3/lpv/WebGLCubeProbeRenderer.js +158 -0
  169. package/src/engine/graphics/sh3/lpv/build_probes_for_scene.d.ts +11 -0
  170. package/src/engine/graphics/sh3/lpv/build_probes_for_scene.d.ts.map +1 -0
  171. package/src/engine/graphics/sh3/lpv/build_probes_for_scene.js +127 -0
  172. package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.d.ts +12 -0
  173. package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.d.ts.map +1 -0
  174. package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.js +89 -0
  175. package/src/engine/graphics/sh3/path_tracer/PathTracedScene.d.ts +90 -0
  176. package/src/engine/graphics/sh3/path_tracer/PathTracedScene.d.ts.map +1 -0
  177. package/src/engine/graphics/sh3/path_tracer/PathTracedScene.js +352 -0
  178. package/src/engine/graphics/sh3/path_tracer/PathTracer.d.ts +5 -91
  179. package/src/engine/graphics/sh3/path_tracer/PathTracer.d.ts.map +1 -1
  180. package/src/engine/graphics/sh3/path_tracer/PathTracer.js +41 -477
  181. package/src/engine/graphics/sh3/path_tracer/make_one_vector3.d.ts +1 -0
  182. package/src/engine/graphics/sh3/path_tracer/make_one_vector3.d.ts.map +1 -1
  183. package/src/engine/graphics/sh3/path_tracer/make_one_vector3.js +6 -3
  184. package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +26 -58
  185. package/src/engine/graphics/sh3/path_tracer/random_in_hemisphere.d.ts.map +1 -1
  186. package/src/engine/graphics/sh3/path_tracer/random_in_hemisphere.js +7 -1
  187. package/src/engine/graphics/sh3/path_tracer/sample_triangle_attribute.d.ts +2 -2
  188. package/src/engine/graphics/sh3/path_tracer/sample_triangle_attribute.d.ts.map +1 -1
  189. package/src/engine/graphics/sh3/path_tracer/sample_triangle_attribute.js +1 -1
  190. package/src/engine/graphics/sh3/path_tracer/texture/SoftwareTextureCache.d.ts +3 -0
  191. package/src/engine/graphics/sh3/path_tracer/texture/SoftwareTextureCache.d.ts.map +1 -0
  192. package/src/engine/graphics/sh3/path_tracer/texture/SoftwareTextureCache.js +3 -0
  193. package/src/engine/graphics/sh3/path_tracer/texture/apply_texture_clamping_to_coordinate.d.ts.map +1 -0
  194. package/src/engine/graphics/sh3/path_tracer/{apply_texture_clamping_to_coordinate.js → texture/apply_texture_clamping_to_coordinate.js} +2 -2
  195. package/src/engine/graphics/sh3/path_tracer/texture/sample_material.d.ts +11 -0
  196. package/src/engine/graphics/sh3/path_tracer/texture/sample_material.d.ts.map +1 -0
  197. package/src/engine/graphics/sh3/path_tracer/texture/sample_material.js +86 -0
  198. package/src/engine/graphics/sh3/path_tracer/texture/sample_texture.d.ts +10 -0
  199. package/src/engine/graphics/sh3/path_tracer/texture/sample_texture.d.ts.map +1 -0
  200. package/src/engine/graphics/sh3/path_tracer/texture/sample_texture.js +56 -0
  201. package/src/engine/graphics/sh3/prototypeSH3Probe.js +87 -195
  202. package/src/engine/graphics/sh3/sky/hosek/sky_hosek_compute_irradiance_by_direction.d.ts +5 -5
  203. package/src/engine/graphics/sh3/sky/hosek/sky_hosek_compute_irradiance_by_direction.d.ts.map +1 -1
  204. package/src/engine/graphics/sh3/sky/hosek/sky_hosek_compute_irradiance_by_direction.js +8 -8
  205. package/src/engine/graphics/sh3/visualise_spherical_harmonic_sphere.d.ts +13 -0
  206. package/src/engine/graphics/sh3/visualise_spherical_harmonic_sphere.d.ts.map +1 -0
  207. package/src/engine/graphics/sh3/visualise_spherical_harmonic_sphere.js +54 -0
  208. package/src/engine/graphics/texture/AttributeDataTexture.d.ts +2 -2
  209. package/src/engine/graphics/texture/AttributeDataTexture.d.ts.map +1 -1
  210. package/src/engine/graphics/texture/AttributeDataTexture.js +11 -11
  211. package/src/engine/input/ecs/systems/InputControllerSystem.js +1 -1
  212. package/src/view/elements/ColorPickerView.d.ts.map +1 -1
  213. package/src/view/elements/ColorPickerView.js +7 -7
  214. package/src/core/geom/3d/tetrahedra/compute_circumsphere.d.ts.map +0 -1
  215. package/src/core/graph/coarsen_graph.d.ts.map +0 -1
  216. package/src/core/graph/coarsen_graph.spec.d.ts +0 -2
  217. package/src/core/graph/coarsen_graph.spec.d.ts.map +0 -1
  218. package/src/core/graph/graph_adjacency_matrix.d.ts +0 -9
  219. package/src/core/graph/graph_adjacency_matrix.d.ts.map +0 -1
  220. package/src/core/graph/graph_degree_matrix.d.ts +0 -9
  221. package/src/core/graph/graph_degree_matrix.d.ts.map +0 -1
  222. package/src/core/graph/graph_degree_matrix.js +0 -18
  223. package/src/core/graph/graph_laplacian_matrix.d.ts.map +0 -1
  224. package/src/core/math/physics/brdf/D_GGX.d.ts.map +0 -1
  225. package/src/engine/graphics/sh3/LightProbeVolume.d.ts.map +0 -1
  226. package/src/engine/graphics/sh3/LightProbeVolume.js +0 -609
  227. package/src/engine/graphics/sh3/path_tracer/apply_texture_clamping_to_coordinate.d.ts.map +0 -1
  228. package/src/engine/graphics/sh3/visualise_probe.d.ts +0 -12
  229. package/src/engine/graphics/sh3/visualise_probe.d.ts.map +0 -1
  230. package/src/engine/graphics/sh3/visualise_probe.js +0 -40
  231. /package/src/engine/graphics/sh3/path_tracer/{apply_texture_clamping_to_coordinate.d.ts → texture/apply_texture_clamping_to_coordinate.d.ts} +0 -0
@@ -1,32 +1,6 @@
1
- import { mat4, vec3 } from "gl-matrix";
2
- import {
3
- LinearEncoding,
4
- LinearFilter,
5
- LinearMipmapLinearFilter,
6
- NearestFilter,
7
- NearestMipMapLinearFilter,
8
- sRGBEncoding,
9
- UnsignedByteType
10
- } from "three";
11
- import { BVH } from "../../../../core/bvh2/bvh3/BVH.js";
12
- import { ebvh_sort_for_traversal_depth_first } from "../../../../core/bvh2/bvh3/ebvh_sort_for_traversal_depth_first.js";
13
- import { bvh_query_user_data_ray } from "../../../../core/bvh2/bvh3/query/bvh_query_user_data_ray.js";
1
+ import { vec3 } from "gl-matrix";
14
2
  import { array_copy } from "../../../../core/collection/array/array_copy.js";
15
- import { linear_to_sRGB } from "../../../../core/color/sRGB/linear_to_sRGB.js";
16
- import { aabb3_matrix4_project } from "../../../../core/geom/3d/aabb/aabb3_matrix4_project.js";
17
- import { ray3_array_compose } from "../../../../core/geom/3d/ray/ray3_array_compose.js";
18
- import { v3_dot } from "../../../../core/geom/vec3/v3_dot.js";
19
- import { TextureAttachmentsByMaterialType } from "../../../asset/loaders/material/TextureAttachmensByMaterialType.js";
20
- import { convertTexture2Sampler2D } from "../../texture/sampler/convertTexture2Sampler2D.js";
21
- import { ensureGeometryBoundingBox } from "../../util/ensureGeometryBoundingBox.js";
22
- import { apply_texture_clamping_to_coordinate } from "./apply_texture_clamping_to_coordinate.js";
23
- import { GeometryBVHBatched } from "./GeometryBVHBatched.js";
24
3
  import { getBiasedNormalSample } from "./getBiasedNormalSample.js";
25
- import { make_one_vector3 } from "./make_one_vector3.js";
26
- import { PathTracedMesh } from "./PathTracedMesh.js";
27
- import { transform_normal_m4 } from "./ray_hit_apply_transform.js";
28
- import { sample_triangle_attribute } from "./sample_triangle_attribute.js";
29
- import { vec3_uint8_to_float } from "./vec3_uint8_to_float.js";
30
4
 
31
5
  /*
32
6
  Ray hit data layout:
@@ -39,465 +13,40 @@ import { vec3_uint8_to_float } from "./vec3_uint8_to_float.js";
39
13
  instance_id: uint
40
14
  */
41
15
 
42
- const temp_ray_results = [];
43
-
44
- const texture_uv = [0, 0];
45
- const color = [];
46
16
 
47
17
  const irradiance = [0, 0, 0];
48
18
 
49
19
  const trace_result = [];
50
20
 
51
21
  const _ray_0 = [];
52
- const _ray_1 = [];
53
22
 
54
23
  const tmp_0 = [];
55
24
  const tmp_1 = [];
56
25
 
57
- const null_output = [];
58
-
26
+ const RUSSIAN_ROULETTE_PROBABILITY = 0.5;
59
27
 
60
28
  export class PathTracer {
61
- constructor() {
62
-
63
- /**
64
- *
65
- * @type {BVH}
66
- */
67
- this.bvh_top_level = new BVH();
68
-
69
- /**
70
- *
71
- * @type {Map<number, PathTracedMesh>}
72
- */
73
- this.meshes = new Map();
74
-
75
- /**
76
- *
77
- * @type {AbstractLight[]}
78
- */
79
- this.__lights = [];
80
-
81
- /**
82
- *
83
- * @type {Map<THREE.BufferGeometry, GeometryBVHBatched>}
84
- */
85
- this.geo_cache = new Map();
86
-
87
- /**
88
- * Maps {@link Texture.id} to relevant sampler
89
- * @type {Map<number, Sampler2D>}
90
- */
91
- this.textures = new Map();
92
-
93
- /**
94
- *
95
- * @type {function}
96
- * @private
97
- */
98
- this.__background_sampler = make_one_vector3();
99
- }
100
-
101
- /**
102
- *
103
- * @param {THREE.BufferGeometry} geo
104
- * @return {GeometryBVHBatched}
105
- */
106
- obtainGeometryBVH(geo) {
107
- const cached = this.geo_cache.get(geo);
108
-
109
- if (cached !== undefined) {
110
- return cached;
111
- }
112
-
113
- const bvh8 = new GeometryBVHBatched();
114
-
115
- bvh8.build(geo);
116
-
117
- this.geo_cache.set(geo, bvh8);
118
-
119
- return bvh8;
120
- }
121
-
122
- optimize() {
123
- this.bvh_top_level.trim();
124
- ebvh_sort_for_traversal_depth_first(this.bvh_top_level);
125
- }
126
-
127
- async build() {
128
- for (const [id, mesh] of this.meshes) {
129
- const material = mesh.material;
130
-
131
- //patch textures
132
- const materialType = material.type;
133
-
134
- /**
135
- *
136
- * @type {TextureAttachment[]}
137
- */
138
- const attachments = TextureAttachmentsByMaterialType[materialType];
139
-
140
- if (attachments === undefined) {
141
- // unsupported
142
- continue;
143
- }
144
-
145
- for (let i = 0; i < attachments.length; i++) {
146
- const attachment = attachments[i];
147
-
148
- const texture = attachment.read(material);
149
-
150
- if (texture === undefined || texture === null) {
151
- continue;
152
- }
153
-
154
- if (this.textures.has(texture.id)) {
155
- continue;
156
- }
157
-
158
- const sampler2D = convertTexture2Sampler2D(texture, undefined, undefined, false);
159
-
160
- this.textures.set(texture.id, sampler2D);
161
- }
162
- }
163
- }
164
-
165
- /**
166
- *
167
- * @param {AbstractLight} light
168
- */
169
- addLight(light) {
170
- this.__lights.push(light);
171
- }
172
-
173
- /**
174
- *
175
- * @param {THREE.BufferGeometry} geo
176
- * @param {THREE.Material} material
177
- * @param {mat4|number[]} transform
178
- */
179
- addMesh(geo, material, transform) {
180
- //meshopt_optimizeVertexCache(geo.getIndex().array, geo.getIndex().array, geo.getIndex().array.length, geo.getAttribute('position').count);
181
-
182
- const mesh = new PathTracedMesh();
183
- mesh.geometry = geo;
184
- mesh.material = material;
185
- mesh.transform = transform;
186
-
187
-
188
- mesh.geo_bvh = this.obtainGeometryBVH(geo);
189
29
 
190
- const bvh = this.bvh_top_level;
191
-
192
- const bvh_node_id = bvh.allocate_node();
193
-
194
- mesh.__bvh_node_id = bvh_node_id;
195
-
196
- ensureGeometryBoundingBox(geo);
197
-
198
- const aabb = [
199
- geo.boundingBox.min.x,
200
- geo.boundingBox.min.y,
201
- geo.boundingBox.min.z,
202
- geo.boundingBox.max.x,
203
- geo.boundingBox.max.y,
204
- geo.boundingBox.max.z,
205
- ];
206
-
207
- const aabb_t = [];
208
-
209
- aabb3_matrix4_project(aabb_t, aabb, transform);
210
-
211
- bvh.node_set_aabb(
212
- bvh_node_id,
213
- aabb_t
214
- );
215
- bvh.node_set_user_data(
216
- bvh_node_id,
217
- mesh.id
218
- );
219
- bvh.insert_leaf(bvh_node_id);
220
-
221
- this.meshes.set(mesh.id, mesh);
222
- }
223
-
224
- /**
225
- *
226
- * @param {number[]} out
227
- * @param {Texture} texture
228
- * @param {number} u
229
- * @param {number} v
230
- */
231
- sample_texture(out, texture, u, v) {
232
- if (texture === undefined || texture == null) {
233
- return;
234
- }
235
-
236
- const sampler = this.textures.get(texture.id);
237
-
238
- if (sampler === undefined) {
239
- return;
240
- }
241
-
242
- // TODO apply texture matrix transform
243
-
244
- const _u = apply_texture_clamping_to_coordinate(texture.wrapS, u);
245
- const _v = apply_texture_clamping_to_coordinate(texture.wrapT, v);
246
-
247
- const magFilter = texture.magFilter;
248
-
249
- switch (magFilter) {
250
- default:
251
- case NearestFilter:
252
- case NearestMipMapLinearFilter:
253
- sampler.sampleNearestUV(_u, _v, out);
254
- break;
255
-
256
- case LinearFilter:
257
- case LinearMipmapLinearFilter:
258
-
259
- sampler.sampleBilinearUV(_u, _v, out);
260
- break;
261
- }
262
-
263
- if (texture.type === UnsignedByteType) {
264
- vec3_uint8_to_float(out, out);
265
- }
266
-
267
- const texture_encoding = texture.encoding;
268
-
269
- if (texture_encoding === LinearEncoding) {
270
- // nothing
271
- } else if (texture_encoding === sRGBEncoding) {
272
- // convert value to sRGB
273
- linear_to_sRGB(out, 0, out, 0);
274
- }
275
-
276
- }
277
-
278
- /**
279
- *
280
- * @param {number[]} out [color_r, color_g, color_b, normal_x, normal_y, normal_z]
281
- * @param {number[]} hit
282
- */
283
- sample_material(out, hit) {
284
- const primitive_id = hit[9];
285
- const instance_id = hit[10];
286
- const u = hit[7];
287
- const v = hit[8];
288
-
289
- out[0] = 1;
290
- out[1] = 1;
291
- out[2] = 1;
292
-
293
- /**
294
- *
295
- * @type {PathTracedMesh}
296
- */
297
- const mesh = this.meshes.get(instance_id);
298
-
299
- if (mesh === undefined) {
300
- // instance not found
301
- return;
302
- }
303
-
304
- const geometry = mesh.geometry;
305
- const index_attribute = geometry.getIndex();
306
- const index_array = index_attribute.array;
307
-
308
-
309
- // sample surface normal
310
- const index_offset = primitive_id * 3;
311
-
312
- const index_0 = index_array[index_offset];
313
- const index_1 = index_array[index_offset + 1];
314
- const index_2 = index_array[index_offset + 2];
315
-
316
- const normal_attribute = geometry.getAttribute('normal');
317
-
318
- if (normal_attribute !== undefined) {
319
- // vertex normals are present, use those
320
- const normal_array = normal_attribute.array;
321
-
322
- sample_triangle_attribute(out, 3, index_0, index_1, index_2, normal_array, 3, u, v);
323
-
324
- // apply transform
325
- transform_normal_m4(out, 3, out, 3, mesh.transform);
326
- } else {
327
- // copy hit normal
328
- array_copy(hit, 3, out, 3, 3);
329
- }
330
-
331
-
332
- const uv_attribute = geometry.getAttribute('uv');
333
-
334
- if (uv_attribute !== undefined) {
335
- const uv_array = uv_attribute.array;
336
- sample_triangle_attribute(texture_uv, 0, index_0, index_1, index_2, uv_array, 2, u, v);
337
- } else {
338
- // default texture uv
339
- texture_uv[0] = 0;
340
- texture_uv[1] = 0;
341
- }
342
-
343
- const material = mesh.material;
344
-
345
- if (material.isMeshStandardMaterial) {
346
- const material_color = material.color;
347
-
348
- out[0] *= material_color.r;
349
- out[1] *= material_color.g;
350
- out[2] *= material_color.b;
351
-
352
- const diffuse_map = material.map;
353
-
354
- if (diffuse_map !== null) {
355
- this.sample_texture(color, diffuse_map, texture_uv[0], texture_uv[1]);
356
-
357
- vec3.multiply(out, out, color);
358
- }
359
-
360
- } else {
361
- // unsupported
362
- }
363
-
364
- }
365
30
 
366
31
  /**
367
32
  *
368
33
  * @param {number[]} out
369
34
  * @param {number[]} ray
370
- * @param {number} min_distance
371
35
  * @param {number} max_distance
372
- * @return {number}
36
+ * @param {number} min_bounce
37
+ * @param {number} max_bounce
38
+ * @param {function} random
39
+ * @param {PathTracedScene} scene
373
40
  */
374
- trace(out, ray, min_distance, max_distance) {
375
- const bvh = this.bvh_top_level;
376
-
377
- const hit_count = bvh_query_user_data_ray(
378
- bvh, bvh.root,
379
- temp_ray_results, 0,
380
- ray[0], ray[1], ray[2],
381
- ray[3], ray[4], ray[5]
382
- );
383
-
384
- let nearest_hit_distance = max_distance;
385
- let nearest_mesh = null;
386
-
387
-
388
- for (let i = 0; i < hit_count; i++) {
389
- const node_user_data = temp_ray_results[i];
390
-
391
- const mesh = this.meshes.get(node_user_data);
392
-
393
- const distance_to_hit = mesh.hit(tmp_0, ray, min_distance, nearest_hit_distance);
394
-
395
- if (distance_to_hit >= 0) {
396
- // since raycast in leaf nodes is already bound by maximum distance, any hit we get is necessarily a closer hit than before
397
- nearest_hit_distance = distance_to_hit;
398
- nearest_mesh = mesh;
399
-
400
- array_copy(tmp_0, 0, out, 0, 11);
401
- }
402
- }
403
-
404
- if (nearest_hit_distance !== max_distance) {
405
-
406
- // out[6] = nearest_mesh;
407
-
408
- return nearest_hit_distance;
409
- }
410
-
411
- return -1;
412
- }
413
-
414
- /**
415
- *
416
- * @param {number[]} out
417
- * @param {number} out_offset
418
- * @param {number[]} direction
419
- * @param {number} direction_offset
420
- */
421
- sample_background(out, out_offset, direction, direction_offset) {
422
- this.__background_sampler(out, out_offset, direction, direction_offset);
423
- }
424
-
425
- /**
426
- *
427
- * @param {number[]} out
428
- * @param {number} out_offset
429
- * @param {number[]} ray
430
- * @param {number} ray_address
431
- * @returns {boolean}
432
- */
433
- sample_lights(out, out_offset, ray, ray_address) {
434
- let lights_sampled = false;
435
-
436
- const lights = this.__lights;
437
- const light_count = lights.length;
438
-
439
- for (let i = 0; i < 3; i++) {
440
- // initialize contribution to 0
441
- out[out_offset + i] = 0;
442
- }
443
-
444
- for (let i = 0; i < light_count; i++) {
445
- const light = lights[i];
446
-
447
- if (light.isDirectionalLight === true) {
448
- const dir = light.direction;
449
-
450
- // see https://github.com/mrdoob/three.js/blob/f0a9e0cf90a2f1ba5017fcb7fd46f02748b920cf/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js#L172
451
-
452
- const ray_direction_x = ray[ray_address + 3];
453
- const ray_direction_y = ray[ray_address + 4];
454
- const ray_direction_z = ray[ray_address + 5];
455
-
456
- const light_dir_inv_x = -dir.x;
457
- const light_dir_inv_y = -dir.y;
458
- const light_dir_inv_z = -dir.z;
459
-
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
- );
464
-
465
- if (dotNL <= 0) {
466
- // no contribution, facing away from the light
467
- continue;
468
- }
469
-
470
- const ray_origin_x = ray[ray_address + 0];
471
- const ray_origin_y = ray[ray_address + 1];
472
- const ray_origin_z = ray[ray_address + 2];
473
-
474
- ray3_array_compose(_ray_1,
475
- ray_origin_x, ray_origin_y, ray_origin_z,
476
- light_dir_inv_x, light_dir_inv_y, light_dir_inv_z
477
- );
478
-
479
- // check if there are any obstacles in the direction of the light
480
- if (this.trace(null_output, _ray_1, 0.0001, Infinity) > 0) {
481
- // light is occluded
482
- continue;
483
- }
484
-
485
-
486
- const intensity = dotNL * light.intensity.getValue();
487
-
488
- for (let j = 0; j < 3; j++) {
489
- // irradiance
490
- out[out_offset + j] += light.color[j] * intensity;
491
- }
492
-
493
- lights_sampled = true;
494
- }
495
- }
496
-
497
- return lights_sampled;
498
- }
499
-
500
- path_trace(out, ray, max_distance, max_bounce, random = Math.random) {
41
+ path_trace(
42
+ out,
43
+ ray,
44
+ max_distance,
45
+ min_bounce,
46
+ max_bounce,
47
+ random = Math.random,
48
+ scene
49
+ ) {
501
50
  //TODO add importance sampling, see https://raytracing.github.io/books/RayTracingTheRestOfYourLife.html#lightscattering/thescatteringpdf
502
51
 
503
52
  array_copy(ray, 0, _ray_0, 0, 6);
@@ -507,22 +56,28 @@ export class PathTracer {
507
56
  irradiance[2] = 1;
508
57
 
509
58
  let i;
510
- for (i = 0; i < max_bounce; i++) {
59
+ for (i = 0; i < max_bounce; ++i) {
511
60
 
512
- const hit_distance = this.trace(trace_result, _ray_0, 0.0001, max_distance);
61
+ if (i >= min_bounce) {
62
+ const russian_roulette_roll = random();
63
+
64
+ if (russian_roulette_roll > RUSSIAN_ROULETTE_PROBABILITY) {
65
+ // terminate ray
66
+ break;
67
+ }
68
+ }
69
+
70
+
71
+ const hit_distance = scene.trace(trace_result, _ray_0, 0.0001, max_distance);
513
72
 
514
73
 
515
74
  if (hit_distance < 0) {
516
75
  // ray didn't hit anything
517
76
 
518
- // sample "environment" and terminate path as there is nothing to reflect off of
519
- this.sample_background(tmp_0, 0, _ray_0, 3);
520
- vec3.multiply(irradiance, irradiance, tmp_0);
521
-
522
77
  break;
523
78
  }
524
79
 
525
- this.sample_material(tmp_0, trace_result);
80
+ scene.sample_material(tmp_0, trace_result);
526
81
 
527
82
  // adjust normal on the hit
528
83
  array_copy(tmp_0, 3, trace_result, 3, 3);
@@ -536,17 +91,26 @@ export class PathTracer {
536
91
 
537
92
  }
538
93
 
94
+
539
95
  if (i > 0) {
540
- // direct lighting
541
- this.sample_lights(tmp_1, 0, trace_result, 0);
96
+ // light sampling
97
+ scene.sample_lights(tmp_1, 0, trace_result, 0);
542
98
 
543
99
  irradiance[0] *= tmp_1[0];
544
100
  irradiance[1] *= tmp_1[1];
545
101
  irradiance[2] *= tmp_1[2];
102
+ } else {
103
+
104
+ // ray didn't hit anything on the very first bounce
105
+
106
+ // sample "environment" and terminate path as there is nothing to reflect off of
107
+ scene.sample_background(tmp_0, 0, _ray_0, 3);
108
+ vec3.multiply(irradiance, irradiance, tmp_0);
109
+
546
110
  }
547
111
 
548
- out[0] = irradiance[0]
549
- out[1] = irradiance[1]
112
+ out[0] = irradiance[0]
113
+ out[1] = irradiance[1]
550
114
  out[2] = irradiance[2]
551
115
 
552
116
  // array_copy(irradiance, 0, out, 0, 3);
@@ -1,2 +1,3 @@
1
1
  export function make_one_vector3(): (out: any, out_offset: any, direction: any, direction_offset: any) => void;
2
+ export function make_vector3(x: any, y: any, z: any): (out: any, out_offset: any, direction: any, direction_offset: any) => void;
2
3
  //# sourceMappingURL=make_one_vector3.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"make_one_vector3.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/make_one_vector3.js"],"names":[],"mappings":"AAAA,+GAMC"}
1
+ {"version":3,"file":"make_one_vector3.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/make_one_vector3.js"],"names":[],"mappings":"AAAA,+GAEC;AACD,iIAMC"}
@@ -1,7 +1,10 @@
1
1
  export function make_one_vector3() {
2
+ return make_vector3(1,1,1);
3
+ }
4
+ export function make_vector3(x,y,z) {
2
5
  return (out, out_offset, direction, direction_offset) => {
3
- out[out_offset] = 1;
4
- out[out_offset + 1] = 1;
5
- out[out_offset + 2] = 1;
6
+ out[out_offset] = x;
7
+ out[out_offset + 1] = y;
8
+ out[out_offset + 2] = z;
6
9
  }
7
10
  }