@zephyr3d/scene 0.9.26 → 0.9.27

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 (95) hide show
  1. package/dist/animation/animationset.js +92 -30
  2. package/dist/animation/animationset.js.map +1 -1
  3. package/dist/animation/joint_dynamics/convex_collider.js +320 -0
  4. package/dist/animation/joint_dynamics/convex_collider.js.map +1 -0
  5. package/dist/animation/skeleton.js +21 -1
  6. package/dist/animation/skeleton.js.map +1 -1
  7. package/dist/asset/model.js +6 -2
  8. package/dist/asset/model.js.map +1 -1
  9. package/dist/camera/camera.js +75 -23
  10. package/dist/camera/camera.js.map +1 -1
  11. package/dist/index.d.ts +4764 -3600
  12. package/dist/index.js +2 -1
  13. package/dist/index.js.map +1 -1
  14. package/dist/material/hairstrand.js +235 -235
  15. package/dist/material/hairstrand.js.map +1 -1
  16. package/dist/material/material.js +296 -296
  17. package/dist/material/material.js.map +1 -1
  18. package/dist/material/mixins/lit.js +33 -1
  19. package/dist/material/mixins/lit.js.map +1 -1
  20. package/dist/material/shader/helper.js +404 -3
  21. package/dist/material/shader/helper.js.map +1 -1
  22. package/dist/material/water.js +2057 -72
  23. package/dist/material/water.js.map +1 -1
  24. package/dist/posteffect/motionblur.js +663 -58
  25. package/dist/posteffect/motionblur.js.map +1 -1
  26. package/dist/posteffect/posteffect.js +12 -1
  27. package/dist/posteffect/posteffect.js.map +1 -1
  28. package/dist/posteffect/sao.js +46 -44
  29. package/dist/posteffect/sao.js.map +1 -1
  30. package/dist/posteffect/sss.js +30 -2
  31. package/dist/posteffect/sss.js.map +1 -1
  32. package/dist/render/abuffer_oit.js +37 -37
  33. package/dist/render/abuffer_oit.js.map +1 -1
  34. package/dist/render/clipmap.js +156 -5
  35. package/dist/render/clipmap.js.map +1 -1
  36. package/dist/render/cull_visitor.js +1 -0
  37. package/dist/render/cull_visitor.js.map +1 -1
  38. package/dist/render/dualdepthpeeling_oit.js +49 -49
  39. package/dist/render/dualdepthpeeling_oit.js.map +1 -1
  40. package/dist/render/fbm_wavegenerator.js +3 -3
  41. package/dist/render/fbm_wavegenerator.js.map +1 -1
  42. package/dist/render/fft_wavegenerator.js +57 -15
  43. package/dist/render/fft_wavegenerator.js.map +1 -1
  44. package/dist/render/gerstner_wavegenerator.js +127 -20
  45. package/dist/render/gerstner_wavegenerator.js.map +1 -1
  46. package/dist/render/hzb.js +80 -22
  47. package/dist/render/hzb.js.map +1 -1
  48. package/dist/render/lightpass.js +6 -3
  49. package/dist/render/lightpass.js.map +1 -1
  50. package/dist/render/oit.js +11 -11
  51. package/dist/render/oit.js.map +1 -1
  52. package/dist/render/render_queue.js +36 -0
  53. package/dist/render/render_queue.js.map +1 -1
  54. package/dist/render/renderer.js +4 -0
  55. package/dist/render/renderer.js.map +1 -1
  56. package/dist/render/rendergraph/blackboard.js +1 -0
  57. package/dist/render/rendergraph/blackboard.js.map +1 -1
  58. package/dist/render/rendergraph/forward_plus_builder.js +318 -9
  59. package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
  60. package/dist/render/rendergraph/frame_resource_requirements.js +1 -0
  61. package/dist/render/rendergraph/frame_resource_requirements.js.map +1 -1
  62. package/dist/render/rendergraph/history_resources.js +8 -1
  63. package/dist/render/rendergraph/history_resources.js.map +1 -1
  64. package/dist/render/underwater.js +624 -0
  65. package/dist/render/underwater.js.map +1 -0
  66. package/dist/render/water_caustics.js +1380 -0
  67. package/dist/render/water_caustics.js.map +1 -0
  68. package/dist/render/weightedblended_oit.js +33 -33
  69. package/dist/render/weightedblended_oit.js.map +1 -1
  70. package/dist/scene/water.js +540 -4
  71. package/dist/scene/water.js.map +1 -1
  72. package/dist/shaders/water.js +22 -19
  73. package/dist/shaders/water.js.map +1 -1
  74. package/dist/shaders/water_medium.js +56 -0
  75. package/dist/shaders/water_medium.js.map +1 -0
  76. package/dist/shadow/shadow_region.js +49 -49
  77. package/dist/shadow/shadow_region.js.map +1 -1
  78. package/dist/utility/serialization/manager.js +3 -1
  79. package/dist/utility/serialization/manager.js.map +1 -1
  80. package/dist/utility/serialization/scene/animation.js +31 -2
  81. package/dist/utility/serialization/scene/animation.js.map +1 -1
  82. package/dist/utility/serialization/scene/camera.js +53 -25
  83. package/dist/utility/serialization/scene/camera.js.map +1 -1
  84. package/dist/utility/serialization/scene/light.js.map +1 -1
  85. package/dist/utility/serialization/scene/water.js +1101 -21
  86. package/dist/utility/serialization/scene/water.js.map +1 -1
  87. package/dist/utility/shprojector.js +87 -87
  88. package/dist/utility/shprojector.js.map +1 -1
  89. package/package.json +1 -1
  90. package/dist/render/rendergraph/frame_graph_context.js +0 -41
  91. package/dist/render/rendergraph/frame_graph_context.js.map +0 -1
  92. package/dist/shaders/ssgi.js +0 -63
  93. package/dist/shaders/ssgi.js.map +0 -1
  94. package/dist/shaders/ssgi_reprojection.js +0 -118
  95. package/dist/shaders/ssgi_reprojection.js.map +0 -1
