@luma.gl/engine 9.2.6 → 9.3.0-alpha.10

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 (186) hide show
  1. package/dist/animation-loop/animation-loop.d.ts +11 -5
  2. package/dist/animation-loop/animation-loop.d.ts.map +1 -1
  3. package/dist/animation-loop/animation-loop.js +83 -47
  4. package/dist/animation-loop/animation-loop.js.map +1 -1
  5. package/dist/animation-loop/make-animation-loop.js +7 -1
  6. package/dist/animation-loop/make-animation-loop.js.map +1 -1
  7. package/dist/animation-loop/request-animation-frame.d.ts.map +1 -1
  8. package/dist/animation-loop/request-animation-frame.js +23 -6
  9. package/dist/animation-loop/request-animation-frame.js.map +1 -1
  10. package/dist/compute/computation.d.ts +3 -7
  11. package/dist/compute/computation.d.ts.map +1 -1
  12. package/dist/compute/computation.js +16 -13
  13. package/dist/compute/computation.js.map +1 -1
  14. package/dist/compute/swap.d.ts +2 -0
  15. package/dist/compute/swap.d.ts.map +1 -1
  16. package/dist/compute/swap.js +10 -5
  17. package/dist/compute/swap.js.map +1 -1
  18. package/dist/dist.dev.js +2639 -1290
  19. package/dist/dist.min.js +325 -210
  20. package/dist/dynamic-texture/dynamic-texture.d.ts +102 -0
  21. package/dist/dynamic-texture/dynamic-texture.d.ts.map +1 -0
  22. package/dist/dynamic-texture/dynamic-texture.js +556 -0
  23. package/dist/dynamic-texture/dynamic-texture.js.map +1 -0
  24. package/dist/dynamic-texture/texture-data.d.ts +144 -0
  25. package/dist/dynamic-texture/texture-data.d.ts.map +1 -0
  26. package/dist/dynamic-texture/texture-data.js +208 -0
  27. package/dist/dynamic-texture/texture-data.js.map +1 -0
  28. package/dist/geometries/cone-geometry.d.ts +3 -1
  29. package/dist/geometries/cone-geometry.d.ts.map +1 -1
  30. package/dist/geometries/cone-geometry.js.map +1 -1
  31. package/dist/geometries/cylinder-geometry.d.ts +2 -1
  32. package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
  33. package/dist/geometries/cylinder-geometry.js.map +1 -1
  34. package/dist/geometry/gpu-geometry.d.ts.map +1 -1
  35. package/dist/geometry/gpu-geometry.js +8 -3
  36. package/dist/geometry/gpu-geometry.js.map +1 -1
  37. package/dist/index.cjs +2497 -1212
  38. package/dist/index.cjs.map +4 -4
  39. package/dist/index.d.ts +20 -6
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +12 -4
  42. package/dist/index.js.map +1 -1
  43. package/dist/material/material-factory.d.ts +73 -0
  44. package/dist/material/material-factory.d.ts.map +1 -0
  45. package/dist/material/material-factory.js +111 -0
  46. package/dist/material/material-factory.js.map +1 -0
  47. package/dist/material/material.d.ts +84 -0
  48. package/dist/material/material.d.ts.map +1 -0
  49. package/dist/material/material.js +176 -0
  50. package/dist/material/material.js.map +1 -0
  51. package/dist/model/model.d.ts +47 -16
  52. package/dist/model/model.d.ts.map +1 -1
  53. package/dist/model/model.js +113 -47
  54. package/dist/model/model.js.map +1 -1
  55. package/dist/model/split-uniforms-and-bindings.d.ts +4 -3
  56. package/dist/model/split-uniforms-and-bindings.d.ts.map +1 -1
  57. package/dist/model/split-uniforms-and-bindings.js +2 -2
  58. package/dist/model/split-uniforms-and-bindings.js.map +1 -1
  59. package/dist/models/billboard-texture-model.d.ts +8 -5
  60. package/dist/models/billboard-texture-model.d.ts.map +1 -1
  61. package/dist/models/billboard-texture-model.js +77 -23
  62. package/dist/models/billboard-texture-model.js.map +1 -1
  63. package/dist/models/billboard-texture-module.d.ts +1 -1
  64. package/dist/models/billboard-texture-module.js +1 -1
  65. package/dist/models/clip-space.js +7 -7
  66. package/dist/models/directional-light-model.d.ts +7 -0
  67. package/dist/models/directional-light-model.d.ts.map +1 -0
  68. package/dist/models/directional-light-model.js +23 -0
  69. package/dist/models/directional-light-model.js.map +1 -0
  70. package/dist/models/light-model-utils.d.ts +69 -0
  71. package/dist/models/light-model-utils.d.ts.map +1 -0
  72. package/dist/models/light-model-utils.js +395 -0
  73. package/dist/models/light-model-utils.js.map +1 -0
  74. package/dist/models/point-light-model.d.ts +7 -0
  75. package/dist/models/point-light-model.d.ts.map +1 -0
  76. package/dist/models/point-light-model.js +22 -0
  77. package/dist/models/point-light-model.js.map +1 -0
  78. package/dist/models/spot-light-model.d.ts +7 -0
  79. package/dist/models/spot-light-model.d.ts.map +1 -0
  80. package/dist/models/spot-light-model.js +23 -0
  81. package/dist/models/spot-light-model.js.map +1 -0
  82. package/dist/modules/picking/color-picking.d.ts +5 -9
  83. package/dist/modules/picking/color-picking.d.ts.map +1 -1
  84. package/dist/modules/picking/color-picking.js +122 -115
  85. package/dist/modules/picking/color-picking.js.map +1 -1
  86. package/dist/modules/picking/index-picking.d.ts +4 -4
  87. package/dist/modules/picking/index-picking.d.ts.map +1 -1
  88. package/dist/modules/picking/index-picking.js +36 -16
  89. package/dist/modules/picking/index-picking.js.map +1 -1
  90. package/dist/modules/picking/legacy-color-picking.d.ts +26 -0
  91. package/dist/modules/picking/legacy-color-picking.d.ts.map +1 -0
  92. package/dist/modules/picking/legacy-color-picking.js +7 -0
  93. package/dist/modules/picking/legacy-color-picking.js.map +1 -0
  94. package/dist/modules/picking/picking-manager.d.ts +29 -3
  95. package/dist/modules/picking/picking-manager.d.ts.map +1 -1
  96. package/dist/modules/picking/picking-manager.js +188 -41
  97. package/dist/modules/picking/picking-manager.js.map +1 -1
  98. package/dist/modules/picking/picking-uniforms.d.ts +13 -12
  99. package/dist/modules/picking/picking-uniforms.d.ts.map +1 -1
  100. package/dist/modules/picking/picking-uniforms.js +27 -14
  101. package/dist/modules/picking/picking-uniforms.js.map +1 -1
  102. package/dist/modules/picking/picking.d.ts +25 -0
  103. package/dist/modules/picking/picking.d.ts.map +1 -0
  104. package/dist/modules/picking/picking.js +18 -0
  105. package/dist/modules/picking/picking.js.map +1 -0
  106. package/dist/passes/get-fragment-shader.js +12 -27
  107. package/dist/passes/get-fragment-shader.js.map +1 -1
  108. package/dist/passes/shader-pass-renderer.d.ts +5 -7
  109. package/dist/passes/shader-pass-renderer.d.ts.map +1 -1
  110. package/dist/passes/shader-pass-renderer.js +16 -42
  111. package/dist/passes/shader-pass-renderer.js.map +1 -1
  112. package/dist/scenegraph/group-node.d.ts +5 -0
  113. package/dist/scenegraph/group-node.d.ts.map +1 -1
  114. package/dist/scenegraph/group-node.js +12 -0
  115. package/dist/scenegraph/group-node.js.map +1 -1
  116. package/dist/scenegraph/model-node.d.ts +2 -2
  117. package/dist/scenegraph/model-node.d.ts.map +1 -1
  118. package/dist/scenegraph/model-node.js.map +1 -1
  119. package/dist/scenegraph/scenegraph-node.d.ts +1 -1
  120. package/dist/scenegraph/scenegraph-node.d.ts.map +1 -1
  121. package/dist/scenegraph/scenegraph-node.js +23 -15
  122. package/dist/scenegraph/scenegraph-node.js.map +1 -1
  123. package/dist/shader-inputs.d.ts +9 -7
  124. package/dist/shader-inputs.d.ts.map +1 -1
  125. package/dist/shader-inputs.js +84 -4
  126. package/dist/shader-inputs.js.map +1 -1
  127. package/dist/utils/buffer-layout-order.d.ts.map +1 -1
  128. package/dist/utils/buffer-layout-order.js +12 -2
  129. package/dist/utils/buffer-layout-order.js.map +1 -1
  130. package/dist/utils/shader-module-utils.d.ts +7 -0
  131. package/dist/utils/shader-module-utils.d.ts.map +1 -0
  132. package/dist/utils/shader-module-utils.js +46 -0
  133. package/dist/utils/shader-module-utils.js.map +1 -0
  134. package/package.json +6 -6
  135. package/src/animation-loop/animation-loop.ts +89 -50
  136. package/src/animation-loop/make-animation-loop.ts +13 -5
  137. package/src/animation-loop/request-animation-frame.ts +32 -6
  138. package/src/compute/computation.ts +32 -17
  139. package/src/compute/swap.ts +13 -7
  140. package/src/dynamic-texture/dynamic-texture.ts +732 -0
  141. package/src/dynamic-texture/texture-data.ts +336 -0
  142. package/src/geometries/cone-geometry.ts +6 -1
  143. package/src/geometries/cylinder-geometry.ts +5 -1
  144. package/src/geometry/gpu-geometry.ts +8 -3
  145. package/src/index.ts +38 -8
  146. package/src/material/material-factory.ts +157 -0
  147. package/src/material/material.ts +254 -0
  148. package/src/model/model.ts +158 -67
  149. package/src/model/split-uniforms-and-bindings.ts +8 -6
  150. package/src/models/billboard-texture-model.ts +88 -27
  151. package/src/models/billboard-texture-module.ts +1 -1
  152. package/src/models/clip-space.ts +7 -7
  153. package/src/models/directional-light-model.ts +32 -0
  154. package/src/models/light-model-utils.ts +587 -0
  155. package/src/models/point-light-model.ts +31 -0
  156. package/src/models/spot-light-model.ts +32 -0
  157. package/src/modules/picking/color-picking.ts +123 -122
  158. package/src/modules/picking/index-picking.ts +36 -16
  159. package/src/modules/picking/legacy-color-picking.ts +8 -0
  160. package/src/modules/picking/picking-manager.ts +252 -50
  161. package/src/modules/picking/picking-uniforms.ts +39 -24
  162. package/src/modules/picking/picking.ts +22 -0
  163. package/src/passes/get-fragment-shader.ts +12 -27
  164. package/src/passes/shader-pass-renderer.ts +25 -48
  165. package/src/scenegraph/group-node.ts +16 -0
  166. package/src/scenegraph/model-node.ts +2 -2
  167. package/src/scenegraph/scenegraph-node.ts +27 -16
  168. package/src/shader-inputs.ts +165 -15
  169. package/src/utils/buffer-layout-order.ts +18 -2
  170. package/src/utils/shader-module-utils.ts +65 -0
  171. package/dist/async-texture/async-texture.d.ts +0 -166
  172. package/dist/async-texture/async-texture.d.ts.map +0 -1
  173. package/dist/async-texture/async-texture.js +0 -386
  174. package/dist/async-texture/async-texture.js.map +0 -1
  175. package/dist/factories/pipeline-factory.d.ts +0 -37
  176. package/dist/factories/pipeline-factory.d.ts.map +0 -1
  177. package/dist/factories/pipeline-factory.js +0 -181
  178. package/dist/factories/pipeline-factory.js.map +0 -1
  179. package/dist/factories/shader-factory.d.ts +0 -22
  180. package/dist/factories/shader-factory.d.ts.map +0 -1
  181. package/dist/factories/shader-factory.js +0 -88
  182. package/dist/factories/shader-factory.js.map +0 -1
  183. package/src/async-texture/async-texture.ts +0 -551
  184. package/src/factories/pipeline-factory.ts +0 -224
  185. package/src/factories/shader-factory.ts +0 -103
  186. /package/src/{async-texture/texture-setters.ts.disabled → dynamic-texture/texture-data.ts.disabled} +0 -0
