@woosh/meep-engine 2.109.16 → 2.109.19

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 (96) hide show
  1. package/build/bundle-worker-terrain.js +1 -1
  2. package/build/meep.cjs +86 -50
  3. package/build/meep.min.js +1 -1
  4. package/build/meep.module.js +86 -50
  5. package/package.json +1 -1
  6. package/src/core/color/Color.d.ts.map +1 -1
  7. package/src/core/color/Color.js +29 -6
  8. package/src/core/color/rgb2uint24.js +1 -0
  9. package/src/core/color/rgb2uint32.d.ts +10 -0
  10. package/src/core/color/rgb2uint32.d.ts.map +1 -0
  11. package/src/core/color/rgb2uint32.js +18 -0
  12. package/src/core/geom/3d/Ray3.d.ts +1 -1
  13. package/src/core/geom/3d/Ray3.d.ts.map +1 -1
  14. package/src/core/geom/3d/Ray3.js +1 -1
  15. package/src/core/geom/3d/aabb/aabb3_raycast.d.ts.map +1 -1
  16. package/src/core/geom/3d/aabb/aabb3_raycast.js +3 -2
  17. package/src/core/geom/3d/apply_mat4_transform_to_direction_v3_array.d.ts.map +1 -1
  18. package/src/core/geom/3d/apply_mat4_transform_to_direction_v3_array.js +3 -1
  19. package/src/core/geom/3d/decompose_matrix_4_array.js +4 -4
  20. package/src/core/geom/3d/frustum/frustum_from_projection_matrix_array.d.ts.map +1 -1
  21. package/src/core/geom/3d/frustum/frustum_from_projection_matrix_array.js +3 -1
  22. package/src/core/geom/3d/normal/octahedron/decode_octahedron_to_unit.d.ts.map +1 -1
  23. package/src/core/geom/3d/normal/octahedron/decode_octahedron_to_unit.js +2 -1
  24. package/src/core/geom/3d/quaternion/quat_encode_to_uint32.d.ts.map +1 -1
  25. package/src/core/geom/3d/quaternion/quat_encode_to_uint32.js +2 -1
  26. package/src/core/geom/3d/ray/ray3_array_apply_matrix4.d.ts.map +1 -1
  27. package/src/core/geom/3d/ray/ray3_array_apply_matrix4.js +3 -1
  28. package/src/core/geom/3d/ray/ray3_interval_array_apply_matrix4.d.ts.map +1 -1
  29. package/src/core/geom/3d/ray/ray3_interval_array_apply_matrix4.js +3 -1
  30. package/src/core/geom/3d/shape/TransformedShape3D.d.ts.map +1 -1
  31. package/src/core/geom/3d/shape/TransformedShape3D.js +7 -6
  32. package/src/core/geom/3d/shape/UnitSphereShape3D.js +1 -1
  33. package/src/core/geom/3d/topology/tm_vertex_compute_normal.d.ts.map +1 -1
  34. package/src/core/geom/3d/topology/tm_vertex_compute_normal.js +2 -1
  35. package/src/core/geom/3d/v3_compute_triangle_normal.spec.js +2 -1
  36. package/src/core/geom/mat3/m3_rm_extract_scale.d.ts.map +1 -1
  37. package/src/core/geom/mat3/m3_rm_extract_scale.js +4 -2
  38. package/src/core/geom/vec2/v2_length.d.ts +8 -0
  39. package/src/core/geom/vec2/v2_length.d.ts.map +1 -0
  40. package/src/core/geom/vec2/v2_length.js +11 -0
  41. package/src/core/geom/vec3/v3_distance.d.ts.map +1 -1
  42. package/src/core/geom/vec3/v3_distance.js +3 -1
  43. package/src/core/geom/vec3/v3_length.js +1 -1
  44. package/src/core/geom/vec3/v3_matrix4_rotate.d.ts.map +1 -1
  45. package/src/core/geom/vec3/v3_matrix4_rotate.js +3 -1
  46. package/src/core/geom/vec3/v3_normalize_array.d.ts.map +1 -1
  47. package/src/core/geom/vec3/v3_normalize_array.js +3 -1
  48. package/src/core/json/abstractJSONSerializer.d.ts +1 -1
  49. package/src/core/json/abstractJSONSerializer.d.ts.map +1 -1
  50. package/src/core/json/abstractJSONSerializer.js +32 -6
  51. package/src/engine/asset/loaders/material/computeTextureHash.d.ts.map +1 -1
  52. package/src/engine/asset/loaders/material/computeTextureHash.js +5 -1
  53. package/src/engine/graphics/canvas/canvas2d_draw_linear_scale.d.ts.map +1 -1
  54. package/src/engine/graphics/canvas/canvas2d_draw_linear_scale.js +2 -1
  55. package/src/engine/graphics/ecs/highlight/HighlightDefinition.d.ts +3 -0
  56. package/src/engine/graphics/ecs/highlight/HighlightDefinition.d.ts.map +1 -1
  57. package/src/engine/graphics/ecs/highlight/HighlightDefinition.js +31 -28
  58. package/src/engine/graphics/ecs/path/tube/build/build_geometry_catmullrom.d.ts.map +1 -1
  59. package/src/engine/graphics/ecs/path/tube/build/build_geometry_catmullrom.js +2 -1
  60. package/src/engine/graphics/ecs/path/tube/build/compute_smooth_profile_normals.d.ts.map +1 -1
  61. package/src/engine/graphics/ecs/path/tube/build/compute_smooth_profile_normals.js +5 -3
  62. package/src/engine/graphics/ecs/path/tube/build/makeTubeGeometry.d.ts.map +1 -1
  63. package/src/engine/graphics/ecs/path/tube/build/makeTubeGeometry.js +2 -1
  64. package/src/engine/graphics/ecs/path/tube/build/make_cap.d.ts.map +1 -1
  65. package/src/engine/graphics/ecs/path/tube/build/make_cap.js +3 -2
  66. package/src/engine/graphics/ecs/path/tube/build/make_ring_vertices.d.ts.map +1 -1
  67. package/src/engine/graphics/ecs/path/tube/build/make_ring_vertices.js +6 -5
  68. package/src/engine/graphics/sh3/gi/material/common.glsl +51 -9
  69. package/src/engine/graphics/sh3/gi/material/makeOctahedralDepthAtlas.d.ts.map +1 -1
  70. package/src/engine/graphics/sh3/gi/material/makeOctahedralDepthAtlas.js +3 -3
  71. package/src/engine/graphics/sh3/lpv/LightProbeVolume.d.ts +5 -0
  72. package/src/engine/graphics/sh3/lpv/LightProbeVolume.d.ts.map +1 -1
  73. package/src/engine/graphics/sh3/lpv/LightProbeVolume.js +11 -0
  74. package/src/engine/graphics/sh3/lpv/LightProbeVolumeBaker.js +1 -1
  75. package/src/engine/graphics/sh3/lpv/depth/octahedral/bake_octahedral_depth_map.d.ts.map +1 -1
  76. package/src/engine/graphics/sh3/lpv/depth/octahedral/bake_octahedral_depth_map.js +30 -15
  77. package/src/engine/graphics/sh3/lpv/depth/octahedral/stitching/frag.glsl +88 -0
  78. package/src/engine/graphics/sh3/lpv/depth/octahedral/stitching/prototype.d.ts +2 -0
  79. package/src/engine/graphics/sh3/lpv/depth/octahedral/stitching/prototype.d.ts.map +1 -0
  80. package/src/engine/graphics/sh3/lpv/depth/octahedral/stitching/prototype.js +96 -0
  81. package/src/engine/graphics/sh3/lpv/depth/octahedral/stitching/vert.glsl +65 -0
  82. package/src/engine/graphics/sh3/lpv/depth/octahedral/v2/VLPDepthMapVisualisation.d.ts.map +1 -1
  83. package/src/engine/graphics/sh3/lpv/depth/octahedral/v2/VLPDepthMapVisualisation.js +2 -1
  84. package/src/engine/graphics/sh3/lpv/depth/octahedral/v2/visualise.frag.glsl +283 -27
  85. package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.d.ts.map +1 -1
  86. package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.js +2 -6
  87. package/src/engine/graphics/sh3/lpv/serialization/LightProbeVolumeSerializationAdapter.d.ts.map +1 -1
  88. package/src/engine/graphics/sh3/lpv/serialization/LightProbeVolumeSerializationAdapter.js +1 -0
  89. package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +1 -1
  90. package/src/engine/graphics/sh3/path_tracer/sampling/getBiasedNormalSample.d.ts.map +1 -1
  91. package/src/engine/graphics/sh3/path_tracer/sampling/getBiasedNormalSample.js +2 -1
  92. package/src/engine/graphics/sh3/path_tracer/sampling/getCosineDirection.d.ts.map +1 -1
  93. package/src/engine/graphics/sh3/path_tracer/sampling/getCosineDirection.js +2 -1
  94. package/src/engine/graphics/sh3/path_tracer/sampling/v3_orthonormal_matrix_from_normal.d.ts.map +1 -1
  95. package/src/engine/graphics/sh3/path_tracer/sampling/v3_orthonormal_matrix_from_normal.js +3 -1
  96. package/src/engine/graphics/sh3/prototypeSH3Probe.js +8 -6
