@woosh/meep-engine 2.42.0 → 2.42.1

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 (69) hide show
  1. package/core/assert.js +2 -2
  2. package/core/collection/array/array_swap.js +3 -3
  3. package/core/collection/map/AsyncLoadingCache.js +47 -0
  4. package/core/geom/3d/aabb/aabb3_compute_distance_above_plane_max.js +1 -1
  5. package/core/math/statistics/computeSampleSize_Cochran.js +3 -3
  6. package/editor/ecs/component/editors/geom/QuaternionEditor.js +12 -5
  7. package/engine/Engine.js +6 -1
  8. package/engine/EngineBootstrapper.js +2 -1
  9. package/engine/EngineHarness.js +5 -1
  10. package/engine/asset/AssetManager.js +97 -7
  11. package/engine/development/performance/AbstractMetric.js +1 -0
  12. package/engine/development/performance/RingBufferMetric.js +25 -4
  13. package/engine/ecs/EntityBuilder.js +29 -4
  14. package/engine/graphics/ecs/camera/topdown/TopDownCameraControllerSystem.js +17 -1
  15. package/engine/graphics/ecs/decal/v2/FPDecalSystem.js +18 -30
  16. package/engine/graphics/ecs/decal/v2/prototypeDecalSystem.js +57 -16
  17. package/engine/graphics/ecs/mesh-v2/allocate_v3.js +37 -0
  18. package/engine/graphics/geometry/MikkT/AddTriToGroup.js +10 -0
  19. package/engine/graphics/geometry/MikkT/AssignRecur.js +84 -0
  20. package/engine/graphics/geometry/MikkT/AvgTSpace.js +38 -0
  21. package/engine/graphics/geometry/MikkT/Build4RuleGroups.js +96 -0
  22. package/engine/graphics/geometry/MikkT/BuildNeighborsFast.js +137 -0
  23. package/engine/graphics/geometry/MikkT/CalcTexArea.js +31 -0
  24. package/engine/graphics/geometry/MikkT/CompareSubGroups.js +26 -0
  25. package/engine/graphics/geometry/MikkT/DegenEpilogue.js +220 -0
  26. package/engine/graphics/geometry/MikkT/DegenPrologue.js +115 -0
  27. package/engine/graphics/geometry/MikkT/EvalTspace.js +128 -0
  28. package/engine/graphics/geometry/MikkT/GenerateInitialVerticesIndexList.js +48 -0
  29. package/engine/graphics/geometry/MikkT/GenerateSharedVerticesIndexList.js +184 -0
  30. package/engine/graphics/geometry/MikkT/GenerateTSpaces.js +226 -0
  31. package/engine/graphics/geometry/MikkT/GetEdge.js +45 -0
  32. package/engine/graphics/geometry/MikkT/GetNormal.js +16 -0
  33. package/engine/graphics/geometry/MikkT/GetPosition.js +25 -0
  34. package/engine/graphics/geometry/MikkT/GetTexCoord.js +18 -0
  35. package/engine/graphics/geometry/MikkT/InitTriInfo.js +180 -0
  36. package/engine/graphics/geometry/MikkT/Length.js +10 -0
  37. package/engine/graphics/geometry/MikkT/MakeIndex.js +18 -0
  38. package/engine/graphics/geometry/MikkT/MikkTSpace.js +165 -2197
  39. package/engine/graphics/geometry/MikkT/NormalizeSafe.js +21 -0
  40. package/engine/graphics/geometry/MikkT/NotZero.js +10 -0
  41. package/engine/graphics/geometry/MikkT/QuickSort.js +54 -0
  42. package/engine/graphics/geometry/MikkT/QuickSortEdges.js +71 -0
  43. package/engine/graphics/geometry/MikkT/SSubGroup.js +15 -0
  44. package/engine/graphics/geometry/MikkT/STSpace.js +36 -0
  45. package/engine/graphics/geometry/MikkT/constants/GROUP_WITH_ANY.js +1 -0
  46. package/engine/graphics/geometry/MikkT/constants/INTERNAL_RND_SORT_SEED.js +1 -0
  47. package/engine/graphics/geometry/MikkT/constants/MARK_DEGENERATE.js +1 -0
  48. package/engine/graphics/geometry/MikkT/constants/ORIENT_PRESERVING.js +1 -0
  49. package/engine/graphics/geometry/MikkT/constants/QUAD_ONE_DEGEN_TRI.js +1 -0
  50. package/engine/graphics/geometry/MikkT/m_getNormal.js +16 -0
  51. package/engine/graphics/geometry/MikkT/m_getNumFaces.js +8 -0
  52. package/engine/graphics/geometry/MikkT/m_getNumVerticesOfFace.js +11 -0
  53. package/engine/graphics/geometry/MikkT/m_getPosition.js +20 -0
  54. package/engine/graphics/geometry/MikkT/m_getTexCoord.js +16 -0
  55. package/engine/graphics/geometry/MikkT/m_setTSpace.js +35 -0
  56. package/engine/graphics/geometry/MikkT/m_setTSpaceBasic.js +22 -0
  57. package/engine/graphics/geometry/MikkT/malloc.js +16 -0
  58. package/engine/graphics/geometry/MikkT/v3_scale_dot_sub_normalize.js +52 -0
  59. package/engine/graphics/impostors/octahedral/ImpostorBaker.js +3 -2
  60. package/engine/graphics/impostors/octahedral/prototypeBaker.js +5 -5
  61. package/engine/graphics/render/forward_plus/LightManager.js +16 -6
  62. package/engine/graphics/render/forward_plus/data/TextureBackedMemoryRegion.js +7 -1
  63. package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_ACCUMULATION.js +13 -3
  64. package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_PREAMBLE.js +2 -1
  65. package/engine/graphics/render/forward_plus/plugin/MaterialTransformer.js +14 -2
  66. package/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_texture.js +2 -2
  67. package/engine/intelligence/behavior/util/RotationBehavior.js +69 -0
  68. package/generation/example/filters/SampleGroundMoistureFilter.js +5 -5
  69. package/package.json +1 -1
