p5 2.2.3 → 2.3.0-rc.0

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 (137) hide show
  1. package/dist/accessibility/color_namer.js +9 -11
  2. package/dist/accessibility/describe.js +0 -1
  3. package/dist/accessibility/gridOutput.js +0 -1
  4. package/dist/accessibility/index.js +9 -10
  5. package/dist/accessibility/outputs.js +0 -1
  6. package/dist/accessibility/textOutput.js +0 -1
  7. package/dist/app.js +11 -10
  8. package/dist/app.node.js +122 -0
  9. package/dist/color/color_conversion.js +9 -11
  10. package/dist/color/creating_reading.js +1 -1
  11. package/dist/color/index.js +2 -2
  12. package/dist/color/p5.Color.js +1 -1
  13. package/dist/color/setting.js +25 -12
  14. package/dist/{constants-BdTiYOQI.js → constants-CYF6mp5_.js} +2 -2
  15. package/dist/core/States.js +1 -1
  16. package/dist/core/constants.js +1 -1
  17. package/dist/core/environment.js +28 -29
  18. package/dist/core/filterShaders.js +1 -1
  19. package/dist/core/friendly_errors/fes_core.js +9 -8
  20. package/dist/core/friendly_errors/file_errors.js +1 -2
  21. package/dist/core/friendly_errors/index.js +1 -1
  22. package/dist/core/friendly_errors/param_validator.js +737 -640
  23. package/dist/core/friendly_errors/sketch_verifier.js +1 -1
  24. package/dist/core/friendly_errors/stacktrace.js +0 -1
  25. package/dist/core/helpers.js +3 -4
  26. package/dist/core/init.js +24 -21
  27. package/dist/core/internationalization.js +1 -1
  28. package/dist/core/legacy.js +9 -11
  29. package/dist/core/main.js +9 -10
  30. package/dist/core/p5.Graphics.js +5 -5
  31. package/dist/core/p5.Renderer.js +3 -3
  32. package/dist/core/p5.Renderer2D.js +9 -10
  33. package/dist/core/p5.Renderer3D.js +5 -5
  34. package/dist/core/rendering.js +5 -5
  35. package/dist/core/structure.js +0 -1
  36. package/dist/core/transform.js +7 -16
  37. package/dist/{creating_reading-C7hu6sg1.js → creating_reading-DLkHH80h.js} +11 -8
  38. package/dist/data/local_storage.js +0 -1
  39. package/dist/dom/dom.js +2 -3
  40. package/dist/dom/index.js +2 -2
  41. package/dist/dom/p5.Element.js +2 -2
  42. package/dist/dom/p5.MediaElement.js +2 -2
  43. package/dist/events/acceleration.js +5 -3
  44. package/dist/events/keyboard.js +0 -1
  45. package/dist/events/pointer.js +0 -2
  46. package/dist/image/const.js +1 -1
  47. package/dist/image/filterRenderer2D.js +19 -12
  48. package/dist/image/image.js +5 -5
  49. package/dist/image/index.js +5 -5
  50. package/dist/image/loading_displaying.js +5 -5
  51. package/dist/image/p5.Image.js +3 -3
  52. package/dist/image/pixels.js +0 -1
  53. package/dist/io/files.js +5 -5
  54. package/dist/io/index.js +5 -5
  55. package/dist/io/p5.Table.js +0 -1
  56. package/dist/io/p5.TableRow.js +0 -1
  57. package/dist/io/p5.XML.js +0 -1
  58. package/dist/{ir_builders-Cd6rU9Vm.js → ir_builders-C2ebb6Lu.js} +234 -1
  59. package/dist/{main-H_nu4eDs.js → main-D2MtO721.js} +107 -136
  60. package/dist/math/Matrices/Matrix.js +1 -1
  61. package/dist/math/Matrices/MatrixNumjs.js +1 -1
  62. package/dist/math/calculation.js +0 -1
  63. package/dist/math/index.js +3 -1
  64. package/dist/math/math.js +3 -17
  65. package/dist/math/noise.js +0 -1
  66. package/dist/math/p5.Matrix.js +1 -2
  67. package/dist/math/p5.Vector.js +233 -279
  68. package/dist/math/patch-vector.js +75 -0
  69. package/dist/math/random.js +0 -1
  70. package/dist/math/trigonometry.js +3 -4
  71. package/dist/{p5.Renderer-BmD2P6Wv.js → p5.Renderer-C0Kzy71d.js} +31 -24
  72. package/dist/{rendering-CC8JNTwG.js → rendering-CvNr0bB8.js} +732 -44
  73. package/dist/shape/2d_primitives.js +1 -4
  74. package/dist/shape/attributes.js +43 -8
  75. package/dist/shape/curves.js +0 -1
  76. package/dist/shape/custom_shapes.js +260 -5
  77. package/dist/shape/index.js +2 -2
  78. package/dist/shape/vertex.js +0 -2
  79. package/dist/strands/ir_builders.js +1 -1
  80. package/dist/strands/ir_types.js +5 -1
  81. package/dist/strands/p5.strands.js +286 -31
  82. package/dist/strands/strands_api.js +179 -8
  83. package/dist/strands/strands_codegen.js +26 -8
  84. package/dist/strands/strands_conditionals.js +1 -1
  85. package/dist/strands/strands_for.js +1 -1
  86. package/dist/strands/strands_node.js +1 -1
  87. package/dist/strands/strands_ternary.js +56 -0
  88. package/dist/strands/strands_transpiler.js +416 -251
  89. package/dist/strands_glslBackend-i-ReKgZo.js +423 -0
  90. package/dist/type/index.js +3 -3
  91. package/dist/type/lib/Typr.js +1 -1
  92. package/dist/type/p5.Font.js +3 -3
  93. package/dist/type/textCore.js +31 -24
  94. package/dist/utilities/conversion.js +0 -1
  95. package/dist/utilities/time_date.js +0 -1
  96. package/dist/utilities/utility_functions.js +0 -1
  97. package/dist/webgl/3d_primitives.js +5 -5
  98. package/dist/webgl/GeometryBuilder.js +1 -1
  99. package/dist/webgl/ShapeBuilder.js +26 -1
  100. package/dist/webgl/enums.js +1 -1
  101. package/dist/webgl/index.js +8 -9
  102. package/dist/webgl/interaction.js +8 -4
  103. package/dist/webgl/light.js +5 -5
  104. package/dist/webgl/loading.js +60 -21
  105. package/dist/webgl/material.js +5 -5
  106. package/dist/webgl/p5.Camera.js +5 -5
  107. package/dist/webgl/p5.Framebuffer.js +5 -5
  108. package/dist/webgl/p5.Geometry.js +3 -5
  109. package/dist/webgl/p5.Quat.js +1 -1
  110. package/dist/webgl/p5.RendererGL.js +17 -21
  111. package/dist/webgl/p5.Shader.js +129 -36
  112. package/dist/webgl/p5.Texture.js +5 -5
  113. package/dist/webgl/strands_glslBackend.js +5 -386
  114. package/dist/webgl/text.js +5 -5
  115. package/dist/webgl/utils.js +5 -5
  116. package/dist/webgl2Compatibility-DA7DLMuq.js +7 -0
  117. package/dist/webgpu/index.js +7 -3
  118. package/dist/webgpu/p5.RendererWebGPU.js +1036 -180
  119. package/dist/webgpu/shaders/color.js +1 -1
  120. package/dist/webgpu/shaders/compute.js +32 -0
  121. package/dist/webgpu/shaders/functions/randomComputeWGSL.js +31 -0
  122. package/dist/webgpu/shaders/functions/randomVertWGSL.js +30 -0
  123. package/dist/webgpu/shaders/functions/randomWGSL.js +30 -0
  124. package/dist/webgpu/shaders/line.js +1 -1
  125. package/dist/webgpu/shaders/material.js +3 -3
  126. package/dist/webgpu/strands_wgslBackend.js +137 -15
  127. package/lib/p5.esm.js +4088 -1950
  128. package/lib/p5.esm.min.js +1 -1
  129. package/lib/p5.js +4088 -1950
  130. package/lib/p5.min.js +1 -1
  131. package/lib/p5.webgpu.esm.js +1638 -306
  132. package/lib/p5.webgpu.js +1637 -305
  133. package/lib/p5.webgpu.min.js +1 -1
  134. package/package.json +6 -1
  135. package/types/global.d.ts +4137 -2396
  136. package/types/p5.d.ts +2702 -1658
  137. package/dist/noise3DGLSL-Bwrdi4gi.js +0 -9
