@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
@@ -1,14 +1,12 @@
1
- import type { TypedArray } from '@math.gl/types';
2
- import type { RenderPipelineProps, RenderPipelineParameters, BufferLayout, VertexArray, TransformFeedback, AttributeInfo, Binding, PrimitiveTopology } from '@luma.gl/core';
3
- import { Device, Buffer, RenderPipeline, RenderPass, UniformStore } from '@luma.gl/core';
4
- import type { ShaderModule, PlatformInfo } from '@luma.gl/shadertools';
1
+ import { type TypedArray } from '@math.gl/types';
2
+ import { type RenderPipelineProps, type RenderPipelineParameters, type BufferLayout, type VertexArray, type TransformFeedback, type AttributeInfo, type Binding, type BindingsByGroup, type PrimitiveTopology, Device, Buffer, RenderPipeline, RenderPass, PipelineFactory, ShaderFactory, UniformStore } from '@luma.gl/core';
3
+ import type { ShaderBindingDebugRow, ShaderModule, PlatformInfo } from '@luma.gl/shadertools';
5
4
  import { ShaderAssembler } from '@luma.gl/shadertools';
6
5
  import type { Geometry } from "../geometry/geometry.js";
7
6
  import { GPUGeometry } from "../geometry/gpu-geometry.js";
8
- import { PipelineFactory } from "../factories/pipeline-factory.js";
9
- import { ShaderFactory } from "../factories/shader-factory.js";
10
7
  import { ShaderInputs } from "../shader-inputs.js";