@@ -3,24 +3,35 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import {Device, Texture} from '@luma.gl/core';
6
- import {AsyncTexture} from '../async-texture/async-texture';
7
- import {ClipSpace} from './clip-space';
6
+ import type {ShaderModule} from '@luma.gl/shadertools';
7
+ import {DynamicTexture} from '../dynamic-texture/dynamic-texture';
8
+ import {ClipSpace, ClipSpaceProps} from './clip-space';
9
+
10
+ const backgroundModule = {
11
+ name: 'background',
12
+ uniformTypes: {
13
+ scale: 'vec2<f32>'
14
+ }
15
+ } as const satisfies ShaderModule<{}, {scale: [number, number]}>;
8
16
 
9
17
  const BACKGROUND_FS_WGSL = /* wgsl */ `\
10
18
  @group(0) @binding(0) var backgroundTexture: texture_2d<f32>;
11
19
  @group(0) @binding(1) var backgroundTextureSampler: sampler;
20
+ struct backgroundUniforms {
21
+ scale: vec2<f32>,
22
+ };
23
+ @group(0) @binding(2) var<uniform> background: backgroundUniforms;
12
24
 
13
- fn billboardTexture_getTextureUV(coordinates: vec2<f32>) -> vec2<f32> {
14
- let iTexSize: vec2<u32> = textureDimensions(backgroundTexture, 0);
15
- let texSize: vec2<f32> = vec2<f32>(f32(iTexSize.x), f32(iTexSize.y));
16
- var position: vec2<f32> = coordinates.xy / texSize;
17
- return position;
18
- }
25
+ fn billboardTexture_getTextureUV(uv: vec2<f32>) -> vec2<f32> {
26
+ let scale: vec2<f32> = background.scale;
27
+ var position: vec2<f32> = (uv - vec2<f32>(0.5, 0.5)) / scale + vec2<f32>(0.5, 0.5);
28
+ return position;
29
+ }
19
30
 
20
31
  @fragment
21
32
  fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4<f32> {
22
- let position: vec2<f32> = billboardTexture_getTextureUV(inputs.coordinate);
23
- return textureSample(backgroundTexture, backgroundTextureSampler, position);
33
+ let position: vec2<f32> = billboardTexture_getTextureUV(inputs.uv);
34
+ return textureSample(backgroundTexture, backgroundTextureSampler, position);
24
35
  }
25
36
  `;