@@ -8,17 +8,17 @@ import 'acorn';
8
8
  import 'acorn-walk';
9
9
  import 'escodegen';
10
10
  import './strands_FES.js';
11
- import '../ir_builders-Cd6rU9Vm.js';
11
+ import '../ir_builders-C2ebb6Lu.js';
12
12
  import './strands_builtins.js';
13
13
  import './strands_conditionals.js';
14
14
  import './strands_phi_utils.js';
15
15
  import './strands_for.js';
16
+ import './strands_ternary.js';
16
17
 
17
18
  /**
18
19
  * @module 3D
19
20
  * @submodule p5.strands
20
21
  * @for p5
21
- * @requires core
22
22
  */
23
23
 
24
24
 
@@ -41,6 +41,7 @@ function strands(p5, fn) {
41
41
  ctx.uniforms = [];
42
42
  ctx.vertexDeclarations = new Set();
43
43
  ctx.fragmentDeclarations = new Set();
44
+ ctx.computeDeclarations = new Set();
44
45
  ctx.hooks = [];
45
46
  ctx.backend = backend;
46
47
  ctx.active = active;
@@ -50,6 +51,7 @@ function strands(p5, fn) {
50
51
  ctx.windowOverrides = {};
51
52
  ctx.fnOverrides = {};
52
53
  ctx.graphicsOverrides = {};
54
+ ctx._randomSeed = null;
53
55
  if (active) {
54
56
  p5.disableFriendlyErrors = true;
55
57
  }
@@ -62,8 +64,10 @@ function strands(p5, fn) {
62
64
  ctx.uniforms = [];
63
65
  ctx.vertexDeclarations = new Set();
64
66
  ctx.fragmentDeclarations = new Set();
67
+ ctx.computeDeclarations = new Set();
65
68
  ctx.hooks = [];
66
69
  ctx.active = false;
70
+ ctx._randomSeed = null;
67
71
  p5.disableFriendlyErrors = ctx.previousFES;
68
72
  for (const key in ctx.windowOverrides) {
69
73
  window[key] = ctx.windowOverrides[key];
@@ -114,7 +118,10 @@ function strands(p5, fn) {
114
118
  //////////////////////////////////////////////
115
119
  const oldModify = p5.Shader.prototype.modify;
116
120
 
117
- p5.Shader.prototype.modify = function (shaderModifier, scope = {}) {
121
+ p5.Shader.prototype.modify = function (shaderModifier, scope = {}, options = {}) {
122
+ const fnOverrides = {};
123
+ const windowOverrides = {};
124
+ const graphicsOverrides = {};
118
125
  try {
119
126
  if (
120
127
  shaderModifier instanceof Function ||
@@ -129,7 +136,8 @@ function strands(p5, fn) {
129
136
  });
130
137
  createShaderHooksFunctions(strandsContext, fn, this);
131
138
  // TODO: expose this, is internal for debugging for now.
132
- const options = { parser: true, srcLocations: false };
139
+ options.parser = true;
140
+ options.srcLocations = false;
133
141
 
134
142
  // 1. Transpile from strands DSL to JS
135
143
  let strandsCallback;
@@ -146,6 +154,8 @@ function strands(p5, fn) {
146
154
  options.srcLocations,
147
155
  scope,
148
156
  );
157
+ } else {
158
+ strandsCallback = shaderModifier;
149
159
  }
150
160
 
151
161
  // 2. Build the IR from JavaScript API
@@ -154,11 +164,24 @@ function strands(p5, fn) {
154
164
  BlockType.GLOBAL,
155
165
  );
156
166
  pushBlock(strandsContext.cfg, globalScope);
167
+ if (options.hook) {
168
+ strandsContext.renderer._pInst[options.hook].begin();
169
+ for (const key of strandsContext.renderer._pInst[options.hook]._properties) {
170
+ const hookProp = strandsContext.renderer._pInst[options.hook][key];
171
+ fnOverrides[key] = fn[key];
172
+ fn[key] = hookProp;
173
+ windowOverrides[key] = window[key];
174
+ window[key] = hookProp;
175
+ graphicsOverrides[key] = p5.Graphics.prototype[key];
176
+ p5.Graphics.prototype[key] = hookProp;
177
+ }
178
+ }
157
179
  if (strandsContext.renderer?._pInst?._runStrandsInGlobalMode) {
158
180
  withTempGlobalMode(strandsContext.renderer._pInst, strandsCallback);
159
181
  } else {
160
182
  strandsCallback();
161
183
  }
184
+ if (options.hook) strandsContext.renderer._pInst[options.hook].end();
162
185
  popBlock(strandsContext.cfg);
163
186
 
164
187
  // 3. Generate shader code hooks object from the IR
@@ -171,6 +194,15 @@ function strands(p5, fn) {
171
194
  return oldModify.call(this, shaderModifier);
172
195
  }
173
196
  } finally {
197
+ for (const key in fnOverrides) {
198
+ fn[key] = fnOverrides[key];
199
+ }
200
+ for (const key in windowOverrides) {
201
+ window[key] = windowOverrides[key];
202
+ }
203
+ for (const key in graphicsOverrides) {
204
+ p5.Graphics[key] = graphicsOverrides[key];
205
+ }
174
206
  // Reset the strands runtime context
175
207
  deinitStrandsContext(strandsContext);
176
208
  }
@@ -183,7 +215,18 @@ if (typeof p5 !== "undefined") {
183
215
 
184
216
  /* ------------------------------------------------------------- */
185
217
  /**
186
- * @property {Object} worldInputs
218
+ * @typedef {Object} WorldInputsHook
219
+ * @property {any} position
220
+ * @property {any} normal
221
+ * @property {any} texCoord
222
+ * @property {any} color
223
+ * @property {function(): undefined} begin
224
+ * @property {function(): undefined} end
225
+ */
226
+
227
+ /**
228
+ * @property {WorldInputsHook} worldInputs
229
+ * @beta
187
230
  * @description
188
231
  * A shader hook block that modifies the world-space properties of each vertex in a shader. This hook can be used inside <a href="#/p5/buildColorShader">`buildColorShader()`</a> and similar shader <a href="#/p5.Shader/modify">`modify()`</a> calls to customize vertex positions, normals, texture coordinates, and colors before rendering. Modifications happen between the `.begin()` and `.end()` methods of the hook. "World space" refers to the coordinate system of the 3D scene, before any camera or projection transformations are applied.
189
232
  *
@@ -227,7 +270,23 @@ if (typeof p5 !== "undefined") {
227
270
  */
228
271
 
229
272
  /**
230
- * @property {Object} combineColors
273
+ * @typedef {Object} CombineColorsHook
274
+ * @property {any} baseColor
275
+ * @property {any} diffuse
276
+ * @property {any} ambientColor
277
+ * @property {any} ambient
278
+ * @property {any} specularColor
279
+ * @property {any} specular
280
+ * @property {any} emissive
281
+ * @property {any} opacity
282
+ * @property {function(): undefined} begin
283
+ * @property {function(): undefined} end
284
+ * @property {function(color: any): void} set
285
+ */
286
+
287
+ /**
288
+ * @property {CombineColorsHook} combineColors
289
+ * @beta
231
290
  * @description
232
291
  * A shader hook block that modifies how color components are combined in the fragment shader. This hook can be used inside <a href="#/p5/buildMaterialShader">`buildMaterialShader()`</a> and similar shader <a href="#/p5.Shader/modify">`modify()`</a> calls to control the final color output of a material. Modifications happen between the `.begin()` and `.end()` methods of the hook.
233
292
  *
@@ -278,8 +337,127 @@ if (typeof p5 !== "undefined") {
278
337
  * }
279
338
  */
280
339
 
340
+ /**
341
+ * @method instanceID
342
+ * @beta
343
+ * @description
344
+ * Returns the index of the current instance when drawing multiple copies of a
345
+ * shape with <a href="#/p5/model">`model(count)`</a>. The first instance has an
346
+ * ID of `0`, the second has `1`, and so on.
347
+ *
348
+ * This lets each copy of a shape behave differently. For example, you can use
349
+ * the ID to place instances at different positions, give them different colors,
350
+ * or animate them at different speeds.
351
+ *
352
+ * `instanceID()` can only be used inside a p5.strands shader callback.
353
+ *
354
+ * ```js example
355
+ * let instancesShader;
356
+ * let instance;
357
+ * let count = 5;
358
+ *
359
+ * function drawInstance() {
360
+ * sphere(15);
361
+ * }
362
+ *
363
+ * function setup() {
364
+ * createCanvas(200, 200, WEBGL);
365
+ * instance = buildGeometry(drawInstance);
366
+ * instancesShader = buildMaterialShader(drawSpaced);
367
+ * describe('Five red spheres arranged in a horizontal line.');
368
+ * }
369
+ *
370
+ * function drawSpaced() {
371
+ * worldInputs.begin();
372
+ * // Spread spheres evenly across the canvas based on their index
373
+ * let spacing = width / count;
374
+ * worldInputs.position.x +=
375
+ * (instanceID() - (count - 1) / 2) * spacing;
376
+ * worldInputs.end();
377
+ * }
378
+ *
379
+ * function draw() {
380
+ * background(220);
381
+ * lights();
382
+ * noStroke();
383
+ * fill('red');
384
+ * shader(instancesShader);
385
+ * model(instance, count);
386
+ * }
387
+ * ```
388
+ *
389
+ * If you are using WebGPU mode, a common pattern is to use `instanceID()` to look up data made with
390
+ * <a href="#/p5/createStorage">`createStorage()`</a>.
391
+ * This lets you give each instance different properties.
392
+ *
393
+ * ```js example
394
+ * let instanceData;
395
+ * let instancesShader;
396
+ * let instance;
397
+ * let count = 5;
398
+ *
399
+ * async function setup() {
400
+ * await createCanvas(200, 200, WEBGPU);
401
+ *
402
+ * let data = [];
403
+ * for (let i = 0; i < count; i++) {
404
+ * data.push({
405
+ * position: createVector(
406
+ * random(-1, 1) * width / 2,
407
+ * random(-1, 1) * height / 2,
408
+ * 0,
409
+ * ),
410
+ * color: color(
411
+ * random(255),
412
+ * random(255),
413
+ * random(255)
414
+ * )
415
+ * });
416
+ * }
417
+ * instanceData = createStorage(data);
418
+ * instance = buildGeometry(drawInstance);
419
+ * instancesShader = buildMaterialShader(drawInstances);
420
+ * describe('Five spheres at random positions, each a different random color.');
421
+ * }
422
+ *
423
+ * function drawInstance() {
424
+ * sphere(15);
425
+ * }
426
+ *
427
+ * function drawInstances() {
428
+ * let data = uniformStorage(instanceData);
429
+ * let itemColor = sharedVec4();
430
+ *
431
+ * worldInputs.begin();
432
+ * let item = data[instanceID()];
433
+ * itemColor = item.color;
434
+ * worldInputs.position += item.position;
435
+ * worldInputs.end();
436
+ *
437
+ * finalColor.begin();
438
+ * finalColor.set(itemColor);
439
+ * finalColor.end();
440
+ * }
441
+ *
442
+ * function draw() {
443
+ * background(220);
444
+ * lights();
445
+ * noStroke();
446
+ * shader(instancesShader);
447
+ * model(instance, count);
448
+ * }
449
+ * ```
450
+ *
451
+ * This can be paired with <a href="#/p5/buildComputeShader">`buildComputeShader`</a>
452
+ * to update the data being read.
453
+ *
454
+ * @webgpu
455
+ * @returns {*} The index of the current instance.
456
+ */
457
+
281
458
  /**
282
459
  * @method smoothstep
460
+ * @beta
283
461
  * @description
284
462
  * A shader function that performs smooth Hermite interpolation between `0.0`
285
463
  * and `1.0`.
@@ -440,7 +618,27 @@ if (typeof p5 !== "undefined") {
440
618
  */
441
619
 
442
620
  /**
443
- * @property {Object} pixelInputs
621
+ * @typedef {Object} PixelInputsHook
622
+ * @property {any} normal
623
+ * @property {any} texCoord
624
+ * @property {any} ambientLight
625
+ * @property {any} ambientMaterial
626
+ * @property {any} specularMaterial
627
+ * @property {any} emissiveMaterial
628
+ * @property {any} color
629
+ * @property {any} shininess
630
+ * @property {any} metalness
631
+ * @property {any} tangent
632
+ * @property {any} center
633
+ * @property {any} position
634
+ * @property {any} strokeWeight
635
+ * @property {function(): undefined} begin
636
+ * @property {function(): undefined} end
637
+ */
638
+
639
+ /**
640
+ * @property {PixelInputsHook} pixelInputs
641
+ * @beta
444
642
  * @description
445
643
  * A shader hook block that modifies the properties of each pixel before the final color is calculated. This hook can be used inside <a href="#/p5/buildMaterialShader">`buildMaterialShader()`</a> and similar shader <a href="#/p5.Shader/modify">`modify()`</a> calls to adjust per-pixel data before lighting is applied. Modifications happen between the `.begin()` and `.end()` methods of the hook.
446
644
  *
@@ -527,12 +725,23 @@ if (typeof p5 !== "undefined") {
527
725
  */
528
726
 
529
727
  /**
530
- * @property finalColor
728
+ * @typedef {Object} FinalColorHook
729
+ * @property {any} color
730
+ * @property {any} texCoord
731
+ * @property {function(): undefined} begin
732
+ * @property {function(): undefined} end
733
+ * @property {function(color: any): void} set
734
+ */
735
+
736
+ /**
737
+ * @property {FinalColorHook} finalColor
738
+ * @beta
531
739
  * @description
532
740
  * A shader hook block that modifies the final color of each pixel after all lighting is applied. This hook can be used inside <a href="#/p5/buildMaterialShader">`buildMaterialShader()`</a> and similar shader <a href="#/p5.Shader/modify">`modify()`</a> calls to adjust the color before it appears on the screen. Modifications happen between the `.begin()` and `.end()` methods of the hook.
533
741
  *
534
742
  * `finalColor` has the following properties:
535
743
  * - `color`: a four-component vector representing the pixel color (red, green, blue, alpha).
744
+ * - `texCoord`: a two-component vector representing the texture coordinates (u, v)
536
745
  *
537
746
  * Call `.set()` on the hook with a vector with four components (red, green, blue, alpha) to update the final color.
538
747
  *
@@ -609,7 +818,18 @@ if (typeof p5 !== "undefined") {
609
818
  */
610
819
 
611
820
  /**
612
- * @property {Object} filterColor
821
+ * @typedef {Object} FilterColorHook
822
+ * @property {any} texCoord
823
+ * @property {any} canvasSize
824
+ * @property {any} texelSize
825
+ * @property {any} canvasContent
826
+ * @property {function(): undefined} begin
827
+ * @property {function(): undefined} end
828
+ * @property {function(color: any): void} set
829
+ */
830
+
831
+ /**
832
+ * @property {FilterColorHook} filterColor
613
833
  * @description
614
834
  * A shader hook block that sets the color for each pixel in a filter shader. This hook can be used inside <a href="#/p5/buildFilterShader">`buildFilterShader()`</a> to control the output color for each pixel.
615
835
  *
@@ -653,7 +873,18 @@ if (typeof p5 !== "undefined") {
653
873
  */
654
874
 
655
875
  /**
656
- * @property {Object} objectInputs
876
+ * @typedef {Object} ObjectInputsHook
877
+ * @property {any} position
878
+ * @property {any} normal
879
+ * @property {any} texCoord
880
+ * @property {any} color
881
+ * @property {function(): undefined} begin
882
+ * @property {function(): undefined} end
883
+ */
884
+
885
+ /**
886
+ * @property {ObjectInputsHook} objectInputs
887
+ * @beta
657
888
  * @description
658
889
  * A shader hook block to modify the properties of each vertex before any transformations are applied. This hook can be used inside <a href="#/p5/buildMaterialShader">`buildMaterialShader()`</a> and similar shader <a href="#/p5.Shader/modify">`modify()`</a> calls to customize vertex positions, normals, texture coordinates, and colors before rendering. Modifications happen between the `.begin()` and `.end()` methods of the hook. "Object space" refers to the coordinate system of the 3D scene before any transformations, cameras, or projection transformations are applied.
659
890
  *
@@ -694,7 +925,18 @@ if (typeof p5 !== "undefined") {
694
925
  */
695
926
 
696
927
  /**
697
- * @property {Object} cameraInputs
928
+ * @typedef {Object} CameraInputsHook
929
+ * @property {any} position
930
+ * @property {any} normal
931
+ * @property {any} texCoord
932
+ * @property {any} color
933
+ * @property {function(): undefined} begin
934
+ * @property {function(): undefined} end
935
+ */
936
+
937
+ /**
938
+ * @property {CameraInputsHook} cameraInputs
939
+ * @beta
698
940
  * @description
699
941
  * A shader hook block that adjusts vertex properties from the perspective of the camera. This hook can be used inside <a href="#/p5/buildMaterialShader">`buildMaterialShader()`</a> and similar shader <a href="#/p5.Shader/modify">`modify()`</a> calls to customize vertex positions, normals, texture coordinates, and colors before rendering. "Camera space" refers to the coordinate system of the 3D scene after transformations have been applied, seen relative to the camera.
700
942
  *
@@ -737,30 +979,37 @@ if (typeof p5 !== "undefined") {
737
979
  */
738
980
 
739
981
  /**
740
- * Retrieves the current color of a given texture at given coordinates.
982
+ * Declares a storage buffer uniform inside a <a href="#/p5.Shader/modify">modify()</a> callback,
983
+ * making a <a href="#/p5/createStorage">createStorage()</a> buffer accessible in the shader.
741
984
  *
742
- * The given coordinates should be between [0, 0] representing the top-left of
743
- * the texture, and [1, 1] representing the bottom-right of the texture.
985
+ * Pass a `p5.StorageBuffer` (or a function returning one) as the second argument
986
+ * to set it as the default value, applied automatically each frame. Pass a plain
987
+ * object with the same field layout as the buffer's struct elements to declare the
988
+ * schema without binding a specific buffer.
744
989
  *
745
- * The given texture could be, for example:
746
- * * <a href="#/p5.Image">p5.Image</a>,
747
- * * a <a href="#/p5.Graphics">p5.Graphics</a>, or
748
- * * a <a href="#/p5.Framebuffer">p5.Framebuffer</a>.
990
+ * When called without a name, p5.strands automatically uses the name of the
991
+ * variable it is assigned to as the uniform name.
749
992
  *
750
- * The retrieved color that is returned will behave like a vec4, with components
751
- * for red, green, blue, and alpha, each between 0.0 and 1.0.
993
+ * Note: `uniformStorage` is only available when using p5.strands.
752
994
  *
753
- * Linear interpolation is used by default. For Framebuffer sources, you can
754
- * prevent this by creating the buffer with:
755
- * ```js
756
- * createFramebuffer({
757
- * textureFiltering: NEAREST
758
- * })
759
- * ```
760
- * This can be useful if you are using your texture to store data other than color.
761
- * See <a href="#/p5/createFramebuffer/">createFramebuffer</a>.
762
- *
763
- * Note: The `getTexture` function is only available when using p5.strands.
995
+ * @method uniformStorage
996
+ * @beta
997
+ * @webgpu
998
+ * @webgpuOnly
999
+ * @submodule p5.strands
1000
+ * @param {String} name The name of the storage buffer uniform in the shader.
1001
+ * @param {p5.StorageBuffer|Function|Object} [bufferOrSchema] A storage buffer to bind,
1002
+ * a function returning a storage buffer (called each frame), or a plain object
1003
+ * describing the struct field layout.
1004
+ * @returns {*} A strands node representing the storage buffer.
1005
+ */
1006
+ /**
1007
+ * @method uniformStorage
1008
+ * @param {p5.StorageBuffer|Function|Object} [bufferOrSchema]
1009
+ * @returns {*}
1010
+ */
1011
+
1012
+ /**
764
1013
  *
765
1014
  * @method getTexture
766
1015
  * @beta
@@ -870,31 +1119,37 @@ if (typeof p5 !== "undefined") {
870
1119
 
871
1120
  /**
872
1121
  * @method getWorldInputs
1122
+ * @beta
873
1123
  * @param {Function} callback
874
1124
  */
875
1125
 
876
1126
  /**
877
1127
  * @method getPixelInputs
1128
+ * @beta
878
1129
  * @param {Function} callback
879
1130
  */
880
1131
 
881
1132
  /**
882
1133
  * @method getFinalColor
1134
+ * @beta
883
1135
  * @param {Function} callback
884
1136
  */
885
1137
 
886
1138
  /**
887
1139
  * @method getColor
1140
+ * @beta
888
1141
  * @param {Function} callback
889
1142
  */
890
1143
 
891
1144
  /**
892
1145
  * @method getObjectInputs
1146
+ * @beta
893
1147
  * @param {Function} callback
894
1148
  */
895
1149
 
896
1150
  /**
897
1151
  * @method getCameraInputs
1152
+ * @beta
898
1153
  * @param {Function} callback
899
1154
  */
900
1155