@luma.gl/engine 10.0.0-alpha.11 → 10.0.0-alpha.13

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 (123) hide show
  1. package/LICENSE +4 -4
  2. package/THIRD-PARTY-NOTICES.md +185 -0
  3. package/dist/compute/swap.d.ts +2 -2
  4. package/dist/compute/swap.d.ts.map +1 -1
  5. package/dist/compute/swap.js.map +1 -1
  6. package/dist/dist.dev.js +313 -196
  7. package/dist/dist.min.js +61 -61
  8. package/dist/dynamic-texture/video-texture.cjs +1 -1
  9. package/dist/dynamic-texture/video-texture.d.ts +3 -3
  10. package/dist/dynamic-texture/video-texture.d.ts.map +1 -1
  11. package/dist/dynamic-texture/video-texture.js +1 -1
  12. package/dist/dynamic-texture/video-texture.js.map +1 -1
  13. package/dist/effects/index.cjs.map +1 -1
  14. package/dist/effects/passes/postprocessing/fxaa/fxaa.d.ts.map +1 -1
  15. package/dist/effects/passes/postprocessing/fxaa/fxaa.js +2 -1
  16. package/dist/effects/passes/postprocessing/fxaa/fxaa.js.map +1 -1
  17. package/dist/effects/passes/postprocessing/image-adjust-filters/brightnesscontrast.d.ts.map +1 -1
  18. package/dist/effects/passes/postprocessing/image-adjust-filters/brightnesscontrast.js +2 -0
  19. package/dist/effects/passes/postprocessing/image-adjust-filters/brightnesscontrast.js.map +1 -1
  20. package/dist/effects/passes/postprocessing/image-adjust-filters/denoise.d.ts.map +1 -1
  21. package/dist/effects/passes/postprocessing/image-adjust-filters/denoise.js +2 -0
  22. package/dist/effects/passes/postprocessing/image-adjust-filters/denoise.js.map +1 -1
  23. package/dist/effects/passes/postprocessing/image-adjust-filters/huesaturation.d.ts.map +1 -1
  24. package/dist/effects/passes/postprocessing/image-adjust-filters/huesaturation.js +2 -0
  25. package/dist/effects/passes/postprocessing/image-adjust-filters/huesaturation.js.map +1 -1
  26. package/dist/effects/passes/postprocessing/image-adjust-filters/noise.d.ts.map +1 -1
  27. package/dist/effects/passes/postprocessing/image-adjust-filters/noise.js +2 -0
  28. package/dist/effects/passes/postprocessing/image-adjust-filters/noise.js.map +1 -1
  29. package/dist/effects/passes/postprocessing/image-adjust-filters/sepia.d.ts.map +1 -1
  30. package/dist/effects/passes/postprocessing/image-adjust-filters/sepia.js +2 -0
  31. package/dist/effects/passes/postprocessing/image-adjust-filters/sepia.js.map +1 -1
  32. package/dist/effects/passes/postprocessing/image-adjust-filters/vibrance.d.ts.map +1 -1
  33. package/dist/effects/passes/postprocessing/image-adjust-filters/vibrance.js +2 -0
  34. package/dist/effects/passes/postprocessing/image-adjust-filters/vibrance.js.map +1 -1
  35. package/dist/effects/passes/postprocessing/image-adjust-filters/vignette.d.ts.map +1 -1
  36. package/dist/effects/passes/postprocessing/image-adjust-filters/vignette.js +2 -0
  37. package/dist/effects/passes/postprocessing/image-adjust-filters/vignette.js.map +1 -1
  38. package/dist/gltf/types/gltf-json-schema.d.ts.map +1 -1
  39. package/dist/gltf/types/gltf-json-schema.js +1 -0
  40. package/dist/gltf/types/gltf-json-schema.js.map +1 -1
  41. package/dist/gltf/types/gltf-postprocessed-schema.d.ts.map +1 -1
  42. package/dist/gltf/types/gltf-postprocessed-schema.js +1 -0
  43. package/dist/gltf/types/gltf-postprocessed-schema.js.map +1 -1
  44. package/dist/index.cjs.map +1 -1
  45. package/dist/lighting/index.cjs +22 -2
  46. package/dist/lighting/index.cjs.map +3 -3
  47. package/dist/lighting/index.d.ts +8 -0
  48. package/dist/lighting/index.d.ts.map +1 -1
  49. package/dist/lighting/index.js +4 -0
  50. package/dist/lighting/index.js.map +1 -1
  51. package/dist/lighting/lightmap-baker.cjs +238 -0
  52. package/dist/lighting/lightmap-baker.d.ts +62 -0
  53. package/dist/lighting/lightmap-baker.d.ts.map +1 -0
  54. package/dist/lighting/lightmap-baker.js +236 -0
  55. package/dist/lighting/lightmap-baker.js.map +1 -0
  56. package/dist/lighting/lightmap-data.cjs +117 -0
  57. package/dist/lighting/lightmap-data.d.ts +20 -0
  58. package/dist/lighting/lightmap-data.d.ts.map +1 -0
  59. package/dist/lighting/lightmap-data.js +110 -0
  60. package/dist/lighting/lightmap-data.js.map +1 -0
  61. package/dist/lighting/lightmap-environment.cjs +61 -0
  62. package/dist/lighting/lightmap-environment.d.ts +18 -0
  63. package/dist/lighting/lightmap-environment.d.ts.map +1 -0
  64. package/dist/lighting/lightmap-environment.js +46 -0
  65. package/dist/lighting/lightmap-environment.js.map +1 -0
  66. package/dist/lighting/pbr-model.cjs +70 -0
  67. package/dist/lighting/pbr-model.d.ts +5 -1
  68. package/dist/lighting/pbr-model.d.ts.map +1 -1
  69. package/dist/lighting/pbr-model.js +71 -1
  70. package/dist/lighting/pbr-model.js.map +1 -1
  71. package/dist/lighting/shadow-map-renderer.cjs +7 -3
  72. package/dist/lighting/shadow-map-renderer.d.ts +1 -1
  73. package/dist/lighting/shadow-map-renderer.d.ts.map +1 -1
  74. package/dist/lighting/shadow-map-renderer.js +8 -3
  75. package/dist/lighting/shadow-map-renderer.js.map +1 -1
  76. package/dist/text/index.cjs +2 -0
  77. package/dist/text/index.cjs.map +2 -2
  78. package/dist/text/index.d.ts +1 -1
  79. package/dist/text/index.d.ts.map +1 -1
  80. package/dist/text/index.js +1 -1
  81. package/dist/text/index.js.map +1 -1
  82. package/dist/text/text-2d/index.cjs +3 -0
  83. package/dist/text/text-2d/index.d.ts +1 -0
  84. package/dist/text/text-2d/index.d.ts.map +1 -1
  85. package/dist/text/text-2d/index.js +1 -0
  86. package/dist/text/text-2d/index.js.map +1 -1
  87. package/dist/text/text-2d/model-utils/text-code-point-source.cjs +41 -0
  88. package/dist/text/text-2d/model-utils/text-code-point-source.d.ts +8 -0
  89. package/dist/text/text-2d/model-utils/text-code-point-source.d.ts.map +1 -0
  90. package/dist/text/text-2d/model-utils/text-code-point-source.js +23 -0
  91. package/dist/text/text-2d/model-utils/text-code-point-source.js.map +1 -0
  92. package/licenses/cesium.txt +207 -0
  93. package/licenses/deck-community.txt +19 -0
  94. package/licenses/deck.txt +19 -0
  95. package/licenses/glfx.txt +19 -0
  96. package/licenses/gltf-loader-ts.txt +21 -0
  97. package/licenses/magenta-font.txt +13 -0
  98. package/licenses/nvidia-fxaa.txt +25 -0
  99. package/licenses/philogl.txt +19 -0
  100. package/licenses/spark.txt +21 -0
  101. package/licenses/three.txt +21 -0
  102. package/package.json +12 -9
  103. package/src/compute/swap.ts +2 -2
  104. package/src/dynamic-texture/video-texture.ts +9 -3
  105. package/src/effects/passes/postprocessing/fxaa/fxaa.ts +2 -1
  106. package/src/effects/passes/postprocessing/image-adjust-filters/brightnesscontrast.ts +2 -0
  107. package/src/effects/passes/postprocessing/image-adjust-filters/denoise.ts +2 -0
  108. package/src/effects/passes/postprocessing/image-adjust-filters/huesaturation.ts +2 -0
  109. package/src/effects/passes/postprocessing/image-adjust-filters/noise.ts +2 -0
  110. package/src/effects/passes/postprocessing/image-adjust-filters/sepia.ts +2 -0
  111. package/src/effects/passes/postprocessing/image-adjust-filters/vibrance.ts +2 -0
  112. package/src/effects/passes/postprocessing/image-adjust-filters/vignette.ts +2 -0
  113. package/src/gltf/types/gltf-json-schema.ts +1 -0
  114. package/src/gltf/types/gltf-postprocessed-schema.ts +1 -0
  115. package/src/lighting/index.ts +19 -0
  116. package/src/lighting/lightmap-baker.ts +306 -0
  117. package/src/lighting/lightmap-data.ts +138 -0
  118. package/src/lighting/lightmap-environment.ts +70 -0
  119. package/src/lighting/pbr-model.ts +78 -1
  120. package/src/lighting/shadow-map-renderer.ts +12 -3
  121. package/src/text/index.ts +1 -0
  122. package/src/text/text-2d/index.ts +1 -0
  123. package/src/text/text-2d/model-utils/text-code-point-source.ts +34 -0
