@woosh/meep-engine 2.107.0 → 2.108.2

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 (315) hide show
  1. package/build/bundle-worker-image-decoder.js +1 -1
  2. package/build/meep.cjs +255 -172
  3. package/build/meep.min.js +1 -1
  4. package/build/meep.module.js +255 -173
  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/int32_to_binary_string.d.ts +3 -2
  11. package/src/core/binary/int32_to_binary_string.d.ts.map +1 -1
  12. package/src/core/binary/int32_to_binary_string.js +18 -14
  13. package/src/core/binary/split_by_3.spec.d.ts +2 -0
  14. package/src/core/binary/split_by_3.spec.d.ts.map +1 -0
  15. package/src/core/binary/split_by_3.spec.js +22 -0
  16. package/src/core/binary/to_half_float_uint16.d.ts.map +1 -1
  17. package/src/core/binary/to_half_float_uint16.js +7 -5
  18. package/src/core/binary/uint8_to_float.d.ts +7 -0
  19. package/src/core/binary/uint8_to_float.d.ts.map +1 -0
  20. package/src/core/binary/{uint82float.js → uint8_to_float.js} +1 -1
  21. package/src/core/binary/uint8_to_float.spec.d.ts +2 -0
  22. package/src/core/binary/uint8_to_float.spec.d.ts.map +1 -0
  23. package/src/core/binary/uint8_to_float.spec.js +7 -0
  24. package/src/core/codegen/codeToBlob.d.ts +8 -0
  25. package/src/core/codegen/codeToBlob.d.ts.map +1 -0
  26. package/src/core/codegen/codeToBlob.js +36 -0
  27. package/src/core/codegen/codeToURL.d.ts +8 -0
  28. package/src/core/codegen/codeToURL.d.ts.map +1 -0
  29. package/src/core/codegen/codeToURL.js +22 -0
  30. package/src/core/collection/array/array_shuffle.d.ts +8 -0
  31. package/src/core/collection/array/array_shuffle.d.ts.map +1 -0
  32. package/src/core/collection/array/array_shuffle.js +22 -0
  33. package/src/core/collection/array/array_shuffle.spec.d.ts +2 -0
  34. package/src/core/collection/array/array_shuffle.spec.d.ts.map +1 -0
  35. package/src/core/collection/array/{randomizeArrayElementOrder.spec.js → array_shuffle.spec.js} +4 -4
  36. package/src/core/collection/array/isArrayEqualStrict.d.ts.map +1 -1
  37. package/src/core/collection/array/isArrayEqualStrict.js +2 -2
  38. package/src/core/collection/array/iterator/ArrayIteratorRandom.js +2 -2
  39. package/src/core/collection/array/randomMultipleFromArray.js +2 -2
  40. package/src/core/color/Color.d.ts.map +1 -1
  41. package/src/core/color/Color.js +16 -11
  42. package/src/core/color/hsv/hsv2rgb.js +4 -4
  43. package/src/core/color/hsv/rgb2hsv.d.ts +3 -3
  44. package/src/core/color/hsv/rgb2hsv.d.ts.map +1 -1
  45. package/src/core/color/hsv/rgb2hsv.js +11 -18
  46. package/src/core/color/rgb2uint24.js +4 -4
  47. package/src/core/color/rgb_to_luminance.d.ts +9 -0
  48. package/src/core/color/rgb_to_luminance.d.ts.map +1 -0
  49. package/src/core/color/rgb_to_luminance.js +10 -0
  50. package/src/core/color/sRGB/linear_to_sRGB.d.ts +1 -0
  51. package/src/core/color/sRGB/linear_to_sRGB.d.ts.map +1 -1
  52. package/src/core/color/sRGB/linear_to_sRGB.js +4 -4
  53. package/src/core/geom/3d/aabb/AABB3.d.ts.map +1 -1
  54. package/src/core/geom/3d/aabb/AABB3.js +4 -1
  55. package/src/core/geom/3d/aabb/aabb3_intersects_ray.js +3 -3
  56. package/src/core/geom/3d/shape/UnitSphereShape3D.d.ts.map +1 -1
  57. package/src/core/geom/3d/shape/UnitSphereShape3D.js +14 -14
  58. package/src/core/geom/3d/sphere/harmonics/README.md +16 -2
  59. package/src/core/geom/3d/sphere/harmonics/SH3_COEFFICIENTS.d.ts +6 -0
  60. package/src/core/geom/3d/sphere/harmonics/SH3_COEFFICIENTS.d.ts.map +1 -0
  61. package/src/core/geom/3d/sphere/harmonics/SH3_COEFFICIENTS.js +17 -0
  62. package/src/core/geom/3d/sphere/harmonics/sh3_basis_at.d.ts.map +1 -1
  63. package/src/core/geom/3d/sphere/harmonics/sh3_basis_at.js +21 -9
  64. package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.d.ts +3 -3
  65. package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.d.ts.map +1 -1
  66. package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.js +35 -206
  67. package/src/core/geom/3d/sphere/harmonics/sh3_rotate.d.ts +8 -0
  68. package/src/core/geom/3d/sphere/harmonics/sh3_rotate.d.ts.map +1 -0
  69. package/src/core/geom/3d/sphere/harmonics/sh3_rotate.js +29 -0
  70. package/src/core/geom/3d/sphere/harmonics/sh3_sample_by_direction.js +10 -10
  71. package/src/core/geom/3d/sphere/harmonics/sh_index.d.ts +8 -0
  72. package/src/core/geom/3d/sphere/harmonics/sh_index.d.ts.map +1 -0
  73. package/src/core/geom/3d/sphere/harmonics/sh_index.js +9 -0
  74. package/src/core/geom/3d/sphere/harmonics/sh_rotate_band1.d.ts +8 -0
  75. package/src/core/geom/3d/sphere/harmonics/sh_rotate_band1.d.ts.map +1 -0
  76. package/src/core/geom/3d/sphere/harmonics/sh_rotate_band1.js +44 -0
  77. package/src/core/geom/3d/sphere/harmonics/sh_rotate_band2.d.ts +8 -0
  78. package/src/core/geom/3d/sphere/harmonics/sh_rotate_band2.d.ts.map +1 -0
  79. package/src/core/geom/3d/sphere/harmonics/sh_rotate_band2.js +86 -0
  80. package/src/core/geom/3d/sphere/in_sphere3d_robust.d.ts.map +1 -1
  81. package/src/core/geom/3d/sphere/in_sphere3d_robust.js +2 -1
  82. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.d.ts +20 -1
  83. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.d.ts.map +1 -1
  84. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.js +53 -7
  85. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.spec.js +2 -2
  86. package/src/core/geom/3d/tetrahedra/build_tetrahedral_mesh_buffer_geometry.d.ts +1 -1
  87. package/src/core/geom/3d/tetrahedra/build_tetrahedral_mesh_buffer_geometry.d.ts.map +1 -1
  88. package/src/core/geom/3d/tetrahedra/build_tetrahedral_mesh_buffer_geometry.js +12 -7
  89. package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_build_from_grid.d.ts +13 -0
  90. package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_build_from_grid.d.ts.map +1 -0
  91. package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_build_from_grid.js +135 -0
  92. package/src/core/geom/3d/tetrahedra/prototypeTetrahedraBuilder.js +38 -24
  93. package/src/core/geom/3d/tetrahedra/{compute_circumsphere.d.ts → tetrahedron_compute_circumsphere.d.ts} +3 -5
  94. package/src/core/geom/3d/tetrahedra/tetrahedron_compute_circumsphere.d.ts.map +1 -0
  95. package/src/core/geom/3d/tetrahedra/{compute_circumsphere.js → tetrahedron_compute_circumsphere.js} +2 -4
  96. package/src/core/geom/3d/tetrahedra/tetrahedron_compute_signed_volume.d.ts.map +1 -1
  97. package/src/core/geom/3d/tetrahedra/tetrahedron_compute_signed_volume.js +3 -1
  98. package/src/core/geom/Vector3.d.ts.map +1 -1
  99. package/src/core/geom/Vector3.js +4 -3
  100. package/src/core/geom/mat3/m3_multiply_vec3.d.ts +8 -0
  101. package/src/core/geom/mat3/m3_multiply_vec3.d.ts.map +1 -0
  102. package/src/core/geom/mat3/m3_multiply_vec3.js +21 -0
  103. package/src/core/geom/random/randomPointInSphere.d.ts +1 -1
  104. package/src/core/geom/random/randomPointInSphere.js +2 -2
  105. package/src/core/geom/random/randomPointOnSphere.d.ts +3 -3
  106. package/src/core/geom/random/randomPointOnSphere.d.ts.map +1 -1
  107. package/src/core/geom/random/randomPointOnSphere.js +5 -9
  108. package/src/core/geom/vec2/v2_cross_product.d.ts +15 -0
  109. package/src/core/geom/vec2/v2_cross_product.d.ts.map +1 -0
  110. package/src/core/geom/vec2/v2_cross_product.js +21 -0
  111. package/src/core/geom/vec3/v3_slerp.d.ts +1 -0
  112. package/src/core/geom/vec3/v3_slerp.d.ts.map +1 -1
  113. package/src/core/geom/vec3/v3_slerp.js +1 -0
  114. package/src/core/graph/MultiNode.d.ts +1 -1
  115. package/src/core/graph/MultiNode.js +1 -1
  116. package/src/core/graph/WeightedEdge.d.ts +6 -4
  117. package/src/core/graph/WeightedEdge.d.ts.map +1 -1
  118. package/src/core/graph/WeightedEdge.js +3 -0
  119. package/src/core/graph/coloring/colorizeGraph.js +19 -19
  120. package/src/core/graph/convert_graph_to_dot_string.d.ts +1 -1
  121. package/src/core/graph/convert_graph_to_dot_string.d.ts.map +1 -1
  122. package/src/core/graph/convert_graph_to_dot_string.js +10 -6
  123. package/src/core/graph/graph_compute_adjacency_matrix.d.ts +9 -0
  124. package/src/core/graph/graph_compute_adjacency_matrix.d.ts.map +1 -0
  125. package/src/core/graph/{graph_adjacency_matrix.js → graph_compute_adjacency_matrix.js} +1 -2
  126. package/src/core/graph/graph_compute_degree_matrix.d.ts +10 -0
  127. package/src/core/graph/graph_compute_degree_matrix.d.ts.map +1 -0
  128. package/src/core/graph/graph_compute_degree_matrix.js +23 -0
  129. package/src/core/graph/graph_compute_distance_matrix.d.ts +13 -0
  130. package/src/core/graph/graph_compute_distance_matrix.d.ts.map +1 -0
  131. package/src/core/graph/graph_compute_distance_matrix.js +103 -0
  132. package/src/core/graph/{graph_laplacian_matrix.d.ts → graph_compute_laplacian_matrix.d.ts} +2 -2
  133. package/src/core/graph/graph_compute_laplacian_matrix.d.ts.map +1 -0
  134. package/src/core/graph/{graph_laplacian_matrix.js → graph_compute_laplacian_matrix.js} +6 -6
  135. package/src/core/graph/graph_k_means_cluster.d.ts.map +1 -1
  136. package/src/core/graph/graph_k_means_cluster.js +4 -119
  137. package/src/core/graph/{coarsen_graph.d.ts → mn_graph_coarsen.d.ts} +2 -2
  138. package/src/core/graph/mn_graph_coarsen.d.ts.map +1 -0
  139. package/src/core/graph/{coarsen_graph.js → mn_graph_coarsen.js} +1 -1
  140. package/src/core/graph/mn_graph_coarsen.spec.d.ts +2 -0
  141. package/src/core/graph/mn_graph_coarsen.spec.d.ts.map +1 -0
  142. package/src/core/graph/{coarsen_graph.spec.js → mn_graph_coarsen.spec.js} +4 -4
  143. package/src/core/graph/mn_graph_collapse_weighted_edge.d.ts +1 -0
  144. package/src/core/graph/mn_graph_collapse_weighted_edge.d.ts.map +1 -1
  145. package/src/core/graph/mn_graph_collapse_weighted_edge.js +7 -1
  146. package/src/core/math/physics/brdf/brdf_burley.d.ts.map +1 -1
  147. package/src/core/math/physics/brdf/brdf_burley.js +9 -1
  148. package/src/core/math/physics/brdf/{D_GGX.d.ts → diffuse_GGX.d.ts} +2 -2
  149. package/src/core/math/physics/brdf/diffuse_GGX.d.ts.map +1 -0
  150. package/src/core/math/physics/brdf/{D_GGX.js → diffuse_GGX.js} +1 -1
  151. package/src/core/math/physics/brdf/fresnel_Schlick.d.ts +3 -0
  152. package/src/core/math/physics/brdf/fresnel_Schlick.d.ts.map +1 -0
  153. package/src/core/math/physics/brdf/fresnel_Schlick.js +3 -0
  154. package/src/core/math/physics/brdf/fresnel_Schlick_optimized.d.ts +9 -0
  155. package/src/core/math/physics/brdf/fresnel_Schlick_optimized.d.ts.map +1 -0
  156. package/src/core/math/physics/brdf/fresnel_Schlick_optimized.js +12 -0
  157. package/src/core/math/physics/brdf/fresnel_Schlick_original.d.ts +9 -0
  158. package/src/core/math/physics/brdf/fresnel_Schlick_original.d.ts.map +1 -0
  159. package/src/core/math/physics/brdf/fresnel_Schlick_original.js +10 -0
  160. package/src/core/math/physics/bsdf/bsdf_schlick.d.ts.map +1 -1
  161. package/src/core/math/physics/bsdf/bsdf_schlick.js +3 -11
  162. package/src/core/math/physics/ior_to_reflectivity.d.ts +7 -0
  163. package/src/core/math/physics/ior_to_reflectivity.d.ts.map +1 -0
  164. package/src/core/math/physics/ior_to_reflectivity.js +9 -0
  165. package/src/core/math/physics/pdf/README.md +1 -0
  166. package/src/core/math/physics/pdf/pdf_GGX.d.ts +16 -0
  167. package/src/core/math/physics/pdf/pdf_GGX.d.ts.map +1 -0
  168. package/src/core/math/physics/pdf/pdf_GGX.js +25 -0
  169. package/src/core/math/physics/reflectivity_to_ior.d.ts +7 -0
  170. package/src/core/math/physics/reflectivity_to_ior.d.ts.map +1 -0
  171. package/src/core/math/physics/reflectivity_to_ior.js +8 -0
  172. package/src/core/process/task/util/randomCountTask.js +3 -3
  173. package/src/core/process/worker/WorkerBuilder.d.ts.map +1 -1
  174. package/src/core/process/worker/WorkerBuilder.js +5 -35
  175. package/src/engine/EngineHarness.d.ts +10 -1
  176. package/src/engine/EngineHarness.d.ts.map +1 -1
  177. package/src/engine/EngineHarness.js +22 -11
  178. package/src/engine/asset/loaders/ArrayBufferLoader.d.ts.map +1 -1
  179. package/src/engine/asset/loaders/ArrayBufferLoader.js +17 -10
  180. package/src/engine/asset/loaders/image/png/PNGReader.d.ts +25 -11
  181. package/src/engine/asset/loaders/image/png/PNGReader.d.ts.map +1 -1
  182. package/src/engine/asset/loaders/image/png/PNGReader.js +38 -24
  183. package/src/engine/asset/loaders/material/TextureAttachmensByMaterialType.d.ts.map +1 -1
  184. package/src/engine/asset/loaders/material/TextureAttachmensByMaterialType.js +5 -0
  185. package/src/engine/ecs/terrain/overlay/TerrainOverlay.js +4 -4
  186. package/src/engine/graphics/GraphicsEngine.js +1 -1
  187. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraController.d.ts.map +1 -1
  188. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraController.js +4 -0
  189. package/src/engine/graphics/ecs/light/LightSystem.d.ts.map +1 -1
  190. package/src/engine/graphics/ecs/light/LightSystem.js +2 -3
  191. package/src/engine/graphics/ecs/light/binding/three/ThreeLightBinding.d.ts +6 -0
  192. package/src/engine/graphics/ecs/light/binding/three/ThreeLightBinding.d.ts.map +1 -1
  193. package/src/engine/graphics/ecs/light/binding/three/ThreeLightBinding.js +22 -11
  194. package/src/engine/graphics/ecs/sprite/SpriteSystemPE.d.ts.map +1 -1
  195. package/src/engine/graphics/ecs/sprite/SpriteSystemPE.js +7 -7
  196. package/src/engine/graphics/impostors/octahedral/bake/prepare_bake_material.js +3 -3
  197. package/src/engine/graphics/render/forward_plus/model/DirectionalLight.d.ts.map +1 -1
  198. package/src/engine/graphics/render/forward_plus/model/DirectionalLight.js +25 -25
  199. package/src/engine/graphics/sh3/SH3VisualisationMaterial.d.ts.map +1 -1
  200. package/src/engine/graphics/sh3/SH3VisualisationMaterial.js +9 -6
  201. package/src/engine/graphics/sh3/fromCubeRenderTarget.d.ts +9 -0
  202. package/src/engine/graphics/sh3/fromCubeRenderTarget.d.ts.map +1 -0
  203. package/src/engine/graphics/sh3/fromCubeRenderTarget.js +145 -0
  204. package/src/engine/graphics/sh3/gi/tetrahedral_mesh_to_texture.d.ts +8 -0
  205. package/src/engine/graphics/sh3/gi/tetrahedral_mesh_to_texture.d.ts.map +1 -0
  206. package/src/engine/graphics/sh3/gi/tetrahedral_mesh_to_texture.js +51 -0
  207. package/src/engine/graphics/sh3/{LightProbeVolume.d.ts → lpv/LightProbeVolume.d.ts} +18 -7
  208. package/src/engine/graphics/sh3/lpv/LightProbeVolume.d.ts.map +1 -0
  209. package/src/engine/graphics/sh3/lpv/LightProbeVolume.js +340 -0
  210. package/src/engine/graphics/sh3/lpv/LightProbeVolumeSerializationAdapter.d.ts +18 -0
  211. package/src/engine/graphics/sh3/lpv/LightProbeVolumeSerializationAdapter.d.ts.map +1 -0
  212. package/src/engine/graphics/sh3/lpv/LightProbeVolumeSerializationAdapter.js +44 -0
  213. package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.d.ts +12 -0
  214. package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.d.ts.map +1 -0
  215. package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.js +122 -0
  216. package/src/engine/graphics/sh3/lpv/ProbeRenderer.d.ts +29 -0
  217. package/src/engine/graphics/sh3/lpv/ProbeRenderer.d.ts.map +1 -0
  218. package/src/engine/graphics/sh3/lpv/ProbeRenderer.js +35 -0
  219. package/src/engine/graphics/sh3/lpv/WebGLCubeProbeRenderer.d.ts +27 -0
  220. package/src/engine/graphics/sh3/lpv/WebGLCubeProbeRenderer.d.ts.map +1 -0
  221. package/src/engine/graphics/sh3/lpv/WebGLCubeProbeRenderer.js +158 -0
  222. package/src/engine/graphics/sh3/lpv/build_probes_for_scene.d.ts +11 -0
  223. package/src/engine/graphics/sh3/lpv/build_probes_for_scene.d.ts.map +1 -0
  224. package/src/engine/graphics/sh3/lpv/build_probes_for_scene.js +127 -0
  225. package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.d.ts +12 -0
  226. package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.d.ts.map +1 -0
  227. package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.js +89 -0
  228. package/src/engine/graphics/sh3/path_tracer/PathTracedScene.d.ts +90 -0
  229. package/src/engine/graphics/sh3/path_tracer/PathTracedScene.d.ts.map +1 -0
  230. package/src/engine/graphics/sh3/path_tracer/PathTracedScene.js +352 -0
  231. package/src/engine/graphics/sh3/path_tracer/PathTracer.d.ts +5 -91
  232. package/src/engine/graphics/sh3/path_tracer/PathTracer.d.ts.map +1 -1
  233. package/src/engine/graphics/sh3/path_tracer/PathTracer.js +41 -477
  234. package/src/engine/graphics/sh3/path_tracer/make_one_vector3.d.ts +1 -0
  235. package/src/engine/graphics/sh3/path_tracer/make_one_vector3.d.ts.map +1 -1
  236. package/src/engine/graphics/sh3/path_tracer/make_one_vector3.js +6 -3
  237. package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +38 -62
  238. package/src/engine/graphics/sh3/path_tracer/random_in_hemisphere.d.ts.map +1 -1
  239. package/src/engine/graphics/sh3/path_tracer/random_in_hemisphere.js +7 -1
  240. package/src/engine/graphics/sh3/path_tracer/sample_triangle_attribute.d.ts +2 -2
  241. package/src/engine/graphics/sh3/path_tracer/sample_triangle_attribute.d.ts.map +1 -1
  242. package/src/engine/graphics/sh3/path_tracer/sample_triangle_attribute.js +1 -1
  243. package/src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples.d.ts +10 -0
  244. package/src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples.d.ts.map +1 -0
  245. package/src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples.js +20 -0
  246. package/src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples_2d.d.ts +10 -0
  247. package/src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples_2d.d.ts.map +1 -0
  248. package/src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples_2d.js +31 -0
  249. package/src/engine/graphics/sh3/path_tracer/sampling/make_stratified_sample.d.ts +9 -0
  250. package/src/engine/graphics/sh3/path_tracer/sampling/make_stratified_sample.d.ts.map +1 -0
  251. package/src/engine/graphics/sh3/path_tracer/sampling/make_stratified_sample.js +21 -0
  252. package/src/engine/graphics/sh3/path_tracer/texture/SoftwareTextureCache.d.ts +3 -0
  253. package/src/engine/graphics/sh3/path_tracer/texture/SoftwareTextureCache.d.ts.map +1 -0
  254. package/src/engine/graphics/sh3/path_tracer/texture/SoftwareTextureCache.js +3 -0
  255. package/src/engine/graphics/sh3/path_tracer/texture/apply_texture_clamping_to_coordinate.d.ts.map +1 -0
  256. package/src/engine/graphics/sh3/path_tracer/{apply_texture_clamping_to_coordinate.js → texture/apply_texture_clamping_to_coordinate.js} +2 -2
  257. package/src/engine/graphics/sh3/path_tracer/texture/sample_material.d.ts +11 -0
  258. package/src/engine/graphics/sh3/path_tracer/texture/sample_material.d.ts.map +1 -0
  259. package/src/engine/graphics/sh3/path_tracer/texture/sample_material.js +86 -0
  260. package/src/engine/graphics/sh3/path_tracer/texture/sample_texture.d.ts +10 -0
  261. package/src/engine/graphics/sh3/path_tracer/texture/sample_texture.d.ts.map +1 -0
  262. package/src/engine/graphics/sh3/path_tracer/texture/sample_texture.js +55 -0
  263. package/src/engine/graphics/sh3/path_tracer/vec3_uint8_to_float.js +4 -4
  264. package/src/engine/graphics/sh3/prototypeSH3Probe.js +145 -185
  265. package/src/engine/graphics/sh3/sky/hosek/sky_hosek_compute_irradiance_by_direction.d.ts +5 -5
  266. package/src/engine/graphics/sh3/sky/hosek/sky_hosek_compute_irradiance_by_direction.d.ts.map +1 -1
  267. package/src/engine/graphics/sh3/sky/hosek/sky_hosek_compute_irradiance_by_direction.js +8 -8
  268. package/src/engine/graphics/sh3/visualise_spherical_harmonic_sphere.d.ts +13 -0
  269. package/src/engine/graphics/sh3/visualise_spherical_harmonic_sphere.d.ts.map +1 -0
  270. package/src/engine/graphics/sh3/visualise_spherical_harmonic_sphere.js +54 -0
  271. package/src/engine/graphics/texture/AttributeDataTexture.d.ts +2 -2
  272. package/src/engine/graphics/texture/AttributeDataTexture.d.ts.map +1 -1
  273. package/src/engine/graphics/texture/AttributeDataTexture.js +11 -11
  274. package/src/engine/graphics/texture/sampler/Sampler2D.d.ts.map +1 -1
  275. package/src/engine/graphics/texture/sampler/Sampler2D.js +2 -2
  276. package/src/engine/input/ecs/systems/InputControllerSystem.js +1 -1
  277. package/src/engine/network/convertPathToURL.d.ts +3 -1
  278. package/src/engine/network/convertPathToURL.d.ts.map +1 -1
  279. package/src/engine/network/convertPathToURL.js +68 -51
  280. package/src/engine/physics/fluid/SliceVisualiser.d.ts.map +1 -1
  281. package/src/engine/physics/fluid/SliceVisualiser.js +4 -4
  282. package/src/generation/filtering/numeric/CellFilterCache.d.ts.map +1 -1
  283. package/src/generation/filtering/numeric/CellFilterCache.js +1 -0
  284. package/src/view/elements/ColorPickerView.d.ts.map +1 -1
  285. package/src/view/elements/ColorPickerView.js +7 -7
  286. package/src/core/binary/float2uint8.d.ts +0 -7
  287. package/src/core/binary/float2uint8.d.ts.map +0 -1
  288. package/src/core/binary/uint82float.d.ts +0 -7
  289. package/src/core/binary/uint82float.d.ts.map +0 -1
  290. package/src/core/binary/uint82float.spec.d.ts +0 -2
  291. package/src/core/binary/uint82float.spec.d.ts.map +0 -1
  292. package/src/core/binary/uint82float.spec.js +0 -7
  293. package/src/core/collection/array/randomizeArrayElementOrder.d.ts +0 -8
  294. package/src/core/collection/array/randomizeArrayElementOrder.d.ts.map +0 -1
  295. package/src/core/collection/array/randomizeArrayElementOrder.js +0 -24
  296. package/src/core/collection/array/randomizeArrayElementOrder.spec.d.ts +0 -2
  297. package/src/core/collection/array/randomizeArrayElementOrder.spec.d.ts.map +0 -1
  298. package/src/core/geom/3d/tetrahedra/compute_circumsphere.d.ts.map +0 -1
  299. package/src/core/graph/coarsen_graph.d.ts.map +0 -1
  300. package/src/core/graph/coarsen_graph.spec.d.ts +0 -2
  301. package/src/core/graph/coarsen_graph.spec.d.ts.map +0 -1
  302. package/src/core/graph/graph_adjacency_matrix.d.ts +0 -9
  303. package/src/core/graph/graph_adjacency_matrix.d.ts.map +0 -1
  304. package/src/core/graph/graph_degree_matrix.d.ts +0 -9
  305. package/src/core/graph/graph_degree_matrix.d.ts.map +0 -1
  306. package/src/core/graph/graph_degree_matrix.js +0 -18
  307. package/src/core/graph/graph_laplacian_matrix.d.ts.map +0 -1
  308. package/src/core/math/physics/brdf/D_GGX.d.ts.map +0 -1
  309. package/src/engine/graphics/sh3/LightProbeVolume.d.ts.map +0 -1
  310. package/src/engine/graphics/sh3/LightProbeVolume.js +0 -609
  311. package/src/engine/graphics/sh3/path_tracer/apply_texture_clamping_to_coordinate.d.ts.map +0 -1
  312. package/src/engine/graphics/sh3/visualise_probe.d.ts +0 -12
  313. package/src/engine/graphics/sh3/visualise_probe.d.ts.map +0 -1
  314. package/src/engine/graphics/sh3/visualise_probe.js +0 -40
  315. /package/src/engine/graphics/sh3/path_tracer/{apply_texture_clamping_to_coordinate.d.ts → texture/apply_texture_clamping_to_coordinate.d.ts} +0 -0