@@ -4,100 +4,100 @@ import { RenderBundleWrapper } from '../render/renderbundle_wrapper.js';
4
4
  import { Disposable } from '@zephyr3d/base';
5
5
  import { getEngine } from '../app/api.js';
6
6
 
7
- /**
8
- * Base class for all materials.
9
- *
10
- * Responsibilities:
11
- * - Defines a multi-pass rendering interface (`numPasses`, `apply`, `bind`, `draw`, `drawPrimitive`).
12
- * - Builds and caches GPU shader programs per pass and per-render-context hash.
13
- * - Manages a per-material bind group (typically at index 2) for uniforms and resources.
14
- * - Updates render states per pass (`updateRenderStates`) and uploads uniforms (`_applyUniforms`).
15
- * - Tracks "option" changes that affect shader variant hashing and render bundles.
16
- *
17
- * Caching and hashing:
18
- * - `createHash(pass)` produces a stable hash representing shader variant options for a pass.
19
- * Override `_createHash()` in subclasses to encode feature toggles (defines, keywords, macros).
20
- * - The global hash used to key `MaterialState` also includes `ctx.materialFlags` and
21
- * `ctx.shaderVariantHash` when provided, allowing context-sensitive variants without
22
- * coupling shader programs to runtime texture identities.
23
- * - GPU programs are additionally memoized in a global static `_programCache` across materials
24
- * by `constructor.name` + hash, to avoid recompilation of identical variants.
25
- *
26
- * Bind groups and uniforms:
27
- * - If a program declares a bind group layout at index 2 (i.e., `bindGroupLayouts.length > 2`),
28
- * `apply()` will allocate the group and keep it in the state. Subclasses should fill it in
29
- * `_applyUniforms()`.
30
- * - `applyUniforms()` only calls `_applyUniforms()` when `needUpdate` is true, based on
31
- * `_optionTag` changes (see `optionChanged()`).
32
- *
33
- * Lifecycle:
34
- * - Constructed materials register a persistent ID into a global registry for serialization.
35
- * - `apply(ctx)` prepares all passes: creates/gets state, programs, bind groups, render states,
36
- * and uploads uniforms as needed.
37
- * - `bind(device, pass)` binds the program, bind group (index 2), and render states.
38
- * - `draw(primitive, ctx, numInstances)` runs all passes, calling `bind()` and `drawPrimitive()`.
39
- * - `onDispose()` releases bind groups and registry entries.
40
- *
41
- * Extending:
42
- * - Override `_createProgram(pb, ctx, pass)` to build a shader.
43
- * - Override `_applyUniforms(bindGroup, ctx, pass)` to upload uniforms and resources.
44
- * - Override `updateRenderStates(pass, renderStates, ctx)` to set depth, blend, cull, etc.
45
- * - Override `_createHash()` to encode options that affect program compilation.
46
- * - Override `supportLighting`, `supportInstancing`, `isTransparentPass`, `getQueueType`, etc.
47
- *
48
- * Thread-safety:
49
- * - Intended for main-thread use in a renderer driving WebGPU/WebGL-like devices.
50
- *
51
- * @public
7
+ /**
8
+ * Base class for all materials.
9
+ *
10
+ * Responsibilities:
11
+ * - Defines a multi-pass rendering interface (`numPasses`, `apply`, `bind`, `draw`, `drawPrimitive`).
12
+ * - Builds and caches GPU shader programs per pass and per-render-context hash.
13
+ * - Manages a per-material bind group (typically at index 2) for uniforms and resources.
14
+ * - Updates render states per pass (`updateRenderStates`) and uploads uniforms (`_applyUniforms`).
15
+ * - Tracks "option" changes that affect shader variant hashing and render bundles.
16
+ *
17
+ * Caching and hashing:
18
+ * - `createHash(pass)` produces a stable hash representing shader variant options for a pass.
19
+ * Override `_createHash()` in subclasses to encode feature toggles (defines, keywords, macros).
20
+ * - The global hash used to key `MaterialState` also includes `ctx.materialFlags` and
21
+ * `ctx.shaderVariantHash` when provided, allowing context-sensitive variants without
22
+ * coupling shader programs to runtime texture identities.
23
+ * - GPU programs are additionally memoized in a global static `_programCache` across materials
24
+ * by `constructor.name` + hash, to avoid recompilation of identical variants.
25
+ *
26
+ * Bind groups and uniforms:
27
+ * - If a program declares a bind group layout at index 2 (i.e., `bindGroupLayouts.length > 2`),
28
+ * `apply()` will allocate the group and keep it in the state. Subclasses should fill it in
29
+ * `_applyUniforms()`.
30
+ * - `applyUniforms()` only calls `_applyUniforms()` when `needUpdate` is true, based on
31
+ * `_optionTag` changes (see `optionChanged()`).
32
+ *
33
+ * Lifecycle:
34
+ * - Constructed materials register a persistent ID into a global registry for serialization.
35
+ * - `apply(ctx)` prepares all passes: creates/gets state, programs, bind groups, render states,
36
+ * and uploads uniforms as needed.
37
+ * - `bind(device, pass)` binds the program, bind group (index 2), and render states.
38
+ * - `draw(primitive, ctx, numInstances)` runs all passes, calling `bind()` and `drawPrimitive()`.
39
+ * - `onDispose()` releases bind groups and registry entries.
40
+ *
41
+ * Extending:
42
+ * - Override `_createProgram(pb, ctx, pass)` to build a shader.
43
+ * - Override `_applyUniforms(bindGroup, ctx, pass)` to upload uniforms and resources.
44
+ * - Override `updateRenderStates(pass, renderStates, ctx)` to set depth, blend, cull, etc.
45
+ * - Override `_createHash()` to encode options that affect program compilation.
46
+ * - Override `supportLighting`, `supportInstancing`, `isTransparentPass`, `getQueueType`, etc.
47
+ *
48
+ * Thread-safety:
49
+ * - Intended for main-thread use in a renderer driving WebGPU/WebGL-like devices.
50
+ *
51
+ * @public
52
52
  */ class Material extends Disposable {
53
- /**
54
- * Monotonic instance ID counter.
55
- * @internal
53
+ /**
54
+ * Monotonic instance ID counter.
55
+ * @internal
56
56
  */ static _nextId = 0;
57
- /**
58
- * Global program cache keyed by global hash
57
+ /**
58
+ * Global program cache keyed by global hash
59
59
  */ static _programCache = {};
60
- /**
61
- * Per-material state cache keyed by global hash (material + context + pass).
62
- * @internal
60
+ /**
61
+ * Per-material state cache keyed by global hash (material + context + pass).
62
+ * @internal
63
63
  */ _states;
64
- /**
65
- * Number of rendering passes.
66
- * Subclasses can increase this to implement multi-pass rendering.
67
- * @internal
64
+ /**
65
+ * Number of rendering passes.
66
+ * Subclasses can increase this to implement multi-pass rendering.
67
+ * @internal
68
68
  */ _numPasses;
69
- /**
70
- * Per-pass hash cached results. Length scales with `numPasses`.
71
- * @internal
69
+ /**
70
+ * Per-pass hash cached results. Length scales with `numPasses`.
71
+ * @internal
72
72
  */ _hash;
73
- /**
74
- * Incremented each time options change (via `optionChanged`), used to decide whether
75
- * uniforms need update on next `apply()`.
76
- * @internal
73
+ /**
74
+ * Incremented each time options change (via `optionChanged`), used to decide whether
75
+ * uniforms need update on next `apply()`.
76
+ * @internal
77
77
  */ _optionTag;
78
- /**
79
- * Unique runtime instance ID.
80
- * @internal
78
+ /**
79
+ * Unique runtime instance ID.
80
+ * @internal
81
81
  */ _id;
82
- /**
83
- * Latest computed global hash per pass, set during `apply()`, read in `bind()`.
84
- * @internal
82
+ /**
83
+ * Latest computed global hash per pass, set during `apply()`, read in `bind()`.
84
+ * @internal
85
85
  */ _currentHash;
86
- /**
87
- * Incremented when material states affecting render bundles change (e.g., bind group id changes
88
- * or `optionChanged(true)`), used to trigger re-recording of render bundles.
89
- * @internal
86
+ /**
87
+ * Incremented when material states affecting render bundles change (e.g., bind group id changes
88
+ * or `optionChanged(true)`), used to trigger re-recording of render bundles.
89
+ * @internal
90
90
  */ _changeTag;
91
- /**
92
- * Unique program id counter for naming compiled programs.
93
- * @internal
91
+ /**
92
+ * Unique program id counter for naming compiled programs.
93
+ * @internal
94
94
  */ _nextProgramId = 0;
95
- /**
96
- * Create a new material instance.
97
- *
98
- * - Initializes one pass by default.
99
- * - Prepares per-pass hash storage and change tracking.
100
- * - Registers a persistent ID in the global registry.
95
+ /**
96
+ * Create a new material instance.
97
+ *
98
+ * - Initializes one pass by default.
99
+ * - Prepares per-pass hash storage and change tracking.
100
+ * - Registers a persistent ID in the global registry.
101
101
  */ constructor(){
102
102
  super();
103
103
  this._id = ++Material._nextId;
@@ -111,46 +111,46 @@ import { getEngine } from '../app/api.js';
111
111
  this._changeTag = 0;
112
112
  this._currentHash = [];
113
113
  }
114
- /**
115
- * Create a shallow clone of this material.
116
- *
117
- * Note: The base implementation returns a base `Material`. Subclasses should
118
- * override to return their own type and copy custom fields.
114
+ /**
115
+ * Create a shallow clone of this material.
116
+ *
117
+ * Note: The base implementation returns a base `Material`. Subclasses should
118
+ * override to return their own type and copy custom fields.
119
119
  */ clone() {
120
120
  const other = new Material();
121
121
  other.copyFrom(this);
122
122
  return other;
123
123
  }
124
- /**
125
- * Copy basic properties from another material.
126
- *
127
- * Disposes existing bind groups/states, copies `numPasses`. Subclasses should
128
- * extend this to copy their own fields and call `optionChanged(true)` if
129
- * shader-affecting options differ.
130
- *
131
- * @param other - Source material.
124
+ /**
125
+ * Copy basic properties from another material.
126
+ *
127
+ * Disposes existing bind groups/states, copies `numPasses`. Subclasses should
128
+ * extend this to copy their own fields and call `optionChanged(true)` if
129
+ * shader-affecting options differ.
130
+ *
131
+ * @param other - Source material.
132
132
  */ copyFrom(other) {
133
133
  this.clearCache();
134
134
  this._numPasses = other._numPasses;
135
135
  getEngine().resourceManager.setAssetId(this, getEngine().resourceManager.getAssetId(other.coreMaterial));
136
136
  }
137
- /**
138
- * Incremented when the material’s GPU-relevant state changes and render bundles
139
- * may need to be rebuilt.
137
+ /**
138
+ * Incremented when the material’s GPU-relevant state changes and render bundles
139
+ * may need to be rebuilt.
140
140
  */ get changeTag() {
141
141
  return this._changeTag;
142
142
  }
143
- /**
144
- * Runtime-unique numeric identifier for the material instance.
143
+ /**
144
+ * Runtime-unique numeric identifier for the material instance.
145
145
  */ get instanceId() {
146
146
  return this._id;
147
147
  }
148
- /**
149
- * Number of rendering passes this material uses.
150
- *
151
- * Increasing this will expand the per-pass hash cache; make sure to implement
152
- * `createHash(pass)`, `_createProgram(pb, ctx, pass)`, and `updateRenderStates(pass, ...)`
153
- * accordingly for each pass.
148
+ /**
149
+ * Number of rendering passes this material uses.
150
+ *
151
+ * Increasing this will expand the per-pass hash cache; make sure to implement
152
+ * `createHash(pass)`, `_createProgram(pb, ctx, pass)`, and `updateRenderStates(pass, ...)`
153
+ * accordingly for each pass.
154
154
  */ get numPasses() {
155
155
  return this._numPasses;
156
156
  }
@@ -160,95 +160,95 @@ import { getEngine } from '../app/api.js';
160
160
  }
