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

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 (40) hide show
  1. package/dist/dist.dev.js +132 -126
  2. package/dist/dist.min.js +57 -57
  3. package/dist/lighting/index.cjs +22 -2
  4. package/dist/lighting/index.cjs.map +3 -3
  5. package/dist/lighting/index.d.ts +8 -0
  6. package/dist/lighting/index.d.ts.map +1 -1
  7. package/dist/lighting/index.js +4 -0
  8. package/dist/lighting/index.js.map +1 -1
  9. package/dist/lighting/lightmap-baker.cjs +238 -0
  10. package/dist/lighting/lightmap-baker.d.ts +62 -0
  11. package/dist/lighting/lightmap-baker.d.ts.map +1 -0
  12. package/dist/lighting/lightmap-baker.js +236 -0
  13. package/dist/lighting/lightmap-baker.js.map +1 -0
  14. package/dist/lighting/lightmap-data.cjs +117 -0
  15. package/dist/lighting/lightmap-data.d.ts +20 -0
  16. package/dist/lighting/lightmap-data.d.ts.map +1 -0
  17. package/dist/lighting/lightmap-data.js +110 -0
  18. package/dist/lighting/lightmap-data.js.map +1 -0
  19. package/dist/lighting/lightmap-environment.cjs +61 -0
  20. package/dist/lighting/lightmap-environment.d.ts +18 -0
  21. package/dist/lighting/lightmap-environment.d.ts.map +1 -0
  22. package/dist/lighting/lightmap-environment.js +46 -0
  23. package/dist/lighting/lightmap-environment.js.map +1 -0
  24. package/dist/lighting/pbr-model.cjs +70 -0
  25. package/dist/lighting/pbr-model.d.ts +5 -1
  26. package/dist/lighting/pbr-model.d.ts.map +1 -1
  27. package/dist/lighting/pbr-model.js +71 -1
  28. package/dist/lighting/pbr-model.js.map +1 -1
  29. package/dist/lighting/shadow-map-renderer.cjs +7 -3
  30. package/dist/lighting/shadow-map-renderer.d.ts +1 -1
  31. package/dist/lighting/shadow-map-renderer.d.ts.map +1 -1
  32. package/dist/lighting/shadow-map-renderer.js +8 -3
  33. package/dist/lighting/shadow-map-renderer.js.map +1 -1
  34. package/package.json +8 -8
  35. package/src/lighting/index.ts +19 -0
  36. package/src/lighting/lightmap-baker.ts +306 -0
  37. package/src/lighting/lightmap-data.ts +138 -0
  38. package/src/lighting/lightmap-environment.ts +70 -0
  39. package/src/lighting/pbr-model.ts +78 -1
  40. package/src/lighting/shadow-map-renderer.ts +12 -3
package/dist/dist.dev.js CHANGED
@@ -6612,8 +6612,13 @@ ${DECLARATION_INJECT_MARKER}
6612
6612
  }
6613
6613
  return decoded;
6614
6614
  }