@@ -11,9 +11,10 @@ import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
11
11
  import { PLYLoader } from "three/examples/jsm/loaders/PLYLoader.js";
12
12
 
13
13
  import '../../../../../../../../css/game.scss';
14
- import { float2uint8 } from "../../../../core/binary/float2uint8.js";
14
+ import { float_to_uint8 } from "../../../../core/binary/float_to_uint8.js";
15
15
  import { Color } from "../../../../core/color/Color.js";
16
16
  import { kelvin_to_rgb } from "../../../../core/color/kelvin/kelvin_to_rgb.js";
17
+ import { linear_to_sRGB } from "../../../../core/color/sRGB/linear_to_sRGB.js";
17
18
 
18
19
  import { noop } from "../../../../core/function/noop.js";
19
20
  import { ray3_array_compose } from "../../../../core/geom/3d/ray/ray3_array_compose.js";
@@ -38,6 +39,7 @@ import { DirectionalLight } from "../../render/forward_plus/model/DirectionalLig
38
39
  import { sampler2d_scale } from "../../texture/sampler/resize/sampler2d_scale.js";
39
40
  import { Sampler2D } from "../../texture/sampler/Sampler2D.js";
40
41
  import sampler2D2Canvas from "../../texture/sampler/Sampler2D2Canvas.js";