161
161
  this._numPasses = val;
162
162
  }
163
- /**
164
- * Get the number of passes this material will render for the given draw context.
165
- *
166
- * Default returns `numPasses`. Subclasses may override to skip passes based on context flags.
167
- * @param _ctx - Draw context (device, flags, pass hash, instance data, etc.).
168
- * @returns Number of passes to render for this context.
163
+ /**
164
+ * Get the number of passes this material will render for the given draw context.
165
+ *
166
+ * Default returns `numPasses`. Subclasses may override to skip passes based on context flags.
167
+ * @param _ctx - Draw context (device, flags, pass hash, instance data, etc.).
168
+ * @returns Number of passes to render for this context.
169
169
  */ getNumPassesForRender(_ctx) {
170
170
  return this._numPasses;
171
171
  }
172
- /**
173
- * Get or compute the per-pass shader hash used for program caching.
174
- *
175
- * Calls `createHash(pass)` lazily and caches the result.
176
- * @internal
172
+ /**
173
+ * Get or compute the per-pass shader hash used for program caching.
174
+ *
175
+ * Calls `createHash(pass)` lazily and caches the result.
176
+ * @internal
177
177
  */ getHash(pass) {
178
178
  if (this._hash[pass] === null) {
179
179
  this._hash[pass] = this.createHash(pass);
180
180
  }
181
181
  return this._hash[pass];
182
182
  }
