@woosh/meep-engine 2.70.0 → 2.72.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/build/bundle-worker-terrain.js +1 -1
  2. package/build/meep.cjs +111 -122
  3. package/build/meep.min.js +1 -1
  4. package/build/meep.module.js +111 -122
  5. package/package.json +1 -1
  6. package/src/core/collection/array/array_get_index_in_range.js +1 -1
  7. package/src/core/collection/array/array_swap.js +2 -2
  8. package/src/core/geom/3d/quaternion/quat_encode_to_uint32.js +2 -3
  9. package/src/core/geom/3d/v3_compute_triangle_normal.js +7 -1
  10. package/src/core/geom/vec3/v3_normalize_array.js +27 -0
  11. package/src/core/math/remap.js +5 -1
  12. package/src/core/math/statistics/computeStatisticalPartialMedian.js +1 -1
  13. package/src/core/process/task/Task.js +53 -34
  14. package/src/engine/achievements/AchievementManager.js +19 -19
  15. package/src/engine/animation/curve/compression/prototypeCurveCompression.js +6 -6
  16. package/src/engine/animation/curve/draw/build_plot_entity_from_array.js +11 -6
  17. package/src/engine/ecs/dynamic_actions/DynamicActor.js +5 -10
  18. package/src/engine/ecs/dynamic_actions/DynamicActorSystem.js +82 -89
  19. package/src/engine/ecs/dynamic_actions/RuleExecution.js +10 -12
  20. package/src/engine/ecs/gui/GUIElement.js +44 -61
  21. package/src/engine/ecs/gui/GUIElementSystem.js +26 -24
  22. package/src/engine/ecs/gui/hud/HeadsUpDisplay.js +12 -15
  23. package/src/engine/ecs/gui/hud/HeadsUpDisplaySystem.js +15 -15
  24. package/src/engine/ecs/gui/parallax/GuiElementParallax.js +3 -3
  25. package/src/engine/ecs/gui/parallax/GuiElementParallaxSystem.js +2 -2
  26. package/src/engine/ecs/gui/position/ViewportPosition.js +5 -50
  27. package/src/engine/ecs/gui/position/ViewportPositionSerializationAdapter.js +42 -0
  28. package/src/engine/ecs/terrain/BufferedGeometryArraysBuilder.js +2 -2
  29. package/src/engine/ecs/transform/TransformSerializationAdapter.js +5 -10
  30. package/src/engine/graphics/geometry/buffered/ComputeNormals.js +11 -26
  31. package/src/engine/graphics/impostors/octahedral/prototypeBaker.js +20 -20
  32. package/src/engine/graphics/texture/sprite/prototypeSpriteCutoutGeometry.js +12 -12
  33. package/src/engine/graphics/texture/virtual/v2/NOTES.md +17 -0
  34. package/src/engine/graphics/texture/virtual/v2/ShaderUsage.js +49 -26
  35. package/src/engine/graphics/texture/virtual/v2/UsageDebugView.js +51 -0
  36. package/src/engine/graphics/texture/virtual/v2/UsageMetadata.js +221 -0
  37. package/src/engine/graphics/texture/virtual/v2/UsagePyramidDebugView.js +239 -0
  38. package/src/engine/graphics/texture/virtual/v2/VirtualTextureManager.js +248 -0
  39. package/src/engine/graphics/texture/virtual/v2/prototype.js +104 -31
  40. package/src/engine/navigation/ecs/components/PathSerializationAdapter.js +1 -4
  41. package/src/core/binary/ValidatingBitSetWrapper.js +0 -81
  42. package/src/core/binary/jsonToStringToByteArray.js +0 -27
  43. package/src/core/geom/2d/quad-tree/PointQuadTree.js +0 -478
  44. package/src/core/math/random/makeRangedRandom.js +0 -19
  45. package/src/engine/ecs/components/AreaOfEffect.js +0 -12
  46. package/src/engine/ecs/components/Mortality.js +0 -27
  47. package/src/engine/ecs/systems/AreaOfEffectSystem.js +0 -48
  48. package/src/engine/ecs/terrain/TerrainGeometryBuilder.js +0 -152
  49. package/src/engine/ecs/terrain/ecs/PromiseSamplerHeight.js +0 -66
  50. package/src/engine/ecs/terrain/ecs/TerrainClassifier.js +0 -125
  51. package/src/engine/graphics/texture/sampler/SampleTraverser.js +0 -165
