@woosh/meep-engine 2.109.6 → 2.109.7

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 (167) hide show
  1. package/build/bundle-worker-terrain.js +1 -1
  2. package/build/meep.cjs +203 -174
  3. package/build/meep.min.js +1 -1
  4. package/build/meep.module.js +203 -174
  5. package/editor/tools/v2/TransformControls.js +39 -33
  6. package/package.json +1 -1
  7. package/src/core/bvh2/bvh3/BVH.d.ts.map +1 -1
  8. package/src/core/bvh2/bvh3/BVH.js +8 -0
  9. package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.d.ts.map +1 -1
  10. package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.js +11 -9
  11. package/src/core/geom/3d/Ray3.js +1 -1
  12. package/src/core/geom/3d/aabb/AABB3.js +1 -1
  13. package/src/core/geom/3d/normal/octahedron/decode_octahedron_to_unit.d.ts +4 -4
  14. package/src/core/geom/3d/normal/octahedron/decode_octahedron_to_unit.d.ts.map +1 -1
  15. package/src/core/geom/3d/normal/octahedron/decode_octahedron_to_unit.js +15 -11
  16. package/src/core/geom/3d/normal/octahedron/encode_unit_to_octahedron.d.ts.map +1 -1
  17. package/src/core/geom/3d/normal/octahedron/encode_unit_to_octahedron.js +13 -7
  18. package/src/core/geom/3d/normal/octahedron/encoding.spec.js +26 -1
  19. package/src/core/geom/3d/normal/octahedron/prototype.d.ts +2 -0
  20. package/src/core/geom/3d/normal/octahedron/prototype.d.ts.map +1 -0
  21. package/src/core/geom/3d/normal/octahedron/prototype.js +226 -0
  22. package/src/core/geom/3d/sphere/harmonics/sh3_rotate_bl.d.ts +1 -1
  23. package/src/core/geom/3d/sphere/harmonics/sh3_rotate_bl.js +4 -4
  24. package/src/core/geom/3d/tetrahedra/triangle/triangle_encode_rasterized_depth.d.ts +7 -1
  25. package/src/core/geom/3d/tetrahedra/triangle/triangle_encode_rasterized_depth.d.ts.map +1 -1
  26. package/src/core/geom/3d/tetrahedra/triangle/triangle_encode_rasterized_depth.js +6 -0
  27. package/src/core/geom/vec3/v3_distance.d.ts.map +1 -1
  28. package/src/core/geom/vec3/v3_distance.js +5 -5
  29. package/src/core/geometry/3d/tetrahedra/tetrahedral_mesh_find_tets_attached_to_vertex.d.ts +10 -0
  30. package/src/core/geometry/3d/tetrahedra/tetrahedral_mesh_find_tets_attached_to_vertex.d.ts.map +1 -0
  31. package/src/core/geometry/3d/tetrahedra/tetrahedral_mesh_find_tets_attached_to_vertex.js +34 -0
  32. package/src/core/model/node-graph/json/serializeNodeGraphToJSON.d.ts +5 -1
  33. package/src/core/model/node-graph/json/serializeNodeGraphToJSON.d.ts.map +1 -1
  34. package/src/core/model/node-graph/json/serializeNodeGraphToJSON.js +11 -6
  35. package/src/engine/asset/loaders/AssetLoader.d.ts.map +1 -1
  36. package/src/engine/asset/loaders/AssetLoader.js +1 -1
  37. package/src/engine/asset/loaders/material/computeTextureEquality.d.ts.map +1 -1
  38. package/src/engine/asset/loaders/material/computeTextureEquality.js +6 -1
  39. package/src/engine/asset/loaders/material/computeTextureHash.d.ts.map +1 -1
  40. package/src/engine/asset/loaders/material/computeTextureHash.js +8 -3
  41. package/src/engine/graphics/geometry/instancing/InstancedMeshGroup.d.ts.map +1 -1
  42. package/src/engine/graphics/geometry/instancing/InstancedMeshGroup.js +9 -15
  43. package/src/engine/graphics/geometry/instancing/geometry_copy.d.ts +7 -0
  44. package/src/engine/graphics/geometry/instancing/geometry_copy.d.ts.map +1 -0
  45. package/src/engine/graphics/geometry/instancing/geometry_copy.js +15 -0
  46. package/src/engine/graphics/impostors/octahedral/ImpostorBaker.d.ts.map +1 -1
  47. package/src/engine/graphics/impostors/octahedral/ImpostorBaker.js +28 -20
  48. package/src/engine/graphics/impostors/octahedral/ImpostorCaptureType.d.ts +1 -0
  49. package/src/engine/graphics/impostors/octahedral/ImpostorCaptureType.d.ts.map +1 -1
  50. package/src/engine/graphics/impostors/octahedral/ImpostorCaptureType.js +4 -0
  51. package/src/engine/graphics/impostors/octahedral/grid/OctahedralUvEncoder.js +6 -6
  52. package/src/engine/graphics/impostors/octahedral/prototypeBaker.js +16 -7
  53. package/src/engine/graphics/impostors/octahedral/util/build_cutout_from_atlas_by_alpha.d.ts +3 -2
  54. package/src/engine/graphics/impostors/octahedral/util/build_cutout_from_atlas_by_alpha.d.ts.map +1 -1
  55. package/src/engine/graphics/impostors/octahedral/util/build_cutout_from_atlas_by_alpha.js +25 -14
  56. package/src/engine/graphics/render/visibility/hiz/buildCanvasViewFromTexture.js +1 -0
  57. package/src/engine/graphics/sh3/gi/material/MaterialTransformer.d.ts.map +1 -1
  58. package/src/engine/graphics/sh3/gi/material/MaterialTransformer.js +48 -33
  59. package/src/engine/graphics/sh3/gi/material/common.glsl +434 -0
  60. package/src/engine/graphics/sh3/gi/material/makeLookupTexture3D.d.ts +8 -0
  61. package/src/engine/graphics/sh3/gi/material/makeLookupTexture3D.d.ts.map +1 -0
  62. package/src/engine/graphics/sh3/gi/material/makeLookupTexture3D.js +35 -0
  63. package/src/engine/graphics/sh3/gi/material/makeOctahedralDepthAtlas.d.ts +8 -0
  64. package/src/engine/graphics/sh3/gi/material/makeOctahedralDepthAtlas.d.ts.map +1 -0
  65. package/src/engine/graphics/sh3/gi/material/makeOctahedralDepthAtlas.js +28 -0
  66. package/src/engine/graphics/sh3/gi/material/space_fragment/build_fragment_shader.d.ts.map +1 -0
  67. package/src/engine/graphics/sh3/gi/material/space_fragment/build_fragment_shader.js +53 -0
  68. package/src/engine/graphics/sh3/gi/material/space_fragment/build_vertex_shader.d.ts.map +1 -0
  69. package/src/engine/graphics/sh3/gi/material/space_fragment/build_vertex_shader.js +29 -0
  70. package/src/engine/graphics/sh3/gi/material/space_fragment/space_fragment_transform_shader.d.ts +9 -0
  71. package/src/engine/graphics/sh3/gi/material/space_fragment/space_fragment_transform_shader.d.ts.map +1 -0
  72. package/src/engine/graphics/sh3/gi/material/space_fragment/space_fragment_transform_shader.js +12 -0
  73. package/src/engine/graphics/sh3/gi/material/space_vertex/build_fragment_shader.d.ts +6 -0
  74. package/src/engine/graphics/sh3/gi/material/space_vertex/build_fragment_shader.d.ts.map +1 -0
  75. package/src/engine/graphics/sh3/gi/material/space_vertex/build_fragment_shader.js +26 -0
  76. package/src/engine/graphics/sh3/gi/material/space_vertex/build_vertex_shader.d.ts +6 -0
  77. package/src/engine/graphics/sh3/gi/material/space_vertex/build_vertex_shader.d.ts.map +1 -0
  78. package/src/engine/graphics/sh3/gi/material/space_vertex/build_vertex_shader.js +62 -0
  79. package/src/engine/graphics/sh3/gi/material/space_vertex/preable.frag.glsl +43 -0
  80. package/src/engine/graphics/sh3/gi/material/space_vertex/preable.vert.glsl +9 -0
  81. package/src/engine/graphics/sh3/gi/material/space_vertex/space_vertex_transform_shader.d.ts +9 -0
  82. package/src/engine/graphics/sh3/gi/material/space_vertex/space_vertex_transform_shader.d.ts.map +1 -0
  83. package/src/engine/graphics/sh3/gi/material/space_vertex/space_vertex_transform_shader.js +12 -0
  84. package/src/engine/graphics/sh3/lpv/LightProbeVolume.d.ts +2 -0
  85. package/src/engine/graphics/sh3/lpv/LightProbeVolume.d.ts.map +1 -1
  86. package/src/engine/graphics/sh3/lpv/LightProbeVolume.js +35 -3
  87. package/src/engine/graphics/sh3/lpv/LightProbeVolumeBaker.d.ts.map +1 -1
  88. package/src/engine/graphics/sh3/lpv/LightProbeVolumeBaker.js +67 -8
  89. package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.d.ts +10 -0
  90. package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.d.ts.map +1 -1
  91. package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.js +27 -41
  92. package/src/engine/graphics/sh3/lpv/depth/octahedral/OctahedralDepthDebuggerWidget.d.ts +17 -0
  93. package/src/engine/graphics/sh3/lpv/depth/octahedral/OctahedralDepthDebuggerWidget.d.ts.map +1 -0
  94. package/src/engine/graphics/sh3/lpv/depth/octahedral/OctahedralDepthDebuggerWidget.js +100 -0
  95. package/src/engine/graphics/sh3/lpv/depth/octahedral/bake_octahedral_depth_map.d.ts +12 -0
  96. package/src/engine/graphics/sh3/lpv/depth/octahedral/bake_octahedral_depth_map.d.ts.map +1 -0
  97. package/src/engine/graphics/sh3/lpv/depth/octahedral/bake_octahedral_depth_map.js +58 -0
  98. package/src/engine/graphics/sh3/lpv/depth/octahedral/shader/OctahedralDepthVisualizationMaterial.d.ts +11 -0
  99. package/src/engine/graphics/sh3/lpv/depth/octahedral/shader/OctahedralDepthVisualizationMaterial.d.ts.map +1 -0
  100. package/src/engine/graphics/sh3/lpv/depth/octahedral/shader/OctahedralDepthVisualizationMaterial.js +45 -0
  101. package/src/engine/graphics/sh3/lpv/depth/octahedral/shader/visualize.frag.glsl +126 -0
  102. package/src/engine/graphics/sh3/lpv/depth/octahedral/shader/visualize.vert.glsl +10 -0
  103. package/src/engine/graphics/sh3/lpv/depth/octahedral/v2/VLPDepthMapVisualisation.d.ts +13 -0
  104. package/src/engine/graphics/sh3/lpv/depth/octahedral/v2/VLPDepthMapVisualisation.d.ts.map +1 -0
  105. package/src/engine/graphics/sh3/lpv/depth/octahedral/v2/VLPDepthMapVisualisation.js +146 -0
  106. package/src/engine/graphics/sh3/lpv/depth/octahedral/v2/visualise.frag.glsl +159 -0
  107. package/src/engine/graphics/sh3/lpv/depth/octahedral/v2/visualise.vert.glsl +13 -0
  108. package/src/engine/graphics/sh3/lpv/depth/sh3_bake_depth.d.ts.map +1 -0
  109. package/src/engine/graphics/sh3/lpv/{sh3_bake_depth.js → depth/sh3_bake_depth.js} +7 -7
  110. package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.d.ts +3 -6
  111. package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.d.ts.map +1 -1
  112. package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.js +34 -58
  113. package/src/engine/graphics/sh3/lpv/serialization/LightProbeVolumeSerializationAdapter.d.ts.map +1 -1
  114. package/src/engine/graphics/sh3/lpv/serialization/LightProbeVolumeSerializationAdapter.js +8 -0
  115. package/src/engine/graphics/sh3/path_tracer/BufferedGeometryBVH.d.ts +2 -2
  116. package/src/engine/graphics/sh3/path_tracer/BufferedGeometryBVH.d.ts.map +1 -1
  117. package/src/engine/graphics/sh3/path_tracer/BufferedGeometryBVH.js +8 -5
  118. package/src/engine/graphics/sh3/path_tracer/populate_path_traced_scene_from_ecd.d.ts +7 -0
  119. package/src/engine/graphics/sh3/path_tracer/populate_path_traced_scene_from_ecd.d.ts.map +1 -0
  120. package/src/engine/graphics/sh3/path_tracer/populate_path_traced_scene_from_ecd.js +50 -0
  121. package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +40 -3
  122. package/src/engine/graphics/sh3/path_tracer/sorting/build_bvh_nodes_distances_along_ray.d.ts.map +1 -0
  123. package/src/engine/graphics/sh3/path_tracer/{build_bvh_nodes_distances_along_ray.js → sorting/build_bvh_nodes_distances_along_ray.js} +2 -2
  124. package/src/engine/graphics/sh3/path_tracer/sorting/build_bvh_nodes_distances_sqr_to_point.d.ts.map +1 -0
  125. package/src/engine/graphics/sh3/path_tracer/{build_bvh_nodes_distances_sqr_to_point.js → sorting/build_bvh_nodes_distances_sqr_to_point.js} +2 -2
  126. package/src/engine/graphics/sh3/path_tracer/sorting/sort_bvh_nodes_by_distance_to_point.d.ts.map +1 -0
  127. package/src/engine/graphics/sh3/path_tracer/{sort_bvh_nodes_by_distance_to_point.js → sorting/sort_bvh_nodes_by_distance_to_point.js} +3 -3
  128. package/src/engine/graphics/sh3/prototypeSH3Probe.js +40 -7
  129. package/src/engine/graphics/sh3/shader/SH3VisualisationMaterial.d.ts.map +1 -0
  130. package/src/engine/graphics/sh3/shader/SH3VisualisationMaterial.js +29 -0
  131. package/src/engine/graphics/sh3/shader/visualize.frag.glsl +41 -0
  132. package/src/engine/graphics/sh3/shader/visualize.vert.glsl +9 -0
  133. package/src/engine/graphics/sh3/visualise_spherical_harmonic_sphere.js +1 -1
  134. package/src/engine/graphics/texture/debug_preview_texture.d.ts +8 -0
  135. package/src/engine/graphics/texture/debug_preview_texture.d.ts.map +1 -0
  136. package/src/engine/graphics/texture/debug_preview_texture.js +38 -0
  137. package/src/view/View.d.ts.map +1 -1
  138. package/src/view/View.js +2 -0
  139. package/src/core/geom/3d/sphere/harmonics/sh3_rotate_filament.d.ts +0 -8
  140. package/src/core/geom/3d/sphere/harmonics/sh3_rotate_filament.d.ts.map +0 -1
  141. package/src/core/geom/3d/sphere/harmonics/sh3_rotate_filament.js +0 -32
  142. package/src/core/geom/3d/sphere/harmonics/sh_rotate_band1.d.ts +0 -8
  143. package/src/core/geom/3d/sphere/harmonics/sh_rotate_band1.d.ts.map +0 -1
  144. package/src/core/geom/3d/sphere/harmonics/sh_rotate_band1.js +0 -44
  145. package/src/core/geom/3d/sphere/harmonics/sh_rotate_band2.d.ts +0 -8
  146. package/src/core/geom/3d/sphere/harmonics/sh_rotate_band2.d.ts.map +0 -1
  147. package/src/core/geom/3d/sphere/harmonics/sh_rotate_band2.js +0 -86
  148. package/src/engine/graphics/sh3/SH3VisualisationMaterial.d.ts.map +0 -1
  149. package/src/engine/graphics/sh3/SH3VisualisationMaterial.js +0 -83
  150. package/src/engine/graphics/sh3/gi/material/build_fragment_shader.d.ts.map +0 -1
  151. package/src/engine/graphics/sh3/gi/material/build_fragment_shader.js +0 -71
  152. package/src/engine/graphics/sh3/gi/material/build_vertex_shader.d.ts.map +0 -1
  153. package/src/engine/graphics/sh3/gi/material/build_vertex_shader.js +0 -256
  154. package/src/engine/graphics/sh3/lpv/sh3_bake_depth.d.ts.map +0 -1
  155. package/src/engine/graphics/sh3/path_tracer/build_bvh_nodes_distances_along_ray.d.ts.map +0 -1
  156. package/src/engine/graphics/sh3/path_tracer/build_bvh_nodes_distances_sqr_to_point.d.ts.map +0 -1
  157. package/src/engine/graphics/sh3/path_tracer/ray_reflect.d.ts +0 -2
  158. package/src/engine/graphics/sh3/path_tracer/ray_reflect.d.ts.map +0 -1
  159. package/src/engine/graphics/sh3/path_tracer/ray_reflect.js +0 -27
  160. package/src/engine/graphics/sh3/path_tracer/sort_bvh_nodes_by_distance_to_point.d.ts.map +0 -1
  161. /package/src/engine/graphics/sh3/gi/material/{build_fragment_shader.d.ts → space_fragment/build_fragment_shader.d.ts} +0 -0
  162. /package/src/engine/graphics/sh3/gi/material/{build_vertex_shader.d.ts → space_fragment/build_vertex_shader.d.ts} +0 -0
  163. /package/src/engine/graphics/sh3/lpv/{sh3_bake_depth.d.ts → depth/sh3_bake_depth.d.ts} +0 -0
  164. /package/src/engine/graphics/sh3/path_tracer/{build_bvh_nodes_distances_along_ray.d.ts → sorting/build_bvh_nodes_distances_along_ray.d.ts} +0 -0
  165. /package/src/engine/graphics/sh3/path_tracer/{build_bvh_nodes_distances_sqr_to_point.d.ts → sorting/build_bvh_nodes_distances_sqr_to_point.d.ts} +0 -0
  166. /package/src/engine/graphics/sh3/path_tracer/{sort_bvh_nodes_by_distance_to_point.d.ts → sorting/sort_bvh_nodes_by_distance_to_point.d.ts} +0 -0
  167. /package/src/engine/graphics/sh3/{SH3VisualisationMaterial.d.ts → shader/SH3VisualisationMaterial.d.ts} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OctahedralDepthVisualizationMaterial.d.ts","sourceRoot":"","sources":["../../../../../../../../../src/engine/graphics/sh3/lpv/depth/octahedral/shader/OctahedralDepthVisualizationMaterial.js"],"names":[],"mappings":"AAIA;IAGI,cAmBC;IAED,oBAGC;IAED;;;OAGG;IACH,8CAKC;CAEJ;+BA5C8B,OAAO"}