@@ -1,11 +1,12 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
3
3
 
4
- import type {Device} from '@luma.gl/core';
4
+ import {assert, type Device} from '@luma.gl/core';
5
5
  import type {Material} from '../material/material';
6
6
  import {Model, type ModelProps} from '../model/model';
7
7
  import {
8
8
  pbrMaterial,
9
+ lightmapBake,
9
10
  pbrScene,
10
11
  pbrShadow,
11
12
  pbrSurface,
@@ -146,6 +147,10 @@ ${hooks.instanceTransform ?? ''} position = instanceMatrix * position;
146
147
  tangent = vec4f(normalize((pbrProjection.modelMatrix * vec4f(tangent.xyz, 0.0)).xyz), tangent.w * sign(determinant(mat3x3f(pbrProjection.modelMatrix[0].xyz, pbrProjection.modelMatrix[1].xyz, pbrProjection.modelMatrix[2].xyz))));
147
148
  #endif
148
149
  outputs.position = pbrProjection.modelViewProjectionMatrix * position;
150
+ #ifdef PBR_LIGHTMAP_PASS
151
+ let atlasUV = (lightmapBake.uvTransform * vec3f(select(textureCoordinates, secondTextureCoordinates, lightmapBake.uvSet == 1), 1.0)).xy;
152
+ outputs.position = vec4f(atlasUV.x * 2.0 - 1.0, 1.0 - atlasUV.y * 2.0, 0.0, 1.0);
153
+ #endif
149
154
  ${hooks.vertexOutput ?? ''}
150
155
  outputs.pbrPosition = worldPosition.xyz / worldPosition.w;
151
156
  outputs.pbrUV0 = textureCoordinates;
@@ -183,6 +188,24 @@ ${
183
188
  ${
184
189
  hooks.fragmentBody ??
185
190
  `
191
+ #ifdef PBR_LIGHTMAP_PASS
192
+ pbr_discardMaskedFragment(inputs.pbrColor);
193
+ var directionalVisibility = 1.0;
194
+ var pointVisibility = vec4f(1.0);
195
+ var spotVisibility = vec4f(1.0);
196
+ let normal = normalize(inputs.pbrNormal);
197
+ #ifdef PBR_RECEIVE_SHADOWS
198
+ if (pbrShadow.enabled != 0) {
199
+ let viewDepth = -(pbrShadow.viewMatrix * vec4f(inputs.pbrPosition, 1.0)).z;
200
+ directionalVisibility = shadow_getDirectionalFactor(inputs.pbrPosition, normal, viewDepth);
201
+ for (var index = 0; index < 4; index++) {
202
+ pointVisibility[index] = shadow_getPointFactor(index, inputs.pbrPosition, normal);
203
+ spotVisibility[index] = shadow_getSpotFactor(index, inputs.pbrPosition, normal);
204
+ }
205
+ }
206
+ #endif
207
+ return vec4f(lightmap_getIrradiance(inputs.pbrPosition, normal, directionalVisibility, pointVisibility, spotVisibility), lightmapBake.chartId);
208
+ #else
186
209
  #ifdef PBR_SHADOW_PASS
187
210
  pbr_discardMaskedFragment(inputs.pbrColor);
188
211
  #else
@@ -221,6 +244,7 @@ ${
221
244
  #endif
222
245
  #endif
223
246
  #endif
247
+ #endif
224
248
  `
225
249
  }
226
250
  }
@@ -318,6 +342,10 @@ void main(void) {
318
342
  secondTextureCoordinates
319
343
  );
320
344
  gl_Position = pbrProjection.modelViewProjectionMatrix * position;
345
+ #ifdef PBR_LIGHTMAP_PASS
346
+ vec2 atlasUV = (lightmapBake.uvTransform * vec3(lightmapBake.uvSet == 1 ? secondTextureCoordinates : textureCoordinates, 1.0)).xy;
347
+ gl_Position = vec4(atlasUV * 2.0 - 1.0, 0.0, 1.0);
348
+ #endif
321
349
  #ifdef PBR_SHADOW_PASS
322
350
  // ShadowMapRenderer light projections use [0, 1] depth on both backends.
323
351
  gl_Position.z = gl_Position.z * 2.0 - gl_Position.w;
@@ -332,6 +360,28 @@ out vec4 fragmentColor;
332
360
  #endif
333
361
 
334
362
  void main(void) {
363
+ #ifdef PBR_LIGHTMAP_PASS
364
+ pbr_discardMaskedFragment(sceneVertexColor);
365
+ #ifdef HAS_TANGENTS
366
+ vec3 normal = normalize(pbr_vTBN[2]);
367
+ #else
368
+ vec3 normal = normalize(pbr_vNormal);
369
+ #endif
370
+ float directionalVisibility = 1.0;
371
+ vec4 pointVisibility = vec4(1.0);
372
+ vec4 spotVisibility = vec4(1.0);
373
+ #ifdef PBR_RECEIVE_SHADOWS
374
+ if (pbrShadow.enabled != 0) {
375
+ float viewDepth = -(pbrShadow.viewMatrix * vec4(pbr_vPosition, 1.0)).z;
376
+ directionalVisibility = shadow_getDirectionalFactor(pbr_vPosition, normal, viewDepth);
377
+ for (int index = 0; index < 4; index++) {
378
+ pointVisibility[index] = shadow_getPointFactor(index, pbr_vPosition, normal);
379
+ spotVisibility[index] = shadow_getSpotFactor(index, pbr_vPosition, normal);
380
+ }
381
+ }
382
+ #endif
383
+ fragmentColor = vec4(lightmap_getIrradiance(pbr_vPosition, normal, directionalVisibility, pointVisibility, spotVisibility), lightmapBake.chartId);
384
+ #else
335
385
  #ifdef PBR_SHADOW_PASS
336
386
  pbr_discardMaskedFragment(sceneVertexColor);
337
387
  #else
@@ -382,6 +432,7 @@ void main(void) {
382
432
  #endif
383
433
  #endif
384
434
  #endif
435
+ #endif
385
436
  }
386
437
  `;
387
438
 
@@ -529,3 +580,29 @@ export function getPBRTextureDefines(bindings: Record<string, unknown>): Record<
529
580
  HAS_MULTISCATTERCOLORMAP: Boolean(bindings['pbr_multiscatterColorSampler'])
530
581
  };
531
582
  }
583
+
584
+ /** Options for a UV-space diffuse irradiance model. Supply normals and nonoverlapping atlas UVs. */
585
+ export type CreatePBRLightmapModelOptions = CreatePBRModelOptions;
586
+
587
+ /** Creates a borrowed-material bake model; output is linear irradiance E with chart ID in alpha. */
588
+ export function createPBRLightmapModel(
589
+ device: Device,
590
+ options: CreatePBRLightmapModelOptions
591
+ ): Model {
592
+ const features = {...getPBRGeometryDefines(options.geometry), ...options.defines};
593
+ // Bake surfaces require geometric normals and the selected atlas UV attributes.
594
+ assert(features['HAS_NORMALS'] && (features['HAS_UV'] || features['HAS_UV_1']));
595
+ return createPBRModel(device, {
596
+ colorAttachmentFormats: ['rgba16float'],
597
+ ...options,
598
+ modules: [lightmapBake, ...(options.modules || [])],
599
+ receiveContactShadows: false,
600
+ receiveAmbientOcclusion: false,
601
+ defines: {...options.defines, HAS_LIGHTMAP: false, USE_IBL: false, PBR_LIGHTMAP_PASS: true},
602
+ parameters: {
603
+ ...options.parameters,
604
+ depthWriteEnabled: false,
605
+ cullMode: 'none'
606
+ }
607
+ });
608
+ }
@@ -229,7 +229,9 @@ export class ShadowMapRenderer {
229
229
  });
230
230
  });
231
231
 
232
- const pointViews = pointLights.flatMap(light => getPointShadowViews(resolvePointLight(light)));
232
+ const pointViews = pointLights.flatMap(light =>
233
+ getPointShadowViews(resolvePointLight(light), this.device.type === 'webgpu')
234
+ );
233
235
  pointLights.forEach((inputLight, lightIndex) => {
234
236
  const light = resolvePointLight(inputLight);
235
237
  for (let faceIndex = 0; faceIndex < POINT_FACE_COUNT; faceIndex++) {
@@ -305,7 +307,9 @@ export class ShadowMapRenderer {
305
307
  depthCompare: 'less-equal',
306
308
  depthBias: options.light.depthBias,
307
309
  depthBiasSlopeScale: options.light.depthBiasSlopeScale,
308
- cullMode: 'back'
310
+ cullMode: 'back',
311
+ // Cube sampling uses top-left texel coordinates on WebGPU; its face projection flips Y.
312
+ frontFace: options.type === 'point' && this.device.type === 'webgpu' ? 'cw' : 'ccw'
309
313
  } satisfies RenderPipelineParameters);
310
314
  const context = {
311
315
  framebuffer: options.framebuffer,
@@ -479,7 +483,10 @@ export function getSpotShadowView(light: Required<SpotShadowLight>): ComputedSha
479
483
  }
480
484
 
481
485
  /** Computes the six canonical cameras used by one cube-array point shadow. */
482
- export function getPointShadowViews(light: Required<PointShadowLight>): ComputedShadowView[] {
486
+ export function getPointShadowViews(
487
+ light: Required<PointShadowLight>,
488
+ invertY = false
489
+ ): ComputedShadowView[] {
483
490
  const projectionMatrix = new Matrix4(OPENGL_TO_WEBGPU_MATRIX).multiplyRight(
484
491
  new Matrix4().perspective({
485
492
  fovy: radians(90),
@@ -488,6 +495,8 @@ export function getPointShadowViews(light: Required<PointShadowLight>): Computed
488
495
  far: light.range
489
496
  })
490
497
  );
498
+ // WebGPU cube lookups use the same face axes as GL but a top-left texture origin.
499
+ if (invertY) projectionMatrix.multiplyLeft(new Matrix4().scale([1, -1, 1]));
491
500
  return POINT_FACE_ORIENTATIONS.map((orientation): ComputedShadowView => {
492
501
  const viewMatrix = new Matrix4().lookAt({
493
502
  eye: light.position,
package/src/text/index.ts CHANGED
@@ -32,6 +32,7 @@ export {
32
32
  type CharacterMapping,
33
33
  type TextKerning,
34
34
  type TextGlyphLayout,
35
+ createTextCodePointSource,
35
36
  buildTextGlyphLayout,
36
37
  type TextCodePointSource,
37
38
  type TextLayoutOptions,
@@ -38,6 +38,7 @@ export {
38
38
  type TextKerning
39
39
  } from '../fonts/atlas/text-utils';
40
40
  export {type TextGlyphLayout} from './model-utils/gpu-text-types';
41
+ export {createTextCodePointSource} from './model-utils/text-code-point-source';
41
42
  export {
42
43
  buildTextGlyphLayout,
43
44
  type TextCodePointSource,
@@ -0,0 +1,34 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import type {TextCodePointSource} from './text-layout';
6
+
7
+ /**
8
+ * Creates a code-point source from one-line text rows. An optional caller-supplied
9
+ * processor converts each row to display order once, before glyph layout.
10
+ * Without it, the input rows must already be in display order.
11
+ */
12
+ export function createTextCodePointSource(
13
+ rows: readonly string[],
14
+ toDisplayOrder?: (text: string, rowIndex: number) => string
15
+ ): TextCodePointSource {
16
+ const codePointRows = rows.map((row, rowIndex) =>
17
+ Uint32Array.from(
18
+ toDisplayOrder ? toDisplayOrder(row, rowIndex) : row,
19
+ character =>
20
+ // String iteration yields a nonempty string for each code point.
21
+ character.codePointAt(0)!
22
+ )
23
+ );
24
+
25
+ return {
26
+ rowCount: codePointRows.length,
27
+ countCodePoints: rowIndex => codePointRows[rowIndex].length,
28
+ visitCodePoints: (rowIndex, visitCodePoint) => {
29
+ for (const codePoint of codePointRows[rowIndex]) {
30
+ visitCodePoint(codePoint);
31
+ }
32
+ }
33
+ };
34
+ }