@@ -12,6 +12,11 @@ export class LightProbeVolume {
12
12
  get mesh(): TetrahedralMesh;
13
13
  get points(): number[];
14
14
  get harmonics(): number[];
15
+ /**
16
+ *
17
+ * @param {number} v
18
+ */
19
+ set depth_map_resolution(arg: number);
15
20
  get depth_map_resolution(): number;
16
21
  get depth(): number[];
17
22
  set count(arg: number);
@@ -1 +1 @@
1
- {"version":3,"file":"LightProbeVolume.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/LightProbeVolume.js"],"names":[],"mappings":"AAUA;;;GAGG;AACH;IAiCI,sBAEC;IAED,cAkBC;IAED;;;OAGG;IACH,4BAEC;IAED,uBAEC;IAED,0BAEC;IAED,mCAEC;IAED,sBAEC;IAMD,uBAEC;IAND,oBAEC;IAMD;;;;;OAKG;IACH,aAJW,MAAM,KACN,MAAM,KACN,MAAM,QAgBhB;IAED;;;;;OAKG;IACH,mBAJW,MAAM,UACN,MAAM,EAAE,iBACR,MAAM,QAIhB;IAED;;OAEG;IACH,mBAaC;IAGD;;;;;OAKG;IACH,mCAJW,MAAM,GAEJ,UAAU,CAsBtB;IAGD,yBAEC;;CAEJ;gCAvL+B,wDAAwD;2BAC7D,mCAAmC"}
1
+ {"version":3,"file":"LightProbeVolume.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/LightProbeVolume.js"],"names":[],"mappings":"AAWA;;;GAGG;AACH;IAiCI,sBAEC;IAED,cAkBC;IAED;;;OAGG;IACH,4BAEC;IAED,uBAEC;IAED,0BAEC;IAMD;;;OAGG;IACH,sCAIC;IAZD,mCAEC;IAYD,sBAEC;IAMD,uBAEC;IAND,oBAEC;IAMD;;;;;OAKG;IACH,aAJW,MAAM,KACN,MAAM,KACN,MAAM,QAgBhB;IAED;;;;;OAKG;IACH,mBAJW,MAAM,UACN,MAAM,EAAE,iBACR,MAAM,QAIhB;IAED;;OAEG;IACH,mBAaC;IAGD;;;;;OAKG;IACH,mCAJW,MAAM,GAEJ,UAAU,CAsBtB;IAGD,yBAEC;;CAEJ;gCAjM+B,wDAAwD;2BAC7D,mCAAmC"}
@@ -1,3 +1,4 @@
1
+ import { assert } from "../../../../core/assert.js";
1
2
  import { array_copy } from "../../../../core/collection/array/array_copy.js";
