@woosh/meep-engine 2.41.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 (98) 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/geom/3d/apply_mat4_transform_to_v3_array.js +2 -4
  6. package/core/geom/3d/sphere/sphere_radius_sqr_from_v3_array_transformed.js +28 -0
  7. package/core/geom/Quaternion.js +14 -0
  8. package/core/math/statistics/computeSampleSize_Cochran.js +3 -3
  9. package/editor/ecs/component/editors/geom/QuaternionEditor.js +12 -5
  10. package/engine/Engine.js +6 -1
  11. package/engine/EngineBootstrapper.js +2 -1
  12. package/engine/EngineHarness.js +13 -3
  13. package/engine/asset/AssetManager.js +97 -7
  14. package/engine/development/performance/AbstractMetric.js +1 -0
  15. package/engine/development/performance/RingBufferMetric.js +25 -4
  16. package/engine/ecs/EntityBuilder.js +29 -4
  17. package/engine/ecs/transform/Transform.js +23 -3
  18. package/engine/graphics/ecs/camera/topdown/TopDownCameraControllerSystem.js +17 -1
  19. package/engine/graphics/ecs/decal/v2/Decal.d.ts +11 -0
  20. package/engine/graphics/ecs/decal/v2/Decal.js +50 -0
  21. package/engine/graphics/ecs/decal/v2/FPDecalSystem.d.ts +8 -0
  22. package/engine/graphics/ecs/decal/v2/FPDecalSystem.js +201 -0
  23. package/engine/graphics/ecs/decal/v2/prototypeDecalSystem.js +278 -0
  24. package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +8 -1
  25. package/engine/graphics/ecs/mesh-v2/allocate_v3.js +37 -0
  26. package/engine/graphics/ecs/mesh-v2/build_three_object.js +4 -0
  27. package/engine/graphics/geometry/MikkT/AddTriToGroup.js +10 -0
  28. package/engine/graphics/geometry/MikkT/AssignRecur.js +84 -0
  29. package/engine/graphics/geometry/MikkT/AvgTSpace.js +38 -0
  30. package/engine/graphics/geometry/MikkT/Build4RuleGroups.js +96 -0
  31. package/engine/graphics/geometry/MikkT/BuildNeighborsFast.js +137 -0
  32. package/engine/graphics/geometry/MikkT/CalcTexArea.js +31 -0
  33. package/engine/graphics/geometry/MikkT/CompareSubGroups.js +26 -0
  34. package/engine/graphics/geometry/MikkT/DegenEpilogue.js +220 -0
  35. package/engine/graphics/geometry/MikkT/DegenPrologue.js +115 -0
  36. package/engine/graphics/geometry/MikkT/EvalTspace.js +128 -0
  37. package/engine/graphics/geometry/MikkT/GenerateInitialVerticesIndexList.js +48 -0
  38. package/engine/graphics/geometry/MikkT/GenerateSharedVerticesIndexList.js +184 -0
  39. package/engine/graphics/geometry/MikkT/GenerateTSpaces.js +226 -0
  40. package/engine/graphics/geometry/MikkT/GetEdge.js +45 -0
  41. package/engine/graphics/geometry/MikkT/GetNormal.js +16 -0
  42. package/engine/graphics/geometry/MikkT/GetPosition.js +25 -0
  43. package/engine/graphics/geometry/MikkT/GetTexCoord.js +18 -0
  44. package/engine/graphics/geometry/MikkT/InitTriInfo.js +180 -0
  45. package/engine/graphics/geometry/MikkT/Length.js +10 -0
  46. package/engine/graphics/geometry/MikkT/MakeIndex.js +18 -0
  47. package/engine/graphics/geometry/MikkT/MikkTSpace.js +197 -2068
  48. package/engine/graphics/geometry/MikkT/NormalizeSafe.js +21 -0
  49. package/engine/graphics/geometry/MikkT/NotZero.js +10 -0
  50. package/engine/graphics/geometry/MikkT/QuickSort.js +54 -0
  51. package/engine/graphics/geometry/MikkT/QuickSortEdges.js +71 -0
  52. package/engine/graphics/geometry/MikkT/SSubGroup.js +15 -0
  53. package/engine/graphics/geometry/MikkT/STSpace.js +36 -0
  54. package/engine/graphics/geometry/MikkT/constants/GROUP_WITH_ANY.js +1 -0
  55. package/engine/graphics/geometry/MikkT/constants/INTERNAL_RND_SORT_SEED.js +1 -0
  56. package/engine/graphics/geometry/MikkT/constants/MARK_DEGENERATE.js +1 -0
  57. package/engine/graphics/geometry/MikkT/constants/ORIENT_PRESERVING.js +1 -0
  58. package/engine/graphics/geometry/MikkT/constants/QUAD_ONE_DEGEN_TRI.js +1 -0
  59. package/engine/graphics/geometry/MikkT/m_getNormal.js +16 -0
  60. package/engine/graphics/geometry/MikkT/m_getNumFaces.js +8 -0
  61. package/engine/graphics/geometry/MikkT/m_getNumVerticesOfFace.js +11 -0
  62. package/engine/graphics/geometry/MikkT/m_getPosition.js +20 -0
  63. package/engine/graphics/geometry/MikkT/m_getTexCoord.js +16 -0
  64. package/engine/graphics/geometry/MikkT/m_setTSpace.js +35 -0
  65. package/engine/graphics/geometry/MikkT/m_setTSpaceBasic.js +22 -0
  66. package/engine/graphics/geometry/MikkT/malloc.js +16 -0
  67. package/engine/graphics/geometry/MikkT/v3_scale_dot_sub_normalize.js +52 -0
  68. package/engine/graphics/geometry/buffered/computeGeometryEquality.js +1 -1
  69. package/engine/graphics/geometry/buffered/computeGeometryHash.js +1 -1
  70. package/engine/graphics/impostors/octahedral/ImpostorBaker.js +28 -14
  71. package/engine/graphics/impostors/octahedral/ImpostorDescription.js +6 -0
  72. package/engine/graphics/impostors/octahedral/README.md +1 -0
  73. package/engine/graphics/impostors/octahedral/bake/compute_bounding_sphere.js +25 -22
  74. package/engine/graphics/impostors/octahedral/bake/compute_bounding_sphere_radius_only.js +37 -0
  75. package/engine/graphics/impostors/octahedral/bake/prepare_bake_material.js +30 -1
  76. package/engine/graphics/impostors/octahedral/grid/HemiOctahedralUvEncoder.js +1 -1
  77. package/engine/graphics/impostors/octahedral/prototypeBaker.js +121 -22
  78. package/engine/graphics/impostors/octahedral/shader/BakeShaderStandard.js +46 -7
  79. package/engine/graphics/impostors/octahedral/shader/ImpostorShaderV0.js +349 -0
  80. package/engine/graphics/impostors/octahedral/shader/ImpostorShaderV1.js +74 -0
  81. package/engine/graphics/impostors/octahedral/shader/glsl/v1/common.glsl +209 -0
  82. package/engine/graphics/impostors/octahedral/shader/glsl/v1/flagment.glsl +80 -0
  83. package/engine/graphics/impostors/octahedral/shader/glsl/v1/vertex.glsl +350 -0
  84. package/engine/graphics/micron/render/v1/getTransformedPositionsCached.js +1 -1
  85. package/engine/graphics/render/forward_plus/LightManager.js +17 -7
  86. package/engine/graphics/render/forward_plus/data/TextureBackedMemoryRegion.js +7 -1
  87. package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_ACCUMULATION.js +13 -5
  88. package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_PREAMBLE.js +3 -1
  89. package/engine/graphics/render/forward_plus/model/Decal.js +19 -2
  90. package/engine/graphics/render/forward_plus/plugin/MaterialTransformer.js +14 -2
  91. package/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_texture.js +2 -2
  92. package/engine/graphics/texture/sampler/Sampler2D.js +10 -10
  93. package/engine/graphics/texture/sampler/prototypeSamplerFiltering.js +117 -11
  94. package/engine/graphics/texture/sampler/resize/sampler2d_downsample_mipmap.js +66 -0
  95. package/engine/graphics/texture/sampler/sampler2_d_scale_down_lanczos.js +2 -2
  96. package/engine/intelligence/behavior/util/RotationBehavior.js +69 -0
  97. package/generation/example/filters/SampleGroundMoistureFilter.js +5 -5
  98. package/package.json +1 -1