183
- /**
184
- * Return the queue type to which this material belongs.
185
- *
186
- * Override this in transparent or special materials (e.g., post-process).
183
+ /**
184
+ * Return the queue type to which this material belongs.
185
+ *
186
+ * Override this in transparent or special materials (e.g., post-process).
187
187
  */ getQueueType() {
188
188
  return QUEUE_OPAQUE;
189
189
  }
190
- /**
191
- * Whether the given pass is transparent.
192
- *
193
- * Used to place draw calls into appropriate render queues and set blending states.
190
+ /**
191
+ * Whether the given pass is transparent.
192
+ *
193
+ * Used to place draw calls into appropriate render queues and set blending states.
194
194
  */ isTransparentPass(_pass) {
195
195
  return false;
196
196
  }
197
- /**
198
- * Whether this material's shading is affected by scene lights.
199
- *
200
- * Override and return `false` for unlit materials.
197
+ /**
198
+ * Whether this material's shading is affected by scene lights.
199
+ *
200
+ * Override and return `false` for unlit materials.
201
201
  */ supportLighting() {
202
202
  return true;
203
203
  }
204
- /**
205
- * Whether this material supports hardware instancing.
206
- *
207
- * Override and return `false` if per-instance data is not supported in the shader.
204
+ /**
205
+ * Whether this material supports hardware instancing.
206
+ *
207
+ * Override and return `false` if per-instance data is not supported in the shader.
208
208
  */ supportInstancing() {
209
209
  return true;
210
210
  }