6615
+ var attributeShaderTypeInfoCache = /* @__PURE__ */ new Map();
6615
6616
  function getAttributeShaderTypeInfo(attributeType) {
6616
6617
  const resolvedAttributeType = resolveAttributeShaderTypeAlias(attributeType);
6618
+ const cached = attributeShaderTypeInfoCache.get(resolvedAttributeType);
6619
+ if (cached) {
6620
+ return cached;
6621
+ }
6617
6622
  const decoded = TYPE_INFO[resolvedAttributeType];
6618
6623
  if (!decoded) {
6619
6624
  throw new Error(`Unsupported attribute shader type: ${attributeType}`);
@@ -6622,13 +6627,15 @@ ${DECLARATION_INJECT_MARKER}
6622
6627
  const integer = primitiveType === "i32" || primitiveType === "u32";
6623
6628
  const signed = primitiveType !== "u32";
6624
6629
  const byteLength = PRIMITIVE_TYPE_SIZES[primitiveType] * components2;
6625
- return {
6630
+ const result = Object.freeze({
6626
6631
  primitiveType,
6627
6632
  components: components2,
6628
6633
  byteLength,
6629
6634
  integer,
6630
6635
  signed
6631
- };
6636
+ });
6637
+ attributeShaderTypeInfoCache.set(resolvedAttributeType, result);
6638
+ return result;
6632
6639
  }
6633
6640
  var ShaderTypeDecoder = class {
6634
6641
  getVariableShaderTypeInfo(format) {
@@ -6737,6 +6744,9 @@ ${DECLARATION_INJECT_MARKER}
6737
6744
  "mat4x3<u32>": { type: "u32", components: 12 },
6738
6745
  "mat4x4<u32>": { type: "u32", components: 16 }
6739
6746
  };
6747
+ for (const info of Object.values(UNIFORM_FORMATS)) {
6748
+ Object.freeze(info);
6749
+ }
6740
6750
  var WGSL_ATTRIBUTE_TYPE_ALIAS_MAP = {
6741
6751
  vec2i: "vec2<i32>",
6742
6752
  vec3i: "vec3<i32>",
@@ -11484,7 +11494,19 @@ ${declarations.join("\n")}`).match(
11484
11494
  }
11485
11495
 
11486
11496
  // ../core/src/shadertypes/data-types/decode-data-types.ts
11497
+ var dataTypeInfoCache = /* @__PURE__ */ new Map();
11487
11498
  function getDataTypeInfo(type) {
11499
+ const cached = dataTypeInfoCache.get(type);
11500
+ if (cached) {
11501
+ return cached;
11502
+ }
11503
+ const decoded = Object.freeze(decodeDataTypeInfo(type));
11504
+ if (Object.hasOwn(NORMALIZED_TYPE_MAP, type)) {
11505
+ dataTypeInfoCache.set(type, decoded);
11506
+ }
11507
+ return decoded;
11508
+ }
11509
+ function decodeDataTypeInfo(type) {
11488
11510
  const normalized2 = type.includes("norm");
11489
11511
  const integer = !normalized2 && !type.startsWith("float");
11490
11512
  const signed = type.startsWith("s");
@@ -11825,40 +11847,33 @@ ${declarations.join("\n")}`).match(
11825
11847
  return this.isCompressed(format) && !format.endsWith("-webgl") ? WEBGPU_CREATE_FILTER2 : 0;
11826
11848
  }
11827
11849
  /** Computes the memory layout for a texture, in particular including row byte alignment */
11828
- computeMemoryLayout(opts) {
11829
- return computeTextureMemoryLayout(opts);
11850
+ computeMemoryLayout(opts, result) {
11851
+ return computeTextureMemoryLayout(opts, result);
11830
11852
  }
11831
11853
  };
11832
11854
  var textureFormatDecoder = new TextureFormatDecoder();
11833
- function computeTextureMemoryLayout({
11834
- format,
11835
- width,
11836
- height,
11837
- depth,
11838
- byteAlignment
11839
- }) {
11855
+ function computeTextureMemoryLayout({ format, width, height, depth, byteAlignment }, result = {}) {
11840
11856
  const formatInfo = textureFormatDecoder.getInfo(format);
11857
+ const { bytesPerPixel, blockHeight = 1, compressed = false } = formatInfo;
11858
+ const bytesPerRow = getTextureBytesPerRow(formatInfo, width, byteAlignment);
11859
+ const rowsPerImage = compressed ? Math.ceil(height / blockHeight) : height;
11860
+ result.bytesPerPixel = bytesPerPixel;
11861
+ result.bytesPerRow = bytesPerRow;
11862
+ result.rowsPerImage = rowsPerImage;
11863
+ result.depthOrArrayLayers = depth;
11864
+ result.bytesPerImage = bytesPerRow * rowsPerImage;
11865
+ result.byteLength = result.bytesPerImage * depth;
11866
+ return result;
11867
+ }
11868
+ function getTextureBytesPerRow(formatInfo, width, byteAlignment) {
11841
11869
  const {
11842
11870
  bytesPerPixel,
11843
11871
  bytesPerBlock = bytesPerPixel,
11844
11872
  blockWidth = 1,
11845
- blockHeight = 1,
11846
11873
  compressed = false
11847
11874
  } = formatInfo;
11848
11875
  const blockColumns = compressed ? Math.ceil(width / blockWidth) : width;
11849
- const blockRows = compressed ? Math.ceil(height / blockHeight) : height;
11850
- const unpaddedBytesPerRow = blockColumns * bytesPerBlock;
11851
- const bytesPerRow = Math.ceil(unpaddedBytesPerRow / byteAlignment) * byteAlignment;
11852
- const rowsPerImage = blockRows;
11853
- const byteLength = bytesPerRow * rowsPerImage * depth;
11854
- return {
11855
- bytesPerPixel,
11856
- bytesPerRow,
11857
- rowsPerImage,
11858
- depthOrArrayLayers: depth,
11859
- bytesPerImage: bytesPerRow * rowsPerImage,
11860
- byteLength
11861
- };
11876
+ return Math.ceil(blockColumns * bytesPerBlock / byteAlignment) * byteAlignment;
11862
11877
  }
11863
11878
  function getTextureFormatCapabilities(format) {
11864
11879
  const info = getTextureFormatDefinition(format);
@@ -11880,7 +11895,18 @@ ${declarations.join("\n")}`).match(
11880
11895
  formatCapabilities.filter &&= !isDepthStencil && !isSigned && !isInteger && !isWebGLSpecific;
11881
11896
  return formatCapabilities;
11882
11897
  }
11898
+ var textureFormatInfoCache = /* @__PURE__ */ new Map();
11883
11899
  function getTextureFormatInfo(format) {
11900
+ let formatInfo = textureFormatInfoCache.get(format);
11901
+ if (!formatInfo) {
11902
+ const decoded = decodeTextureFormatInfo(format);
11903
+ decoded.bitsPerChannel = Object.freeze([...decoded.bitsPerChannel]);
11904
+ formatInfo = Object.freeze(decoded);
11905
+ textureFormatInfoCache.set(format, formatInfo);
11906
+ }
11907
+ return formatInfo;
11908
+ }
11909
+ function decodeTextureFormatInfo(format) {
11884
11910
  let formatInfo = getTextureFormatInfoUsingTable(format);
11885
11911
  if (textureFormatDecoder.isCompressed(format)) {
11886
11912
  formatInfo.channels = "rgb";
@@ -12049,6 +12075,8 @@ ${declarations.join("\n")}`).match(
12049
12075
  };
12050
12076
 
12051
12077
  // ../core/src/api/adapter/resources/texture.ts
12078
+ var textureLayoutScratchPool = [];
12079
+ var emptyTextureReadOptions = Object.freeze({});
12052
12080
  var BASE_DIMENSIONS = {
12053
12081
  "1d": "1d",
12054
12082
  "2d": "2d",
@@ -12167,17 +12195,24 @@ ${declarations.join("\n")}`).match(
12167
12195
  * Calculates the memory layout of the texture, required when reading and writing data.
12168
12196
  * @return the backend-aligned linear layout, in particular bytesPerRow which includes any required padding for buffer copy/read paths
12169
12197
  */
12170
- computeMemoryLayout(options_ = {}) {
12171
- const options = this._normalizeTextureReadOptions(options_);
12172
- const { width = this.width, height = this.height, depthOrArrayLayers = this.depth } = options;
12173
- const { format, byteAlignment } = this;
12174
- return textureFormatDecoder.computeMemoryLayout({
12175
- format,
12176
- width,
12177
- height,
12178
- depth: depthOrArrayLayers,
12179
- byteAlignment
12180
- });
12198
+ /** The optional result is caller-owned; internal scratch never escapes this call. */
12199
+ computeMemoryLayout(options_ = emptyTextureReadOptions, result) {
12200
+ const scratch = textureLayoutScratchPool.pop() || {
12201
+ readOptions: {},
12202
+ layoutOptions: {}
12203
+ };
12204
+ try {
12205
+ const options = this._normalizeTextureReadOptions(options_, scratch.readOptions);
12206
+ const layoutOptions = scratch.layoutOptions;
12207
+ layoutOptions.format = this.format;
12208
+ layoutOptions.width = options.width;
12209
+ layoutOptions.height = options.height;
12210
+ layoutOptions.depth = options.depthOrArrayLayers;
12211
+ layoutOptions.byteAlignment = this.byteAlignment;
12212
+ return textureFormatDecoder.computeMemoryLayout(layoutOptions, result);
12213
+ } finally {
12214
+ textureLayoutScratchPool.push(scratch);
12215
+ }
12181
12216
  }
12182
12217
  /**
12183
12218
  * Read the contents of a texture into a GPU Buffer.
@@ -12286,59 +12321,57 @@ ${declarations.join("\n")}`).match(
12286
12321
  });
12287
12322
  }
12288
12323
  }