@@ -0,0 +1,21 @@
1
+ import { Length } from "./Length.js";
2
+ import { vec3 } from "gl-matrix";
3
+
4
+ /**
5
+ *
6
+ * @param {vec3} out
7
+ * @param {vec3} input
8
+ */
9
+ export function NormalizeSafe(out, input) {
10
+
11
+ const len = Length(input);
12
+
13
+ if (len !== 0) {
14
+ const m = 1 / len;
15
+
16
+ vec3.scale(out, input, m)
17
+
18
+ } else {
19
+ vec3.copy(out, input);
20
+ }
21
+ }
@@ -0,0 +1,10 @@
1
+ import { EPSILON } from "../../../../core/math/MathUtils.js";
2
+
3
+ /**
4
+ *
5
+ * @param {number} v
6
+ * @returns {boolean}
7
+ */
8
+ export function NotZero(v) {
9
+ return Math.abs(v) > EPSILON;
10
+ }
@@ -0,0 +1,54 @@
1
+ import { assert } from "../../../../core/assert.js";
2
+
3
+ /**
4
+ *
5
+ * @param {number[]|ArrayLike<number>|Uint32Array|Int32Array} pSortBuffer
6
+ * @param {number} iLeft
7
+ * @param {number} iRight
8
+ * @param {number} uSeed
9
+ * @returns {void}
10
+ */
11
+ export function QuickSort(pSortBuffer, iLeft, iRight, uSeed) {
12
+ let iL, iR, n, index, iMid, iTmp;
13
+
14
+ // Random
15
+ let t = uSeed & 31;
16
+ t = (uSeed << t) | (uSeed >> (32 - t));
17
+ uSeed = uSeed + t + 3;
18
+ uSeed = uSeed >>> 0; // make unsigned
19
+ // Random end
20
+
21
+ iL = iLeft;
22
+ iR = iRight;
23
+ n = (iR - iL) + 1;
24
+
25
+ assert.greaterThanOrEqual(n , 0);
26
+
27
+ index = (uSeed % n);
28
+
29
+ iMid = pSortBuffer[index + iL];
30
+
31
+
32
+ do {
33
+ while (pSortBuffer[iL] < iMid)
34
+ ++iL;
35
+ while (pSortBuffer[iR] > iMid)
36
+ --iR;
37
+
38
+ if (iL <= iR) {
39
+
40
+ iTmp = pSortBuffer[iL];
41
+ pSortBuffer[iL] = pSortBuffer[iR];
42
+ pSortBuffer[iR] = iTmp;
43
+
44
+ ++iL;
45
+ --iR;
46
+ }
47
+ }
48
+ while (iL <= iR);
49
+
50
+ if (iLeft < iR)
51
+ QuickSort(pSortBuffer, iLeft, iR, uSeed);
52
+ if (iL < iRight)
53
+ QuickSort(pSortBuffer, iL, iRight, uSeed);
54
+ }
@@ -0,0 +1,71 @@
1
+ import { array_swap } from "../../../../core/collection/array/array_swap.js";
2
+ import { assert } from "../../../../core/assert.js";
3
+
4
+ /**
5
+ *
6
+ * @param {number[]} pSortBuffer
7
+ * @param {number} iLeft
8
+ * @param {number} iRight
9
+ * @param {number} channel
10
+ * @param {number} uSeed
11
+ * @returns {void}
12
+ */
13
+ export function QuickSortEdges(pSortBuffer, iLeft, iRight, channel, uSeed) {
14
+ let t;
15
+ let iL, iR, n, index, iMid;
16
+
17
+ // early out
18
+ const iElems = iRight - iLeft + 1;
19
+
20
+ if (iElems < 2) {
21
+ return;
22
+ } else if (iElems === 2) {
23
+
24
+ if (pSortBuffer[iLeft * 3 + channel] > pSortBuffer[iRight * 3 + channel]) {
25
+
26
+ array_swap(pSortBuffer, iLeft * 3, pSortBuffer, iRight * 3, 3); // swap elements
27
+
28
+ }
29
+
30
+ return;
31
+ }
32
+
33
+ // Random
34
+ t = uSeed & 31;
35
+ t = (uSeed << t) | (uSeed >> (32 - t));
36
+ uSeed = uSeed + t + 3;
37
+
38
+ uSeed = uSeed >>> 0; // make unsigned
39
+ // Random end
40
+
41
+ iL = iLeft;
42
+ iR = iRight;
43
+ n = (iR - iL) + 1;
44
+
45
+ assert.greaterThanOrEqual(n, 0);
46
+
47
+ index = (uSeed % n);
48
+
49
+ iMid = pSortBuffer[(index + iL) * 3 + channel];
50
+
51
+ do {
52
+ while (pSortBuffer[iL * 3 + channel] < iMid)
53
+ ++iL;
54
+ while (pSortBuffer[iR * 3 + channel] > iMid)
55
+ --iR;
56
+
57
+ if (iL <= iR) {
58
+
59
+ array_swap(pSortBuffer, iL * 3, pSortBuffer, iR * 3, 3); // do swap
60
+
61
+ ++iL;
62
+ --iR;
63
+ }
64
+ }
65
+ while (iL <= iR);
66
+
67
+ if (iLeft < iR)
68
+ QuickSortEdges(pSortBuffer, iLeft, iR, channel, uSeed);
69
+ if (iL < iRight)
70
+ QuickSortEdges(pSortBuffer, iL, iRight, channel, uSeed);
71
+ }
@@ -0,0 +1,15 @@
1
+ export class SSubGroup {
2
+ constructor() {
3
+ /**
4
+ *
5
+ * @type {number}
6
+ */
7
+ this.iNrFaces = 0;
8
+
9
+ /**
10
+ * *int
11
+ * @type {Int32Array|null}
12
+ */
13
+ this.pTriMembers = null;
14
+ }
15
+ }
@@ -0,0 +1,36 @@
1
+ import { vec3 } from "gl-matrix";
2
+ import { allocate_v3 } from "../../ecs/mesh-v2/allocate_v3.js";
3
+
4
+ export class STSpace {
5
+ constructor() {
6
+ /**
7
+ *
8
+ * @type {vec3|Float32Array}
9
+ */
10
+ this.vOs = allocate_v3();
11
+ /**
12
+ *
13
+ * @type {vec3|Float32Array}
14
+ */
15
+ this.vOt = allocate_v3();
16
+
17
+ this.fMagS = 0;
18
+ this.fMagT = 0;
19
+
20
+ this.iCounter = 0; // this is to average back into quads.
21
+ this.bOrient = false;
22
+ }
23
+
24
+ /**
25
+ *
26
+ * @param {STSpace} other
27
+ */
28
+ copy(other) {
29
+ vec3.copy(this.vOs, other.vOs);
30
+ this.fMagS = other.fMagS;
31
+ vec3.copy(this.vOt, other.vOt);
32
+ this.fMagT = other.fMagT;
33
+ this.iCounter = other.iCounter;
34
+ this.bOrient = other.bOrient;
35
+ }
36
+ }
@@ -0,0 +1 @@
1
+ export const GROUP_WITH_ANY = 4;
@@ -0,0 +1 @@
1
+ export const INTERNAL_RND_SORT_SEED = 39871946;
@@ -0,0 +1 @@
1
+ export const MARK_DEGENERATE = 1;
@@ -0,0 +1 @@
1
+ export const ORIENT_PRESERVING = 8;
@@ -0,0 +1 @@
1
+ export const QUAD_ONE_DEGEN_TRI = 2;
@@ -0,0 +1,16 @@
1
+ import { array_copy } from "../../../../core/collection/array/copyArray.js";
2
+
3
+ /**
4
+ *
5
+ * @param {SMikkTSpaceContext} pContext
6
+ * @param {number[]|{0:number,1:number,2:number}} fvNormOut
7
+ * @param {number} iFace
8
+ * @param {number} iVert
9
+ * @returns {void}
10
+ */
11
+ export function m_getNormal(pContext, fvNormOut, iFace, iVert) {
12
+ // figure out which vertex it is
13
+ const vertex_index = pContext.geometry_buffer_index[iFace * 3 + iVert];
14
+
15
+ array_copy(pContext.geometry_buffer_vertex_normal, vertex_index * 3, fvNormOut, 0, 3);
16
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Returns the number of faces (triangles/quads) on the mesh to be processed.
3
+ * @param {SMikkTSpaceContext} pContext
4
+ * @returns {number}
5
+ */
6
+ export function m_getNumFaces(pContext) {
7
+ return pContext.geometry_buffer_index.length / 3;
8
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Returns the number of vertices on face number iFace
3
+ * iFace is a number in the range {0, 1, ..., getNumFaces()-1}
4
+ * @param {SMikkTSpaceContext} pContext
5
+ * @param {number} iFace
6
+ * @returns {number}
7
+ */
8
+ function m_getNumVerticesOfFace(pContext, iFace) {
9
+ // only support triangles
10
+ return 3;
11
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ *
3
+ * @param {SMikkTSpaceContext} pContext
4
+ * @param {number[]|{0:number,1:number,2:number}} fvPosOut
5
+ * @param {number} iFace
6
+ * @param {number} iVert
7
+ * @returns {void}
8
+ */
9
+ export function m_getPosition(pContext, fvPosOut, iFace, iVert) {
10
+ // figure out which vertex it is
11
+ const vertex_index = pContext.geometry_buffer_index[iFace * 3 + iVert];
12
+
13
+ const position = pContext.geometry_buffer_vertex_position;
14
+
15
+ const position_offset = vertex_index * 3;
16
+
17
+ fvPosOut[0] = position[position_offset];
18
+ fvPosOut[1] = position[position_offset + 1];
19
+ fvPosOut[2] = position[position_offset + 2];
20
+ }
@@ -0,0 +1,16 @@
1
+ import { array_copy } from "../../../../core/collection/array/copyArray.js";
2
+
3
+ /**
4
+ *
5
+ * @param {SMikkTSpaceContext} pContext
6
+ * @param {number[]|{0:number,1:number}} fvTexcOut
7
+ * @param {number} iFace
8
+ * @param {number} iVert
9
+ * @returns {void}
10
+ */
11
+ export function m_getTexCoord(pContext, fvTexcOut, iFace, iVert) {
12
+ // figure out which vertex it is
13
+ const vertex_index = pContext.geometry_buffer_index[iFace * 3 + iVert];
14
+
15
+ array_copy(pContext.geometry_buffer_vertex_uv, vertex_index * 2, fvTexcOut, 0, 3);
16
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ *
3
+ * @param {SMikkTSpaceContext} pContext
4
+ * @param {number[]} tangent
5
+ * @param {number[]} bi_tangent
6
+ * @param {number} fMagS
7
+ * @param {number} fMagT
8
+ * @param {boolean} bi_tangent_preserves_orientation
9
+ * @param {number} iFace
10
+ * @param {number} iVert
11
+ * @returns {void}
12
+ */
13
+ export function m_setTSpace(
14
+ pContext,
15
+ tangent,
16
+ bi_tangent,
17
+ fMagS,
18
+ fMagT,
19
+ bi_tangent_preserves_orientation,
20
+ iFace,
21
+ iVert
22
+ ) {
23
+
24
+ // figure out which vertex it is
25
+ const vertex_index = pContext.geometry_buffer_index[iFace * 3 + iVert];
26
+
27
+ const tangent_destination = pContext.geometry_buffer_vertex_tangent;
28
+ const tangent_address = vertex_index * 4;
29
+
30
+ // for logic explanation, see https://github.com/gltf-rs/mikktspace/blob/6275cc4f15cff8be29819fb34ae8be3b9129dae1/src/lib.rs#L33
31
+ tangent_destination[tangent_address] = tangent[0];
32
+ tangent_destination[tangent_address + 1] = tangent[1];
33
+ tangent_destination[tangent_address + 2] = tangent[2];
34
+ tangent_destination[tangent_address + 3] = bi_tangent_preserves_orientation ? 1 : -1;
35
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * either (or both) of the two setTSpace callbacks can be set.
3
+ * The call-back m_setTSpaceBasic() is sufficient for basic normal mapping.
4
+ *
5
+ * This function is used to return the tangent and fSign to the application.
6
+ * fvTangent is a unit length vector.
7
+ * For normal maps it is sufficient to use the following simplified version of the bitangent which is generated at pixel/vertex level.
8
+ * bitangent = fSign * cross(vN, tangent);
9
+ * Note that the results are returned unindexed. It is possible to generate a new index list
10
+ * But averaging/overwriting tangent spaces by using an already existing index list WILL produce INCRORRECT results.
11
+ * DO NOT! use an already existing index list.
12
+ *
13
+ * @param {SMikkTSpaceContext} pContext
14
+ * @param {number[]} fvTangent
15
+ * @param {number} fSign
16
+ * @param {number} iFace
17
+ * @param {number} iVert
18
+ * @returns {void}
19
+ */
20
+ function m_setTSpaceBasic(pContext, fvTangent, fSign, iFace, iVert) {
21
+ throw new Error('Not supported');
22
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Mimics C malloc somewhat, allocates an array of class instances of fixed size
3
+ * @template T
4
+ * @param {constructor<T>} Klass
5
+ * @param {number} count
6
+ * @returns {T[]}
7
+ */
8
+ export function malloc(Klass, count) {
9
+ const r = new Array(count);
10
+
11
+ for (let i = 0; i < count; i++) {
12
+ r[i] = new Klass();
13
+ }
14
+
15
+ return r;
16
+ }
@@ -0,0 +1,52 @@
1
+ import { vec3 } from "gl-matrix";
2
+ import { v3_length } from "../../../../core/geom/v3_length.js";
3
+ import { v3_dot } from "../../../../core/geom/v3_dot.js";
4
+
5
+ /**
6
+ * executes following formula: v1 - v0*( dot(v0,v1) )
7
+ * @param {vec3} out
8
+ * @param {vec3} v0
9
+ * @param {vec3} v1
10
+ */
11
+ export function v3_scale_dot_sub_normalize(out, v0, v1) {
12
+ const v0x = v0[0];
13
+ const v0y = v0[1];
14
+ const v0z = v0[2];
15
+
16
+ const v1x = v1[0];
17
+ const v1y = v1[1];
18
+ const v1z = v1[2];
19
+
20
+ // dot product
21
+ const _dot = v3_dot(v0x, v0y, v0z, v1x, v1y, v1z);
22
+
23
+ // scale
24
+ const _x0 = v0x * _dot;
25
+ const _y0 = v0y * _dot;
26
+ const _z0 = v0z * _dot;
27
+
28
+ // subtract
29
+ const _x1 = v1x - _x0;
30
+ const _z1 = v1z - _z0;
31
+ const _y1 = v1y - _y0;
32
+
33
+ // "safe" normalization
34
+ const len = v3_length(_x1, _y1, _z1);
35
+
36
+ if (len !== 0) {
37
+
38
+ const m = 1 / len;
39
+
40
+ out[0] = _x1 * m;
41
+ out[1] = _y1 * m;
42
+ out[2] = _z1 * m;
43
+
44
+ } else {
45
+
46
+ out[0] = _x1;
47
+ out[1] = _y1;
48
+ out[2] = _z1;
49
+
50
+ }
51
+
52
+ }
@@ -16,6 +16,7 @@ import { HemiOctahedralUvEncoder } from "./grid/HemiOctahedralUvEncoder.js";
16
16
  import { prepare_bake_material } from "./bake/prepare_bake_material.js";
17
17
  import { collectIteratorValueToArray } from "../../../../core/collection/IteratorUtils.js";
18
18
  import { compute_bounding_sphere } from "./bake/compute_bounding_sphere.js";
19
+ import { buffer_geometry_ensure_tangents } from "../../geometry/MikkT/buffer_geometry_ensure_tangents.js";
19
20
 
20
21
  export class ImpostorBaker {
21
22
 
@@ -133,7 +134,7 @@ export class ImpostorBaker {
133
134
  const source_mesh = object.mesh;
134
135
 
135
136
  // ensure tangents are generated
136
- //buffer_geometry_ensure_tangents(source_mesh.geometry);
137
+ buffer_geometry_ensure_tangents(source_mesh.geometry);
137
138
 
138
139
  const source_material = source_mesh.material;
139
140
 
@@ -336,7 +337,7 @@ export class ImpostorBaker {
336
337
 
337
338
  r.capture_type = type;
338
339
  r.sphere_radius = bounding_sphere[3];
339
- vec3.copy(r.offset,bounding_sphere);
340
+ vec3.copy(r.offset, bounding_sphere);
340
341
 
341
342
  console.timeEnd('bake');
342
343
 
@@ -28,7 +28,7 @@ import { TransformAttachmentSystem } from "../../../ecs/transform-attachment/Tra
28
28
  import { BehaviorComponent } from "../../../intelligence/behavior/ecs/BehaviorComponent.js";
29
29
  import Vector3 from "../../../../core/geom/Vector3.js";
30
30
  import { BehaviorSystem } from "../../../intelligence/behavior/ecs/BehaviorSystem.js";
31
- import { RotationBehavior } from "../../../../../model/game/util/behavior/RotationBehavior.js";
31
+ import { RotationBehavior } from "../../../intelligence/behavior/util/RotationBehavior.js";
32
32
 
33
33
  /**
34
34
  *
@@ -47,9 +47,9 @@ async function main(engine) {
47
47
  baker.renderer = renderer;
48
48
 
49
49
 
50
- const path = 'data/models/LowPolyTownshipSet/Small_house/Small_house.gltf';
50
+ // const path = 'data/models/LowPolyTownshipSet/Small_house/Small_house.gltf';
51
51
  // const path = 'data/models/LowPolyTownshipSet/Barrel/model.gltf';
52
- // const path = 'data/models/LowPolyTownshipSet/Town_Hall/model.gltf';
52
+ const path = 'data/models/LowPolyTownshipSet/Town_Hall/model.gltf';
53
53
  // const path = 'data/models/RTS_Buildings_Humans/18/Building_R_18_out/Building_R_18.gltf';
54
54
  // const path = 'data/models/MOBA and Tower Defense/Tree_01.gltf';
55
55
  // const path = 'data/models/samples/transform-hierarchy.glb';
@@ -88,14 +88,14 @@ async function main(engine) {
88
88
  // }
89
89
  // );
90
90
 
91
- // console.profile('bake');
91
+ console.profile('bake');
92
92
  const id = baker.bake({
93
93
  objects,
94
94
  frames: 16,
95
95
  resolution: 2048,
96
96
  type: ImpostorCaptureType.FullSphere
97
97
  });
98
- // console.profileEnd('bake');
98
+ console.profileEnd('bake');
99
99
 
100
100
  console.log(id);
101
101
 
@@ -403,10 +403,11 @@ export class LightManager {
403
403
  /**
404
404
  *
405
405
  * @param {number} size
406
+ * @returns {boolean}
406
407
  * @private
407
408
  */
408
409
  __ensure_lookup_size(size) {
409
- this.__lookup_data.resize(size);
410
+ return this.__lookup_data.resize(size);
410
411
  }
411
412
 
412
413
  /**
@@ -451,8 +452,11 @@ export class LightManager {
451
452
  *
452
453
  * @private
453
454
  */
454
- __request_update_visible_bvh() {
455
+ __handle_light_dimensions_change() {
456
+ // internal BVH needs to be rebuilt
455
457
  this.__visible_bvh_needs_update = true;
458
+ // when dimensions change, typically data will need to be re-written to the GPU, things like light positions or projection matrix
459
+ this.__light_data_needs_update = true;
456
460
  }
457
461
 
458
462
  /**
@@ -465,7 +469,7 @@ export class LightManager {
465
469
 
466
470
  const light = data.light;
467
471
 
468
- light.onDimensionChanged(this.__request_update_visible_bvh, this);
472
+ light.onDimensionChanged(this.__handle_light_dimensions_change, this);
469
473
 
470
474
  if (light instanceof Decal) {
471
475
  const ref = this.__decal_patch_references.acquire(light.texture_diffuse);
@@ -494,7 +498,7 @@ export class LightManager {
494
498
  this.__light_data_needs_update = true;
495
499
 
496
500
  const light = data.light;
497
- light.offDimensionChanged(this.__request_update_visible_bvh, this);
501
+ light.offDimensionChanged(this.__handle_light_dimensions_change, this);
498
502
 
499
503
  if (light instanceof Decal) {
500
504
  const ref = this.__decal_references.get(light);
@@ -959,11 +963,14 @@ export class LightManager {
959
963
  // Post-fact lookup texture resize, this frame will be wrong, but next one should be ok
960
964
  const current_lookup_size = this.__lookup_data.size;
961
965
 
962
- this.__ensure_lookup_size(assignment_count);
966
+ const lookup_memory_resized = this.__ensure_lookup_size(assignment_count);
963
967
 
964
968
  const cluster_resized = this.__set_cluster_addressable_bit_range(Math.max(0, Math.log2(lookup_address_offset)));
965
969
 
966
- if (current_lookup_size < assignment_count || cluster_resized) {
970
+ if (
971
+ (lookup_memory_resized && current_lookup_size < assignment_count)
972
+ || cluster_resized
973
+ ) {
967
974
  this.__update_cluster_texture();
968
975
 
969
976
  // re-do assignment
@@ -1137,6 +1144,9 @@ export class LightManager {
1137
1144
  this.__sort_visible_light();
1138
1145
 
1139
1146
  this.__write_light_data_texture();
1147
+
1148
+ // clear flag
1149
+ this.__light_data_needs_update = false;
1140
1150
  }
1141
1151
  // console.timeEnd('__write_light_data_texture');
1142
1152
 
@@ -90,7 +90,7 @@ export class TextureBackedMemoryRegion {
90
90
  this.__data_type = DataType.Uint8;
91
91
  }
92
92
 
93
- get concrete_type(){
93
+ get concrete_type() {
94
94
  return this.__data_type;
95
95
  }
96
96
 
@@ -234,6 +234,7 @@ export class TextureBackedMemoryRegion {
234
234
  /**
235
235
  *
236
236
  * @param {number} size
237
+ * @returns {boolean} whether container was resized or not
237
238
  */
238
239
  resize(size) {
239
240
  assert.isNonNegativeInteger(size, 'size');
@@ -252,11 +253,16 @@ export class TextureBackedMemoryRegion {
252
253
  //Over-provision to prevent thrashing
253
254
  this.__height = Math.ceil(target_height * GROW_FACTOR);
254
255
  this.needsRebuild = true;
256
+ return true;
255
257
  } else if (current_height * SHRINK_FACTOR > target_height) {
256
258
  // texture too large, lets shrink it down
257
259
  this.__height = target_height;
258
260
  this.needsRebuild = true;
261
+ return true;
259
262
  }
263
+
264
+ // no actual container change
265
+ return false;
260
266
  }
261
267
 
262
268
  /**
@@ -64,13 +64,23 @@ export const FP_SHADER_CHUNK_ACCUMULATION = `
64
64
  // we fade out decals when the projection angle to the surface gets too steep
65
65
  // 0.7 is cos(45deg) and 0.5 is cos(60deg), dot returns cos of angle between two normals
66
66
  float decal_surface_angle_fade = smoothstep(-0.5,-0.7,decal_surface_dot);
67
+
68
+ if(decal_surface_angle_fade <= 0.0){
69
+ continue;
70
+ }
67
71
 
68
- vec2 decal_uv = (local_position.xy + 0.5)*light_data_4.zw + light_data_4.xy;
72
+ vec2 decal_local_uv = (local_position.xy + 0.5);
73
+ vec2 decal_uv = decal_local_uv*light_data_4.zw + light_data_4.xy;
69
74
 
70
- vec4 decal_color = texture(fp_t_decal_atlas, decal_uv);
75
+ vec4 decal_color = texture2D(fp_t_decal_atlas,decal_uv, -0.2);
71
76
 
77
+ // compute decal alpha
72
78
  float decal_alpha = decal_color.a * decal_surface_angle_fade;
73
-
79
+
80
+ if(decal_alpha < 0.003){
81
+ continue;
82
+ }
83
+
74
84
  material.diffuseColor = material.diffuseColor*(1.0-decal_alpha) + decal_color.xyz*decal_alpha;
75
85
  }
76
86
 
@@ -6,6 +6,7 @@ export const FP_SHADER_CHUNK_PREAMBLE = `precision mediump usampler3D;
6
6
  uniform usampler2D fp_t_light_lookup;
7
7
  uniform sampler2D fp_t_light_data;
8
8
  uniform sampler2D fp_t_decal_atlas;
9
+ uniform vec2 fp_t_decal_atlas_resolution;
9
10
 
10
11
  uniform vec3 fp_v3_light_cluster_resolution;
11
12
 
@@ -23,5 +24,5 @@ export const FP_SHADER_CHUNK_PREAMBLE = `precision mediump usampler3D;
23
24
  #define texture2DProjGradEXT textureProjGrad
24
25
  #define textureCubeGradEXT textureGrad
25
26
 
26
- uniform vec2 fp_resolution;
27
+ uniform vec2 fp_resolution;
27
28
  `;