211
211
  /** Returns true if this is a instance of material */ isBatchable() {
212
212
  return false;
213
213
  }
214
- /**
215
- * Whether this material requires the scene color texture (e.g., for refraction).
214
+ /**
215
+ * Whether this material requires the scene color texture (e.g., for refraction).
216
216
  */ needSceneColor() {
217
217
  return false;
218
218
  }
219
- /**
220
- * Whether this material requires the linear scene depth texture (e.g., for depth-aware effects).
219
+ /**
220
+ * Whether this material requires the linear scene depth texture (e.g., for depth-aware effects).
221
221
  */ needSceneDepth() {
222
222
  return false;
223
223
  }
224
- /**
225
- * Create a material instance (instance-uniform-driven variant).
226
- *
227
- * Base returns `null`. Subclasses that support instancing can return a lightweight instance.
224
+ /**
225
+ * Create a material instance (instance-uniform-driven variant).
226
+ *
227
+ * Base returns `null`. Subclasses that support instancing can return a lightweight instance.
228
228
  */ createInstance() {
229
229
  throw new Error('Abstract function call');
230
230
  }
231
- /**
232
- * Returns the core material that owns GPU state.
233
- *
234
- * Instances may delegate to a shared core to reuse compiled programs and caches.
235
- * @public
231
+ /**
232
+ * Returns the core material that owns GPU state.
233
+ *
234
+ * Instances may delegate to a shared core to reuse compiled programs and caches.
235
+ * @public
236
236
  */ get coreMaterial() {
237
237
  return this;
238
238
  }
239
- /**
240
- * Prepare the material for drawing across all passes for the given draw context.
241
- *
242
- * Steps per pass:
243
- * - Compute global hash (material variant + context).
244
- * - Retrieve or build the GPU program, cache in `_programCache`.
245
- * - Create per-material bind group (index 2) if the program exposes it.
246
- * - Update uniforms if `_optionTag` indicates changes since last apply.
247
- * - Update and cache render states for the pass.
248
- * - Detect bind group GPU ID changes to bump `changeTag` and notify `RenderBundleWrapper`.
249
- *
250
- * @param ctx - Draw context (device, flags, pass hash, instance data, etc.).
251
- * @returns `true` if successful; `false` if any pass lacks a valid program.
239
+ /**
240
+ * Prepare the material for drawing across all passes for the given draw context.
241
+ *
242
+ * Steps per pass:
243
+ * - Compute global hash (material variant + context).
244
+ * - Retrieve or build the GPU program, cache in `_programCache`.
245
+ * - Create per-material bind group (index 2) if the program exposes it.
246
+ * - Update uniforms if `_optionTag` indicates changes since last apply.
247
+ * - Update and cache render states for the pass.
248
+ * - Detect bind group GPU ID changes to bump `changeTag` and notify `RenderBundleWrapper`.
249
+ *
250
+ * @param ctx - Draw context (device, flags, pass hash, instance data, etc.).
251
+ * @returns `true` if successful; `false` if any pass lacks a valid program.
252
252
  */ apply(ctx) {
253
253
  const numPasses = this.getNumPassesForRender(ctx);
254
254
  for(let pass = 0; pass < numPasses; pass++){
@@ -328,15 +328,15 @@ import { getEngine } from '../app/api.js';
328
328
  }
329
329
  return true;
330
330
  }