@@ -1,8 +1,9 @@
1
1
  import { System } from "../../System.js";
2
- import { GuiElementParallax } from "./GuiElementParallax.js";
3
2
  import GUIElement from "../GUIElement.js";
3
+ import { GuiElementParallax } from "./GuiElementParallax.js";
4
4
 
5
5
  export class GuiElementParallaxSystem extends System {
6
+ dependencies = [GuiElementParallax, GUIElement];
6
7
 
7
8
  /**
8
9
  *
@@ -12,7 +13,6 @@ export class GuiElementParallaxSystem extends System {
12
13
  constructor({ viewport, pointer }) {
13
14
  super();
14
15
 
15
- this.dependencies = [GuiElementParallax, GUIElement];
16
16
 
17
17
  /**
18
18
  *
@@ -2,10 +2,9 @@
2
2
  * Created by Alex on 28/01/2015.
3
3
  */
4
4
 
5
+ import { computeHashIntegerArray } from "../../../../core/collection/array/computeHashIntegerArray.js";
5
6
  import Vector2 from "../../../../core/geom/Vector2.js";
6
7
  import ObservedBoolean from "../../../../core/model/ObservedBoolean.js";
7
- import { BinaryClassSerializationAdapter } from "../../storage/binary/BinaryClassSerializationAdapter.js";
8
- import { computeHashIntegerArray } from "../../../../core/collection/array/computeHashIntegerArray.js";
9
8
  import { computeHashFloat } from "../../../../core/primitives/numbers/computeHashFloat.js";
10
9
 
11
10
  /**
@@ -20,11 +19,9 @@ export const ViewportPositionFlags = {
20
19
  class ViewportPosition {
21
20
  /**
22
21
  *
23
- * @param {Vector2} [position]
24
- * @param {Vector2} [offset]
25
22
  * @constructor
26
23
  */
27
- constructor({ position, offset } = {}) {
24
+ constructor(options) {
28
25
  /**
29
26
  * Clip-scale position, on-screen values are in range of 0 to 1
30
27
  * @type {Vector2}
@@ -70,12 +67,9 @@ class ViewportPosition {
70
67
  */
71
68
  this.enabled = new ObservedBoolean(true);
72
69
 
73
- if (position !== void 0) {
74
- this.position.copy(position);
75
- }
76
-
77
- if (offset !== void 0) {
78
- this.offset.copy(offset);
70
+ if (options !== undefined) {
71
+ console.warn("ViewportPosition constructor options is deprecated, please use static fromJSON method instead if you need similar functionality");
72
+ this.fromJSON(options);
79
73
  }
80
74
  }
81
75
 
@@ -150,42 +144,3 @@ ViewportPosition.serializable = true;
150
144
 
151
145
  export default ViewportPosition;
152
146
 
153
- export class ViewportPositionSerializationAdapter extends BinaryClassSerializationAdapter {
154
-
155
- version = 0;
156
- klass = ViewportPosition;
157
-
158
- /**
159
- *
160
- * @param {BinaryBuffer} buffer
161
- * @param {ViewportPosition} value
162
- */
163
- serialize(buffer, value) {
164
- value.position.toBinaryBufferFloat32(buffer);
165
- value.offset.toBinaryBufferFloat32(buffer);
166
- value.anchor.toBinaryBufferFloat32(buffer);
167
-
168
- buffer.writeFloat32(value.screenEdgeWidth);
169
-
170
- buffer.writeUint8(value.resolveGuiCollisions ? 1 : 0);
171
- buffer.writeUint8(value.stickToScreenEdge ? 1 : 0);
172
- buffer.writeUint8(value.enabled.getValue() ? 1 : 0);
173
- }
174
-
175
- /**
176
- *
177
- * @param {BinaryBuffer} buffer
178
- * @param {ViewportPosition} value
179
- */
180
- deserialize(buffer, value) {
181
- value.position.fromBinaryBufferFloat32(buffer);
182
- value.offset.fromBinaryBufferFloat32(buffer);
183
- value.anchor.fromBinaryBufferFloat32(buffer);
184
-
185
- value.screenEdgeWidth = buffer.readFloat32();
186
-
187
- value.resolveGuiCollisions = buffer.readUint8() !== 0;
188
- value.stickToScreenEdge = buffer.readUint8() !== 0;
189
- value.enabled.set(buffer.readUint8() !== 0);
190
- }
191
- }
@@ -0,0 +1,42 @@
1
+ import { BinaryClassSerializationAdapter } from "../../storage/binary/BinaryClassSerializationAdapter.js";
2
+ import ViewportPosition from "./ViewportPosition.js";
3
+
4
+ export class ViewportPositionSerializationAdapter extends BinaryClassSerializationAdapter {
5
+
6
+ version = 0;
7
+ klass = ViewportPosition;
8
+
9
+ /**
10
+ *
11
+ * @param {BinaryBuffer} buffer
12
+ * @param {ViewportPosition} value
13
+ */
14
+ serialize(buffer, value) {
15
+ value.position.toBinaryBufferFloat32(buffer);
16
+ value.offset.toBinaryBufferFloat32(buffer);
17
+ value.anchor.toBinaryBufferFloat32(buffer);
18
+
19
+ buffer.writeFloat32(value.screenEdgeWidth);
20
+
21
+ buffer.writeUint8(value.resolveGuiCollisions ? 1 : 0);
22
+ buffer.writeUint8(value.stickToScreenEdge ? 1 : 0);
23
+ buffer.writeUint8(value.enabled.getValue() ? 1 : 0);
24
+ }
25
+
26
+ /**
27
+ *
28
+ * @param {BinaryBuffer} buffer
29
+ * @param {ViewportPosition} value
30
+ */
31
+ deserialize(buffer, value) {
32
+ value.position.fromBinaryBufferFloat32(buffer);
33
+ value.offset.fromBinaryBufferFloat32(buffer);
34
+ value.anchor.fromBinaryBufferFloat32(buffer);
35
+
36
+ value.screenEdgeWidth = buffer.readFloat32();
37
+
38
+ value.resolveGuiCollisions = buffer.readUint8() !== 0;
39
+ value.stickToScreenEdge = buffer.readUint8() !== 0;
40
+ value.enabled.set(buffer.readUint8() !== 0);
41
+ }
42
+ }
@@ -3,7 +3,7 @@
3
3
  */
4
4
 
5
5
 
6
- import ComputeNormals from '../../graphics/geometry/buffered/ComputeNormals.js';
6
+ import { computeVertexNormals } from '../../graphics/geometry/buffered/ComputeNormals.js';
7
7
 
8
8
  /**
9
9
  *
@@ -108,7 +108,7 @@ function buildBufferGeometry(samplerHeight, position, size, scale, totalSize, re
108
108
  }
109
109
  }
110
110
 
111
- ComputeNormals.computeNormals(vertices, normals, indices);
111
+ computeVertexNormals(vertices, normals, indices);
112
112
 
113
113
  //CleanupGeometry(geometry);
114
114
  return {
@@ -18,16 +18,13 @@ export class TransformSerializationAdapter extends BinaryClassSerializationAdapt
18
18
  serialize(buffer, value) {
19
19
 
20
20
  const position = value.position;
21
+ const rotation = value.rotation;
22
+ const scale = value.scale;
21
23
 
22
- const positionX = position.x;
23
- const positionY = position.y;
24
- const positionZ = position.z;
25
-
26
- buffer.writeFloat64(positionX);
27
- buffer.writeFloat64(positionY);
28
- buffer.writeFloat64(positionZ);
24
+ buffer.writeFloat64(position.x);
25
+ buffer.writeFloat64(position.y);
26
+ buffer.writeFloat64(position.z);
29
27
 
30
- const rotation = value.rotation;
31
28
  const encoded_rotation = quat_encode_to_uint32(
32
29
  rotation.x,
33
30
  rotation.y,
@@ -37,8 +34,6 @@ export class TransformSerializationAdapter extends BinaryClassSerializationAdapt
37
34
 
38
35
  buffer.writeUint32(encoded_rotation);
39
36
 
40
- const scale = value.scale;
41
-
42
37
  v3_binary_equality_encode(buffer, scale.x, scale.y, scale.z);
43
38
  }
44
39
 
@@ -3,28 +3,17 @@
3
3
  */
4
4
 
5
5
 
6
+ import { v3_normalize_array } from "../../../../core/geom/vec3/v3_normalize_array.js";
7
+
6
8
  /**
7
9
  *
8
- * @param {Array.<Number>} normals
10
+ * @param {Array.<number>} normals
9
11
  */
10
12
  function normalizeVectors(normals) {
11
- let x, y, z, n;
12
-
13
- let i = 0;
14
- const il = normals.length;
15
- for (; i < il; i += 3) {
13
+ const count = normals.length;
14
+ for (let i = 0; i < count; i += 3) {
16
15
 
17
- // extract vector components
18
- x = normals[i];
19
- y = normals[i + 1];
20
- z = normals[i + 2];
21
-
22
- // compute vector inverse magnitude
23
- n = 1.0 / Math.sqrt(x * x + y * y + z * z);
24
-
25
- normals[i] *= n;
26
- normals[i + 1] *= n;
27
- normals[i + 2] *= n;
16
+ v3_normalize_array(normals, i, normals, i);
28
17
 
29
18
  }
30
19
  }
@@ -32,11 +21,11 @@ function normalizeVectors(normals) {
32
21
  /**
33
22
  * based on code from THREE.js
34
23
  * normals need to be set to 0
35
- * @param {Array.<Number>} vertices
36
- * @param {Array.<Number>} normals
37
- * @param {Array.<Number>} indices
24
+ * @param {Array.<number>|Float32Array} vertices
25
+ * @param {Array.<number>|Float32Array} normals
26
+ * @param {Array.<number>|Uint32Array} indices
38
27
  */
39
- function computeVertexNormals(vertices, normals, indices) {
28
+ export function computeVertexNormals(vertices, normals, indices) {
40
29
  let vA, vB, vC;
41
30
 
42
31
  let vAx, vAy, vAz, vBx, vBy, vBz, vCx, vCy, vCz;
@@ -94,8 +83,4 @@ function computeVertexNormals(vertices, normals, indices) {
94
83
  }
95
84
 
96
85
  normalizeVectors(normals);
97
- }
98
-
99
- export default {
100
- computeNormals: computeVertexNormals
101
- };
86
+ }
@@ -1,32 +1,32 @@
1
- import { EngineHarness } from "../../../EngineHarness.js";
2
- import { ImpostorBaker } from "./ImpostorBaker.js";
3
- import { ShadedGeometry } from "../../ecs/mesh-v2/ShadedGeometry.js";
1
+ import Quaternion from "../../../../core/geom/Quaternion.js";
2
+ import Vector2 from "../../../../core/geom/Vector2.js";
3
+ import Vector3 from "../../../../core/geom/Vector3.js";
4
+ import { DEG_TO_RAD } from "../../../../core/math/DEG_TO_RAD.js";
5
+ import { GameAssetType } from "../../../asset/GameAssetType.js";
6
+ import { GLTFAssetLoader } from "../../../asset/loaders/GLTFAssetLoader.js";
4
7
  import Entity from "../../../ecs/Entity.js";
5
- import ViewportPosition from "../../../ecs/gui/position/ViewportPosition.js";
6
8
  import GUIElement from "../../../ecs/gui/GUIElement.js";
7
9
  import GUIElementSystem from "../../../ecs/gui/GUIElementSystem.js";
10
+ import ViewportPosition from "../../../ecs/gui/position/ViewportPosition.js";
8
11
  import ViewportPositionSystem from "../../../ecs/gui/position/ViewportPositionSystem.js";
9
- import Vector2 from "../../../../core/geom/Vector2.js";
10
- import { GameAssetType } from "../../../asset/GameAssetType.js";
11
- import { Transform } from "../../../ecs/transform/Transform.js";
12
- import { GLTFAssetLoader } from "../../../asset/loaders/GLTFAssetLoader.js";
13
- import { ImpostorCaptureType } from "./ImpostorCaptureType.js";
14
- import { ShadedGeometrySystem } from "../../ecs/mesh-v2/ShadedGeometrySystem.js";
15
- import { ImpostorShaderV0 } from "./shader/ImpostorShaderV0.js";
16
- import Quaternion from "../../../../core/geom/Quaternion.js";
17
- import { SGMesh } from "../../ecs/mesh-v2/aggregate/SGMesh.js";
18
- import { SGMeshSystem } from "../../ecs/mesh-v2/aggregate/SGMeshSystem.js";
19
- import { ShadedGeometryFlags } from "../../ecs/mesh-v2/ShadedGeometryFlags.js";
20
12
  import { TransformAttachmentSystem } from "../../../ecs/transform-attachment/TransformAttachmentSystem.js";
13
+ import { Transform } from "../../../ecs/transform/Transform.js";
14
+ import { EngineHarness } from "../../../EngineHarness.js";
21
15
  import { BehaviorComponent } from "../../../intelligence/behavior/ecs/BehaviorComponent.js";
22
- import Vector3 from "../../../../core/geom/Vector3.js";
23
16
  import { BehaviorSystem } from "../../../intelligence/behavior/ecs/BehaviorSystem.js";
24
17
  import { RotationBehavior } from "../../../intelligence/behavior/util/RotationBehavior.js";
25
- import { DEG_TO_RAD } from "../../../../core/math/DEG_TO_RAD.js";
18
+ import { SGMesh } from "../../ecs/mesh-v2/aggregate/SGMesh.js";
19
+ import { SGMeshSystem } from "../../ecs/mesh-v2/aggregate/SGMeshSystem.js";
20
+ import { ShadedGeometry } from "../../ecs/mesh-v2/ShadedGeometry.js";
21
+ import { ShadedGeometryFlags } from "../../ecs/mesh-v2/ShadedGeometryFlags.js";
22
+ import { ShadedGeometrySystem } from "../../ecs/mesh-v2/ShadedGeometrySystem.js";
23
+ import { ImpostorBaker } from "./ImpostorBaker.js";
24
+ import { ImpostorCaptureType } from "./ImpostorCaptureType.js";
25
+ import { ImpostorShaderV0 } from "./shader/ImpostorShaderV0.js";
26
26
  import { ImpostorShaderWireframeV0 } from "./shader/ImpostorShaderWireframeV0.js";
27
- import { makeImpostorAtlasPreview } from "./util/makeImpostorAtlasPreview.js";
28
- import { load_mesh_for_bake } from "./util/load_mesh_for_bake.js";
29
27
  import { build_geometry_from_cutout_shape } from "./util/build_geometry_from_cutout_shape.js";
28
+ import { load_mesh_for_bake } from "./util/load_mesh_for_bake.js";
29
+ import { makeImpostorAtlasPreview } from "./util/makeImpostorAtlasPreview.js";
30
30
 
31
31
  /**
32
32
  *
@@ -80,7 +80,7 @@ async function main(engine) {
80
80
  });
81
81
 
82
82
  new Entity()
83
- .add(new ViewportPosition({
83
+ .add(ViewportPosition.fromJSON({
84
84
  offset: new Vector2(0, 0)
85
85
  }))
86
86
  .add(GUIElement.fromView(ctrl))
@@ -1,20 +1,20 @@
1
- import { EngineHarness } from "../../../EngineHarness.js";
2
- import GUIElementSystem from "../../../ecs/gui/GUIElementSystem.js";
3
- import { ImageRGBADataLoader } from "../../../asset/loaders/image/ImageRGBADataLoader.js";
1
+ import { compute_polygon_area_2d } from "../../../../core/geom/2d/compute_polygon_area_2d.js";
2
+ import { convex_hull_jarvis_2d } from "../../../../core/geom/2d/convex-hull/convex_hull_jarvis_2d.js";
3
+ import { fixed_convex_hull_humus } from "../../../../core/geom/2d/convex-hull/fixed_convex_hull_humus.js";
4
+ import Vector2 from "../../../../core/geom/Vector2.js";
5
+ import { CanvasView } from "../../../../view/elements/CanvasView.js";
4
6
  import EmptyView from "../../../../view/elements/EmptyView.js";
7
+ import { ImageRGBADataLoader } from "../../../asset/loaders/image/ImageRGBADataLoader.js";
5
8
  import Entity from "../../../ecs/Entity.js";
6
9
  import GUIElement from "../../../ecs/gui/GUIElement.js";
7
- import ViewportPositionSystem from "../../../ecs/gui/position/ViewportPositionSystem.js";
8
- import { CanvasView } from "../../../../view/elements/CanvasView.js";
9
- import sampler2D2Canvas from "../sampler/Sampler2D2Canvas.js";
10
+ import GUIElementSystem from "../../../ecs/gui/GUIElementSystem.js";
10
11
  import ViewportPosition from "../../../ecs/gui/position/ViewportPosition.js";
11
- import Vector2 from "../../../../core/geom/Vector2.js";
12
- import { convex_hull_jarvis_2d } from "../../../../core/geom/2d/convex-hull/convex_hull_jarvis_2d.js";
12
+ import ViewportPositionSystem from "../../../ecs/gui/position/ViewportPositionSystem.js";
13
+ import { EngineHarness } from "../../../EngineHarness.js";
13
14
  import { Sampler2D } from "../sampler/Sampler2D.js";
14
- import { compute_polygon_area_2d } from "../../../../core/geom/2d/compute_polygon_area_2d.js";
15
- import { sampler2d_find_pixels } from "../sampler/search/sampler2d_find_pixels.js";
15
+ import sampler2D2Canvas from "../sampler/Sampler2D2Canvas.js";
16
16
  import { make_edge_condition_channel_threshold } from "../sampler/search/make_edge_condition_channel_threshold.js";
17
- import { fixed_convex_hull_humus } from "../../../../core/geom/2d/convex-hull/fixed_convex_hull_humus.js";
17
+ import { sampler2d_find_pixels } from "../sampler/search/sampler2d_find_pixels.js";
18
18
 
19
19
  const edge_condition_alpha0 = make_edge_condition_channel_threshold(3, 0);
20
20
 
@@ -195,7 +195,7 @@ async function main(engine) {
195
195
 
196
196
  new Entity()
197
197
  .add(GUIElement.fromView(vContainer))
198
- .add(new ViewportPosition({
198
+ .add(ViewportPosition.fromJSON({
199
199
  offset: new Vector2(100, 100)
200
200
  }))
201
201
  .build(engine.entityManager.dataset);
@@ -0,0 +1,17 @@
1
+ # Sparse Virtual Texture
2
+
3
+ This tech is based on popular Megatexture technique developed for Rage by John Carmack, working at id software.
4
+
5
+ The key idea boils down to having a very large texture that is impractical to keep in memory, and only load and keep in memory pieces of it that are relevant to the current view.
6
+
7
+ There are 2 parts to this technique, offline and online.
8
+
9
+ ## Offline
10
+
11
+ The original texture is mip-mapped, down to the size of a single tile, for the sake of this document let it be 128x128 pixels. Each mip level is then cut into tiles and stored on disk. A good intuition for this is to think of each tile as a separate pixel, representing non-color data.
12
+
13
+ ## Online
14
+
15
+ This is achieved by pre-rendering the scene with a special shader that records UV and mip-level information, which we call `Usage`, this is then analysed to build a list of used tiles (mip level, x, y) and by counting occurrence of this tile in the `Usage` texture we get a much more useful data structure.
16
+
17
+ Based on the `Usage` data, we populate our `Physical` texture of pages, and based on what's currently in the `Physical` texture - we populate the `Reference` texture that stores information about the entire mip pyramid, and for each tile contains a pointer to the `Physical` texture, where representative tile can be found.
@@ -1,6 +1,15 @@
1
1
  function vertex() {
2
2
  return `
3
- varying vec2 vUv;
3
+ precision mediump float;
4
+ precision mediump int;
5
+
6
+ uniform mat4 modelViewMatrix;
7
+ uniform mat4 projectionMatrix;
8
+
9
+ in vec2 uv;
10
+ in vec3 position;
11
+
12
+ out vec2 vUv;
4
13
  void main()
5
14
  {
6
15
  vUv = uv;
@@ -13,32 +22,46 @@ function vertex() {
13
22
 
14
23
  function fragment() {
15
24
  return `
16
- uniform vec4 u_mt_tex; // [ width, height, tileSize, id ]
17
- uniform vec2 u_mt_params; // [ bias, maxLevel, xx, xx ]
18
- varying vec2 vUv;
19
-
20
- float MTCalculateMipLevel( const in vec2 uv, const in float bias ) {
21
- vec2 dx = dFdx( uv * u_mt_tex.x );
22
- vec2 dy = dFdy( uv * u_mt_tex.y );
23
- return log2( max( dot( dx, dx ), dot( dy, dy ) ) ) / 2.0 + bias;
24
- }
25
-
26
- vec4 MTCalculateTileKeyRGBA( const in vec2 uv ) {
27
- float level = clamp( floor( MTCalculateMipLevel( uv, u_mt_params.x ) ), 0.0, u_mt_params.y );
28
- vec2 texIS = uv.xy * u_mt_tex.xy; // [0-1]x[0-1] -> [0-texwidth]x[0-texheight]
29
- vec2 texLS = texIS / exp2( level ); // -> [0-levelwidth]x[0-levelheight]
30
- vec2 texTS = floor( texLS / u_mt_tex.z ); // -> [0->tileswide]x[0-tileshigh]
31
- return vec4( u_mt_params.y - level, texTS.xy, u_mt_tex.w ) / 255.0; // [ level, tileX, tileY, texId ] -> RGBA
32
- }
33
-
25
+ precision highp float;
26
+ precision highp int;
34
27
 
35
- void main(){
36
- vec4 tile = MTCalculateTileKeyRGBA(vUv);
37
- // gl_FragColor = tile;
38
- gl_FragColor = vec4(mix(0.1,1.0,tile.x*255.0/u_mt_params.y), tile.yz*64.0, 1.0);
39
- // gl_FragColor = MTCalculateTileKeyRGBA(vUv);
40
- // gl_FragColor = vec4(1.0);
41
- }
28
+ uniform uvec4 u_mt_tex; // [ width, height, tileSize, id ]
29
+ uniform vec2 u_mt_params; // [ bias, maxLevel ]
30
+ uniform vec2 u_mt_viewport_size;
31
+ in vec2 vUv;
32
+
33
+ out uvec4 out_decoded;
34
+
35
+ float MTCalculateMipLevel( const in vec2 uv, const in float bias ) {
36
+
37
+ float scale_x = float(u_mt_tex.x) / u_mt_viewport_size.x;
38
+ float scale_y = float(u_mt_tex.y) / u_mt_viewport_size.y;
39
+
40
+ vec2 dx = dFdx( uv * scale_x);
41
+ vec2 dy = dFdy( uv * scale_y);
42
+
43
+ return log2( max( dot( dx, dx ), dot( dy, dy ) ) ) * 0.5 + bias;
44
+ }
45
+
46
+ uvec4 MTCalculateTileKeyRGBA( const in vec2 uv ) {
47
+ uint level = clamp( uint( floor( MTCalculateMipLevel( uv, u_mt_params.x ) ) ), 0u, uint(u_mt_params.y) );
48
+
49
+ uint mip_resolution_in_tiles = 1u << level;
50
+
51
+ uint mip_resolution_in_texels = mip_resolution_in_tiles * u_mt_tex.z;
52
+
53
+ vec2 texel_position = fract(uv.xy) * vec2(u_mt_tex.xy);
54
+
55
+ uvec2 tile_position = uvec2( texel_position / float(mip_resolution_in_texels) );
56
+
57
+ // [ level, tileX, tileY, texId ] -> RGBA
58
+ return uvec4( uint(u_mt_params.y) - level, tile_position, u_mt_tex.w );
59
+ }
60
+
61
+
62
+ void main(){
63
+ out_decoded = MTCalculateTileKeyRGBA(vUv);
64
+ }
42
65
  `;
43
66
  }
44
67
 
@@ -0,0 +1,51 @@
1
+ import LabelView from "../../../../../view/common/LabelView.js";
2
+ import EmptyView from "../../../../../view/elements/EmptyView.js";
3
+
4
+ export class UsageDebugView extends EmptyView {
5
+ #tileCount = new LabelView("")
6
+ #tiles = new EmptyView();
7
+
8
+
9
+ constructor(opt) {
10
+ super(opt);
11
+
12
+ this.addChild(this.#tileCount);
13
+ this.addChild(this.#tiles);
14
+
15
+ this.css({
16
+ position: "absolute",
17
+ left: "0",
18
+ top: "0",
19
+ background: "rgba(255,255,255,0.5)",
20
+ fontFamily: "monospace",
21
+ fontSize: "10px"
22
+ });
23
+ }
24
+
25
+ /**
26
+ *
27
+ * @param {UsageMetadata} usage
28
+ */
29
+ set usage(usage) {
30
+
31
+ const tileCount = usage.tile_count;
32
+
33
+ this.#tileCount.updateText(`Tile Count: ${tileCount}`);
34
+
35
+ this.#tiles.removeAllChildren();
36
+
37
+ for (let i = 0; i < tileCount; i++) {
38
+ const finger_print = usage.getTile(i);
39
+ const count = usage.getCount(i);
40
+
41
+ const level = (finger_print >> 24) & 0xFF;
42
+ const x = (finger_print >> 16) & 0xFF;
43
+ const y = (finger_print >> 8) & 0xFF;
44
+ const texture_id = (finger_print) & 0xFF;
45
+
46
+ this.#tiles.addChild(new LabelView(`ID: ${texture_id} Level: ${level} X: ${x} Y: ${y} USAGE: ${count}`));
47
+ }
48
+ }
49
+
50
+
51
+ }