2
3
  import {
3
4
  compute_delaunay_tetrahedral_mesh
@@ -89,6 +90,16 @@ export class LightProbeVolume {
89
90
  return this.#probe_depth_resolution;
90
91
  }
91
92
 
93
+ /**
94
+ *
95
+ * @param {number} v
96
+ */
97
+ set depth_map_resolution(v) {
98
+ assert.isNonNegativeInteger(v, 'v');
99
+
100
+ this.#probe_depth_resolution = v;
101
+ }
102
+
92
103
  get depth() {
93
104
  return this.#probe_depth;
94
105
  }
@@ -46,7 +46,7 @@ export class LightProbeVolumeBaker {
46
46
 
47
47
  const depth_resolution = lpv.depth_map_resolution;
48
48
 
49
- const probe_element_count = depth_resolution * depth_resolution * 2;
49
+ const probe_element_count = depth_resolution * depth_resolution;
50
50
 
51
51
  renderer.bake_depth_octahedral(
52
52
  depth_resolution,
@@ -1 +1 @@
1
- {"version":3,"file":"bake_octahedral_depth_map.d.ts","sourceRoot":"","sources":["../../../../../../../../src/engine/graphics/sh3/lpv/depth/octahedral/bake_octahedral_depth_map.js"],"names":[],"mappings":"AA2BA;;;;;;;;;GASG;AACH,kDARW,MAAM,EAAE,iBACR,MAAM,oCAEN,MAAM,EAAE,UAAQ,mBAChB,MAAM,cACN,MAAM,aACN,MAAM,QA+GhB"}
1
+ {"version":3,"file":"bake_octahedral_depth_map.d.ts","sourceRoot":"","sources":["../../../../../../../../src/engine/graphics/sh3/lpv/depth/octahedral/bake_octahedral_depth_map.js"],"names":[],"mappings":"AA6BA;;;;;;;;;GASG;AACH,kDARW,MAAM,EAAE,iBACR,MAAM,oCAEN,MAAM,EAAE,UAAQ,mBAChB,MAAM,cACN,MAAM,aACN,MAAM,QA4HhB"}
@@ -6,7 +6,9 @@ import { Ray3 } from "../../../../../../core/geom/3d/Ray3.js";
6
6
  import { v3_distance } from "../../../../../../core/geom/vec3/v3_distance.js";
7
7
  import { v3_dot } from "../../../../../../core/geom/vec3/v3_dot.js";
8
8
  import { v3_dot_array_array } from "../../../../../../core/geom/vec3/v3_dot_array_array.js";
9
+ import { clamp01 } from "../../../../../../core/math/clamp01.js";
9
10
  import { max2 } from "../../../../../../core/math/max2.js";
11
+ import { PI_HALF } from "../../../../../../core/math/PI_HALF.js";
10
12
  import { generate_halton_jitter } from "../../../../../../core/math/random/generate_halton_jitter.js";
11
13
 
12
14
  const scratch_ray = new Ray3();
@@ -21,9 +23,9 @@ const ray_hit = [];
21
23
  *
22
24
  * @type {number}
23
25
  */
24
- const SUB_SAMPLE_COUNT = 7;
26
+ const SUB_SAMPLE_COUNT = 1;
25
27
 
26
- const DEPTH_SHARPNESS = 1;
28
+ const DEPTH_SHARPNESS = 7;
27
29
 
28
30
  /**
29
31
  *
@@ -46,13 +48,25 @@ export function bake_octahedral_depth_map(
46
48
  scratch_ray.tMax = max_depth;
47
49
  array_copy(position, position_offset, scratch_ray, 0, 3);
48
50
 
49
- const CONSTANT_NORMAL_BIAS = max_depth * 0.01 + 1e-6;
51
+
52
+ /**
53
+ * Resolution bias is to compensate for discontinuities between samples
54
+ * The lower the resolution - the higher the discontinuities
55
+ * This is heights of an arch on a unit sphere, where arch spans 1/resolution angle
56
+ * Half-PI is to get the height at midpoint of the arch
57
+ * x2 is to get error over the entire circle, as the previous term only gets us to semicircle (we can skip this to get half the max rise, or mean)
58
+ * xMath.SQRT2 is to allow for diagonals between pixels
59
+ * @type {number}
60
+ */
61
+ const RESOLUTION_BIAS = Math.sin(PI_HALF / resolution) * Math.SQRT2;
62
+
63
+ const NORMAL_BIAS = max_depth * 0.01 + 1e-6;
50
64
 
51
65
  const ray_direction = scratch_ray.direction;
52
66
 
53
67
  const probe_direction = new Float32Array(3);
54
68
 
55
- const texel_uv_scale = 0.5 / (resolution - 1);
69
+ const texel_uv_scale = 0.5 / (resolution);
56
70
 
57
71
  const jittered_sub_samples = generate_halton_jitter(SUB_SAMPLE_COUNT);
58
72
 
@@ -61,11 +75,14 @@ export function bake_octahedral_depth_map(
61
75
  for (let oct_y = 0; oct_y < resolution; oct_y++) {
62
76
 
63
77
  let distance_sum = 0;
64
- let distance2_sum = 0;
65
78
  let weight_sum = 0;
66
79
 
67
- const u = (oct_x) / (resolution - 1);
68
- const v = (oct_y) / (resolution - 1);
80
+ // offset position by half a pixel, as we are storing values for pixel centers
81
+ const u = (oct_x ) / (resolution);
82
+ const v = (oct_y ) / (resolution);
83
+
84
+ // const u = (oct_x + 0.5) / (resolution - 1);
85
+ // const v = (oct_y + 0.5) / (resolution - 1);
69
86
 
70
87
  decode_octahedron_to_unit(
71
88
  probe_direction, 0,
@@ -104,14 +121,14 @@ export function bake_octahedral_depth_map(
104
121
  ray_direction[0], ray_direction[1], ray_direction[2]
105
122
  );
106
123
 
107
- const resolution_bias_offset = max_depth * texel_uv_scale;
124
+ const resolution_bias_offset = max_depth * RESOLUTION_BIAS;
108
125
 
109
- const hit_normal_bias = CONSTANT_NORMAL_BIAS;
126
+ const hit_normal_bias = clamp01( 1-hit_angle_cos) * (resolution_bias_offset) + NORMAL_BIAS;
110
127
 
111
128
  // sink the contact into the surface along the hit normal
112
- const biased_hit_x = surface_position_x + surface_normal_x * hit_normal_bias;
113
- const biased_hit_y = surface_position_y + surface_normal_y * hit_normal_bias;
114
- const biased_hit_z = surface_position_z + surface_normal_z * hit_normal_bias;
129
+ const biased_hit_x = surface_position_x - surface_normal_x * hit_normal_bias;
130
+ const biased_hit_y = surface_position_y - surface_normal_y * hit_normal_bias;
131
+ const biased_hit_z = surface_position_z - surface_normal_z * hit_normal_bias;
115
132
 
116
133
  distance = v3_distance(
117
134
  scratch_ray[0], scratch_ray[1], scratch_ray[2],
@@ -131,16 +148,14 @@ export function bake_octahedral_depth_map(
131
148
  );
132
149
 
133
150
  distance_sum += distance * weight;
134
- distance2_sum += distance * distance * weight;
135
151
  weight_sum += weight;
136
152
  }
137
153
 
138
154
  const pixel_index = oct_y * resolution + oct_x;
139
155
 
140
- const address = result_offset + pixel_index * 2;
156
+ const address = result_offset + pixel_index;
141
157
 
142
158
  result[address] = distance_sum / weight_sum;
143
- result[address + 1] = distance2_sum / weight_sum;
144
159
  }
145
160
  }
146
161
 
@@ -0,0 +1,88 @@
1
+ uniform sampler2D t_texture;
2
+
3
+ varying vec2 vUv;
4
+
5
+ float lpv_bilinear_lerp(float v00, float v01, float v10, float v11, vec2 fraction) {
6
+
7
+ float x0 = mix(v00, v01, fraction.x);
8
+ float x1 = mix(v10, v11, fraction.x);
9
+
10
+ return mix(x0, x1, fraction.y);
11
+ }
12
+
13
+ vec3 lpv_bilinear_lerp(vec3 v00, vec3 v01, vec3 v10, vec3 v11, vec2 fraction) {
14
+
15
+ vec3 x0 = mix(v00, v01, fraction.x);
16
+ vec3 x1 = mix(v10, v11, fraction.x);
17
+
18
+ return mix(x0, x1, fraction.y);
19
+ }
20
+
21
+ ivec2 wrapOctahedralTexelCoordinates(const in ivec2 texel, const in int texture_size) {
22
+ ivec2 wrapped = ((texel % texture_size) + texture_size) % texture_size;
23
+
24
+ int fx = (abs(texel.x / texture_size) + int(texel.x < 0));
25
+ int fy = (abs(texel.y / texture_size) + int(texel.y < 0));
26
+
27
+ // return texel;
28
+
29
+ if (((fx ^ fy) & 1) != 0) {
30
+ return (texture_size - (wrapped + ivec2(1)));
31
+ // return ivec2(
32
+ // texSize.x - (wrapped.x + 1),
33
+ // (wrapped.y - texSize.y + 1)
34
+ // );
35
+ return wrapped;
36
+ } else {
37
+ return wrapped;
38
+ }
39
+ }
40
+
41
+
42
+ void main() {
43
+ int depth_tile_resolution = 4;
44
+ vec2 depth_tile_resolution_v2 = vec2(depth_tile_resolution);
45
+
46
+ vec2 octahedral_uv = vUv;
47
+
48
+ vec2 grid = octahedral_uv * depth_tile_resolution_v2 - 0.5;
49
+
50
+
51
+ vec2 gridFrac = fract(grid);
52
+ // vec2 gridFrac = vec2(0.0);
53
+
54
+ ivec2 texel_position = ivec2(floor(grid));
55
+
56
+ ivec2 tile_p_00;
57
+ ivec2 tile_p_01;
58
+ ivec2 tile_p_10;
59
+ ivec2 tile_p_11;
60
+
61
+ tile_p_00 = texel_position;
62
+
63
+
64
+ //
65
+ // tile_p_00 = wrapOctahedralTexelCoordinates(ivec2(floor(grid + vec2(-0.5, -0.5))), depth_tile_resolution);
66
+ // tile_p_01 = wrapOctahedralTexelCoordinates(ivec2(floor(grid + vec2(0.5, -0.5))), depth_tile_resolution);
67
+ // tile_p_10 = wrapOctahedralTexelCoordinates(ivec2(floor(grid + vec2(-0.5, 0.5))), depth_tile_resolution);
68
+ // tile_p_11 = wrapOctahedralTexelCoordinates(ivec2(floor(grid + vec2(0.5, 0.5))), depth_tile_resolution);
69
+
70
+ tile_p_00 = wrapOctahedralTexelCoordinates(texel_position , depth_tile_resolution);
71
+ tile_p_01 = wrapOctahedralTexelCoordinates(texel_position + ivec2(1, 0), depth_tile_resolution);
72
+ tile_p_10 = wrapOctahedralTexelCoordinates(texel_position + ivec2(0, 1), depth_tile_resolution);
73
+ tile_p_11 = wrapOctahedralTexelCoordinates(texel_position + ivec2(1, 1), depth_tile_resolution);
74
+
75
+
76
+ vec3 texel_00 = texelFetch(t_texture, tile_p_00, 0).rgb;
77
+ vec3 texel_01 = texelFetch(t_texture, tile_p_01, 0).rgb;
78
+ vec3 texel_10 = texelFetch(t_texture, tile_p_10, 0).rgb;
79
+ vec3 texel_11 = texelFetch(t_texture, tile_p_11, 0).rgb;
80
+
81
+ vec3 texel = lpv_bilinear_lerp(
82
+ texel_00, texel_01,
83
+ texel_10, texel_11,
84
+ gridFrac
85
+ );
86
+
87
+ gl_FragColor = vec4(texel, 1.0);
88
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=prototype.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prototype.d.ts","sourceRoot":"","sources":["../../../../../../../../../src/engine/graphics/sh3/lpv/depth/octahedral/stitching/prototype.js"],"names":[],"mappings":""}
@@ -0,0 +1,96 @@
1
+ import { GUI } from "dat.gui";
2
+ import {
3
+ ClampToEdgeWrapping,
4
+ DataTexture,
5
+ DoubleSide,
6
+ Mesh,
7
+ NearestFilter,
8
+ PerspectiveCamera,
9
+ PlaneBufferGeometry,
10
+ RGBFormat,
11
+ Scene,
12
+ ShaderMaterial,
13
+ WebGLRenderer
14
+ } from "three";
15
+ import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
16
+ import { float_to_uint8 } from "../../../../../../../core/binary/float_to_uint8.js";
17
+ import { Color } from "../../../../../../../core/color/Color.js";
18
+ import { FrameRunner } from "../../../../../FrameRunner.js";
19
+ import fragment from "./frag.glsl";
20
+ import vertex from "./vert.glsl";
21
+
22
+ const renderer = new WebGLRenderer();
23
+
24
+ const camera = new PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.01, 100);
25
+ camera.position.set(0, 0, -5);
26
+ camera.lookAt(0, 0, 0);
27
+
28
+ const scene = new Scene();
29
+
30
+ const geometry = new PlaneBufferGeometry(1, 1,16,16);
31
+
32
+ const texture = new DataTexture(new Uint8Array([
33
+ '#000000', '#ff0000', '#00FF00', '#00FFFF',
34
+ '#f8f8f8', '#FFAAFF', '#ffbc00', '#dd00ff',
35
+ '#0071ff', '#FFFF00', '#a62c2c', '#ff7c2d',
36
+ '#c5ff34', '#ffb7b7', '#833d1a', '#7b00ff',
37
+ ].map(c => Color.parse(c).toArray().slice(0,3).map(float_to_uint8)).flat()), 4, 4, RGBFormat);
38
+ texture.needsUpdate = true;
39
+ texture.magFilter = NearestFilter;
40
+ texture.minFilter = NearestFilter;
41
+
42
+ texture.wrapS = ClampToEdgeWrapping;
43
+ texture.wrapT = ClampToEdgeWrapping;
44
+
45
+ texture.flipY = false;
46
+
47
+ console.log(texture);
48
+
49
+ const uniforms = {
50
+ t_texture: {
51
+ value: texture
52
+ },
53
+ scale: {
54
+ value: 1
55
+ },
56
+ fold: {
57
+ value: 1
58
+ }
59
+ };
60
+ scene.add(new Mesh(geometry, new ShaderMaterial({
61
+ fragmentShader: [fragment].join('\n'),
62
+ vertexShader: vertex,
63
+ lights: false,
64
+ side: DoubleSide,
65
+ uniforms: uniforms
66
+ })));
67
+
68
+ new OrbitControls(camera, document.body);
69
+
70
+ new FrameRunner(() => {
71
+
72
+ renderer.render(scene, camera);
73
+
74
+ }).startup();
75
+
76
+ document.body.appendChild(renderer.domElement);
77
+
78
+ window.addEventListener('resize', onWindowResize, false);
79
+
80
+ function onWindowResize() {
81
+
82
+ camera.aspect = window.innerWidth / window.innerHeight;
83
+ camera.updateProjectionMatrix();
84
+
85
+ renderer.pixelRatio = window.devicePixelRatio;
86
+ renderer.setSize(window.innerWidth, window.innerHeight);
87
+
88
+ }
89
+
90
+ onWindowResize();
91
+
92
+
93
+ const gui = new GUI();
94
+
95
+ gui.add(uniforms.scale, 'value').min(0.1).max(3).name('scale');
96
+ gui.add(uniforms.fold, 'value').min(0).max(1).name('fold');
@@ -0,0 +1,65 @@
1
+ varying vec3 vNormal;
2
+ varying vec2 vUv;
3
+
4
+ uniform float scale;
5
+ uniform float fold;
6
+
7
+ float sign_not_zero(float x) {
8
+ return x >= 0.0 ? 1.0 : -1.0;
9
+ }
10
+
11
+ vec2 sign_not_zero(vec2 x) {
12
+ return vec2(
13
+ sign_not_zero(x.x),
14
+ sign_not_zero(x.y)
15
+ );
16
+ }
17
+
18
+ vec3 sign_not_zero(vec3 x) {
19
+ return vec3(
20
+ sign_not_zero(x.x),
21
+ sign_not_zero(x.y),
22
+ sign_not_zero(x.z)
23
+ );
24
+ }
25
+ vec3 OctaSphereEnc(vec2 coord)
26
+ {
27
+ coord = (coord - 0.5) * 2.0;
28
+ vec3 position = vec3(coord.x, 0.0, coord.y);
29
+ vec2 absolute = abs(position.xz);
30
+ position.y = 1.0 - absolute.x - absolute.y;
31
+
32
+ if (position.y < 0.0)
33
+ {
34
+ position.xz = sign(position.xz) * vec2(1.0 - absolute.y, 1.0 - absolute.x);
35
+ }
36
+
37
+ return position;
38
+ }
39
+
40
+ vec2 VecToSphereOct(vec3 v)
41
+ {
42
+ float l1norm = abs(v.x) + abs(v.y) + abs(v.z);
43
+
44
+ vec2 result = v.xz / l1norm;
45
+
46
+ if (v.y < 0.0) {
47
+ result = (1.0 - abs(result.yx)) * sign_not_zero(result.xy);
48
+ }
49
+
50
+ return result;
51
+ }
52
+
53
+ void main() {
54
+
55
+ vNormal = normalize(normalMatrix * normal);
56
+ vUv = uv;
57
+
58
+ vec3 position_grid = vec3(uv.x, 0.0, uv.y);
59
+ vec3 position_octa = normalize(OctaSphereEnc(uv));
60
+
61
+ vec3 position_morphed = mix(position_grid, position_octa, fold) * scale;
62
+
63
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(position_morphed, 1.0);
64
+
65
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"VLPDepthMapVisualisation.d.ts","sourceRoot":"","sources":["../../../../../../../../../src/engine/graphics/sh3/lpv/depth/octahedral/v2/VLPDepthMapVisualisation.js"],"names":[],"mappings":"AA6EA;IAYI;;;;OAIG;IACH,oCAFa,wBAAwB,CAQpC;IAfD,qBAEC;IAeD,gBA4CC;;CAEJ;mBAzIkB,iCAAiC"}
1
+ {"version":3,"file":"VLPDepthMapVisualisation.d.ts","sourceRoot":"","sources":["../../../../../../../../../src/engine/graphics/sh3/lpv/depth/octahedral/v2/VLPDepthMapVisualisation.js"],"names":[],"mappings":"AA8EA;IAYI;;;;OAIG;IACH,oCAFa,wBAAwB,CAQpC;IAfD,qBAEC;IAeD,gBA4CC;;CAEJ;mBAzIkB,iCAAiC"}
@@ -9,6 +9,7 @@ import {
9
9
  import { BinaryDataType } from "../../../../../../../core/binary/type/BinaryDataType.js";
10
10
  import { AABB3 } from "../../../../../../../core/geom/3d/aabb/AABB3.js";
11
11
  import { aabb3_from_v3_array } from "../../../../../../../core/geom/3d/aabb/aabb3_from_v3_array.js";
12
+ import { v3_length } from "../../../../../../../core/geom/vec3/v3_length.js";
12
13
  import Entity from "../../../../../../ecs/Entity.js";
13
14
  import { Transform } from "../../../../../../ecs/transform/Transform.js";
14
15
  import { ShadedGeometry } from "../../../../../ecs/mesh-v2/ShadedGeometry.js";
@@ -72,7 +73,7 @@ function buffer_geometry_set_bounds_by_aabb3(geometry, bounds) {
72
73
  geometry.boundingBox.max.set(bounds.x1, bounds.y1, bounds.z1);
73
74
 
74
75
  bounds.getCenter(geometry.boundingSphere.center);
75
- geometry.boundingSphere.radius = Math.hypot(bounds.getHalfExtentsX(), bounds.getHalfExtentsY(), bounds.getHalfExtentsZ());
76
+ geometry.boundingSphere.radius = v3_length(bounds.getHalfExtentsX(), bounds.getHalfExtentsY(), bounds.getHalfExtentsZ());
76
77
  }
77
78
 
78
79
  export class VLPDepthMapVisualisation {