11
- import { AsyncTexture } from "../async-texture/async-texture.js";
8
+ import { DynamicTexture } from "../dynamic-texture/dynamic-texture.js";
9
+ import { Material } from "../material/material.js";
12
10
  export type ModelProps = Omit<RenderPipelineProps, 'vs' | 'fs' | 'bindings'> & {
13
11
  source?: string;
14
12
  vs?: string | null;
@@ -19,8 +17,12 @@ export type ModelProps = Omit<RenderPipelineProps, 'vs' | 'fs' | 'bindings'> & {
19
17
  defines?: Record<string, boolean>;
20
18
  /** Shader inputs, used to generated uniform buffers and bindings */
21
19
  shaderInputs?: ShaderInputs;
20
+ /** Material-owned group-3 bindings */
21
+ material?: Material;
22
22
  /** Bindings */
23
- bindings?: Record<string, Binding | AsyncTexture>;
23
+ bindings?: Record<string, Binding | DynamicTexture>;
24
+ /** WebGL-only uniforms */
25
+ uniforms?: Record<string, unknown>;
24
26
  /** Parameters that are built into the pipeline */
25
27
  parameters?: RenderPipelineParameters;
26
28
  /** Geometry */
@@ -51,22 +53,37 @@ export type ModelProps = Omit<RenderPipelineProps, 'vs' | 'fs' | 'bindings'> & {
51
53
  shaderAssembler?: ShaderAssembler;
52
54
  };
53
55
  /**
54
- * v9 Model API
55
- * A model
56
- * - automatically reuses pipelines (programs) when possible
57
- * - automatically rebuilds pipelines if necessary to accommodate changed settings
58
- * shadertools integration
59
- * - accepts modules and performs shader transpilation
56
+ * High level draw API for luma.gl.
57
+ *
58
+ * A `Model` encapsulates shaders, geometry attributes, bindings and render
59
+ * pipeline state into a single object. It automatically reuses and rebuilds
60
+ * pipelines as render parameters change and exposes convenient hooks for
61
+ * updating uniforms and attributes.
62
+ *
63
+ * Features:
64
+ * - Reuses and lazily recompiles {@link RenderPipeline | pipelines} as needed.
65
+ * - Integrates with `@luma.gl/shadertools` to assemble GLSL or WGSL from shader modules.
66
+ * - Manages geometry attributes and buffer bindings.
67
+ * - Accepts textures, samplers and uniform buffers as bindings, including `DynamicTexture`.
68
+ * - Provides detailed debug logging and optional shader source inspection.
60
69
  */
61
70
  export declare class Model {
62
71
  static defaultProps: Required<ModelProps>;
72
+ /** Device that created this model */
63
73
  readonly device: Device;
74
+ /** Application provided identifier */
64
75
  readonly id: string;
76
+ /** WGSL shader source when using unified shader */
65
77
  readonly source: string;
78
+ /** GLSL vertex shader source */
66
79
  readonly vs: string;
80
+ /** GLSL fragment shader source */
67
81
  readonly fs: string;
82
+ /** Factory used to create render pipelines */
68
83
  readonly pipelineFactory: PipelineFactory;
84
+ /** Factory used to create shaders */
69
85
  readonly shaderFactory: ShaderFactory;
86
+ /** User-supplied per-model data */
70
87
  userData: {
71
88
  [key: string]: any;
72
89
  };
@@ -89,7 +106,7 @@ export declare class Model {
89
106
  /** Constant-valued attributes */
90
107
  constantAttributes: Record<string, TypedArray>;
91
108
  /** Bindings (textures, samplers, uniform buffers) */
92
- bindings: Record<string, Binding | AsyncTexture>;
109
+ bindings: Record<string, Binding | DynamicTexture>;
93
110
  /**
94
111
  * VertexArray
95
112
  * @note not implemented: if bufferLayout is updated, vertex array has to be rebuilt!
@@ -102,6 +119,7 @@ export declare class Model {
102
119
  pipeline: RenderPipeline;
103
120
  /** ShaderInputs instance */
104
121
  shaderInputs: ShaderInputs;
122
+ material: Material | null;
105
123
  _uniformStore: UniformStore;
106
124
  _attributeInfos: Record<string, AttributeInfo>;
107
125
  _gpuGeometry: GPUGeometry | null;
@@ -111,6 +129,7 @@ export declare class Model {
111
129
  private _destroyed;
112
130
  /** "Time" of last draw. Monotonically increasing timestamp */
113
131
  _lastDrawTimestamp: number;
132
+ private _bindingTable;
114
133
  get [Symbol.toStringTag](): string;
115
134
  toString(): string;
116
135
  constructor(device: Device, props: ModelProps);
@@ -119,7 +138,15 @@ export declare class Model {
119
138
  needsRedraw(): false | string;
120
139
  /** Mark the model as needing a redraw */
121
140
  setNeedsRedraw(reason: string): void;
141
+ /** Returns WGSL binding debug rows for the assembled shader. Returns an empty array for GLSL models. */
142
+ getBindingDebugTable(): readonly ShaderBindingDebugRow[];
143
+ /** Update uniforms and pipeline state prior to drawing. */
122
144
  predraw(): void;
145
+ /**
146
+ * Issue one draw call.
147
+ * @param renderPass - render pass to draw into
148
+ * @returns `true` if the draw call was executed, `false` if resources were not ready.
149
+ */
123
150
  draw(renderPass: RenderPass): boolean;
124
151
  /**
125
152
  * Updates the optional geometry
@@ -155,12 +182,13 @@ export declare class Model {
155
182
  setVertexCount(vertexCount: number): void;
156
183
  /** Set the shader inputs */
157
184
  setShaderInputs(shaderInputs: ShaderInputs): void;
185
+ setMaterial(material: Material | null): void;
158
186
  /** Update uniform buffers from the model's shader inputs */
159
187
  updateShaderInputs(): void;
160
188
  /**
161
189
  * Sets bindings (textures, samplers, uniform buffers)
162
190
  */
163
- setBindings(bindings: Record<string, Binding | AsyncTexture>): void;
191
+ setBindings(bindings: Record<string, Binding | DynamicTexture>): void;
164
192
  /**
165
193
  * Updates optional transform feedback. WebGL only.
166
194
  */
@@ -192,6 +220,8 @@ export declare class Model {
192
220
  _areBindingsLoading(): string | false;
193
221
  /** Extracts texture view from loaded async textures. Returns null if any textures have not yet been loaded. */
194
222
  _getBindings(): Record<string, Binding>;
223
+ _getBindGroups(): BindingsByGroup;
224
+ _getBindGroupCacheKeys(): Partial<Record<number, object>>;
195
225
  /** Get the timestamp of the latest updated bound GPU memory resource (buffer/texture). */
196
226
  _getBindingsUpdateTimestamp(): number;
197
227
  /**
@@ -213,6 +243,7 @@ export declare class Model {
213
243
  _logFramebuffer(renderPass: RenderPass): void;
214
244
  _getAttributeDebugTable(): Record<string, Record<string, unknown>>;
215
245
  _getBufferOrConstantValues(attribute: Buffer | TypedArray, dataType: any): string;
246
+ private _getNonMaterialBindings;
216
247
  }
217
248
  /** Create a shadertools platform info from the Device */
218
249
  export declare function getPlatformInfo(device: Device): PlatformInfo;
@@ -1 +1 @@
1
- {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/model/model.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EACV,mBAAmB,EACnB,wBAAwB,EACxB,YAAY,EAEZ,WAAW,EACX,iBAAiB,EACjB,aAAa,EACb,OAAO,EACP,iBAAiB,EAClB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,MAAM,EAEN,MAAM,EAIN,cAAc,EACd,UAAU,EACV,YAAY,EAIb,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EAAC,YAAY,EAAE,YAAY,EAAC,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAC,eAAe,EAA0B,MAAM,sBAAsB,CAAC;AAE9E,OAAO,KAAK,EAAC,QAAQ,EAAC,gCAA6B;AACnD,OAAO,EAAC,WAAW,EAAkB,oCAAiC;AACtE,OAAO,EAAC,eAAe,EAA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AAC,EAAE;QAAC,eAAe,CAAC,EAAE,OAAO,CAAA;KAAC,GACpC,IAAI;IAgBP,yFAAyF;IACzF,mBAAmB,IAAI,MAAM,GAAG,KAAK;IAcrC,+GAA+G;IAC/G,YAAY,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAiBvC,cAAc,IAAI,eAAe;IAqBjC,sBAAsB,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAKzD,0FAA0F;IAC1F,2BAA2B,IAAI,MAAM;IAmBrC;;;;OAIG;IACH,sBAAsB,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI;IAqBtD,sCAAsC;IACtC,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAK7C,gCAAgC;IAChC,eAAe,IAAI,cAAc;IA0DjC,iCAAiC;IACjC,YAAY,SAAK;IACjB,QAAQ,UAAS;IAEjB,iBAAiB,IAAI,IAAI;IAazB,eAAe,IAAI,IAAI;IAoBvB,SAAS,CAAC,UAAU,SAAK;IACzB,eAAe,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;IAgB7C,uBAAuB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IA4BlE,0BAA0B,CAAC,SAAS,EAAE,MAAM,GAAG,UAAU,EAAE,QAAQ,EAAE,GAAG,GAAG,MAAM;IAOjF,OAAO,CAAC,uBAAuB;CAehC;AAID,yDAAyD;AACzD,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAS5D"}
@@ -1,28 +1,34 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
- import { Buffer, Texture, TextureView, Sampler, RenderPipeline, UniformStore, log, getTypedArrayConstructor, getAttributeInfosFromLayouts } from '@luma.gl/core';
5
- import { ShaderAssembler, getShaderLayoutFromWGSL } from '@luma.gl/shadertools';
4
+ import { Buffer, Texture, TextureView, Sampler, RenderPipeline, PipelineFactory, ShaderFactory, UniformStore, log, dataTypeDecoder, getAttributeInfosFromLayouts, normalizeBindingsByGroup } from '@luma.gl/core';
5
+ import { ShaderAssembler } from '@luma.gl/shadertools';
6
6
  import { makeGPUGeometry } from "../geometry/gpu-geometry.js";
7
- import { PipelineFactory } from "../factories/pipeline-factory.js";
8
- import { ShaderFactory } from "../factories/shader-factory.js";
9
7
  import { getDebugTableForShaderLayout } from "../debug/debug-shader-layout.js";
10
8
  import { debugFramebuffer } from "../debug/debug-framebuffer.js";
11
9
  import { deepEqual } from "../utils/deep-equal.js";
12
10
  import { BufferLayoutHelper } from "../utils/buffer-layout-helper.js";
13
11
  import { sortedBufferLayoutByShaderSourceLocations } from "../utils/buffer-layout-order.js";
12
+ import { mergeShaderModuleBindingsIntoLayout, shaderModuleHasUniforms } from "../utils/shader-module-utils.js";
14
13
  import { uid } from "../utils/uid.js";
15
14
  import { ShaderInputs } from "../shader-inputs.js";
16
- import { AsyncTexture } from "../async-texture/async-texture.js";
15
+ import { DynamicTexture } from "../dynamic-texture/dynamic-texture.js";
17
16
  const LOG_DRAW_PRIORITY = 2;
18
17
  const LOG_DRAW_TIMEOUT = 10000;
19
18
  /**
20
- * v9 Model API
21
- * A model
22
- * - automatically reuses pipelines (programs) when possible
23
- * - automatically rebuilds pipelines if necessary to accommodate changed settings
24
- * shadertools integration
25
- * - accepts modules and performs shader transpilation
19
+ * High level draw API for luma.gl.
20
+ *
21
+ * A `Model` encapsulates shaders, geometry attributes, bindings and render
22
+ * pipeline state into a single object. It automatically reuses and rebuilds
23
+ * pipelines as render parameters change and exposes convenient hooks for
24
+ * updating uniforms and attributes.
25
+ *
26
+ * Features:
27
+ * - Reuses and lazily recompiles {@link RenderPipeline | pipelines} as needed.
28
+ * - Integrates with `@luma.gl/shadertools` to assemble GLSL or WGSL from shader modules.
29
+ * - Manages geometry attributes and buffer bindings.
30
+ * - Accepts textures, samplers and uniform buffers as bindings, including `DynamicTexture`.
31
+ * - Provides detailed debug logging and optional shader source inspection.
26
32
  */
27
33
  export class Model {
28
34
  static defaultProps = {
@@ -39,11 +45,14 @@ export class Model {
39
45
  indexBuffer: null,
40
46
  attributes: {},
41
47
  constantAttributes: {},
48
+ bindings: {},
49
+ uniforms: {},
42
50
  varyings: [],
43
51
  isInstanced: undefined,
44
52
  instanceCount: 0,
45
53
  vertexCount: 0,
46
54
  shaderInputs: undefined,
55
+ material: undefined,
47
56
  pipelineFactory: undefined,
48
57
  shaderFactory: undefined,
49
58
  transformFeedback: undefined,
@@ -51,16 +60,24 @@ export class Model {
51
60
  debugShaders: undefined,
52
61
  disableWarnings: undefined
53
62
  };
63
+ /** Device that created this model */
54
64
  device;
65
+ /** Application provided identifier */
55
66
  id;
67
+ /** WGSL shader source when using unified shader */
56
68
  // @ts-expect-error assigned in function called from constructor
57
69
  source;
70
+ /** GLSL vertex shader source */
58
71
  // @ts-expect-error assigned in function called from constructor
59
72
  vs;
73
+ /** GLSL fragment shader source */
60
74
  // @ts-expect-error assigned in function called from constructor
61
75
  fs;
76
+ /** Factory used to create render pipelines */
62
77
  pipelineFactory;
78
+ /** Factory used to create shaders */
63
79
  shaderFactory;
80
+ /** User-supplied per-model data */
64
81
  userData = {};
65
82
  // Fixed properties (change can trigger pipeline rebuild)
66
83
  /** The render pipeline GPU parameters, depth testing etc */
@@ -97,6 +114,7 @@ export class Model {
97
114
  /** ShaderInputs instance */
98
115
  // @ts-expect-error Assigned in function called by constructor
99
116
  shaderInputs;
117
+ material = null;
100
118
  // @ts-expect-error Assigned in function called by constructor
101
119
  _uniformStore;
102
120
  _attributeInfos = {};
@@ -107,6 +125,7 @@ export class Model {
107
125
  _destroyed = false;
108
126
  /** "Time" of last draw. Monotonically increasing timestamp */
109
127
  _lastDrawTimestamp = -1;
128
+ _bindingTable = [];
110
129
  get [Symbol.toStringTag]() {
111
130
  return 'Model';
112
131
  }
@@ -119,6 +138,7 @@ export class Model {
119
138
  this.id = props.id || uid('model');
120
139
  this.device = device;
121
140
  Object.assign(this.userData, props.userData);
141
+ this.material = props.material || null;
122
142
  // Setup shader module inputs
123
143
  const moduleMap = Object.fromEntries(this.props.modules?.map(module => [module.name, module]) || []);
124
144
  const shaderInputs = props.shaderInputs ||
@@ -131,13 +151,15 @@ export class Model {
131
151
  const modules =
132
152
  // @ts-ignore shaderInputs is assigned in setShaderInputs above.
133
153
  (this.props.modules?.length > 0 ? this.props.modules : this.shaderInputs?.getModules()) || [];
154
+ this.props.shaderLayout =
155
+ mergeShaderModuleBindingsIntoLayout(this.props.shaderLayout, modules) || null;
134
156
  const isWebGPU = this.device.type === 'webgpu';
135
157
  // WebGPU
136
158
  // TODO - hack to support unified WGSL shader
137
159
  // TODO - this is wrong, compile a single shader
138
160
  if (isWebGPU && this.props.source) {
139
161
  // WGSL
140
- const { source, getUniforms } = this.props.shaderAssembler.assembleWGSLShader({
162
+ const { source, getUniforms, bindingTable } = this.props.shaderAssembler.assembleWGSLShader({
141
163
  platformInfo,
142
164
  ...this.props,
143
165
  modules
@@ -145,8 +167,11 @@ export class Model {
145
167
  this.source = source;
146
168
  // @ts-expect-error
147
169
  this._getModuleUniforms = getUniforms;
170
+ this._bindingTable = bindingTable;
148
171
  // Extract shader layout after modules have been added to WGSL source, to include any bindings added by modules
149
- this.props.shaderLayout ||= getShaderLayoutFromWGSL(this.source);
172
+ const inferredShaderLayout = device.getShaderLayout?.(this.source);
173
+ this.props.shaderLayout =
174
+ mergeShaderModuleBindingsIntoLayout(this.props.shaderLayout || inferredShaderLayout || null, modules) || null;
150
175
  }
151
176
  else {
152
177
  // GLSL
@@ -159,6 +184,7 @@ export class Model {
159
184
  this.fs = fs;
160
185
  // @ts-expect-error
161
186
  this._getModuleUniforms = getUniforms;
187
+ this._bindingTable = [];
162
188
  }
163
189
  this.vertexCount = this.props.vertexCount;
164
190
  this.instanceCount = this.props.instanceCount;
@@ -208,8 +234,6 @@ export class Model {
208
234
  if (props.transformFeedback) {
209
235
  this.transformFeedback = props.transformFeedback;
210
236
  }
211
- // Catch any access to non-standard props
212
- Object.seal(this);
213
237
  }
214
238
  destroy() {
215
239
  if (!this._destroyed) {
@@ -217,7 +241,7 @@ export class Model {
217
241
  this.pipelineFactory.release(this.pipeline);
218
242
  // Release the shaders
219
243
  this.shaderFactory.release(this.pipeline.vs);
220
- if (this.pipeline.fs) {
244
+ if (this.pipeline.fs && this.pipeline.fs !== this.pipeline.vs) {
221
245
  this.shaderFactory.release(this.pipeline.fs);
222
246
  }
223
247
  this._uniformStore.destroy();
@@ -241,12 +265,22 @@ export class Model {
241
265
  setNeedsRedraw(reason) {
242
266
  this._needsRedraw ||= reason;
243
267
  }
268
+ /** Returns WGSL binding debug rows for the assembled shader. Returns an empty array for GLSL models. */
269
+ getBindingDebugTable() {
270
+ return this._bindingTable;
271
+ }
272
+ /** Update uniforms and pipeline state prior to drawing. */
244
273
  predraw() {
245
274
  // Update uniform buffers if needed
246
275
  this.updateShaderInputs();
247
276
  // Check if the pipeline is invalidated
248
277
  this.pipeline = this._updatePipeline();
249
278
  }
279
+ /**
280
+ * Issue one draw call.
281
+ * @param renderPass - render pass to draw into
282
+ * @returns `true` if the draw call was executed, `false` if resources were not ready.
283
+ */
250
284
  draw(renderPass) {
251
285
  const loadingBinding = this._areBindingsLoading();
252
286
  if (loadingBinding) {
@@ -268,13 +302,8 @@ export class Model {
268
302
  // TODO - inside RenderPass is likely the worst place to do this from performance perspective.
269
303
  // Application can call Model.predraw() to avoid this.
270
304
  this.pipeline = this._updatePipeline();
271
- // Set pipeline state, we may be sharing a pipeline so we need to set all state on every draw
272
- // Any caching needs to be done inside the pipeline functions
273
- // TODO this is a busy initialized check for all bindings every frame
274
305
  const syncBindings = this._getBindings();
275
- this.pipeline.setBindings(syncBindings, {
276
- disableWarnings: this.props.disableWarnings
277
- });
306
+ const syncBindGroups = this._getBindGroups();
278
307
  const { indexBuffer } = this.vertexArray;
279
308
  const indexCount = indexBuffer
280
309
  ? indexBuffer.byteLength / (indexBuffer.indexType === 'uint32' ? 4 : 2)
@@ -287,6 +316,13 @@ export class Model {
287
316
  instanceCount: this.instanceCount,
288
317
  indexCount,
289
318
  transformFeedback: this.transformFeedback || undefined,
319
+ // Pipelines may be shared across models when caching is enabled, so bindings
320
+ // and WebGL uniforms must be supplied on every draw instead of being stored
321
+ // on the pipeline instance.
322
+ bindings: syncBindings,
323
+ bindGroups: syncBindGroups,
324
+ _bindGroupCacheKeys: this._getBindGroupCacheKeys(),
325
+ uniforms: this.props.uniforms,
290
326
  // WebGL shares underlying cached pipelines even for models that have different parameters and topology,
291
327
  // so we must provide our unique parameters to each draw
292
328
  // (In WebGPU most parameters are encoded in the pipeline and cannot be changed per draw call)
@@ -397,20 +433,24 @@ export class Model {
397
433
  /** Set the shader inputs */
398
434
  setShaderInputs(shaderInputs) {
399
435
  this.shaderInputs = shaderInputs;
400
- this._uniformStore = new UniformStore(this.shaderInputs.modules);
436
+ this._uniformStore = new UniformStore(this.device, this.shaderInputs.modules);
401
437
  // Create uniform buffer bindings for all modules that actually have uniforms
402
438
  for (const [moduleName, module] of Object.entries(this.shaderInputs.modules)) {
403
- if (shaderModuleHasUniforms(module)) {
404
- const uniformBuffer = this._uniformStore.getManagedUniformBuffer(this.device, moduleName);
439
+ if (shaderModuleHasUniforms(module) && !this.material?.ownsModule(moduleName)) {
440
+ const uniformBuffer = this._uniformStore.getManagedUniformBuffer(moduleName);
405
441
  this.bindings[`${moduleName}Uniforms`] = uniformBuffer;
406
442
  }
407
443
  }
408
444
  this.setNeedsRedraw('shaderInputs');
409
445
  }
446
+ setMaterial(material) {
447
+ this.material = material;
448
+ this.setNeedsRedraw('material');
449
+ }
410
450
  /** Update uniform buffers from the model's shader inputs */
411
451
  updateShaderInputs() {
412
452
  this._uniformStore.setUniforms(this.shaderInputs.getUniformValues());
413
- this.setBindings(this.shaderInputs.getBindingValues());
453
+ this.setBindings(this._getNonMaterialBindings(this.shaderInputs.getBindingValues()));
414
454
  // TODO - this is already tracked through buffer/texture update times?
415
455
  this.setNeedsRedraw('shaderInputs');
416
456
  }
@@ -502,7 +542,12 @@ export class Model {
502
542
  /** Check that bindings are loaded. Returns id of first binding that is still loading. */
503
543
  _areBindingsLoading() {
504
544
  for (const binding of Object.values(this.bindings)) {
505
- if (binding instanceof AsyncTexture && !binding.isReady) {
545
+ if (binding instanceof DynamicTexture && !binding.isReady) {
546
+ return binding.id;
547
+ }
548
+ }
549
+ for (const binding of Object.values(this.material?.bindings || {})) {
550
+ if (binding instanceof DynamicTexture && !binding.isReady) {
506
551
  return binding.id;
507
552
  }
508
553
  }
@@ -512,7 +557,7 @@ export class Model {
512
557
  _getBindings() {
513
558
  const validBindings = {};
514
559
  for (const [name, binding] of Object.entries(this.bindings)) {
515
- if (binding instanceof AsyncTexture) {
560
+ if (binding instanceof DynamicTexture) {
516
561
  // Check that async textures are loaded
517
562
  if (binding.isReady) {
518
563
  validBindings[name] = binding.texture;
@@ -524,6 +569,27 @@ export class Model {
524
569
  }
525
570
  return validBindings;
526
571
  }
572
+ _getBindGroups() {
573
+ const shaderLayout = this.pipeline?.shaderLayout || this.props.shaderLayout || { bindings: [] };
574
+ const bindGroups = shaderLayout.bindings.length
575
+ ? normalizeBindingsByGroup(shaderLayout, this._getBindings())
576
+ : { 0: this._getBindings() };
577
+ if (!this.material) {
578
+ return bindGroups;
579
+ }
580
+ for (const [groupKey, groupBindings] of Object.entries(this.material.getBindingsByGroup())) {
581
+ const group = Number(groupKey);
582
+ bindGroups[group] = {
583
+ ...(bindGroups[group] || {}),
584
+ ...groupBindings
585
+ };
586
+ }
587
+ return bindGroups;
588
+ }
589
+ _getBindGroupCacheKeys() {
590
+ const bindGroupCacheKey = this.material?.getBindGroupCacheKey(3);
591
+ return bindGroupCacheKey ? { 3: bindGroupCacheKey } : {};
592
+ }
527
593
  /** Get the timestamp of the latest updated bound GPU memory resource (buffer/texture). */
528
594
  _getBindingsUpdateTimestamp() {
529
595
  let timestamp = 0;
@@ -534,7 +600,7 @@ export class Model {
534
600
  else if (binding instanceof Buffer || binding instanceof Texture) {
535
601
  timestamp = Math.max(timestamp, binding.updateTimestamp);
536
602
  }
537
- else if (binding instanceof AsyncTexture) {
603
+ else if (binding instanceof DynamicTexture) {
538
604
  timestamp = binding.texture
539
605
  ? Math.max(timestamp, binding.texture.updateTimestamp)
540
606
  : // The texture will become available in the future
@@ -544,7 +610,7 @@ export class Model {
544
610
  timestamp = Math.max(timestamp, binding.buffer.updateTimestamp);
545
611
  }
546
612
  }
547
- return timestamp;
613
+ return Math.max(timestamp, this.material?.getBindingsUpdateTimestamp() || 0);
548
614
  }
549
615
  /**
550
616
  * Updates the optional geometry attributes
@@ -603,20 +669,20 @@ export class Model {
603
669
  }
604
670
  this.pipeline = this.pipelineFactory.createRenderPipeline({
605
671
  ...this.props,
672
+ bindings: undefined,
606
673
  bufferLayout: this.bufferLayout,
607
674
  topology: this.topology,
608
675
  parameters: this.parameters,
609
- // TODO - why set bindings here when we reset them every frame?
610
- // Should we expose a BindGroup abstraction?
611
- bindings: this._getBindings(),
676
+ bindGroups: this._getBindGroups(),
612
677
  vs,
613
678
  fs
614
679
  });
615
680
  this._attributeInfos = getAttributeInfosFromLayouts(this.pipeline.shaderLayout, this.bufferLayout);
616
681
  if (prevShaderVs)
617
682
  this.shaderFactory.release(prevShaderVs);
618
- if (prevShaderFs)
683
+ if (prevShaderFs && prevShaderFs !== prevShaderVs) {
619
684
  this.shaderFactory.release(prevShaderFs);
685
+ }
620
686
  }
621
687
  return this.pipeline;
622
688
  }
@@ -691,13 +757,22 @@ export class Model {
691
757
  }
692
758
  // TODO - fix typing of luma data types
693
759
  _getBufferOrConstantValues(attribute, dataType) {
694
- const TypedArrayConstructor = getTypedArrayConstructor(dataType);
760
+ const TypedArrayConstructor = dataTypeDecoder.getTypedArrayConstructor(dataType);
695
761
  const typedArray = attribute instanceof Buffer ? new TypedArrayConstructor(attribute.debugData) : attribute;
696
762
  return typedArray.toString();
697
763
  }
698
- }
699
- function shaderModuleHasUniforms(module) {
700
- return Boolean(module.uniformTypes && !isObjectEmpty(module.uniformTypes));
764
+ _getNonMaterialBindings(bindings) {
765
+ if (!this.material) {
766
+ return bindings;
767
+ }
768
+ const filteredBindings = {};
769
+ for (const [name, binding] of Object.entries(bindings)) {
770
+ if (!this.material.ownsBinding(name)) {
771
+ filteredBindings[name] = binding;
772
+ }
773
+ }
774
+ return filteredBindings;
775
+ }
701
776
  }
702
777
  // HELPERS
703
778
  /** Create a shadertools platform info from the Device */
@@ -711,13 +786,4 @@ export function getPlatformInfo(device) {
711
786
  features: device.features
712
787
  };
713
788
  }
714
- /** Returns true if given object is empty, false otherwise. */
715
- function isObjectEmpty(obj) {
716
- // @ts-ignore key is unused
717
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
718
- for (const key in obj) {
719
- return false;
720
- }
721
- return true;
722
- }
723
789
  //# sourceMappingURL=model.js.map