331
- /**
332
- * Bind the program, bind group, and render states for the specified pass.
333
- *
334
- * Must be called after `apply(ctx)` for the same pass.
335
- *
336
- * @param device - Rendering device.
337
- * @param pass - Pass index to bind.
338
- * @returns `true` on success; `false` if state or program missing.
339
- * @internal
331
+ /**
332
+ * Bind the program, bind group, and render states for the specified pass.
333
+ *
334
+ * Must be called after `apply(ctx)` for the same pass.
335
+ *
336
+ * @param device - Rendering device.
337
+ * @param pass - Pass index to bind.
338
+ * @returns `true` on success; `false` if state or program missing.
339
+ * @internal
340
340
  */ bind(device, pass) {
341
341
  const hash = this._currentHash[pass];
342
342
  const state = this._states[hash];
@@ -354,29 +354,29 @@ import { getEngine } from '../app/api.js';
354
354
  device.setRenderStates(state.renderStateSet);
355
355
  return true;
356
356
  }
357
- /**
358
- * Compute the global hash for the given pass and draw context.
359
- *
360
- * Includes:
361
- * - Per-pass material hash from `getHash(pass)`.
362
- * - `ctx.materialFlags` for context-dependent toggles.
363
- * - `ctx.shaderVariantHash` for shader layout/feature variants, falling back
364
- * to `ctx.renderPassHash` for passes without a shader-only hash.
365
- * @internal
357
+ /**
358
+ * Compute the global hash for the given pass and draw context.
359
+ *
360
+ * Includes:
361
+ * - Per-pass material hash from `getHash(pass)`.
362
+ * - `ctx.materialFlags` for context-dependent toggles.
363
+ * - `ctx.shaderVariantHash` for shader layout/feature variants, falling back
364
+ * to `ctx.renderPassHash` for passes without a shader-only hash.
365
+ * @internal
366
366
  */ calcGlobalHash(ctx, pass) {
367
367
  const shaderVariantHash = ctx.shaderVariantHash ?? ctx.renderPassHash;
368
368
  return `${this.getHash(pass)}:${ctx.materialFlags}:${shaderVariantHash}:${ctx.drawEnvLight ? 1 : 0}:${ctx.currentShadowLight ? 1 : 0}:${ctx.lightBlending ? 1 : 0}`;
369
369
  }
370
- /**
371
- * Draw a primitive for all passes using this material.
372
- *
373
- * Calls `bind()` then `drawPrimitive()` per pass. If `numInstances` is zero,
374
- * and `ctx.instanceData` exists, uses `ctx.instanceData.numInstances`.
375
- *
376
- * @param primitive - Geometry to draw.
377
- * @param ctx - Draw context.
378
- * @param numInstances - Instance count; 0 means auto-detect from context.
379
- * @internal
370
+ /**
371
+ * Draw a primitive for all passes using this material.
372
+ *
373
+ * Calls `bind()` then `drawPrimitive()` per pass. If `numInstances` is zero,
374
+ * and `ctx.instanceData` exists, uses `ctx.instanceData.numInstances`.
375
+ *
376
+ * @param primitive - Geometry to draw.
377
+ * @param ctx - Draw context.
378
+ * @param numInstances - Instance count; 0 means auto-detect from context.
379
+ * @internal
380
380
  */ draw(primitive, ctx, numInstances = 0) {
381
381
  const numPasses = this.getNumPassesForRender(ctx);
382
382
  for(let pass = 0; pass < numPasses; pass++){
@@ -384,29 +384,29 @@ import { getEngine } from '../app/api.js';
384
384
  this.drawPrimitive(pass, primitive, ctx, numInstances);
385
385
  }
386
386
  }
387
- /**
388
- * Conditionally update uniforms/resources into the material bind group.
389
- *
390
- * Delegates to `_applyUniforms()` when `needUpdate` is true (based on `_optionTag` check).
391
- *
392
- * @param bindGroup - Material bind group at index 2 (may be `null` if program has no layout).
393
- * @param ctx - Draw context.
394
- * @param needUpdate - Whether uniforms need to be refreshed.
395
- * @param pass - Pass index.
387
+ /**
388
+ * Conditionally update uniforms/resources into the material bind group.
389
+ *
390
+ * Delegates to `_applyUniforms()` when `needUpdate` is true (based on `_optionTag` check).
391
+ *
392
+ * @param bindGroup - Material bind group at index 2 (may be `null` if program has no layout).
393
+ * @param ctx - Draw context.
394
+ * @param needUpdate - Whether uniforms need to be refreshed.
395
+ * @param pass - Pass index.
396
396
  */ applyUniforms(bindGroup, ctx, needUpdate, pass) {
397
397
  if (needUpdate) {
398
398
  this._applyUniforms(bindGroup, ctx, pass);
399
399
  }
400
400
  }