26
37
 
@@ -29,17 +40,21 @@ const BACKGROUND_FS = /* glsl */ `\
29
40
  precision highp float;
30
41
 
31
42
  uniform sampler2D backgroundTexture;
43
+
44
+ layout(std140) uniform backgroundUniforms {
45
+ vec2 scale;
46
+ } background;
47
+
48
+ in vec2 coordinate;
32
49
  out vec4 fragColor;
33
50
 
34
- vec2 billboardTexture_getTextureUV() {
35
- ivec2 iTexSize = textureSize(backgroundTexture, 0);
36
- vec2 texSize = vec2(float(iTexSize.x), float(iTexSize.y));
37
- vec2 position = gl_FragCoord.xy / texSize;
51
+ vec2 billboardTexture_getTextureUV(vec2 coord) {
52
+ vec2 position = (coord - 0.5) / background.scale + 0.5;
38
53
  return position;
39
54
  }
40
55
 
41
56
  void main(void) {
42
- vec2 position = billboardTexture_getTextureUV();
57
+ vec2 position = billboardTexture_getTextureUV(coordinate);
43
58
  fragColor = texture(backgroundTexture, position);
44
59
  }
45
60
  `;
@@ -47,11 +62,11 @@ void main(void) {
47
62
  /**
48
63
  * Props for a Model that renders a bitmap into the "background", i.e covering the screen
49
64
  */
50
- export type BackgroundTextureModelProps = {
65
+ export type BackgroundTextureModelProps = ClipSpaceProps & {
51
66
  /** id of this model */
52
67
  id?: string;
53
68
  /** The texture to render */
54
- backgroundTexture: Texture | AsyncTexture;
69
+ backgroundTexture: Texture | DynamicTexture;
55
70
  /** If true, the texture is rendered into transparent areas of the screen only, i.e blended in where background alpha is small */
56
71
  blend?: boolean;
57
72
  };
@@ -60,22 +75,27 @@ export type BackgroundTextureModelProps = {
60
75
  * Model that renders a bitmap into the "background", i.e covering the screen
61
76
  */
62
77
  export class BackgroundTextureModel extends ClipSpace {
78
+ backgroundTexture: Texture = null!;
79
+
63
80
  constructor(device: Device, props: BackgroundTextureModelProps) {
64
81
  super(device, {
82
+ ...props,
65
83
  id: props.id || 'background-texture-model',
66
84
  source: BACKGROUND_FS_WGSL,
67
85
  fs: BACKGROUND_FS,
86
+ modules: [...(props.modules || []), backgroundModule],
68
87
  parameters: {
69
88
  depthWriteEnabled: false,
89
+ ...(props.parameters || {}),
70
90
  ...(props.blend
71
91
  ? {
72
92
  blend: true,
73
93
  blendColorOperation: 'add',
74
94
  blendAlphaOperation: 'add',
75
- blendColorSrcFactor: 'one',
76
- blendColorDstFactor: 'one-minus-src',
77
- blendAlphaSrcFactor: 'one',
78
- blendAlphaDstFactor: 'one-minus-src-alpha'
95
+ blendColorSrcFactor: 'one-minus-dst-alpha',
96
+ blendColorDstFactor: 'one',
97
+ blendAlphaSrcFactor: 'one-minus-dst-alpha',
98
+ blendAlphaDstFactor: 'one'
79
99
  }
80
100
  : {})
81
101
  }
@@ -84,17 +104,58 @@ export class BackgroundTextureModel extends ClipSpace {
84
104
  if (!props.backgroundTexture) {
85
105
  throw new Error('BackgroundTextureModel requires a backgroundTexture prop');
86
106
  }
87
- this.setTexture(props.backgroundTexture);
107
+ this.setProps(props);
88
108
  }
89
109
 
90
- setTexture(backgroundTexture: Texture | AsyncTexture): void {
91
- this.setBindings({
92
- backgroundTexture
93
- });
110
+ /** Update the background texture */
111
+ setProps(props: Partial<BackgroundTextureModelProps>): void {
112
+ const {backgroundTexture} = props;
113
+ if (backgroundTexture) {
114
+ this.setBindings({backgroundTexture});
115
+
116
+ if (backgroundTexture.isReady) {
117
+ const texture =
118
+ backgroundTexture instanceof DynamicTexture
119
+ ? backgroundTexture.texture
120
+ : backgroundTexture;
121
+ this.backgroundTexture = texture;
122
+ this.updateScale(texture);
123
+ } else {
124
+ backgroundTexture.ready.then(texture => {
125
+ this.backgroundTexture = texture;
126
+ this.updateScale(texture);
127
+ });
128
+ }
129
+ }
94
130
  }
95
131
 
96
132
  override predraw(): void {
97
- this.shaderInputs.setProps({});
133
+ // this.updateScale(this.backgroundTexture);
98
134
  super.predraw();
99
135
  }
136
+
137
+ updateScale(texture: Texture): void {
138
+ if (!texture) {
139
+ // Initial scale to avoid rendering issues before texture is loaded
140
+ this.shaderInputs.setProps({background: {scale: [1, 1]}});
141
+ return;
142
+ }
143
+ const [screenWidth, screenHeight] = this.device.getCanvasContext().getDrawingBufferSize();
144
+
145
+ const textureWidth = texture.width;
146
+ const textureHeight = texture.height;
147
+
148
+ const screenAspect = screenWidth / screenHeight;
149
+ const textureAspect = textureWidth / textureHeight;
150
+
151
+ let scaleX = 1;
152
+ let scaleY = 1;
153
+ if (screenAspect > textureAspect) {
154
+ scaleY = screenAspect / textureAspect;
155
+ } else {
156
+ scaleX = textureAspect / screenAspect;
157
+ }
158
+
159
+ this.shaderInputs.setProps({background: {scale: [scaleX, scaleY]}});
160
+ }
100
161
  }
@@ -7,7 +7,7 @@ import {ShaderModule} from '@luma.gl/shadertools';
7
7
  const BACKGROUND_FS = /* glsl */ `\
8
8
  #version 300 es
9
9
 
10
- uniform billboardTextureUniforms {
10
+ layout(std140) uniform billboardTextureUniforms {
11
11
  vec2 topLeft;
12
12
  vec2 bottomRight;
13
13
  } billboardTexture;
@@ -10,9 +10,9 @@ import {uid} from '../utils/uid';
10
10
 
11
11
  const CLIPSPACE_VERTEX_SHADER_WGSL = /* wgsl */ `\
12
12
  struct VertexInputs {
13
- @location(0) clipSpacePosition: vec2<f32>,
14
- @location(1) texCoord: vec2<f32>,
15
- @location(2) coordinate: vec2<f32>
13
+ @location(0) clipSpacePositions: vec2<f32>,
14
+ @location(1) texCoords: vec2<f32>,
15
+ @location(2) coordinates: vec2<f32>
16
16
  }
17
17
 
18
18
  struct FragmentInputs {
@@ -25,10 +25,10 @@ struct FragmentInputs {
25
25
  @vertex
26
26
  fn vertexMain(inputs: VertexInputs) -> FragmentInputs {
27
27
  var outputs: FragmentInputs;
28
- outputs.Position = vec4(inputs.clipSpacePosition, 0., 1.);
29
- outputs.position = inputs.clipSpacePosition;
30
- outputs.coordinate = inputs.coordinate;
31
- outputs.uv = inputs.texCoord;
28
+ outputs.Position = vec4(inputs.clipSpacePositions, 0., 1.);
29
+ outputs.position = inputs.clipSpacePositions;
30
+ outputs.coordinate = inputs.coordinates;
31
+ outputs.uv = inputs.texCoords;
32
32
  return outputs;
33
33
  }
34
34
  `;
@@ -0,0 +1,32 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import {Device} from '@luma.gl/core';
6
+ import {ConeGeometry} from '../geometries/cone-geometry';
7
+ import {
8
+ BaseLightModel,
9
+ buildDirectionalLightInstanceData,
10
+ type DirectionalLightModelProps
11
+ } from './light-model-utils';
12
+
13
+ const DIRECTIONAL_LIGHT_GEOMETRY = new ConeGeometry({
14
+ cap: true,
15
+ nradial: 12,
16
+ nvertical: 1,
17
+ radius: 1
18
+ });
19
+
20
+ export type {DirectionalLightModelProps} from './light-model-utils';
21
+
22
+ export class DirectionalLightModel extends BaseLightModel<DirectionalLightModelProps> {
23
+ constructor(device: Device, props: DirectionalLightModelProps) {
24
+ super(device, props, {
25
+ anchorMode: 'apex',
26
+ buildInstanceData: buildDirectionalLightInstanceData,
27
+ geometry: DIRECTIONAL_LIGHT_GEOMETRY,
28
+ idPrefix: 'directional-light-model',
29
+ sizePropNames: ['directionalLightLength']
30
+ });
31
+ }
32
+ }