@@ -0,0 +1,45 @@
1
+ import { ShaderMaterial } from "three";
2
+ import shader_fg from './visualize.frag.glsl';
3
+ import shader_vx from './visualize.vert.glsl';
4
+
5
+ export class OctahedralDepthVisualizationMaterial extends ShaderMaterial {
6
+
7
+
8
+ constructor() {
9
+
10
+
11
+ super({
12
+ fragmentShader: shader_fg,
13
+ vertexShader: shader_vx,
14
+ lights: false,
15
+ uniforms: {
16
+ uResolution: {
17
+ value: 1
18
+ },
19
+ fScale: { value: 1 },
20
+ tDepth: {
21
+ value: null
22
+ }
23
+ }
24
+ })
25
+
26
+
27
+ }
28
+
29
+ set scale(v) {
30
+ this.uniforms.fScale.value = 1 / v;
31
+ this.uniformsNeedUpdate = true;
32
+ }
33
+
34
+ /**
35
+ *
36
+ * @param {THREE.DataTexture} v
37
+ */
38
+ set texture(v) {
39
+ this.uniforms.tDepth.value = v;
40
+ this.uniforms.uResolution.value = v.image.width;
41
+
42
+ this.uniformsNeedUpdate = true;
43
+ }
44
+
45
+ }
@@ -0,0 +1,126 @@
1
+ vec3 inverseTransformDirection(in vec3 normal, in mat4 matrix) {
2
+ // matrix is assumed to be orthogonal
3
+ return normalize((vec4(normal, 0.0) * matrix).xyz);
4
+ }
5
+
6
+ vec3 OctaSphereEnc(vec2 coord)
7
+ {
8
+ coord = (coord - 0.5) * 2.0;
9
+ vec3 position = vec3(coord.x, 0.0, coord.y);
10
+ vec2 absolute = abs(position.xz);
11
+ position.y = 1.0 - absolute.x - absolute.y;
12
+
13
+ if (position.y < 0.0)
14
+ {
15
+ position.xz = sign(position.xz) * vec2(1.0 - absolute.y, 1.0 - absolute.x);
16
+ }
17
+
18
+ return position;
19
+ }
20
+
21
+ vec3 sign_not_zero(vec3 x) {
22
+ return vec3(
23
+ x.x >= 0.0 ? 1.0 : -1.0,
24
+ x.y >= 0.0 ? 1.0 : -1.0,
25
+ x.z >= 0.0 ? 1.0 : -1.0
26
+ );
27
+ }
28
+
29
+ vec2 VecToSphereOct(vec3 direction)
30
+ {
31
+ vec3 octant = sign_not_zero(direction);
32
+
33
+ // |x| + |y| + |z| = 1
34
+ float sum = dot(direction, octant);
35
+ vec3 octahedron = direction / sum;
36
+
37
+ if (direction.z < 0.0)
38
+ {
39
+ vec3 absolute = abs(octahedron);
40
+
41
+ octahedron.xy = octant.xy * vec2(1.0f - absolute.y, 1.0f - absolute.x);
42
+ }
43
+
44
+ return octahedron.xy;
45
+ }
46
+
47
+
48
+ vec4 TriangleInterpolate(vec2 uv) {
49
+ uv = fract(uv);
50
+
51
+ vec2 omuv = vec2(1.0, 1.0) - uv.xy;
52
+
53
+ vec4 res = vec4(0, 0, 0, 0);
54
+ //frame 0
55
+ res.x = min(omuv.x, omuv.y);
56
+ //frame 1
57
+ res.y = abs(dot(uv, vec2(1.0, -1.0)));
58
+ //frame 2
59
+ res.z = min(uv.x, uv.y);
60
+ //mask
61
+ res.w = clamp(ceil(uv.x - uv.y), 0.0, 1.0);
62
+
63
+ return res;
64
+ }
65
+
66
+ vec4 quadBlendWieghts(vec2 coords)
67
+ {
68
+ vec4 res;
69
+ /* 0 0 0
70
+ 0 0 0
71
+ 1 0 0 */
72
+ res.x = min(1.0f - coords.x, 1.0f - coords.y);
73
+ /* 1 0 0
74
+ 0 0 0
75
+ 0 0 1 */
76
+ res.y = abs(coords.x - coords.y);
77
+ /* 0 0 1
78
+ 0 0 0
79
+ 0 0 0 */
80
+ res.z = min(coords.x, coords.y);
81
+ /* 0 0 0
82
+ 0 0 1
83
+ 0 1 1 */
84
+ res.w = ceil(coords.x - coords.y);
85
+ //res.xyz /= (res.x + res.y + res.z);
86
+ return res;
87
+ }
88
+
89
+ float SampleBlended(sampler2D tex, vec2 uv0, vec2 uv1, vec2 uv2, vec4 weights) {
90
+
91
+ float samp0 = textureLod(tex, uv0, 0.0).r;
92
+ float samp1 = textureLod(tex, uv1, 0.0).r;
93
+ float samp2 = textureLod(tex, uv2, 0.0).r;
94
+
95
+ return samp0 * weights.x + samp1 * weights.y + samp2 * weights.z;
96
+ }
97
+
98
+
99
+
100
+
101
+ uniform sampler2D tDepth; // octahedron-encoded texture
102
+ uniform float fScale; // depth visualisation space
103
+ uniform float uResolution; // texture resulution
104
+ varying vec3 vNormal;
105
+
106
+ void main() {
107
+ vec3 normal = normalize(vNormal);
108
+ vec3 worldNormal = normalize(inverseTransformDirection(normal, viewMatrix));
109
+
110
+ vec2 octahedral_uv = clamp(VecToSphereOct(worldNormal) * 0.5 + 0.5, 0.0, 1.0);
111
+ vec2 grid = octahedral_uv * vec2(uResolution - 1.0);
112
+
113
+ vec2 gridFrac = fract(grid);
114
+ vec2 gridFloor = floor(grid);
115
+
116
+ vec4 weights = quadBlendWieghts(gridFrac);
117
+
118
+ //3 nearest frames
119
+ vec2 frame0 = gridFloor;
120
+ vec2 frame1 = gridFloor + mix(vec2(0, 1), vec2(1, 0), weights.w);
121
+ vec2 frame2 = gridFloor + vec2(1.0, 1.0);
122
+
123
+ float value = SampleBlended(tDepth, (frame0+0.5) / uResolution, (frame1+0.5) / uResolution, (frame2+0.5) / uResolution, weights) * fScale;
124
+
125
+ gl_FragColor = vec4(vec3(value), 1.0);
126
+ }
@@ -0,0 +1,10 @@
1
+ varying vec3 vNormal;
2
+
3
+ void main() {
4
+
5
+ vNormal = normalize( normalMatrix * normal );
6
+
7
+
8
+ gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
9
+
10
+ }
@@ -0,0 +1,13 @@
1
+ export class VLPDepthMapVisualisation {
2
+ /**
3
+ *
4
+ * @param {LightProbeVolume} lpv
5
+ * @returns {VLPDepthMapVisualisation}
6
+ */
7
+ static from(lpv: LightProbeVolume): VLPDepthMapVisualisation;
8
+ set volume(arg: any);
9
+ build(): Entity;
10
+ #private;
11
+ }
12
+ import Entity from "../../../../../../ecs/Entity.js";
13
+ //# sourceMappingURL=VLPDepthMapVisualisation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VLPDepthMapVisualisation.d.ts","sourceRoot":"","sources":["../../../../../../../../../src/engine/graphics/sh3/lpv/depth/octahedral/v2/VLPDepthMapVisualisation.js"],"names":[],"mappings":"AA0EA;IAYI;;;;OAIG;IACH,oCAFa,wBAAwB,CAQpC;IAfD,qBAEC;IAeD,gBA4CC;;CAEJ;mBAtIkB,iCAAiC"}
@@ -0,0 +1,146 @@
1
+ import {
2
+ Box3,
3
+ InstancedBufferAttribute,
4
+ InstancedBufferGeometry,
5
+ OctahedronBufferGeometry,
6
+ ShaderMaterial,
7
+ Sphere
8
+ } from "three";
9
+ import { BinaryDataType } from "../../../../../../../core/binary/type/BinaryDataType.js";
10
+ import { AABB3 } from "../../../../../../../core/geom/3d/aabb/AABB3.js";
11
+ import { aabb3_from_v3_array } from "../../../../../../../core/geom/3d/aabb/aabb3_from_v3_array.js";
12
+ import Entity from "../../../../../../ecs/Entity.js";
13
+ import { Transform } from "../../../../../../ecs/transform/Transform.js";
14
+ import { ShadedGeometry } from "../../../../../ecs/mesh-v2/ShadedGeometry.js";
15
+ import { ShadedGeometryFlags } from "../../../../../ecs/mesh-v2/ShadedGeometryFlags.js";
16
+ import { AttributeSpec } from "../../../../../geometry/AttributeSpec.js";
17
+ import { geometry_copy } from "../../../../../geometry/instancing/geometry_copy.js";
18
+ import { AttributeDataTexture } from "../../../../../texture/AttributeDataTexture.js";
19
+ import { makeOctahedralDepthAtlas } from "../../../../gi/material/makeOctahedralDepthAtlas.js";
20
+ import { octahedral_depth_to_atlas, vector_buffer_to_attribute_texture } from "../../../probe_volume_to_textures.js";
21
+ import fragment from './visualise.frag.glsl'
22
+ import vertex from './visualise.vert.glsl'
23
+
24
+ /**
25
+ *
26
+ * @param {LightProbeVolume} lpv
27
+ */
28
+ function makeMaterial(lpv) {
29
+ const depth_atlas = makeOctahedralDepthAtlas();
30
+ const positions = new AttributeDataTexture(
31
+ AttributeSpec.fromJSON({
32
+ name: "positions",
33
+ type: BinaryDataType.Float32,
34
+ itemSize: 3,
35
+ normalized: false
36
+ }),
37
+ 256, 1
38
+ );
39
+ vector_buffer_to_attribute_texture(positions, lpv.points, lpv.count, 3);
40
+ octahedral_depth_to_atlas(lpv, depth_atlas.image.data, depth_atlas.image.width);
41
+
42
+ const material = new ShaderMaterial({
43
+ fragmentShader: [fragment].join('\n'),
44
+ vertexShader: vertex,
45
+ lights: false,
46
+ uniforms: {
47
+ lpv_t_probe_positions: {
48
+ value: positions.texture
49
+ },
50
+ lpv_t_probe_depth: {
51
+ value: depth_atlas
52
+ }
53
+ }
54
+ });
55
+
56
+ return material;
57
+ }
58
+
59
+ /**
60
+ *
61
+ * @param {THREE.BufferGeometry} geometry
62
+ * @param {AABB3} bounds
63
+ */
64
+ function buffer_geometry_set_bounds_by_aabb3(geometry, bounds) {
65
+ geometry.boundingBox = new Box3()
66
+ geometry.boundingSphere = new Sphere()
67
+
68
+ geometry.boundingBox.min.set(bounds.x0, bounds.y0, bounds.z0);
69
+ geometry.boundingBox.max.set(bounds.x1, bounds.y1, bounds.z1);
70
+
71
+ bounds.getCenter(geometry.boundingSphere.center);
72
+ geometry.boundingSphere.radius = Math.hypot(bounds.getHalfExtentsX(), bounds.getHalfExtentsY(), bounds.getHalfExtentsZ());
73
+ }
74
+
75
+ export class VLPDepthMapVisualisation {
76
+
77
+ /**
78
+ * @type {LightProbeVolume}
79
+ */
80
+ #volume
81
+
82
+
83
+ set volume(lpv) {
84
+ this.#volume = lpv;
85
+ }
86
+
87
+ /**
88
+ *
89
+ * @param {LightProbeVolume} lpv
90
+ * @returns {VLPDepthMapVisualisation}
91
+ */
92
+ static from(lpv) {
93
+ const r = new VLPDepthMapVisualisation();
94
+
95
+ r.volume = lpv;
96
+
97
+ return r;
98
+ }
99
+
100
+ build() {
101
+
102
+ const geometry = new InstancedBufferGeometry();
103
+
104
+ const volume = this.#volume;
105
+
106
+ geometry.instanceCount = volume.count;
107
+
108
+ geometry_copy(geometry, new OctahedronBufferGeometry(0.4, 4));
109
+
110
+ const positions_attribute = new InstancedBufferAttribute(new Float32Array(volume.points), 3);
111
+ geometry.setAttribute("instancePosition", positions_attribute);
112
+
113
+ const bounds = new AABB3();
114
+
115
+ aabb3_from_v3_array(bounds, volume.points, volume.points.length);
116
+
117
+ const instance_bounds = new AABB3();
118
+
119
+ const geo_position_data = geometry.getAttribute('position').array;
120
+ aabb3_from_v3_array(instance_bounds, geo_position_data, geo_position_data.length);
121
+
122
+ // extend by bounds of a single instance
123
+ bounds.x0 += instance_bounds.x0;
124
+ bounds.y0 += instance_bounds.y0;
125
+ bounds.z0 += instance_bounds.z0;
126
+
127
+ bounds.x1 += instance_bounds.x1;
128
+ bounds.y1 += instance_bounds.y1;
129
+ bounds.z1 += instance_bounds.z1;
130
+
131
+ buffer_geometry_set_bounds_by_aabb3(geometry, bounds);
132
+
133
+ const sg = ShadedGeometry.from(geometry, makeMaterial(volume));
134
+
135
+ sg.setFlag(ShadedGeometryFlags.DrawMethodLocked);
136
+
137
+ const entity = new Entity();
138
+
139
+ entity.add(new Transform());
140
+ entity.add(sg);
141
+
142
+ return entity;
143
+
144
+ }
145
+
146
+ }
@@ -0,0 +1,159 @@
1
+
2
+
3
+ vec3 inverseTransformDirection(in vec3 normal, in mat4 matrix) {
4
+ // matrix is assumed to be orthogonal
5
+ return normalize((vec4(normal, 0.0) * matrix).xyz);
6
+ }
7
+
8
+
9
+ precision highp usampler2D;
10
+ precision highp usampler3D;
11
+
12
+ uniform sampler2D lpv_t_probe_positions;
13
+ uniform sampler2D lpv_t_probe_depth;
14
+
15
+ #define SEARCH_STEP_LIMIT 64u
16
+ #define INVALID_TET 1073741823u
17
+
18
+ ivec2 lpv_index_to_256_coordinate(uint index) {
19
+
20
+ uint pixel_x = index % 256u;
21
+ uint pixel_y = index / 256u;
22
+
23
+ return ivec2(int(pixel_x), int(pixel_y));
24
+ }
25
+
26
+ vec3 sign_not_zero(vec3 x) {
27
+ return vec3(
28
+ x.x >= 0.0 ? 1.0 : -1.0,
29
+ x.y >= 0.0 ? 1.0 : -1.0,
30
+ x.z >= 0.0 ? 1.0 : -1.0
31
+ );
32
+ }
33
+
34
+ vec4 quadBlendWieghts(vec2 coords)
35
+ {
36
+ vec4 res;
37
+ /* 0 0 0
38
+ 0 0 0
39
+ 1 0 0 */
40
+ res.x = min(1.0f - coords.x, 1.0f - coords.y);
41
+ /* 1 0 0
42
+ 0 0 0
43
+ 0 0 1 */
44
+ res.y = abs(coords.x - coords.y);
45
+ /* 0 0 1
46
+ 0 0 0
47
+ 0 0 0 */
48
+ res.z = min(coords.x, coords.y);
49
+ /* 0 0 0
50
+ 0 0 1
51
+ 0 1 1 */
52
+ res.w = ceil(coords.x - coords.y);
53
+ //res.xyz /= (res.x + res.y + res.z);
54
+ return res;
55
+ }
56
+
57
+
58
+ vec2 VecToSphereOct(vec3 direction)
59
+ {
60
+ vec3 octant = sign_not_zero(direction);
61
+
62
+ // |x| + |y| + |z| = 1
63
+ float sum = dot(direction, octant);
64
+ vec3 octahedron = direction / sum;
65
+
66
+ if (direction.y < 0.0)
67
+ {
68
+ vec3 absolute = abs(octahedron);
69
+
70
+ octahedron.xz = octant.xz * vec2(1.0f - absolute.z, 1.0f - absolute.x);
71
+ }
72
+
73
+ return octahedron.xz;
74
+ }
75
+
76
+ float SampleBlended(sampler2D tex, vec2 uv0, vec2 uv1, vec2 uv2, vec4 weights) {
77
+
78
+ float samp0 = textureLod(tex, uv0, 0.0).r;
79
+ float samp1 = textureLod(tex, uv1, 0.0).r;
80
+ float samp2 = textureLod(tex, uv2, 0.0).r;
81
+
82
+ return samp0 * weights.x + samp1 * weights.y + samp2 * weights.z;
83
+ }
84
+
85
+ float lpv_probe_getDepth(uint probe_index, vec3 direction) {
86
+ // get offset
87
+ uint depth_tile_resolution = 24u;
88
+ uvec2 atlas_size = uvec2(4096u);
89
+
90
+ uint tiles_per_row = atlas_size.x / depth_tile_resolution;
91
+
92
+ uint tile_x = probe_index % tiles_per_row;
93
+ uint tile_y = probe_index / tiles_per_row;
94
+
95
+ vec2 tile_offset = vec2(
96
+ tile_x * depth_tile_resolution,
97
+ tile_y * depth_tile_resolution
98
+ );
99
+
100
+ // convert direction to UV
101
+ vec2 octahedral_uv = clamp(VecToSphereOct(direction) * 0.5 + 0.5, 0.0, 1.0);
102
+ vec2 grid = octahedral_uv * vec2(depth_tile_resolution - 1u);
103
+
104
+ vec2 gridFrac = fract(grid);
105
+ vec2 gridFloor = floor(grid);
106
+
107
+ vec4 weights = quadBlendWieghts(gridFrac);
108
+
109
+ //3 nearest frames
110
+ vec2 frame0 = gridFloor;
111
+ vec2 frame1 = gridFloor + mix(vec2(0, 1), vec2(1, 0), weights.w);
112
+ vec2 frame2 = gridFloor + vec2(1.0, 1.0);
113
+
114
+ // move frames to atlas space
115
+ frame0 += tile_offset;
116
+ frame1 += tile_offset;
117
+ frame2 += tile_offset;
118
+
119
+ vec2 uv0 = (frame0 + 0.5) / vec2(atlas_size);
120
+ vec2 uv1 = (frame1 + 0.5) / vec2(atlas_size);
121
+ vec2 uv2 = (frame2 + 0.5) / vec2(atlas_size);
122
+
123
+ return SampleBlended(
124
+ lpv_t_probe_depth,
125
+ uv0, uv1, uv2,
126
+ weights
127
+ );
128
+ }
129
+
130
+ vec3 lpv_probe_getPosition(uint probe_index) {
131
+ return texelFetch(lpv_t_probe_positions, lpv_index_to_256_coordinate(probe_index), 0).rgb;
132
+ }
133
+
134
+ float lpv_probe_getVisibilityMask(vec3 position, uint probe_index) {
135
+
136
+ vec3 probe_position = lpv_probe_getPosition(probe_index);
137
+
138
+ vec3 local_probe_offset = probe_position - position;
139
+
140
+ vec3 direction = normalize(local_probe_offset);
141
+
142
+ float depth = lpv_probe_getDepth(probe_index, -direction);
143
+
144
+ // return step(depth, length(local_probe_offset));
145
+ return step(depth, 20.0);
146
+ }
147
+
148
+ varying vec3 vNormal;
149
+ flat varying uint instance_index;
150
+
151
+ void main() {
152
+ vec3 normal = normalize(vNormal);
153
+ vec3 worldNormal = normalize(inverseTransformDirection(normal, viewMatrix));
154
+
155
+ float depth = lpv_probe_getDepth(instance_index , worldNormal) / 10.0;
156
+
157
+ gl_FragColor = vec4(vec3(depth), 1.0);
158
+ // gl_FragColor = vec4( 1.0);
159
+ }
@@ -0,0 +1,13 @@
1
+ varying vec3 vNormal;
2
+
3
+ attribute vec3 instancePosition;
4
+ flat varying uint instance_index;
5
+
6
+ void main() {
7
+
8
+ vNormal = normalize( normalMatrix * normal );
9
+ instance_index = uint(gl_InstanceID);
10
+
11
+ gl_Position = projectionMatrix * modelViewMatrix * vec4( position + instancePosition, 1.0 );
12
+
13
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sh3_bake_depth.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/lpv/depth/sh3_bake_depth.js"],"names":[],"mappings":"AAQA;;;;;;;;;;GAUG;AACH,uCATW,MAAM,EAAE,iBACR,MAAM,sCAEN,MAAM,cACN,MAAM,cACN,MAAM,cACN,MAAM,eACN,MAAM,QAsDhB"}
@@ -1,10 +1,10 @@
1
- import { array_copy } from "../../../../core/collection/array/array_copy.js";
2
- import { Ray3 } from "../../../../core/geom/3d/Ray3.js";
3
- import { sh3_basis_at } from "../../../../core/geom/3d/sphere/harmonics/sh3_basis_at.js";
4
- import { sh3_vector_accumulate } from "../../../../core/geom/3d/sphere/harmonics/sh3_vector_accumulate.js";
5
- import { vector_scale_array } from "../../../../core/geom/vec/vector_scale_array.js";
6
- import { clamp01 } from "../../../../core/math/clamp01.js";
7
- import { OctahedralUvEncoder } from "../../impostors/octahedral/grid/OctahedralUvEncoder.js";
1
+ import { array_copy } from "../../../../../core/collection/array/array_copy.js";
2
+ import { Ray3 } from "../../../../../core/geom/3d/Ray3.js";
3
+ import { sh3_basis_at } from "../../../../../core/geom/3d/sphere/harmonics/sh3_basis_at.js";
4
+ import { sh3_vector_accumulate } from "../../../../../core/geom/3d/sphere/harmonics/sh3_vector_accumulate.js";
5
+ import { vector_scale_array } from "../../../../../core/geom/vec/vector_scale_array.js";
6
+ import { clamp01 } from "../../../../../core/math/clamp01.js";
7
+ import { OctahedralUvEncoder } from "../../../impostors/octahedral/grid/OctahedralUvEncoder.js";
8
8
 
9
9
  /**
10
10
  *
@@ -1,13 +1,10 @@
1
1
  /**
2
2
  *
3
3
  * @param {LightProbeVolume} lpv
4
+ * @param {number[]} atlas_data
5
+ * @param {number} atlas_width
4
6
  */
5
- export function probe_volume_to_textures(lpv: LightProbeVolume): {
6
- mesh_vertices: AttributeDataTexture;
7
- mesh_neighbours: AttributeDataTexture;
8
- probe_positions: AttributeDataTexture;
9
- probe_values: AttributeDataTexture;
10
- };
7
+ export function octahedral_depth_to_atlas(lpv: LightProbeVolume, atlas_data: number[], atlas_width: number): void;
11
8
  /**
12
9
  *
13
10
  * @param {AttributeDataTexture} target
@@ -1 +1 @@
1
- {"version":3,"file":"probe_volume_to_textures.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/probe_volume_to_textures.js"],"names":[],"mappings":"AAMA;;;GAGG;AACH;;;;;EAuDC;AAED;;;;;;GAMG;AACH,2DALW,oBAAoB,UACpB,MAAM,EAAE,eACR,MAAM,eACN,MAAM,QAiBhB;qCAtFoC,uCAAuC"}
1
+ {"version":3,"file":"probe_volume_to_textures.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/probe_volume_to_textures.js"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,6EAHW,MAAM,EAAE,eACR,MAAM,QAiChB;AAGD;;;;;;GAMG;AACH,2DALW,oBAAoB,UACpB,MAAM,EAAE,eACR,MAAM,eACN,MAAM,QAiBhB;qCAhEoC,uCAAuC"}
@@ -1,70 +1,46 @@
1
- import { BinaryDataType } from "../../../../core/binary/type/BinaryDataType.js";
2
1
  import { array_copy } from "../../../../core/collection/array/array_copy.js";
3
- import { AttributeSpec } from "../../geometry/AttributeSpec.js";
4
2
  import { AttributeDataTexture } from "../../texture/AttributeDataTexture.js";
5
- import { tetrahedral_mesh_to_texture } from "../gi/tetrahedral_mesh_to_texture.js";
6
3
 
7
4
  /**
8
5
  *
9
6
  * @param {LightProbeVolume} lpv
7
+ * @param {number[]} atlas_data
8
+ * @param {number} atlas_width
10
9
  */
11
- export function probe_volume_to_textures(lpv) {
12
-
13
- const tex_vertices = new AttributeDataTexture(
14
- AttributeSpec.fromJSON({
15
- name: "vertex",
16
- type: BinaryDataType.Uint16,
17
- itemSize: 4,
18
- normalized: false
19
- }),
20
- 256, 1
21
- );
22
-
23
- const tex_neighbours = new AttributeDataTexture(
24
- AttributeSpec.fromJSON({
25
- name: "neighbour",
26
- type: BinaryDataType.Uint32,
27
- itemSize: 4,
28
- normalized: false
29
- }),
30
- 256, 1
31
- );
32
-
33
- const tex_positions = new AttributeDataTexture(
34
- AttributeSpec.fromJSON({
35
- name: "positions",
36
- type: BinaryDataType.Float32,
37
- itemSize: 3,
38
- normalized: false
39
- }),
40
- 256, 1
41
- );
42
-
43
- const tex_harmonics = new AttributeDataTexture(
44
- AttributeSpec.fromJSON({
45
- name: "harmonics",
46
- type: BinaryDataType.Float32,
47
- itemSize: 3,
48
- normalized: false
49
- }),
50
- 256, 9
51
- );
52
-
53
- vector_buffer_to_attribute_texture(tex_positions, lpv.points, lpv.count, 3);
54
- vector_buffer_to_attribute_texture(tex_harmonics, lpv.harmonics, lpv.count * 9, 3);
55
- tetrahedral_mesh_to_texture(
56
- tex_vertices, tex_neighbours, lpv.mesh
57
- );
58
-
59
- return {
60
- mesh_vertices: tex_vertices,
61
- mesh_neighbours: tex_neighbours,
62
-
63
- probe_positions: tex_positions,
64
- probe_values: tex_harmonics
65
- };
10
+ export function octahedral_depth_to_atlas(lpv, atlas_data, atlas_width) {
11
+ const tile_resolution = lpv.depth_map_resolution;
12
+ const probe_count = lpv.count;
13
+ const probe_depth = lpv.depth;
14
+
15
+ const tiles_per_row = Math.floor(atlas_width / tile_resolution);
16
+
17
+ // populate atlas
18
+ for (let i = 0; i < probe_count; i++) {
19
+
20
+ const tile_x = i % tiles_per_row;
21
+ const tile_y = (i / tiles_per_row) >>> 0;
22
+
23
+ for (let pixel_y = 0; pixel_y < tile_resolution; pixel_y++) {
24
+ for (let pixel_x = 0; pixel_x < tile_resolution; pixel_x++) {
25
+
26
+ const source_offset = i * tile_resolution * tile_resolution;
27
+
28
+ const tile_pixel_index = pixel_y * tile_resolution + pixel_x;
29
+
30
+ const source_value = probe_depth[source_offset + tile_pixel_index];
31
+
32
+ const target_pixel_x = tile_x * tile_resolution + pixel_x;
33
+ const target_pixel_y = tile_y * tile_resolution + pixel_y;
34
+
35
+ const target_pixel_index = target_pixel_y * atlas_width + target_pixel_x;
36
+
37
+ atlas_data[target_pixel_index] = source_value;
38
+ }
39
+ }
40
+ }
66
41
  }
67
42
 
43
+
68
44
  /**
69
45
  *
70
46
  * @param {AttributeDataTexture} target
@@ -1 +1 @@
1
- {"version":3,"file":"LightProbeVolumeSerializationAdapter.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/lpv/serialization/LightProbeVolumeSerializationAdapter.js"],"names":[],"mappings":"AAGA;IAEI,+BAAwB;IAGxB;;;;OAIG;IACH,8BAFW,gBAAgB,QAY1B;IAED;;;;OAIG;IACH,gCAFW,gBAAgB,QAc1B;CACJ;gDA3C+C,mEAAmE;iCAClF,wBAAwB"}
1
+ {"version":3,"file":"LightProbeVolumeSerializationAdapter.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/lpv/serialization/LightProbeVolumeSerializationAdapter.js"],"names":[],"mappings":"AAGA;IAEI,+BAAwB;IAGxB;;;;OAIG;IACH,8BAFW,gBAAgB,QAiB1B;IAED;;;;OAIG;IACH,gCAFW,gBAAgB,QAiB1B;CACJ;gDAnD+C,mEAAmE;iCAClF,wBAAwB"}