401
- /**
402
- * Notify the material that some option changed.
403
- *
404
- * - Always increments `_optionTag`. This will trigger uniforms update on next `apply()`.
405
- * - If `changeHash` is true, clears per-pass hashes so programs/states will be rebuilt,
406
- * increments `_changeTag`, and notifies `RenderBundleWrapper` to regenerate recorded bundles.
407
- *
408
- * @param changeHash - Set true if the change affects shader compilation or render states.
409
- * @internal
401
+ /**
402
+ * Notify the material that some option changed.
403
+ *
404
+ * - Always increments `_optionTag`. This will trigger uniforms update on next `apply()`.
405
+ * - If `changeHash` is true, clears per-pass hashes so programs/states will be rebuilt,
406
+ * increments `_changeTag`, and notifies `RenderBundleWrapper` to regenerate recorded bundles.
407
+ *
408
+ * @param changeHash - Set true if the change affects shader compilation or render states.
409
+ * @internal
410
410
  */ optionChanged(changeHash) {
411
411
  this._optionTag++;
412
412
  if (changeHash) {
@@ -437,39 +437,39 @@ import { getEngine } from '../app/api.js';
437
437
  }
438
438
  this._states = {};
439
439
  }
440
- /**
441
- * Convert a pass index to a hash seed string.
442
- *
443
- * Subclasses may override to encode per-pass role (e.g., "depth", "forward", "shadow").
444
- *
445
- * @param pass - Pass number.
446
- * @returns String used when building full hash.
440
+ /**
441
+ * Convert a pass index to a hash seed string.
442
+ *
443
+ * Subclasses may override to encode per-pass role (e.g., "depth", "forward", "shadow").
444
+ *
445
+ * @param pass - Pass number.
446
+ * @returns String used when building full hash.
447
447
  */ passToHash(pass) {
448
448
  return String(pass);
449
449
  }
450
- /**
451
- * Build the material hash for a pass (excluding context-dependent parts).
452
- *
453
- * Default formula: `${constructor.name}|${pass}|${_createHash()}`
454
- *
455
- * @param pass - Pass number.
456
- * @returns Hash string used in program caching.
457
- * @internal
450
+ /**
451
+ * Build the material hash for a pass (excluding context-dependent parts).
452
+ *
453
+ * Default formula: `${constructor.name}|${pass}|${_createHash()}`
454
+ *
455
+ * @param pass - Pass number.
456
+ * @returns Hash string used in program caching.
457
+ * @internal
458
458
  */ createHash(pass) {
459
459
  return `${this.constructor.name}|${this.passToHash(pass)}|${this._createHash()}`;
460
460
  }
461
- /**
462
- * Issue the actual draw call for a pass.
463
- *
464
- * Override for custom per-pass draw behavior if necessary. The default implementation:
465
- * - Draws instanced if `numInstances > 0`.
466
- * - Else uses `ctx.instanceData.numInstances` if available.
467
- * - Else issues a non-instanced draw.
468
- *
469
- * @param pass - Pass number.
470
- * @param primitive - Primitive to draw.
471
- * @param ctx - Draw context.
472
- * @param numInstances - Explicit instance count (0 = auto).
461
+ /**
462
+ * Issue the actual draw call for a pass.
463
+ *
464
+ * Override for custom per-pass draw behavior if necessary. The default implementation:
465
+ * - Draws instanced if `numInstances > 0`.
466
+ * - Else uses `ctx.instanceData.numInstances` if available.
467
+ * - Else issues a non-instanced draw.
468
+ *
469
+ * @param pass - Pass number.
470
+ * @param primitive - Primitive to draw.
471
+ * @param ctx - Draw context.
472
+ * @param numInstances - Explicit instance count (0 = auto).
473
473
  */ drawPrimitive(pass, primitive, ctx, numInstances) {
474
474
  if (numInstances > 0) {
475
475
  primitive.drawInstanced(numInstances);
@@ -479,88 +479,88 @@ import { getEngine } from '../app/api.js';
479
479
  primitive.draw();
480
480
  }
481
481
  }
482
- /**
483
- * Dispose the material and release GPU-side resource references.
484
- *
485
- * - Unregisters from the global registry.
486
- * - Disposes the per-material bind groups kept in `_states`.
482
+ /**
483
+ * Dispose the material and release GPU-side resource references.
484
+ *
485
+ * - Unregisters from the global registry.
486
+ * - Disposes the per-material bind groups kept in `_states`.
487
487
  */ onDispose() {
488
488
  super.onDispose();
489
489
  this.clearCache();
490
490
  }
491
- /**
492
- * Build the GPU program for a pass.
493
- *
494
- * Default creates a `ProgramBuilder` and calls `_createProgram(pb, ctx, pass)`.
495
- * Subclasses should override `_createProgram` instead of this method unless
496
- * they need to replace builder instantiation.
497
- *
498
- * @param ctx - Draw context.
499
- * @param pass - Pass number.
500
- * @returns The compiled `GPUProgram`, or `null` on failure.
501
- * @internal
491
+ /**
492
+ * Build the GPU program for a pass.
493
+ *
494
+ * Default creates a `ProgramBuilder` and calls `_createProgram(pb, ctx, pass)`.
495
+ * Subclasses should override `_createProgram` instead of this method unless
496
+ * they need to replace builder instantiation.
497
+ *
498
+ * @param ctx - Draw context.
499
+ * @param pass - Pass number.
500
+ * @returns The compiled `GPUProgram`, or `null` on failure.
501
+ * @internal
502
502
  */ createProgram(ctx, pass) {
503
503
  const pb = new ProgramBuilder(ctx.device);
504
504
  return this._createProgram(pb, ctx, pass);
505
505
  }
