@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.
- package/build/bundle-worker-image-decoder.js +1 -1
- package/build/meep.cjs +255 -172
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +255 -173
- package/editor/tools/paint/TerrainHeightPaintTool.js +5 -5
- package/package.json +1 -1
- package/src/core/binary/float_to_uint8.d.ts +7 -0
- package/src/core/binary/float_to_uint8.d.ts.map +1 -0
- package/src/core/binary/{float2uint8.js → float_to_uint8.js} +1 -1
- package/src/core/binary/int32_to_binary_string.d.ts +3 -2
- package/src/core/binary/int32_to_binary_string.d.ts.map +1 -1
- package/src/core/binary/int32_to_binary_string.js +18 -14
- package/src/core/binary/split_by_3.spec.d.ts +2 -0
- package/src/core/binary/split_by_3.spec.d.ts.map +1 -0
- package/src/core/binary/split_by_3.spec.js +22 -0
- package/src/core/binary/to_half_float_uint16.d.ts.map +1 -1
- package/src/core/binary/to_half_float_uint16.js +7 -5
- package/src/core/binary/uint8_to_float.d.ts +7 -0
- package/src/core/binary/uint8_to_float.d.ts.map +1 -0
- package/src/core/binary/{uint82float.js → uint8_to_float.js} +1 -1
- package/src/core/binary/uint8_to_float.spec.d.ts +2 -0
- package/src/core/binary/uint8_to_float.spec.d.ts.map +1 -0
- package/src/core/binary/uint8_to_float.spec.js +7 -0
- package/src/core/codegen/codeToBlob.d.ts +8 -0
- package/src/core/codegen/codeToBlob.d.ts.map +1 -0
- package/src/core/codegen/codeToBlob.js +36 -0
- package/src/core/codegen/codeToURL.d.ts +8 -0
- package/src/core/codegen/codeToURL.d.ts.map +1 -0
- package/src/core/codegen/codeToURL.js +22 -0
- package/src/core/collection/array/array_shuffle.d.ts +8 -0
- package/src/core/collection/array/array_shuffle.d.ts.map +1 -0
- package/src/core/collection/array/array_shuffle.js +22 -0
- package/src/core/collection/array/array_shuffle.spec.d.ts +2 -0
- package/src/core/collection/array/array_shuffle.spec.d.ts.map +1 -0
- package/src/core/collection/array/{randomizeArrayElementOrder.spec.js → array_shuffle.spec.js} +4 -4
- package/src/core/collection/array/isArrayEqualStrict.d.ts.map +1 -1
- package/src/core/collection/array/isArrayEqualStrict.js +2 -2
- package/src/core/collection/array/iterator/ArrayIteratorRandom.js +2 -2
- package/src/core/collection/array/randomMultipleFromArray.js +2 -2
- package/src/core/color/Color.d.ts.map +1 -1
- package/src/core/color/Color.js +16 -11
- package/src/core/color/hsv/hsv2rgb.js +4 -4
- package/src/core/color/hsv/rgb2hsv.d.ts +3 -3
- package/src/core/color/hsv/rgb2hsv.d.ts.map +1 -1
- package/src/core/color/hsv/rgb2hsv.js +11 -18
- package/src/core/color/rgb2uint24.js +4 -4
- package/src/core/color/rgb_to_luminance.d.ts +9 -0
- package/src/core/color/rgb_to_luminance.d.ts.map +1 -0
- package/src/core/color/rgb_to_luminance.js +10 -0
- package/src/core/color/sRGB/linear_to_sRGB.d.ts +1 -0
- package/src/core/color/sRGB/linear_to_sRGB.d.ts.map +1 -1
- package/src/core/color/sRGB/linear_to_sRGB.js +4 -4
- package/src/core/geom/3d/aabb/AABB3.d.ts.map +1 -1
- package/src/core/geom/3d/aabb/AABB3.js +4 -1
- package/src/core/geom/3d/aabb/aabb3_intersects_ray.js +3 -3
- package/src/core/geom/3d/shape/UnitSphereShape3D.d.ts.map +1 -1
- package/src/core/geom/3d/shape/UnitSphereShape3D.js +14 -14
- package/src/core/geom/3d/sphere/harmonics/README.md +16 -2
- package/src/core/geom/3d/sphere/harmonics/SH3_COEFFICIENTS.d.ts +6 -0
- package/src/core/geom/3d/sphere/harmonics/SH3_COEFFICIENTS.d.ts.map +1 -0
- package/src/core/geom/3d/sphere/harmonics/SH3_COEFFICIENTS.js +17 -0
- package/src/core/geom/3d/sphere/harmonics/sh3_basis_at.d.ts.map +1 -1
- package/src/core/geom/3d/sphere/harmonics/sh3_basis_at.js +21 -9
- package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.d.ts +3 -3
- package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.d.ts.map +1 -1
- package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.js +35 -206
- package/src/core/geom/3d/sphere/harmonics/sh3_rotate.d.ts +8 -0
- package/src/core/geom/3d/sphere/harmonics/sh3_rotate.d.ts.map +1 -0
- package/src/core/geom/3d/sphere/harmonics/sh3_rotate.js +29 -0
- package/src/core/geom/3d/sphere/harmonics/sh3_sample_by_direction.js +10 -10
- package/src/core/geom/3d/sphere/harmonics/sh_index.d.ts +8 -0
- package/src/core/geom/3d/sphere/harmonics/sh_index.d.ts.map +1 -0
- package/src/core/geom/3d/sphere/harmonics/sh_index.js +9 -0
- package/src/core/geom/3d/sphere/harmonics/sh_rotate_band1.d.ts +8 -0
- package/src/core/geom/3d/sphere/harmonics/sh_rotate_band1.d.ts.map +1 -0
- package/src/core/geom/3d/sphere/harmonics/sh_rotate_band1.js +44 -0
- package/src/core/geom/3d/sphere/harmonics/sh_rotate_band2.d.ts +8 -0
- package/src/core/geom/3d/sphere/harmonics/sh_rotate_band2.d.ts.map +1 -0
- package/src/core/geom/3d/sphere/harmonics/sh_rotate_band2.js +86 -0
- package/src/core/geom/3d/sphere/in_sphere3d_robust.d.ts.map +1 -1
- package/src/core/geom/3d/sphere/in_sphere3d_robust.js +2 -1
- package/src/core/geom/3d/tetrahedra/TetrahedralMesh.d.ts +20 -1
- package/src/core/geom/3d/tetrahedra/TetrahedralMesh.d.ts.map +1 -1
- package/src/core/geom/3d/tetrahedra/TetrahedralMesh.js +53 -7
- package/src/core/geom/3d/tetrahedra/TetrahedralMesh.spec.js +2 -2
- package/src/core/geom/3d/tetrahedra/build_tetrahedral_mesh_buffer_geometry.d.ts +1 -1
- package/src/core/geom/3d/tetrahedra/build_tetrahedral_mesh_buffer_geometry.d.ts.map +1 -1
- package/src/core/geom/3d/tetrahedra/build_tetrahedral_mesh_buffer_geometry.js +12 -7
- package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_build_from_grid.d.ts +13 -0
- package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_build_from_grid.d.ts.map +1 -0
- package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_build_from_grid.js +135 -0
- package/src/core/geom/3d/tetrahedra/prototypeTetrahedraBuilder.js +38 -24
- package/src/core/geom/3d/tetrahedra/{compute_circumsphere.d.ts → tetrahedron_compute_circumsphere.d.ts} +3 -5
- package/src/core/geom/3d/tetrahedra/tetrahedron_compute_circumsphere.d.ts.map +1 -0
- package/src/core/geom/3d/tetrahedra/{compute_circumsphere.js → tetrahedron_compute_circumsphere.js} +2 -4
- package/src/core/geom/3d/tetrahedra/tetrahedron_compute_signed_volume.d.ts.map +1 -1
- package/src/core/geom/3d/tetrahedra/tetrahedron_compute_signed_volume.js +3 -1
- package/src/core/geom/Vector3.d.ts.map +1 -1
- package/src/core/geom/Vector3.js +4 -3
- package/src/core/geom/mat3/m3_multiply_vec3.d.ts +8 -0
- package/src/core/geom/mat3/m3_multiply_vec3.d.ts.map +1 -0
- package/src/core/geom/mat3/m3_multiply_vec3.js +21 -0
- package/src/core/geom/random/randomPointInSphere.d.ts +1 -1
- package/src/core/geom/random/randomPointInSphere.js +2 -2
- package/src/core/geom/random/randomPointOnSphere.d.ts +3 -3
- package/src/core/geom/random/randomPointOnSphere.d.ts.map +1 -1
- package/src/core/geom/random/randomPointOnSphere.js +5 -9
- package/src/core/geom/vec2/v2_cross_product.d.ts +15 -0
- package/src/core/geom/vec2/v2_cross_product.d.ts.map +1 -0
- package/src/core/geom/vec2/v2_cross_product.js +21 -0
- package/src/core/geom/vec3/v3_slerp.d.ts +1 -0
- package/src/core/geom/vec3/v3_slerp.d.ts.map +1 -1
- package/src/core/geom/vec3/v3_slerp.js +1 -0
- package/src/core/graph/MultiNode.d.ts +1 -1
- package/src/core/graph/MultiNode.js +1 -1
- package/src/core/graph/WeightedEdge.d.ts +6 -4
- package/src/core/graph/WeightedEdge.d.ts.map +1 -1
- package/src/core/graph/WeightedEdge.js +3 -0
- package/src/core/graph/coloring/colorizeGraph.js +19 -19
- package/src/core/graph/convert_graph_to_dot_string.d.ts +1 -1
- package/src/core/graph/convert_graph_to_dot_string.d.ts.map +1 -1
- package/src/core/graph/convert_graph_to_dot_string.js +10 -6
- package/src/core/graph/graph_compute_adjacency_matrix.d.ts +9 -0
- package/src/core/graph/graph_compute_adjacency_matrix.d.ts.map +1 -0
- package/src/core/graph/{graph_adjacency_matrix.js → graph_compute_adjacency_matrix.js} +1 -2
- package/src/core/graph/graph_compute_degree_matrix.d.ts +10 -0
- package/src/core/graph/graph_compute_degree_matrix.d.ts.map +1 -0
- package/src/core/graph/graph_compute_degree_matrix.js +23 -0
- package/src/core/graph/graph_compute_distance_matrix.d.ts +13 -0
- package/src/core/graph/graph_compute_distance_matrix.d.ts.map +1 -0
- package/src/core/graph/graph_compute_distance_matrix.js +103 -0
- package/src/core/graph/{graph_laplacian_matrix.d.ts → graph_compute_laplacian_matrix.d.ts} +2 -2
- package/src/core/graph/graph_compute_laplacian_matrix.d.ts.map +1 -0
- package/src/core/graph/{graph_laplacian_matrix.js → graph_compute_laplacian_matrix.js} +6 -6
- package/src/core/graph/graph_k_means_cluster.d.ts.map +1 -1
- package/src/core/graph/graph_k_means_cluster.js +4 -119
- package/src/core/graph/{coarsen_graph.d.ts → mn_graph_coarsen.d.ts} +2 -2
- package/src/core/graph/mn_graph_coarsen.d.ts.map +1 -0
- package/src/core/graph/{coarsen_graph.js → mn_graph_coarsen.js} +1 -1
- package/src/core/graph/mn_graph_coarsen.spec.d.ts +2 -0
- package/src/core/graph/mn_graph_coarsen.spec.d.ts.map +1 -0
- package/src/core/graph/{coarsen_graph.spec.js → mn_graph_coarsen.spec.js} +4 -4
- package/src/core/graph/mn_graph_collapse_weighted_edge.d.ts +1 -0
- package/src/core/graph/mn_graph_collapse_weighted_edge.d.ts.map +1 -1
- package/src/core/graph/mn_graph_collapse_weighted_edge.js +7 -1
- package/src/core/math/physics/brdf/brdf_burley.d.ts.map +1 -1
- package/src/core/math/physics/brdf/brdf_burley.js +9 -1
- package/src/core/math/physics/brdf/{D_GGX.d.ts → diffuse_GGX.d.ts} +2 -2
- package/src/core/math/physics/brdf/diffuse_GGX.d.ts.map +1 -0
- package/src/core/math/physics/brdf/{D_GGX.js → diffuse_GGX.js} +1 -1
- package/src/core/math/physics/brdf/fresnel_Schlick.d.ts +3 -0
- package/src/core/math/physics/brdf/fresnel_Schlick.d.ts.map +1 -0
- package/src/core/math/physics/brdf/fresnel_Schlick.js +3 -0
- package/src/core/math/physics/brdf/fresnel_Schlick_optimized.d.ts +9 -0
- package/src/core/math/physics/brdf/fresnel_Schlick_optimized.d.ts.map +1 -0
- package/src/core/math/physics/brdf/fresnel_Schlick_optimized.js +12 -0
- package/src/core/math/physics/brdf/fresnel_Schlick_original.d.ts +9 -0
- package/src/core/math/physics/brdf/fresnel_Schlick_original.d.ts.map +1 -0
- package/src/core/math/physics/brdf/fresnel_Schlick_original.js +10 -0
- package/src/core/math/physics/bsdf/bsdf_schlick.d.ts.map +1 -1
- package/src/core/math/physics/bsdf/bsdf_schlick.js +3 -11
- package/src/core/math/physics/ior_to_reflectivity.d.ts +7 -0
- package/src/core/math/physics/ior_to_reflectivity.d.ts.map +1 -0
- package/src/core/math/physics/ior_to_reflectivity.js +9 -0
- package/src/core/math/physics/pdf/README.md +1 -0
- package/src/core/math/physics/pdf/pdf_GGX.d.ts +16 -0
- package/src/core/math/physics/pdf/pdf_GGX.d.ts.map +1 -0
- package/src/core/math/physics/pdf/pdf_GGX.js +25 -0
- package/src/core/math/physics/reflectivity_to_ior.d.ts +7 -0
- package/src/core/math/physics/reflectivity_to_ior.d.ts.map +1 -0
- package/src/core/math/physics/reflectivity_to_ior.js +8 -0
- package/src/core/process/task/util/randomCountTask.js +3 -3
- package/src/core/process/worker/WorkerBuilder.d.ts.map +1 -1
- package/src/core/process/worker/WorkerBuilder.js +5 -35
- package/src/engine/EngineHarness.d.ts +10 -1
- package/src/engine/EngineHarness.d.ts.map +1 -1
- package/src/engine/EngineHarness.js +22 -11
- package/src/engine/asset/loaders/ArrayBufferLoader.d.ts.map +1 -1
- package/src/engine/asset/loaders/ArrayBufferLoader.js +17 -10
- package/src/engine/asset/loaders/image/png/PNGReader.d.ts +25 -11
- package/src/engine/asset/loaders/image/png/PNGReader.d.ts.map +1 -1
- package/src/engine/asset/loaders/image/png/PNGReader.js +38 -24
- package/src/engine/asset/loaders/material/TextureAttachmensByMaterialType.d.ts.map +1 -1
- package/src/engine/asset/loaders/material/TextureAttachmensByMaterialType.js +5 -0
- package/src/engine/ecs/terrain/overlay/TerrainOverlay.js +4 -4
- package/src/engine/graphics/GraphicsEngine.js +1 -1
- package/src/engine/graphics/ecs/camera/topdown/TopDownCameraController.d.ts.map +1 -1
- package/src/engine/graphics/ecs/camera/topdown/TopDownCameraController.js +4 -0
- package/src/engine/graphics/ecs/light/LightSystem.d.ts.map +1 -1
- package/src/engine/graphics/ecs/light/LightSystem.js +2 -3
- package/src/engine/graphics/ecs/light/binding/three/ThreeLightBinding.d.ts +6 -0
- package/src/engine/graphics/ecs/light/binding/three/ThreeLightBinding.d.ts.map +1 -1
- package/src/engine/graphics/ecs/light/binding/three/ThreeLightBinding.js +22 -11
- package/src/engine/graphics/ecs/sprite/SpriteSystemPE.d.ts.map +1 -1
- package/src/engine/graphics/ecs/sprite/SpriteSystemPE.js +7 -7
- package/src/engine/graphics/impostors/octahedral/bake/prepare_bake_material.js +3 -3
- package/src/engine/graphics/render/forward_plus/model/DirectionalLight.d.ts.map +1 -1
- package/src/engine/graphics/render/forward_plus/model/DirectionalLight.js +25 -25
- package/src/engine/graphics/sh3/SH3VisualisationMaterial.d.ts.map +1 -1
- package/src/engine/graphics/sh3/SH3VisualisationMaterial.js +9 -6
- package/src/engine/graphics/sh3/fromCubeRenderTarget.d.ts +9 -0
- package/src/engine/graphics/sh3/fromCubeRenderTarget.d.ts.map +1 -0
- package/src/engine/graphics/sh3/fromCubeRenderTarget.js +145 -0
- package/src/engine/graphics/sh3/gi/tetrahedral_mesh_to_texture.d.ts +8 -0
- package/src/engine/graphics/sh3/gi/tetrahedral_mesh_to_texture.d.ts.map +1 -0
- package/src/engine/graphics/sh3/gi/tetrahedral_mesh_to_texture.js +51 -0
- package/src/engine/graphics/sh3/{LightProbeVolume.d.ts → lpv/LightProbeVolume.d.ts} +18 -7
- package/src/engine/graphics/sh3/lpv/LightProbeVolume.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpv/LightProbeVolume.js +340 -0
- package/src/engine/graphics/sh3/lpv/LightProbeVolumeSerializationAdapter.d.ts +18 -0
- package/src/engine/graphics/sh3/lpv/LightProbeVolumeSerializationAdapter.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpv/LightProbeVolumeSerializationAdapter.js +44 -0
- package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.d.ts +12 -0
- package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.js +122 -0
- package/src/engine/graphics/sh3/lpv/ProbeRenderer.d.ts +29 -0
- package/src/engine/graphics/sh3/lpv/ProbeRenderer.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpv/ProbeRenderer.js +35 -0
- package/src/engine/graphics/sh3/lpv/WebGLCubeProbeRenderer.d.ts +27 -0
- package/src/engine/graphics/sh3/lpv/WebGLCubeProbeRenderer.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpv/WebGLCubeProbeRenderer.js +158 -0
- package/src/engine/graphics/sh3/lpv/build_probes_for_scene.d.ts +11 -0
- package/src/engine/graphics/sh3/lpv/build_probes_for_scene.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpv/build_probes_for_scene.js +127 -0
- package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.d.ts +12 -0
- package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.js +89 -0
- package/src/engine/graphics/sh3/path_tracer/PathTracedScene.d.ts +90 -0
- package/src/engine/graphics/sh3/path_tracer/PathTracedScene.d.ts.map +1 -0
- package/src/engine/graphics/sh3/path_tracer/PathTracedScene.js +352 -0
- package/src/engine/graphics/sh3/path_tracer/PathTracer.d.ts +5 -91
- package/src/engine/graphics/sh3/path_tracer/PathTracer.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/PathTracer.js +41 -477
- package/src/engine/graphics/sh3/path_tracer/make_one_vector3.d.ts +1 -0
- package/src/engine/graphics/sh3/path_tracer/make_one_vector3.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/make_one_vector3.js +6 -3
- package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +38 -62
- package/src/engine/graphics/sh3/path_tracer/random_in_hemisphere.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/random_in_hemisphere.js +7 -1
- package/src/engine/graphics/sh3/path_tracer/sample_triangle_attribute.d.ts +2 -2
- package/src/engine/graphics/sh3/path_tracer/sample_triangle_attribute.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/sample_triangle_attribute.js +1 -1
- package/src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples.d.ts +10 -0
- package/src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples.d.ts.map +1 -0
- package/src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples.js +20 -0
- package/src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples_2d.d.ts +10 -0
- package/src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples_2d.d.ts.map +1 -0
- package/src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples_2d.js +31 -0
- package/src/engine/graphics/sh3/path_tracer/sampling/make_stratified_sample.d.ts +9 -0
- package/src/engine/graphics/sh3/path_tracer/sampling/make_stratified_sample.d.ts.map +1 -0
- package/src/engine/graphics/sh3/path_tracer/sampling/make_stratified_sample.js +21 -0
- package/src/engine/graphics/sh3/path_tracer/texture/SoftwareTextureCache.d.ts +3 -0
- package/src/engine/graphics/sh3/path_tracer/texture/SoftwareTextureCache.d.ts.map +1 -0
- package/src/engine/graphics/sh3/path_tracer/texture/SoftwareTextureCache.js +3 -0
- package/src/engine/graphics/sh3/path_tracer/texture/apply_texture_clamping_to_coordinate.d.ts.map +1 -0
- package/src/engine/graphics/sh3/path_tracer/{apply_texture_clamping_to_coordinate.js → texture/apply_texture_clamping_to_coordinate.js} +2 -2
- package/src/engine/graphics/sh3/path_tracer/texture/sample_material.d.ts +11 -0
- package/src/engine/graphics/sh3/path_tracer/texture/sample_material.d.ts.map +1 -0
- package/src/engine/graphics/sh3/path_tracer/texture/sample_material.js +86 -0
- package/src/engine/graphics/sh3/path_tracer/texture/sample_texture.d.ts +10 -0
- package/src/engine/graphics/sh3/path_tracer/texture/sample_texture.d.ts.map +1 -0
- package/src/engine/graphics/sh3/path_tracer/texture/sample_texture.js +55 -0
- package/src/engine/graphics/sh3/path_tracer/vec3_uint8_to_float.js +4 -4
- package/src/engine/graphics/sh3/prototypeSH3Probe.js +145 -185
- package/src/engine/graphics/sh3/sky/hosek/sky_hosek_compute_irradiance_by_direction.d.ts +5 -5
- package/src/engine/graphics/sh3/sky/hosek/sky_hosek_compute_irradiance_by_direction.d.ts.map +1 -1
- package/src/engine/graphics/sh3/sky/hosek/sky_hosek_compute_irradiance_by_direction.js +8 -8
- package/src/engine/graphics/sh3/visualise_spherical_harmonic_sphere.d.ts +13 -0
- package/src/engine/graphics/sh3/visualise_spherical_harmonic_sphere.d.ts.map +1 -0
- package/src/engine/graphics/sh3/visualise_spherical_harmonic_sphere.js +54 -0
- package/src/engine/graphics/texture/AttributeDataTexture.d.ts +2 -2
- package/src/engine/graphics/texture/AttributeDataTexture.d.ts.map +1 -1
- package/src/engine/graphics/texture/AttributeDataTexture.js +11 -11
- package/src/engine/graphics/texture/sampler/Sampler2D.d.ts.map +1 -1
- package/src/engine/graphics/texture/sampler/Sampler2D.js +2 -2
- package/src/engine/input/ecs/systems/InputControllerSystem.js +1 -1
- package/src/engine/network/convertPathToURL.d.ts +3 -1
- package/src/engine/network/convertPathToURL.d.ts.map +1 -1
- package/src/engine/network/convertPathToURL.js +68 -51
- package/src/engine/physics/fluid/SliceVisualiser.d.ts.map +1 -1
- package/src/engine/physics/fluid/SliceVisualiser.js +4 -4
- package/src/generation/filtering/numeric/CellFilterCache.d.ts.map +1 -1
- package/src/generation/filtering/numeric/CellFilterCache.js +1 -0
- package/src/view/elements/ColorPickerView.d.ts.map +1 -1
- package/src/view/elements/ColorPickerView.js +7 -7
- package/src/core/binary/float2uint8.d.ts +0 -7
- package/src/core/binary/float2uint8.d.ts.map +0 -1
- package/src/core/binary/uint82float.d.ts +0 -7
- package/src/core/binary/uint82float.d.ts.map +0 -1
- package/src/core/binary/uint82float.spec.d.ts +0 -2
- package/src/core/binary/uint82float.spec.d.ts.map +0 -1
- package/src/core/binary/uint82float.spec.js +0 -7
- package/src/core/collection/array/randomizeArrayElementOrder.d.ts +0 -8
- package/src/core/collection/array/randomizeArrayElementOrder.d.ts.map +0 -1
- package/src/core/collection/array/randomizeArrayElementOrder.js +0 -24
- package/src/core/collection/array/randomizeArrayElementOrder.spec.d.ts +0 -2
- package/src/core/collection/array/randomizeArrayElementOrder.spec.d.ts.map +0 -1
- package/src/core/geom/3d/tetrahedra/compute_circumsphere.d.ts.map +0 -1
- package/src/core/graph/coarsen_graph.d.ts.map +0 -1
- package/src/core/graph/coarsen_graph.spec.d.ts +0 -2
- package/src/core/graph/coarsen_graph.spec.d.ts.map +0 -1
- package/src/core/graph/graph_adjacency_matrix.d.ts +0 -9
- package/src/core/graph/graph_adjacency_matrix.d.ts.map +0 -1
- package/src/core/graph/graph_degree_matrix.d.ts +0 -9
- package/src/core/graph/graph_degree_matrix.d.ts.map +0 -1
- package/src/core/graph/graph_degree_matrix.js +0 -18
- package/src/core/graph/graph_laplacian_matrix.d.ts.map +0 -1
- package/src/core/math/physics/brdf/D_GGX.d.ts.map +0 -1
- package/src/engine/graphics/sh3/LightProbeVolume.d.ts.map +0 -1
- package/src/engine/graphics/sh3/LightProbeVolume.js +0 -609
- package/src/engine/graphics/sh3/path_tracer/apply_texture_clamping_to_coordinate.d.ts.map +0 -1
- package/src/engine/graphics/sh3/visualise_probe.d.ts +0 -12
- package/src/engine/graphics/sh3/visualise_probe.d.ts.map +0 -1
- package/src/engine/graphics/sh3/visualise_probe.js +0 -40
- /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 {
|
|
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
|
|
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
|
-
* @
|
|
36
|
+
* @param {number} min_bounce
|
|
37
|
+
* @param {number} max_bounce
|
|
38
|
+
* @param {function} random
|
|
39
|
+
* @param {PathTracedScene} scene
|
|
373
40
|
*/
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
//
|
|
541
|
-
|
|
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] =
|
|
549
|
-
out[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,+
|
|
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] =
|
|
4
|
-
out[out_offset + 1] =
|
|
5
|
-
out[out_offset + 2] =
|
|
6
|
+
out[out_offset] = x;
|
|
7
|
+
out[out_offset + 1] = y;
|
|
8
|
+
out[out_offset + 2] = z;
|
|
6
9
|
}
|
|
7
10
|
}
|