@@ -0,0 +1,350 @@
1
+ const float aabb_max = 1.0;
2
+
3
+ uniform float uFrames;
4
+ uniform bool uIsFullSphere;
5
+ uniform float uRadius;
6
+ uniform vec3 uOffset;
7
+
8
+ // = object.matrixWorld
9
+ uniform mat4 modelMatrix;
10
+
11
+ // = camera.matrixWorldInverse * object.matrixWorld
12
+ uniform mat4 modelViewMatrix;
13
+
14
+ // = camera.projectionMatrix
15
+ uniform mat4 projectionMatrix;
16
+
17
+ // = camera.matrixWorldInverse
18
+ uniform mat4 viewMatrix;
19
+
20
+ // = inverse transpose of modelViewMatrix
21
+ uniform mat3 normalMatrix;
22
+
23
+ // = camera position in world space
24
+ uniform vec3 cameraPosition;
25
+
26
+ in vec2 uv;
27
+
28
+ out vec2 uv_frame1;
29
+ out vec2 xy_frame1;
30
+ flat out vec2 frame1;
31
+ flat out vec3 frame1_normal;
32
+ out vec2 uv_frame2;
33
+ out vec2 xy_frame2;
34
+ flat out vec2 frame2;
35
+ flat out vec3 frame2_normal;
36
+ out vec2 uv_frame3;
37
+ out vec2 xy_frame3;
38
+ flat out vec2 frame3;
39
+ flat out vec3 frame3_normal;
40
+ out vec4 quad_blend_weights;
41
+
42
+ vec2 VecToSphereOct(vec3 pivotToCamera)
43
+ {
44
+ vec3 octant = sign(pivotToCamera);
45
+
46
+ // |x| + |y| + |z| = 1
47
+ float sum = dot(pivotToCamera, octant);
48
+ vec3 octahedron = pivotToCamera / sum;
49
+
50
+ if (octahedron.y < 0.0){
51
+ vec3 absolute = abs(octahedron);
52
+ octahedron.xz = octant.xz * vec2(1.0 - absolute.z, 1.0 - absolute.x);
53
+ }
54
+ return octahedron.xz;
55
+ }
56
+
57
+ //for hemisphere
58
+ vec2 VecToHemiSphereOct(vec3 vec)
59
+ {
60
+ vec.y = max(vec.y, 0.001);
61
+ vec = normalize(vec);
62
+ vec3 octant = sign(vec);
63
+
64
+ // |x| + |y| + |z| = 1
65
+ float sum = dot(vec, octant);
66
+ vec3 octahedron = vec / sum;
67
+
68
+ return vec2(
69
+ octahedron.x + octahedron.z,
70
+ octahedron.z - octahedron.x
71
+ );
72
+ }
73
+
74
+ vec2 VectorToGrid(vec3 vec)
75
+ {
76
+ if (uIsFullSphere)
77
+ {
78
+ return VecToSphereOct(vec);
79
+ }
80
+ else
81
+ {
82
+ return VecToHemiSphereOct(vec);
83
+ }
84
+ }
85
+ //for sphere
86
+ vec3 OctaSphereEnc(vec2 coord)
87
+ {
88
+ coord = (coord - 0.5) * 2.0;
89
+ vec3 position = vec3(coord.x, 0.0, coord.y);
90
+ vec2 absolute = abs(position.xz);
91
+ position.y = 1.0 - absolute.x - absolute.y;
92
+
93
+ if (position.y < 0.0)
94
+ {
95
+ position.xz = sign(position.xz) * vec2(1.0 - absolute.y, 1.0 - absolute.x);
96
+ }
97
+
98
+ return position;
99
+ }
100
+
101
+ //for hemisphere
102
+ vec3 OctaHemiSphereEnc(vec2 coord)
103
+ {
104
+ //coord = (0, 0.27)
105
+ //pos = -0.27, 0, -0.63
106
+
107
+ vec3 position = vec3(coord.x - coord.y, 0.0, -1.0 + coord.x + coord.y);
108
+ vec2 absolute = abs(position.xz);
109
+ position.y = 1.0 - absolute.x - absolute.y;
110
+ return position;
111
+ }
112
+
113
+ vec3 GridToVector(vec2 coord)
114
+ {
115
+ if (uIsFullSphere)
116
+ {
117
+ return OctaSphereEnc(coord);
118
+ }
119
+ else
120
+ {
121
+ return OctaHemiSphereEnc(coord);
122
+ }
123
+ }
124
+
125
+ vec3 FrameXYToRay(vec2 frame, vec2 frameCountMinusOne)
126
+ {
127
+ //divide frame x y by framecount minus one to get 0-1
128
+ vec2 f = (frame.xy/ frameCountMinusOne);
129
+ //bias and scale to -1 to 1
130
+
131
+ vec3 vec = GridToVector(f);
132
+ vec = normalize(vec);
133
+ return vec;
134
+ }
135
+
136
+ vec3 SpriteProjection(vec3 pivotToCameraRayLocal, vec2 size, vec2 loc_uv)
137
+ {
138
+ vec3 z = normalize(pivotToCameraRayLocal);
139
+ vec3 x, y;
140
+ vec3 up = vec3(0, 1, 0);
141
+ //cross product doesnt work if we look directly from bottom
142
+ if (abs(z.y) > 0.999f)
143
+ {
144
+ up = vec3(0, 0, -1);
145
+ }
146
+ x = normalize(cross(up, z));
147
+ y = normalize(cross(x, z));
148
+
149
+ loc_uv -= vec2(0.5, 0.5);
150
+ vec2 uv = (loc_uv) * 2.0;//-1 to 1
151
+
152
+ vec3 newX = x * uv.x;
153
+ vec3 newY = y * uv.y;
154
+
155
+ vec2 vecSize = size * 0.5;
156
+
157
+ newX *= vecSize.x;
158
+ newY *= vecSize.y;
159
+
160
+ return newX + newY;
161
+ }
162
+
163
+ vec4 quadBlendWieghts(vec2 coords)
164
+ {
165
+ vec4 res;
166
+ /* 0 0 0
167
+ 0 0 0
168
+ 1 0 0 */
169
+ res.x = min(1.0 - coords.x, 1.0 - coords.y);
170
+ /* 1 0 0
171
+ 0 0 0
172
+ 0 0 1 */
173
+ res.y = abs(coords.x - coords.y);
174
+ /* 0 0 1
175
+ 0 0 0
176
+ 0 0 0 */
177
+ res.z = min(coords.x, coords.y);
178
+ /* 0 0 0
179
+ 0 0 1
180
+ 0 1 1 */
181
+ res.w = ceil(coords.x - coords.y);
182
+ //res.xyz /= (res.x + res.y + res.z);
183
+ return res;
184
+ }
185
+
186
+ //this function works well in orthogonal projection. It works okeyish with further distances of perspective projection
187
+ vec2 virtualPlaneUV(vec3 plane_normal, vec3 plane_x, vec3 plane_y, vec3 pivotToCameraRay, vec3 vertexToCameraRay, float size)
188
+ {
189
+ plane_normal = normalize(plane_normal);
190
+ plane_x = normalize(plane_x);
191
+ plane_y = normalize(plane_y);
192
+
193
+ // plane_normal is normalized but pivotToCameraRay & vertexToCameraRay are NOT
194
+ // so what are we doing here ?
195
+ // We are calculating length of pivotToCameraRay projected onto plane_normal
196
+ // so pivotToCameraRay is vector to camera from CENTER OF object
197
+ // we are recalculting this distance taking into account new plane normal
198
+ float projectedNormalRayLength = dot(plane_normal, pivotToCameraRay);
199
+ // tihs is direction is almost the same as origin, but its to individual vertex
200
+ // not sure this is correct for perspective projection
201
+ float projectedVertexRayLength = dot(plane_normal, vertexToCameraRay);
202
+ // basically its length difference betwen center and vertex - "not precise"
203
+ // projectedVertexRayLength is bigger than projectedNormalRayLength when vertex is
204
+ // further than "main front facing billboard"
205
+ // so offsetLength is getting smaller, otherwise is getting bigger
206
+ float offsetLength = projectedNormalRayLength/projectedVertexRayLength;
207
+
208
+ // ok so offsetLength is just a length
209
+ // we want a vector so we multiply it by vertexToCameraRay to get this offset
210
+ // now what are we REALY doing is calculuating distance difference
211
+ // se are SUBSTRACTING pivotToCameraRay vector
212
+ // we would get difference between center of plane and vertex rotated
213
+ vec3 offsetVector = vertexToCameraRay * offsetLength - pivotToCameraRay;
214
+
215
+ // we got the offset of rotated vertex, but we need to offset it from correct plane axis
216
+ // so again we projecting length of intersection (offset of rotated vertex) onto plane_x
217
+ // and plane_y
218
+ vec2 duv = vec2(
219
+ dot(plane_x, offsetVector),
220
+ dot(plane_y, offsetVector)
221
+ );
222
+
223
+ //we are in space -1 to 1
224
+ duv /= 2.0 * size;
225
+ duv += 0.5;
226
+ return duv;
227
+ }
228
+ void calcuateXYbasis(vec3 plane_normal, out vec3 plane_x, out vec3 plane_y)
229
+ {
230
+ vec3 up = vec3(0, 1, 0);
231
+ //cross product doesnt work if we look directly from bottom
232
+ if (abs(plane_normal.y) > 0.999f)
233
+ {
234
+ up = vec3(0, 0, 1);
235
+ }
236
+ plane_x = normalize(cross(plane_normal, up));
237
+ plane_y = normalize(cross(plane_x, plane_normal));
238
+ }
239
+ vec3 projectOnPlaneBasis(vec3 ray, vec3 plane_normal, vec3 plane_x, vec3 plane_y)
240
+ {
241
+ //reproject plane normal onto planeXY basos
242
+ return normalize(vec3(
243
+ dot(plane_x, ray),
244
+ dot(plane_y, ray),
245
+ dot(plane_normal, ray)
246
+ ));
247
+ }
248
+
249
+ void main()
250
+ {
251
+ vec2 framesMinusOne = vec2(uFrames-1.0);
252
+ vec3 cameraPos_WS = cameraPosition;
253
+ vec3 cameraPos_OS = (viewMatrix* vec4(cameraPos_WS, 1.0)).xyz;
254
+
255
+ //radius * 2
256
+ vec2 size = vec2(2.0) * uRadius;
257
+
258
+ mat4 m4 = modelViewMatrix;
259
+
260
+ m4[0][0] = 1.0;
261
+ m4[0][1] = 0.0;
262
+ m4[0][2] = 0.0;
263
+
264
+ m4[1][0] = 0.0;
265
+ m4[1][1] = 1.0;
266
+ m4[1][2] = 0.0;
267
+
268
+ m4[2][0] = 0.0;
269
+ m4[2][1] = 0.0;
270
+ m4[2][2] = 1.0;
271
+
272
+ vec3 object_scale = vec3(
273
+ length(modelViewMatrix[0].xyz),
274
+ length(modelViewMatrix[1].xyz),
275
+ length(modelViewMatrix[2].xyz)
276
+ );
277
+
278
+ vec4 mvPosition = m4 * vec4(object_scale*(vec3(uv.x -0.5, uv.y - 0.5, 0.0) + uOffset/ (uRadius*2.0)), 1.0);
279
+ gl_Position = projectionMatrix * mvPosition;
280
+ vec2 pos = gl_Position.xy/gl_Position.w;
281
+
282
+
283
+ mat4 inverse_matrix = inverse(projectionMatrix * modelViewMatrix);
284
+ //compute ray's start and end as inversion of this coordinates
285
+ //in near and far clip planes
286
+ vec4 near_4 = inverse_matrix * (vec4(pos, -1.0, 1.0));
287
+ vec4 far_4 = inverse_matrix * (vec4(pos, 1.0, 1.0));
288
+
289
+ vec3 local_ray_near = near_4.xyz / near_4.w;
290
+ vec3 local_ray_far = far_4.xyz/ far_4.w;
291
+
292
+ //TODO: check if this is correct. We are using orho projected images, so
293
+ // camera far away
294
+ //vec3 pivotToCameraRay = (cameraPos_OS) * 10.0;
295
+ //vec3 pivotToCameraDir = normalize(cameraPos_OS);
296
+
297
+ vec3 ray_direction = local_ray_far-local_ray_near;
298
+ ray_direction *= -1.0;
299
+
300
+ vec2 grid = VectorToGrid(ray_direction);
301
+ //bias and scale to 0 to 1
302
+ grid = clamp((grid + 1.0) * 0.5, 0.0, 1.0);
303
+ grid *= framesMinusOne;
304
+ grid = clamp(grid, vec2(0.0), framesMinusOne);
305
+ vec2 gridFloor = min(floor(grid), framesMinusOne);
306
+ vec2 gridFract = fract(grid);
307
+
308
+ //vec3 projected = SpriteProjection(pivotToCameraDir, size, uv);
309
+ //vec3 vertexToCameraRay = (pivotToCameraRay - (projected));
310
+ //vec3 vertexToCameraDir = normalize(vertexToCameraRay);
311
+
312
+ frame1 = gridFloor;
313
+ quad_blend_weights = quadBlendWieghts(gridFract);
314
+ //convert frame coordinate to octahedron direction
315
+ vec3 projectedQuadADir = FrameXYToRay(frame1, framesMinusOne);
316
+
317
+ frame2 = clamp(frame1 + mix(vec2(0, 1), vec2(1, 0), quad_blend_weights.w), vec2(0, 0), framesMinusOne);
318
+ vec3 projectedQuadBDir = FrameXYToRay(frame2, framesMinusOne);
319
+
320
+ frame3 = clamp(frame1 + vec2(1.0), vec2(0, 0), framesMinusOne);
321
+ vec3 projectedQuadCDir = FrameXYToRay(frame3, framesMinusOne);
322
+
323
+ frame1_normal = (modelViewMatrix *vec4(projectedQuadADir, 0)).xyz;
324
+ frame2_normal = (modelViewMatrix *vec4(projectedQuadBDir, 0)).xyz;
325
+ frame3_normal = (modelViewMatrix *vec4(projectedQuadCDir, 0)).xyz;
326
+
327
+ //calcute virtual planes projections
328
+ vec3 plane_x1, plane_y1, plane_x2, plane_y2, plane_x3, plane_y3;
329
+ calcuateXYbasis(projectedQuadADir, plane_x1, plane_y1);
330
+ uv_frame1 = virtualPlaneUV(projectedQuadADir, plane_x1, plane_y1, local_ray_near, local_ray_far, uRadius);
331
+ xy_frame1 = projectOnPlaneBasis(-ray_direction, projectedQuadADir, plane_x1, plane_y1).xy;
332
+
333
+ calcuateXYbasis(projectedQuadBDir, plane_x2, plane_y2);
334
+ uv_frame2 = virtualPlaneUV(projectedQuadBDir, plane_x2, plane_y2, local_ray_near, local_ray_far, uRadius);
335
+ xy_frame2 = projectOnPlaneBasis(-ray_direction, projectedQuadBDir, plane_x2, plane_y2).xy;
336
+
337
+ calcuateXYbasis(projectedQuadCDir, plane_x3, plane_y3);
338
+ uv_frame3 = virtualPlaneUV(projectedQuadCDir, plane_x3, plane_y3, local_ray_near, local_ray_far, uRadius);
339
+ xy_frame3 = projectOnPlaneBasis(-ray_direction, projectedQuadCDir, plane_x3, plane_y3).xy;
340
+
341
+ //to fragment shader
342
+ //to fragment shader
343
+ // vec3 p = (projected+uOffset)+pivotToCameraDir*aabb_max;
344
+
345
+ // gl_Position = projectionMatrix * vec4(p,1.0);
346
+
347
+ // NORMAL = normalize(pivotToCameraDir);
348
+ // TANGENT= normalize(cross(NORMAL, vec3(0.0, 1.0, 0.0)));
349
+ // BINORMAL = normalize(cross(TANGENT, NORMAL));
350
+ }
@@ -45,7 +45,7 @@ export function getTransformedPositionsCached(occurrence, attribute_index) {
45
45
 
46
46
  const destination = new Float32Array(source_array.length);
47
47
 
48
- apply_mat4_transform_to_v3_array(source_array, 0, destination, 0, patch.vertex_count, occurrence.transform);
48
+ apply_mat4_transform_to_v3_array(source_array, 0, destination, 0, patch.vertex_count, occurrence.transform.elements);
49
49
 
50
50
  // store in cache
51
51
  transformed_position_cache.put(key, destination);
@@ -200,7 +200,7 @@ export class LightManager {
200
200
  this.__decal_atlas_texture.minFilter = LinearMipMapLinearFilter;
201
201
  this.__decal_atlas_texture.magFilter = LinearFilter;
202
202
  this.__decal_atlas_texture.generateMipmaps = true;
203
- this.__decal_atlas_texture.anisotropy = 4;
203
+ this.__decal_atlas_texture.anisotropy = 8;
204
204
 
205
205
  /**
206
206
  *
@@ -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,16 +64,24 @@ 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;
74
+
75
+ vec4 decal_color = texture2D(fp_t_decal_atlas,decal_uv, -0.2);
69
76
 
77
+ // compute decal alpha
78
+ float decal_alpha = decal_color.a * decal_surface_angle_fade;
70
79
 
71
- vec4 decal_color = texture(fp_t_decal_atlas, decal_uv);
80
+ if(decal_alpha < 0.003){
81
+ continue;
82
+ }
72
83
 
73
- float decal_alpha = decal_color.a * decal_surface_angle_fade;
74
-
75
84
  material.diffuseColor = material.diffuseColor*(1.0-decal_alpha) + decal_color.xyz*decal_alpha;
76
-
77
85
  }
78
86
 
79
87
  }
@@ -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,4 +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;
28
+ `;
@@ -2,6 +2,8 @@ import { AbstractLight } from "./AbstractLight.js";
2
2
  import { aabb3_matrix4_project_by_corners } from "../../../../../core/geom/3d/aabb/aabb3_matrix4_project_by_corners.js";
3
3
  import { aabb3_build_corners } from "../../../../../core/geom/3d/aabb/aabb3_build_corners.js";
4
4
  import { array_copy } from "../../../../../core/collection/array/copyArray.js";
5
+ import { mat4 } from "gl-matrix";
6
+ import Signal from "../../../../../core/events/signal/Signal.js";
5
7
 
6
8
  const corners = [];
7
9
  const aabb_array = new Float32Array(6);
@@ -30,6 +32,19 @@ export class Decal extends AbstractLight {
30
32
  * @type {number}
31
33
  */
32
34
  this.draw_priority = 0;
35
+
36
+ this.__signal_transfom_changed = new Signal();
37
+ }
38
+
39
+ /**
40
+ *
41
+ * @param {number[]} m
42
+ */
43
+ setTransform(m) {
44
+ mat4.copy(this.transform, m);
45
+ mat4.invert(this.transform_inverse, this.transform);
46
+
47
+ this.__signal_transfom_changed.send0();
33
48
  }
34
49
 
35
50
  handleUvPositionChange(x, y) {
@@ -55,11 +70,13 @@ export class Decal extends AbstractLight {
55
70
  }
56
71
 
57
72
  onDimensionChanged(f, thisArg) {
58
- // TODO implement
73
+
74
+ this.__signal_transfom_changed.add(f, thisArg);
59
75
  }
60
76
 
61
77
  offDimensionChanged(f, thisArg) {
62
- // TODO implement
78
+
79
+ this.__signal_transfom_changed.remove(f, thisArg);
63
80
  }
64
81
 
65
82
  getCenter(result) {
@@ -36,6 +36,10 @@ export class MaterialTransformer extends AbstractMaterialTransformer {
36
36
  type: 't',
37
37
  value: light_manager.getTextureDecalAtlas()
38
38
  },
39
+ fp_t_decal_atlas_resolution: {
40
+ type: 't',
41
+ value: new Vector2(1, 1)
42
+ },
39
43
  fp_f_camera_near: {
40
44
  type: 'f',
41
45
  value: 0
@@ -71,8 +75,16 @@ export class MaterialTransformer extends AbstractMaterialTransformer {
71
75
  * @param {CameraView} c
72
76
  */
73
77
  updateCamera(c) {
74
- this.__common_uniforms.fp_f_camera_far.value = c.camera.far;
75
- this.__common_uniforms.fp_f_camera_near.value = c.camera.near;
78
+ const us = this.__common_uniforms;
79
+
80
+ us.fp_f_camera_far.value = c.camera.far;
81
+ us.fp_f_camera_near.value = c.camera.near;
82
+
83
+ // TODO move to "onbefore render"
84
+ us.fp_t_decal_atlas_resolution.value.set(
85
+ us.fp_t_decal_atlas.value.image.width,
86
+ us.fp_t_decal_atlas.value.image.height,
87
+ );
76
88
  }
77
89
 
78
90
  transform(source) {
@@ -21,6 +21,7 @@ function frustum_check(data_view, address, planes) {
21
21
  const n_x0 = data_view.getFloat32(address);
22
22
  const n_y0 = data_view.getFloat32(address + 4);
23
23
  const n_z0 = data_view.getFloat32(address + 8);
24
+
24
25
  const n_x1 = data_view.getFloat32(address + 12);
25
26
  const n_y1 = data_view.getFloat32(address + 16);
26
27
  const n_z1 = data_view.getFloat32(address + 20);
@@ -72,7 +73,6 @@ export function query_bvh_frustum_from_texture(
72
73
 
73
74
  let stackPointer = 1;
74
75
  let result = 0;
75
- let plane_address;
76
76
 
77
77
  const binary_node_count = root.getBinaryNodeCount();
78
78
 
@@ -90,7 +90,7 @@ export function query_bvh_frustum_from_texture(
90
90
  const last_valid_index = binary_node_count + root.getLeafNodeCount();
91
91
  const data_view = root.getDataView();
92
92
 
93
- stack_loop:while (stackPointer-- > 0) {
93
+ while (stackPointer-- > 0) {
94
94
 
95
95
  // query_bvh_frustum_from_objects.iteration_count++;
96
96
  const node_index = stack[stackPointer];
@@ -271,10 +271,10 @@ export class Sampler2D {
271
271
  * @returns {number}
272
272
  */
273
273
  sampleChannelCatmullRomUV(u, v, channel) {
274
- const x = u * (this.width);
275
- const y = v * (this.height);
274
+ const x = u * (this.width - 1);
275
+ const y = v * (this.height - 1);
276
276
 
277
- return this.sampleChannelCatmullRom(x - 0.5, y - 0.5, channel);
277
+ return this.sampleChannelCatmullRom(x, y, channel);
278
278
  }
279
279
 
280
280
  /**
@@ -366,8 +366,8 @@ export class Sampler2D {
366
366
  * @returns {number}
367
367
  */
368
368
  sampleChannelBicubicUV(u, v, channel) {
369
- const x = u * (this.width);
370
- const y = v * (this.height);
369
+ const x = u * (this.width - 1);
370
+ const y = v * (this.height - 1);
371
371
 
372
372
  return this.sampleChannelBicubic(x - 0.5, y - 0.5, channel);
373
373
  }
@@ -511,10 +511,10 @@ export class Sampler2D {
511
511
  * @return {number}
512
512
  */
513
513
  sampleChannelBilinearUV(u, v, channel) {
514
- const x = u * (this.width);
515
- const y = v * (this.height);
514
+ const x = u * (this.width - 1);
515
+ const y = v * (this.height - 1);
516
516
 
517
- return this.sampleChannelBilinear(x - 0.5, y - 0.5, channel);
517
+ return this.sampleChannelBilinear(x, y, channel);
518
518
  }
519
519
 
520
520
  /**
@@ -599,8 +599,8 @@ export class Sampler2D {
599
599
  }
600
600
 
601
601
  sampleNearestUV(u, v, result) {
602
- const x = Math.round(u * (this.width) - 0.5);
603
- const y = Math.round(v * (this.height) - 0.5);
602
+ const x = Math.round(u * (this.width - 1));
603
+ const y = Math.round(v * (this.height - 1));
604
604
 
605
605
  this.read(min2(x, this.width - 1), min2(y, this.height - 1), result);
606
606
  }