506
- /**
507
- * Create and compile the shader program for this material/pass.
508
- *
509
- * Implement in subclasses:
510
- * - Define shader stages, entry points, macros/defines, and resource layouts.
511
- * - Return a compiled `GPUProgram`.
512
- *
513
- * @param pb - Program builder.
514
- * @param ctx - Draw context.
515
- * @param _pass - Pass number.
516
- * @returns The created program, or `null` on failure.
506
+ /**
507
+ * Create and compile the shader program for this material/pass.
508
+ *
509
+ * Implement in subclasses:
510
+ * - Define shader stages, entry points, macros/defines, and resource layouts.
511
+ * - Return a compiled `GPUProgram`.
512
+ *
513
+ * @param pb - Program builder.
514
+ * @param ctx - Draw context.
515
+ * @param _pass - Pass number.
516
+ * @returns The created program, or `null` on failure.
517
517
  */ _createProgram(_pb, _ctx, _pass) {
518
518
  throw new Error('Abstract function call');
519
519
  }
520
- /**
521
- * Upload uniforms and bind resources to the per-material bind group (index 2).
522
- *
523
- * Implement in subclasses to:
524
- * - Write uniform buffers/textures/samplers to the `bindGroup`.
525
- * - Respect the current `pass` and `ctx`.
526
- *
527
- * @param _bindGroup - The bind group to populate.
528
- * @param _ctx - Draw context.
529
- * @param _pass - Pass number.
520
+ /**
521
+ * Upload uniforms and bind resources to the per-material bind group (index 2).
522
+ *
523
+ * Implement in subclasses to:
524
+ * - Write uniform buffers/textures/samplers to the `bindGroup`.
525
+ * - Respect the current `pass` and `ctx`.
526
+ *
527
+ * @param _bindGroup - The bind group to populate.
528
+ * @param _ctx - Draw context.
529
+ * @param _pass - Pass number.
530
530
  */ _applyUniforms(_bindGroup, _ctx, _pass) {}
531
- /**
532
- * Update render states (depth/stencil, blending, rasterization) for the pass.
533
- *
534
- * Implement in subclasses based on transparency, double-sidedness, depth writes/tests,
535
- * color mask, stencil ops, etc., and any context flags in `ctx`.
536
- *
537
- * @param _pass - Current pass index.
538
- * @param _renderStates - Render state set to mutate.
539
- * @param _ctx - Draw context.
531
+ /**
532
+ * Update render states (depth/stencil, blending, rasterization) for the pass.
533
+ *
534
+ * Implement in subclasses based on transparency, double-sidedness, depth writes/tests,
535
+ * color mask, stencil ops, etc., and any context flags in `ctx`.
536
+ *
537
+ * @param _pass - Current pass index.
538
+ * @param _renderStates - Render state set to mutate.
539
+ * @param _ctx - Draw context.
540
540
  */ updateRenderStates(_pass, _renderStates, _ctx) {}
541
- /**
542
- * Compute the material-specific portion of the shader hash for the current options.
543
- *
544
- * Subclasses should override to include macro/define sets that influence program compilation.
545
- * Example return: `"USE_NORMALMAP=1;ALPHA_MODE=BLEND;RECEIVE_SHADOWS=1"`.
546
- *
547
- * @returns Hash fragment string (no context/pass info).
541
+ /**
542
+ * Compute the material-specific portion of the shader hash for the current options.
543
+ *
544
+ * Subclasses should override to include macro/define sets that influence program compilation.
545
+ * Example return: `"USE_NORMALMAP=1;ALPHA_MODE=BLEND;RECEIVE_SHADOWS=1"`.
546
+ *
547
+ * @returns Hash fragment string (no context/pass info).
548
548
  */ _createHash() {
549
549
  return '';
550
550
  }
551
- /**
552
- * Whether this is a lightweight instance of a core material.
553
- *
554
- * Instances typically share GPU programs with a core and only override instance uniforms.
555
- * @internal
551
+ /**
552
+ * Whether this is a lightweight instance of a core material.
553
+ *
554
+ * Instances typically share GPU programs with a core and only override instance uniforms.
555
+ * @internal
556
556
  */ get $isInstance() {
557
557
  return false;
558
558
  }
559
- /**
560
- * Instance-uniform buffer for material instances, if supported.
561
- *
562
- * Returned as a typed Float32 view over a backing ArrayBuffer.
563
- * @internal
559
+ /**
560
+ * Instance-uniform buffer for material instances, if supported.
561
+ *
562
+ * Returned as a typed Float32 view over a backing ArrayBuffer.
563
+ * @internal
564
564
  */ get $instanceUniforms() {
565
565
  throw new Error('Abstract function call');
566
566
  }