12289
- _normalizeCopyImageDataOptions(options_) {
12290
- const { data, depth, ...writeOptions } = options_;
12291
- const options = this._normalizeTextureWriteOptions({
12292
- ...writeOptions,
12293
- depthOrArrayLayers: writeOptions.depthOrArrayLayers ?? depth
12294
- });
12295
- return { data, depth: options.depthOrArrayLayers, ...options };
12324
+ /** The optional result is caller-owned scratch storage; every result field is overwritten. */
12325
+ _normalizeCopyImageDataOptions(options_, result = {}) {
12326
+ const { data, depth, depthOrArrayLayers } = options_;
12327
+ this._normalizeTextureWriteOptions(options_, result);
12328
+ if (depthOrArrayLayers === void 0 && depth !== void 0) {
12329
+ const mipDepth = this.dimension === "3d" ? Math.max(1, this.depth >> result.mipLevel) : this.depth;
12330
+ result.depthOrArrayLayers = Math.min(depth, mipDepth - result.z);
12331
+ }
12332
+ result.data = data;
12333
+ result.depth = result.depthOrArrayLayers;
12334
+ return result;
12296
12335
  }
12297
- _normalizeCopyExternalImageOptions(options_) {
12298
- const optionsWithoutUndefined = _Texture._omitUndefined(options_);
12299
- const mipLevel = optionsWithoutUndefined.mipLevel ?? 0;
12300
- const mipLevelSize = this._getMipLevelSize(mipLevel);
12336
+ _normalizeCopyExternalImageOptions(options_, result = {}) {
12337
+ const { width, height } = options_;
12301
12338
  const size = this.device.getExternalImageSize(options_.image);
12302
- const options = {
12303
- ..._Texture.defaultCopyExternalImageOptions,
12304
- ...mipLevelSize,
12305
- ...size,
12306
- ...optionsWithoutUndefined
12307
- };
12308
- options.width = Math.min(options.width, mipLevelSize.width - options.x);
12309
- options.height = Math.min(options.height, mipLevelSize.height - options.y);
12310
- options.depth = Math.min(options.depth, mipLevelSize.depthOrArrayLayers - options.z);
12339
+ const options = _Texture._normalizeOptions(
12340
+ options_,
12341
+ _Texture.defaultCopyExternalImageOptions,
12342
+ result
12343
+ );
12344
+ const mipWidth = Math.max(1, this.width >> options.mipLevel);
12345
+ const mipHeight = this.baseDimension === "1d" ? 1 : Math.max(1, this.height >> options.mipLevel);
12346
+ const mipDepth = this.dimension === "3d" ? Math.max(1, this.depth >> options.mipLevel) : this.depth;
12347
+ options.width = Math.min(width ?? size.width, mipWidth - options.x);
12348
+ options.height = Math.min(height ?? size.height, mipHeight - options.y);
12349
+ options.depth = Math.min(options.depth, mipDepth - options.z);
12311
12350
  return options;
12312
12351
  }
12313
- _normalizeCopyElementImageOptions(options_) {
12314
- const optionsWithoutUndefined = _Texture._omitUndefined(options_);
12315
- const mipLevel = optionsWithoutUndefined.mipLevel ?? 0;
12316
- const mipLevelSize = this._getMipLevelSize(mipLevel);
12317
- const options = {
12318
- ..._Texture.defaultCopyElementImageOptions,
12319
- ...mipLevelSize,
12320
- ...optionsWithoutUndefined
12321
- };
12322
- options.width = Math.min(options.width, mipLevelSize.width - options.x);
12323
- options.height = Math.min(options.height, mipLevelSize.height - options.y);
12324
- options.depth = Math.min(options.depth, mipLevelSize.depthOrArrayLayers - options.z);
12352
+ _normalizeCopyElementImageOptions(options_, result = {}) {
12353
+ const options = _Texture._normalizeOptions(
12354
+ options_,
12355
+ _Texture.defaultCopyElementImageOptions,
12356
+ result
12357
+ );
12358
+ const mipWidth = Math.max(1, this.width >> options.mipLevel);
12359
+ const mipHeight = this.baseDimension === "1d" ? 1 : Math.max(1, this.height >> options.mipLevel);
12360
+ const mipDepth = this.dimension === "3d" ? Math.max(1, this.depth >> options.mipLevel) : this.depth;
12361
+ options.width = Math.min(options.width ?? mipWidth, mipWidth - options.x);
12362
+ options.height = Math.min(options.height ?? mipHeight, mipHeight - options.y);
12363
+ options.depth = Math.min(options.depth, mipDepth - options.z);
12325
12364
  return options;
12326
12365
  }
12327
- _normalizeTextureReadOptions(options_) {
12328
- const optionsWithoutUndefined = _Texture._omitUndefined(options_);
12329
- const mipLevel = optionsWithoutUndefined.mipLevel ?? 0;
12330
- const mipLevelSize = this._getMipLevelSize(mipLevel);
12331
- const options = {
12332
- ..._Texture.defaultTextureReadOptions,
12333
- ...mipLevelSize,
12334
- ...optionsWithoutUndefined
12335
- };
12336
- options.width = Math.min(options.width, mipLevelSize.width - options.x);
12337
- options.height = Math.min(options.height, mipLevelSize.height - options.y);
12338
- options.depthOrArrayLayers = Math.min(
12339
- options.depthOrArrayLayers,
12340
- mipLevelSize.depthOrArrayLayers - options.z
12341
- );
12366
+ _normalizeTextureReadOptions(options_, result = {}) {
12367
+ const { depthOrArrayLayers } = options_;
12368
+ const options = _Texture._normalizeOptions(options_, _Texture.defaultTextureReadOptions, result);
12369
+ const mipWidth = Math.max(1, this.width >> options.mipLevel);
12370
+ const mipHeight = this.baseDimension === "1d" ? 1 : Math.max(1, this.height >> options.mipLevel);
12371
+ const mipDepth = this.dimension === "3d" ? Math.max(1, this.depth >> options.mipLevel) : this.depth;
12372
+ options.width = Math.min(options.width ?? mipWidth, mipWidth - options.x);
12373
+ options.height = Math.min(options.height ?? mipHeight, mipHeight - options.y);
12374
+ options.depthOrArrayLayers = Math.min(depthOrArrayLayers ?? mipDepth, mipDepth - options.z);
12342
12375
  return options;
12343
12376
  }
12344
12377
  /**
@@ -12393,31 +12426,15 @@ ${declarations.join("\n")}`).match(
12393
12426
  throw new Error(`${this} color readback does not support format ${this.format}`);
12394
12427
  }
12395
12428
  }
12396
- _normalizeTextureWriteOptions(options_) {
12397
- const optionsWithoutUndefined = _Texture._omitUndefined(options_);
12398
- const mipLevel = optionsWithoutUndefined.mipLevel ?? 0;
12399
- const mipLevelSize = this._getMipLevelSize(mipLevel);
12400
- const options = {
12401
- ..._Texture.defaultTextureWriteOptions,
12402
- ...mipLevelSize,
12403
- ...optionsWithoutUndefined
12404
- };
12405
- options.width = Math.min(options.width, mipLevelSize.width - options.x);
12406
- options.height = Math.min(options.height, mipLevelSize.height - options.y);
12407
- options.depthOrArrayLayers = Math.min(
12408
- options.depthOrArrayLayers,
12409
- mipLevelSize.depthOrArrayLayers - options.z
12410
- );
12411
- const layout = textureFormatDecoder.computeMemoryLayout({
12412
- format: this.format,
12413
- width: options.width,
12414
- height: options.height,
12415
- depth: options.depthOrArrayLayers,
12416
- byteAlignment: this.byteAlignment
12417
- });
12418
- const minimumBytesPerRow = layout.bytesPerPixel * options.width;
12419
- options.bytesPerRow = optionsWithoutUndefined.bytesPerRow ?? layout.bytesPerRow;
12420
- options.rowsPerImage = optionsWithoutUndefined.rowsPerImage ?? options.height;
12429
+ _normalizeTextureWriteOptions(options_, result = {}) {
12430
+ const { byteOffset = 0, bytesPerRow, rowsPerImage } = options_;
12431
+ this._normalizeTextureReadOptions(options_, result);
12432
+ const options = result;
12433
+ options.byteOffset = byteOffset;
12434
+ const formatInfo = this.device.getTextureFormatInfo(this.format);
12435
+ const minimumBytesPerRow = formatInfo.bytesPerPixel * options.width;
12436
+ options.bytesPerRow = bytesPerRow ?? getTextureBytesPerRow(formatInfo, options.width, this.byteAlignment);
12437
+ options.rowsPerImage = rowsPerImage ?? options.height;
12421
12438
  if (options.bytesPerRow < minimumBytesPerRow) {
12422
12439
  throw new Error(
12423
12440
  `bytesPerRow (${options.bytesPerRow}) must be at least ${minimumBytesPerRow} for ${this.format}`
@@ -12428,7 +12445,7 @@ ${declarations.join("\n")}`).match(
12428
12445
  `rowsPerImage (${options.rowsPerImage}) must be at least ${options.height} for ${this.format}`
12429
12446
  );
12430
12447
  }
12431
- const bytesPerPixel = this.device.getTextureFormatInfo(this.format).bytesPerPixel;
12448
+ const { bytesPerPixel } = formatInfo;
12432
12449
  if (bytesPerPixel && options.bytesPerRow % bytesPerPixel !== 0) {
12433
12450
  throw new Error(
12434
12451
  `bytesPerRow (${options.bytesPerRow}) must be a multiple of bytesPerPixel (${bytesPerPixel}) for ${this.format}`
@@ -12456,10 +12473,12 @@ ${declarations.join("\n")}`).match(
12456
12473
  }
12457
12474
  return allocatedByteLength * this.samples;
12458
12475
  }
12459
- static _omitUndefined(options) {
12460
- return Object.fromEntries(
12461
- Object.entries(options).filter(([, value]) => value !== void 0)
12462
- );
12476
+ /** Fill every declared field, resetting stale scratch values without allocating entries or spreads. */
12477
+ static _normalizeOptions(options, defaults, result) {
12478
+ for (const key in defaults) {
12479
+ result[key] = options[key] === void 0 ? defaults[key] : options[key];
12480
+ }
12481
+ return result;
12463
12482
  }
12464
12483
  static defaultProps = {
12465
12484
  ...Resource.defaultProps,
@@ -12536,19 +12555,6 @@ ${declarations.join("\n")}`).match(
12536
12555
  mipLevel: 0,
12537
12556
  aspect: "all"
12538
12557
  };
12539
- static defaultTextureWriteOptions = {
12540
- byteOffset: 0,
12541
- bytesPerRow: void 0,
12542
- rowsPerImage: void 0,
12543
- x: 0,
12544
- y: 0,
12545
- z: 0,
12546
- width: void 0,
12547
- height: void 0,
12548
- depthOrArrayLayers: 1,
12549
- mipLevel: 0,
12550
- aspect: "all"
12551
- };
12552
12558
  };
12553
12559
 
12554
12560
  // ../core/src/api/adapter-utils/bind-groups.ts