42
+ import { PathTracedScene } from "./PathTracedScene.js";
41
43
  import { PathTracer } from "./PathTracer.js";
42
44
 
43
45
  document.body.style.margin = 0;
@@ -73,43 +75,9 @@ vCanvas.css({
73
75
  */
74
76
  const PIXEL_SAMPLE_COUNT = 64;
75
77
 
78
+ const scene = new PathTracedScene();
76
79
  const pt = new PathTracer();
77
80
 
78
- const gltfLoader = new GLTFLoader();
79
- // const gltf_url = 'data/models/LowPolyTownshipSet/Town_Hall/model.gltf';
80
- // const gltf_url = 'data/models/road_bike/road_bike.gltf';
81
- // const gltf_url = 'data/models/sponza-pbr/gltf/sponza.glb';
82
- // const gltf_url = 'data/models/sibenik/model.gltf';
83
- // gltfLoader.load(gltf_url, (gltf) => {
84
- //
85
- // gltf.scene.updateMatrixWorld();
86
- //
87
- // gltf.scene.traverse(m => {
88
- //
89
- // if (m.isMesh) {
90
- //
91
- // pt.addMesh(
92
- // m.geometry,
93
- // m.material,
94
- // m.matrixWorld.elements
95
- // );
96
- //
97
- // }
98
- // });
99
- //
100
- // trace_image(vCanvas);
101
- // });
102
-
103
- //
104
- // pt.addMesh(
105
- // new TorusKnotBufferGeometry(1, 0.3, 128, 128),
106
- // new MeshStandardMaterial({ color: '#FF0000' }),
107
- // Transform.fromJSON({
108
- // scale: 0.5
109
- // }).matrix
110
- // );
111
- //
112
-
113
81
  function make_sun({
114
82
  temperature = 5000, // around clear-sky day
115
83
  color = '#FFFFFF',
@@ -193,20 +161,20 @@ function promise_gltf(url) {
193
161
 
194
162
  /**
195
163
  *
196
- * @param {PathTracer} pt
164
+ * @param {PathTracedScene} scene
197
165
  * @param {THREE.Camera} camera
198
166
  * @param {string} url
199
167
  * @param zoom
200
168
  * @return {Promise<void>}
201
169
  */
202
- async function prepare_scene_gltf(pt, camera, url, zoom = 1) {
170
+ async function prepare_scene_gltf(scene, camera, url, zoom = 1) {
203
171
  const gltf = await promise_gltf(url);
204
172
 
205
173
 
206
174
  const ground_material = new MeshStandardMaterial({
207
175
  color: '#ffceae'
208
176
  });
209
- pt.addMesh(new PlaneBufferGeometry(), ground_material, Transform.fromJSON({
177
+ scene.addMesh(new PlaneBufferGeometry(), ground_material, Transform.fromJSON({
210
178
  position: new Vector3(0, 0, 0),
211
179
  scale: 5000,
212
180
  rotation: Quaternion.fromEulerAngles(-Math.PI / 2, 0, 0)
@@ -217,7 +185,7 @@ async function prepare_scene_gltf(pt, camera, url, zoom = 1) {
217
185
 
218
186
  gltf.scene.traverse((m) => {
219
187
  if (m.isMesh) {
220
- pt.addMesh(m.geometry, m.material, m.matrixWorld.elements);
188
+ scene.addMesh(m.geometry, m.material, m.matrixWorld.elements);
221
189
  }
222
190
  });
223
191
 
@@ -228,7 +196,7 @@ async function prepare_scene_gltf(pt, camera, url, zoom = 1) {
228
196
 
229
197
  box3.getBoundingSphere(sphere);
230
198
 
231
- pt.addLight(make_sun());
199
+ scene.addLight(make_sun());
232
200
 
233
201
  camera.position.set(1, 1.3, 1)
234
202
  .normalize()
@@ -239,11 +207,11 @@ async function prepare_scene_gltf(pt, camera, url, zoom = 1) {
239
207
 
240
208
  /**
241
209
  *
242
- * @param {PathTracer} pt
210
+ * @param {PathTracedScene} scene
243
211
  * @param {THREE.Camera} camera
244
212
  * @return {Promise<void>}
245
213
  */
246
- async function prepare_scene_lucy(pt, camera) {
214
+ async function prepare_scene_lucy(scene, camera) {
247
215
 
248
216
 
249
217
  const lucy_geom = await promise_ply("data/models/stanford/Lucy100k.ply")
@@ -251,7 +219,7 @@ async function prepare_scene_lucy(pt, camera) {
251
219
  const lucy_material = new MeshStandardMaterial({
252
220
  color: '#95c9ff'
253
221
  });
254
- pt.addMesh(lucy_geom, lucy_material, Transform.fromJSON({
222
+ scene.addMesh(lucy_geom, lucy_material, Transform.fromJSON({
255
223
  position: new Vector3(0, 0, 0),
256
224
  scale: 1,
257
225
  // rotation: Quaternion.fromEulerAngles(-Math.PI / 2, 0, 0)
@@ -260,14 +228,14 @@ async function prepare_scene_lucy(pt, camera) {
260
228
  const ground_material = new MeshStandardMaterial({
261
229
  color: '#ffceae'
262
230
  });
263
- pt.addMesh(new PlaneBufferGeometry(), ground_material, Transform.fromJSON({
231
+ scene.addMesh(new PlaneBufferGeometry(), ground_material, Transform.fromJSON({
264
232
  position: new Vector3(0, -800, 0),
265
233
  scale: 5000,
266
234
  rotation: Quaternion.fromEulerAngles(-Math.PI / 2, 0, 0)
267
235
  }).matrix);
268
236
 
269
237
 
270
- pt.addLight(make_sun());
238
+ scene.addLight(make_sun());
271
239
 
272
240
  camera.position.set(0, 0, -2300);
273
241
  camera.lookAt(0, 0, 0);
@@ -287,7 +255,7 @@ async function prepare_scene_rtiow(pt, camera) {
287
255
  const ground_material = new MeshStandardMaterial({
288
256
  color: '#ffffff'
289
257
  });
290
- pt.addMesh(new PlaneBufferGeometry(), ground_material, Transform.fromJSON({
258
+ scene.addMesh(new PlaneBufferGeometry(), ground_material, Transform.fromJSON({
291
259
  position: new Vector3(0, 0, 0),
292
260
  scale: 50,
293
261
  rotation: Quaternion.fromEulerAngles(-Math.PI / 2, 0, 0)
@@ -314,7 +282,7 @@ async function prepare_scene_rtiow(pt, camera) {
314
282
  const mat = new Float32Array(16);
315
283
  mat4.fromRotationTranslationScale(mat, [0, 0, 0, 1], center, [radius, radius, radius])
316
284
 
317
- pt.addMesh(sphere_geo, material, mat);
285
+ scene.addMesh(sphere_geo, material, mat);
318
286
 
319
287
  spheres.push([
320
288
  center[0],
@@ -379,7 +347,7 @@ async function prepare_scene_rtiow(pt, camera) {
379
347
  }
380
348
 
381
349
 
382
- pt.addLight(make_sun());
350
+ scene.addLight(make_sun());
383
351
 
384
352
  camera.position.set(13, 2, 3);
385
353
  camera.lookAt(0, 0, 0);
@@ -392,9 +360,10 @@ async function prepare_scene_rtiow(pt, camera) {
392
360
  * @param {Sampler2D} target
393
361
  * @param {PathTracer} pt
394
362
  * @param {Camera} camera
363
+ * @param {PathTracedScene} scene
395
364
  * @param {{current:number, total:number}} progress
396
365
  */
397
- function* render(target, pt, camera, progress = { current: 0, total: 0 }) {
366
+ function* render(target, pt, camera, scene, progress = { current: 0, total: 0 }) {
398
367
  const random = seededRandom(0);
399
368
 
400
369
  // update camera
@@ -460,7 +429,8 @@ function* render(target, pt, camera, progress = { current: 0, total: 0 }) {
460
429
 
461
430
  const pixel_address = ((max_y - y) * width + x) * 4;
462
431
 
463
- target.data[pixel_address + 3] = 255;
432
+ const output_data = target.data;
433
+ output_data[pixel_address + 3] = 255;
464
434
 
465
435
  for (let i = 0; i < pixel_sample_count; i++) {
466
436
 
@@ -476,7 +446,7 @@ function* render(target, pt, camera, progress = { current: 0, total: 0 }) {
476
446
  ray_direction.x, ray_direction.y, ray_direction.z
477
447
  );
478
448
 
479
- pt.path_trace(pixel_color, ray, Infinity, 3, random);
449
+ pt.path_trace(pixel_color, ray, Infinity, 3, 7, random, scene);
480
450
 
481
451
  pixel_accummulation[0] += pixel_color[0];
482
452
  pixel_accummulation[1] += pixel_color[1];
@@ -486,9 +456,15 @@ function* render(target, pt, camera, progress = { current: 0, total: 0 }) {
486
456
  sample_count++;
487
457
  }
488
458
 
489
- target.data[pixel_address] = float2uint8(pixel_accummulation[0] / pixel_sample_count);
490
- target.data[pixel_address + 1] = float2uint8(pixel_accummulation[1] / pixel_sample_count);
491
- target.data[pixel_address + 2] = float2uint8(pixel_accummulation[2] / pixel_sample_count);
459
+ pixel_accummulation[0] /= pixel_sample_count
460
+ pixel_accummulation[1] /= pixel_sample_count
461
+ pixel_accummulation[2] /= pixel_sample_count
462
+
463
+ linear_to_sRGB(pixel_accummulation, 0, pixel_accummulation, 0);
464
+
465
+ output_data[pixel_address] = float_to_uint8(pixel_accummulation[0]);
466
+ output_data[pixel_address + 1] = float_to_uint8(pixel_accummulation[1]);
467
+ output_data[pixel_address + 2] = float_to_uint8(pixel_accummulation[2]);
492
468
 
493
469
 
494
470
  progress.current++;
@@ -528,12 +504,12 @@ async function start_renderer(camera) {
528
504
  const path = 'data/models/pica_pica/pica_pica.gltf';
529
505
  // const path = 'data/models/road_bike/road_bike.gltf'; //large CAD-type model
530
506
 
531
- // await prepare_scene_lucy(pt, camera);
507
+ // await prepare_scene_lucy(scene, camera);
532
508
  // await prepare_scene_rtiow(pt, camera);
533
509
  // await prepare_scene_sphere_01(pt, camera);
534
- await prepare_scene_gltf(pt, camera, path);
510
+ await prepare_scene_gltf(scene, camera, path);
535
511
 
536
- await pt.build();
512
+ await scene.build();
537
513
  // pt.optimize();
538
514
 
539
515
  const pixelRatio = 1;
@@ -548,7 +524,7 @@ async function start_renderer(camera) {
548
524
  function make_render_task() {
549
525
  const progress_v = { current: 0, total: 0 };
550
526
 
551
- const it = render(scaled_rt, pt, camera, progress_v);
527
+ const it = render(scaled_rt, pt, camera, scene, progress_v);
552
528
 
553
529
  return new Task({
554
530
  name: 'render',
@@ -577,9 +553,9 @@ async function start_renderer(camera) {
577
553
  const t = make_render_task();
578
554
 
579
555
 
580
- const vProgress =makeSimpleTaskProgressView({
556
+ const vProgress = makeSimpleTaskProgressView({
581
557
  task: t,
582
- size:vContainer.size,
558
+ size: vContainer.size,
583
559
  localization: loc
584
560
  })
585
561
 
@@ -632,7 +608,7 @@ vCanvas.el.addEventListener(MouseEvents.Click, (evt) => {
632
608
 
633
609
  const out = [];
634
610
 
635
- pt.trace(out, ray, 0, Infinity);
611
+ scene.trace(out, ray, 0, Infinity);
636
612
 
637
613
  console.log(pointer, out, ray, pt);
638
614
 
@@ -1 +1 @@
1
- {"version":3,"file":"random_in_hemisphere.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/random_in_hemisphere.js"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,+DALW,MAAM,EAAE,iBACR,MAAM,UACN,MAAM,EAAE,iBACR,MAAM,QA8BhB"}
1
+ {"version":3,"file":"random_in_hemisphere.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/random_in_hemisphere.js"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,+DALW,MAAM,EAAE,iBACR,MAAM,UACN,MAAM,EAAE,iBACR,MAAM,QAoChB"}
@@ -8,7 +8,13 @@ import { v3_dot } from "../../../../core/geom/vec3/v3_dot.js";
8
8
  * @param {number[]} normal
9
9
  * @param {number} normal_offset
10
10
  */
11
- export function random_in_hemisphere(random, result, result_offset, normal, normal_offset) {
11
+ export function random_in_hemisphere(
12
+ random,
13
+ result,
14
+ result_offset,
15
+ normal,
16
+ normal_offset
17
+ ) {
12
18
  const nx = normal[normal_offset + 0];
13
19
  const ny = normal[normal_offset + 1];
14
20
  const nz = normal[normal_offset + 2];
@@ -5,10 +5,10 @@
5
5
  * @param {number} a vertex index 0
6
6
  * @param {number} b vertex index 0
7
7
  * @param {number} c vertex index 0
8
- * @param {number[]} attribute_array
8
+ * @param {number[]|ArrayLike<number>|Float32Array} attribute_array
9
9
  * @param {number} dimensions
10
10
  * @param {number} u Barycentric coordinate
11
11
  * @param {number} v Barycentric coordinate
12
12
  */
13
- export function sample_triangle_attribute(out: number[], out_offset: number, a: number, b: number, c: number, attribute_array: number[], dimensions: number, u: number, v: number): void;
13
+ export function sample_triangle_attribute(out: number[], out_offset: number, a: number, b: number, c: number, attribute_array: number[] | ArrayLike<number> | Float32Array, dimensions: number, u: number, v: number): void;
14
14
  //# sourceMappingURL=sample_triangle_attribute.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sample_triangle_attribute.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/sample_triangle_attribute.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,+CAVW,MAAM,EAAE,cACR,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,mBACN,MAAM,EAAE,cACR,MAAM,KACN,MAAM,KACN,MAAM,QAwBhB"}
1
+ {"version":3,"file":"sample_triangle_attribute.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/sample_triangle_attribute.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,+CAVW,MAAM,EAAE,cACR,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,mBACN,MAAM,EAAE,GAAC,UAAU,MAAM,CAAC,GAAC,YAAY,cACvC,MAAM,KACN,MAAM,KACN,MAAM,QAwBhB"}
@@ -5,7 +5,7 @@
5
5
  * @param {number} a vertex index 0
6
6
  * @param {number} b vertex index 0
7
7
  * @param {number} c vertex index 0
8
- * @param {number[]} attribute_array
8
+ * @param {number[]|ArrayLike<number>|Float32Array} attribute_array
9
9
  * @param {number} dimensions
10
10
  * @param {number} u Barycentric coordinate
11
11
  * @param {number} v Barycentric coordinate
@@ -0,0 +1,10 @@
1
+ /**
2
+ *
3
+ * @param {number[]} result
4
+ * @param {number} result_offset
5
+ * @param {number} result_stride
6
+ * @param {number} num_samples
7
+ * @param {function():number} random
8
+ */
9
+ export function generate_stratified_samples(result: number[], result_offset: number, result_stride: number, num_samples: number, random: () => number): void;
10
+ //# sourceMappingURL=generate_stratified_samples.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate_stratified_samples.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples.js"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,oDANW,MAAM,EAAE,iBACR,MAAM,iBACN,MAAM,eACN,MAAM,gBACK,MAAM,QAW3B"}
@@ -0,0 +1,20 @@
1
+ import { make_stratified_sample } from "./make_stratified_sample.js";
2
+
3
+ /**
4
+ *
5
+ * @param {number[]} result
6
+ * @param {number} result_offset
7
+ * @param {number} result_stride
8
+ * @param {number} num_samples
9
+ * @param {function():number} random
10
+ */
11
+ export function generate_stratified_samples(result, result_offset, result_stride, num_samples, random) {
12
+
13
+ const delta = 1 / num_samples;
14
+
15
+ for (let i = 0; i < num_samples; ++i) {
16
+
17
+ result[result_offset + i * result_stride] = make_stratified_sample(i, delta, random);
18
+ }
19
+
20
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Based on https://github.com/TheRealMJP/DXRPathTracer/blob/e01b893c76ad629fa6e715d35b98901f5195d000/SampleFramework12/v1.02/Graphics/Sampling.cpp#L440
3
+ * @param {number[]} result
4
+ * @param {number} result_offset
5
+ * @param {number} num_samples_x
6
+ * @param {number} num_samples_y
7
+ * @param {function():number} random
8
+ */
9
+ export function generate_stratified_samples_2d(result: number[], result_offset: number, num_samples_x: number, num_samples_y: number, random: () => number): number;
10
+ //# sourceMappingURL=generate_stratified_samples_2d.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate_stratified_samples_2d.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples_2d.js"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,uDANW,MAAM,EAAE,iBACR,MAAM,iBACN,MAAM,iBACN,MAAM,gBACK,MAAM,UAqB3B"}
@@ -0,0 +1,31 @@
1
+ import { make_stratified_sample } from "./make_stratified_sample.js";
2
+
3
+ /**
4
+ * Based on https://github.com/TheRealMJP/DXRPathTracer/blob/e01b893c76ad629fa6e715d35b98901f5195d000/SampleFramework12/v1.02/Graphics/Sampling.cpp#L440
5
+ * @param {number[]} result
6
+ * @param {number} result_offset
7
+ * @param {number} num_samples_x
8
+ * @param {number} num_samples_y
9
+ * @param {function():number} random
10
+ */
11
+ export function generate_stratified_samples_2d(result, result_offset, num_samples_x, num_samples_y, random) {
12
+
13
+ const delta_x = 1 / num_samples_x;
14
+ const delta_y = 1 / num_samples_y;
15
+
16
+ let sample_index = 0;
17
+ for (let y = 0; y < num_samples_y; y++) {
18
+ for (let x = 0; x < num_samples_x; x++) {
19
+
20
+ const address = result_offset + sample_index * 2;
21
+
22
+ result[address] = make_stratified_sample(x, delta_x, random);
23
+ result[address + 1] = make_stratified_sample(y, delta_y, random);
24
+
25
+ ++sample_index;
26
+ }
27
+ }
28
+
29
+ return sample_index;
30
+ }
31
+
@@ -0,0 +1,9 @@
1
+ /**
2
+ *
3
+ * @param {number} index
4
+ * @param {number} delta
5
+ * @param {function} random
6
+ * @return {number}
7
+ */
8
+ export function make_stratified_sample(index: number, delta: number, random: Function): number;
9
+ //# sourceMappingURL=make_stratified_sample.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"make_stratified_sample.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/path_tracer/sampling/make_stratified_sample.js"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,8CALW,MAAM,SACN,MAAM,qBAEL,MAAM,CAWjB"}
@@ -0,0 +1,21 @@
1
+ import { clamp } from "../../../../../core/math/clamp.js";
2
+
3
+ const ONE_MINUS_EPSILON = 0.999999;
4
+
5
+ /**
6
+ *
7
+ * @param {number} index
8
+ * @param {number} delta
9
+ * @param {function} random
10
+ * @return {number}
11
+ */
12
+ export function make_stratified_sample(index, delta, random) {
13
+
14
+ let sample = index + random();
15
+
16
+ sample *= delta;
17
+
18
+ sample = clamp(sample, 0, ONE_MINUS_EPSILON);
19
+
20
+ return sample;
21
+ }
@@ -0,0 +1,3 @@
1
+ export class SoftwareTextureCache {
2
+ }
3
+ //# sourceMappingURL=SoftwareTextureCache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SoftwareTextureCache.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/path_tracer/texture/SoftwareTextureCache.js"],"names":[],"mappings":"AAAA;CAEC"}
@@ -0,0 +1,3 @@
1
+ export class SoftwareTextureCache{
2
+
3
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply_texture_clamping_to_coordinate.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/path_tracer/texture/apply_texture_clamping_to_coordinate.js"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,+DAJW,MAAM,KACN,MAAM,GACL,MAAM,CAcjB"}
@@ -1,5 +1,5 @@
1
1
  import { ClampToEdgeWrapping, RepeatWrapping } from "three";
2
- import { clamp01 } from "../../../../core/math/clamp01.js";
2
+ import { clamp01 } from "../../../../../core/math/clamp01.js";
3
3
 
4
4
  /**
5
5
  *
@@ -10,7 +10,7 @@ import { clamp01 } from "../../../../core/math/clamp01.js";
10
10
  export function apply_texture_clamping_to_coordinate(clamping, v) {
11
11
 
12
12
  switch (clamping) {
13
- case RepeatWrapping:
13
+ case RepeatWrapping:
14
14
  return v % 1;
15
15
  case ClampToEdgeWrapping:
16
16
  return clamp01(v);
@@ -0,0 +1,11 @@
1
+ /**
2
+ *
3
+ * @param {number[]} out
4
+ * @param {PathTracedMesh} mesh
5
+ * @param {Map<number, Sampler2D>} textures
6
+ * @param {number} primitive_id
7
+ * @param {number} u
8
+ * @param {number} v
9
+ */
10
+ export function sample_material(out: number[], mesh: PathTracedMesh, textures: Map<number, Sampler2D>, primitive_id: number, u: number, v: number): void;
11
+ //# sourceMappingURL=sample_material.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sample_material.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/path_tracer/texture/sample_material.js"],"names":[],"mappings":"AASA;;;;;;;;GAQG;AACH,qCAPW,MAAM,EAAE,kCAER,IAAI,MAAM,YAAY,gBACtB,MAAM,KACN,MAAM,KACN,MAAM,QAqEhB"}
@@ -0,0 +1,86 @@
1
+ import { vec3 } from "gl-matrix";
2
+ import { array_copy } from "../../../../../core/collection/array/array_copy.js";
3
+ import { transform_normal_m4 } from "../ray_hit_apply_transform.js";
4
+ import { sample_triangle_attribute } from "../sample_triangle_attribute.js";
5
+ import { sample_texture } from "./sample_texture.js";
6
+
7
+ const texture_uv = [0, 0];
8
+ const color = [1, 1, 1];
9
+
10
+ /**
11
+ *
12
+ * @param {number[]} out
13
+ * @param {PathTracedMesh} mesh
14
+ * @param {Map<number, Sampler2D>} textures
15
+ * @param {number} primitive_id
16
+ * @param {number} u
17
+ * @param {number} v
18
+ */
19
+ export function sample_material(
20
+ out,
21
+ mesh, textures,
22
+ primitive_id,
23
+ u, v
24
+ ) {
25
+
26
+ const geometry = mesh.geometry;
27
+ const index_attribute = geometry.getIndex();
28
+ const index_array = index_attribute.array;
29
+
30
+
31
+ // sample surface normal
32
+ const index_offset = primitive_id * 3;
33
+
34
+ const index_0 = index_array[index_offset];
35
+ const index_1 = index_array[index_offset + 1];
36
+ const index_2 = index_array[index_offset + 2];
37
+
38
+ const normal_attribute = geometry.getAttribute('normal');
39
+
40
+ if (normal_attribute !== undefined) {
41
+ // vertex normals are present, use those
42
+ const normal_array = normal_attribute.array;
43
+
44
+ sample_triangle_attribute(out, 3, index_0, index_1, index_2, normal_array, 3, u, v);
45
+
46
+ // apply transform
47
+ transform_normal_m4(out, 3, out, 3, mesh.transform);
48
+ } else {
49
+ // copy hit normal
50
+ array_copy(hit, 3, out, 3, 3);
51
+ }
52
+
53
+
54
+ const uv_attribute = geometry.getAttribute('uv');
55
+
56
+ if (uv_attribute !== undefined) {
57
+ const uv_array = uv_attribute.array;
58
+ sample_triangle_attribute(texture_uv, 0, index_0, index_1, index_2, uv_array, 2, u, v);
59
+ } else {
60
+ // default texture uv
61
+ texture_uv[0] = 0;
62
+ texture_uv[1] = 0;
63
+ }
64
+
65
+ const material = mesh.material;
66
+
67
+ if (material.isMeshStandardMaterial || material.isMeshBasicMaterial) {
68
+ const material_color = material.color;
69
+
70
+ out[0] *= material_color.r;
71
+ out[1] *= material_color.g;
72
+ out[2] *= material_color.b;
73
+
74
+ const diffuse_map = material.map;
75
+
76
+ if (diffuse_map !== null) {
77
+ const sampler2D = textures.get(diffuse_map.id);
78
+
79
+ sample_texture(color, sampler2D, diffuse_map, texture_uv[0], texture_uv[1]);
80
+
81
+ vec3.multiply(out, out, color);
82
+ }
83
+ } else {
84
+ // unsupported
85
+ }
86
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ *
3
+ * @param {number[]|Float32Array} out
4
+ * @param {Sampler2D} sampler
5
+ * @param {Texture} texture
6
+ * @param {number} u
7
+ * @param {number} v
8
+ */
9
+ export function sample_texture(out: number[] | Float32Array, sampler: Sampler2D, texture: Texture, u: number, v: number): void;
10
+ //# sourceMappingURL=sample_texture.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sample_texture.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/path_tracer/texture/sample_texture.js"],"names":[],"mappings":"AAYA;;;;;;;GAOG;AACH,oCANW,MAAM,EAAE,GAAC,YAAY,2CAGrB,MAAM,KACN,MAAM,QAoChB"}
@@ -0,0 +1,55 @@
1
+ import {
2
+ LinearEncoding,
3
+ LinearFilter,
4
+ LinearMipmapLinearFilter,
5
+ NearestFilter,
6
+ NearestMipMapLinearFilter,
7
+ sRGBEncoding,
8
+ UnsignedByteType
9
+ } from "three";
10
+ import { vec3_uint8_to_float } from "../vec3_uint8_to_float.js";
11
+ import { apply_texture_clamping_to_coordinate } from "./apply_texture_clamping_to_coordinate.js";
12
+
13
+ /**
14
+ *
15
+ * @param {number[]|Float32Array} out
16
+ * @param {Sampler2D} sampler
17
+ * @param {Texture} texture
18
+ * @param {number} u
19
+ * @param {number} v
20
+ */
21
+ export function sample_texture(out, sampler, texture, u, v) {
22
+ // TODO apply texture matrix transform
23
+
24
+ const _u = apply_texture_clamping_to_coordinate(texture.wrapS, u);
25
+ const _v = apply_texture_clamping_to_coordinate(texture.wrapT, v);
26
+
27
+ const magFilter = texture.magFilter;
28
+
29
+ switch (magFilter) {
30
+ default:
31
+ case NearestFilter:
32
+ case NearestMipMapLinearFilter:
33
+ sampler.sampleNearestUV(_u, _v, out);
34
+ break;
35
+
36
+ case LinearFilter:
37
+ case LinearMipmapLinearFilter:
38
+
39
+ sampler.sampleBilinearUV(_u, _v, out);
40
+ break;
41
+ }
42
+
43
+ if (texture.type === UnsignedByteType) {
44
+ vec3_uint8_to_float(out, out);
45
+ }
46
+
47
+ const texture_encoding = texture.encoding;
48
+
49
+ if (texture_encoding === LinearEncoding) {
50
+ // nothing
51
+ } else if (texture_encoding === sRGBEncoding) {
52
+ // convert value to linear space
53
+ // sRGB_to_linear(out, 0, out, 0);
54
+ }
55
+ }
@@ -1,4 +1,4 @@
1
- import { uint82float } from "../../../../core/binary/uint82float.js";
1
+ import { uint8_to_float } from "../../../../core/binary/uint8_to_float.js";
2
2
 
3
3
  /**
4
4
  *
@@ -6,7 +6,7 @@ import { uint82float } from "../../../../core/binary/uint82float.js";
6
6
  * @param {number[]} input
7
7
  */
8
8
  export function vec3_uint8_to_float(out, input) {
9
- out[0] = uint82float(input[0]);
10
- out[1] = uint82float(input[1]);
11
- out[2] = uint82float(input[2]);
9
+ out[0] = uint8_to_float(input[0]);
10
+ out[1] = uint8_to_float(input[1]);
11
+ out[2] = uint8_to_float(input[2]);
12
12
  }