p5.js icon indicating copy to clipboard operation
p5.js copied to clipboard

Make p5.strands matrix uniform helpers (uniformMat2x2/3x3/4x4) production-ready: tests, docs, p5.Matrix support

Open harshiltewari2004 opened this issue 4 months ago • 8 comments

Increasing access

Matrix uniforms are a basic building block for shader work (transforms, instancing, lighting), but the strands helpers for them are currently discoverable only by reading the source, and parts of the path fail silently. Silent failures are hardest on exactly the learners p5.js serves — a sketch that renders nothing with a clean console gives a beginner no thread to pull. Documenting and testing these helpers turns an undocumented internal into a supported, learnable feature, and removes the need for workarounds like the three-vec3 hack in Renderer3D.js.

Most appropriate sub-area of p5.js?

  • [ ] Accessibility
  • [ ] Color
  • [ ] Core/Environment/Rendering
  • [ ] Data
  • [ ] DOM
  • [ ] Events
  • [ ] Image
  • [ ] IO
  • [ ] Math
  • [ ] Typography
  • [ ] Utilities
  • [x] WebGL
  • [ ] Build process
  • [x] Unit testing
  • [ ] Internationalization
  • [ ] Friendly errors
  • [x] Other (specify if possible)

Feature enhancement details

Other-p5.strands,WEBGPU. Context: in #8953 (comment: [https://github.com/processing/p5.js/issues/8953#issuecomment-5000277736]) I traced the current state of strands matrix uniforms on main (8886f4c6e), and @perminder-17 confirmed the uniforms half is a good separate piece and asked for a scoped issue. The operator/arithmetic side (m * v etc. in binaryOpNode) is explicitly out of scope here — @perminder-17 is working on that under #8953.

What exists today (verified empirically):

  • The DataType loop in strands_api.js auto-registers uniformMat2x2, uniformMat3x3, and uniformMat4x4 from the mat entries in ir_types.js.
  • WebGL: uniformMat3x3('uM', [...9 floats]) generates a valid uniform mat3x3 uM; declaration (strands shaders are #version 300 es), compiles, links, and renders.
  • WebGPU: the same call generates a correct mat3x3<f32> member in the hook uniforms struct with proper bindings.
  • However: zero references in docs/ or test/ — the helpers are generated-only, never exercised, never documented.

Proposed scope:

  • [ ] Unit tests for mat2/mat3/mat4 uniform declaration + upload on the WebGL backend (test/unit/webgl/), including the mat2 upload path added in #8978
  • [ ] Equivalent unit tests on the WebGPU backend (test/unit/webgpu/), verifying upload end-to-end (codegen is confirmed correct; the upload/buffer-layout path is currently untested)
  • [ ] Visual regression test(s) exercising a matrix uniform in a .modify() sketch on both backends
  • [ ] Reference documentation for the three helpers, following the existing documentation pattern in p5.strands.js
  • [ ] setUniform accepting a p5.Matrix directly (there is currently no isMatrix unwrapping alongside isVector/isColor, so only flat column-major arrays work)

Open questions for maintainers:

  1. Naming: the registration only produces uniformMat3x3-style names (no uniformMat3 alias, since the alias branch covers only vec and sampler types). Should shorter aliases be added, or is the explicit NxN form preferred? Happy to follow whichever.
  2. Should the p5.Matrix acceptance in setUniform be part of this issue or split out?

I'd like to fix this myself if approved.

harshiltewari2004 avatar Jul 19 '26 05:07 harshiltewari2004

Hi @perminder-17 — just a gentle bump on this, it's been about 5 days since filing. Happy to be assigned whenever it works for you.

In the meantime I went ahead and drafted the WebGL + WebGPU unit test skeletons for the mat2/mat3/mat4 uniform declaration/upload paths, based on the existing test/unit/webgl/ and test/unit/webgpu/ patterns — so I can move quickly once assigned. Let me know if the proposed scope still looks right or if anything's shifted since #8953.

harshiltewari2004 avatar Jul 23 '26 18:07 harshiltewari2004

Hi @harshiltewari2004 , please note that we do not guarantee any specific timing on reviewing incoming proposals, and while reminders are very welcome if a few weeks has passed, or if it is a time-sensitive bug. In this case, the proposal is an enhancement. It will be considered when we are able to get to it. Please refrain from tagging maintainers too often. I understand it may be frustrating, but I hope you can appreciate that if we are all tagged in everything all the time, it slows down the process overall. Thanks for understanding

ksen0 avatar Jul 23 '26 19:07 ksen0

Understood, and appreciate you flagging it directly. Sorry for the inconvenience — I'll keep this in mind in future threads and hold off on bumping unassigned proposals like this for several weeks rather than days, and keep tagging to only when it's actually needed. Thanks for your patience!

harshiltewari2004 avatar Jul 24 '26 07:07 harshiltewari2004

Hi @perminder-17 — gentle bump on this, it's been about six weeks since filing. Just checking whether the proposed scope (uniform tests + docs on both backends, p5.Matrix support in setUniform) still looks right, or if anything's changed on your end since the #8953 discussion — happy to adjust or get started once this is assigned.

harshiltewari2004 avatar Aug 31 '26 21:08 harshiltewari2004

CC: @davepagurek , do you have any feedback on this as well?

perminder-17 avatar Aug 31 '26 21:08 perminder-17

Hi @davepagurek — following up here since @perminder-17 looped you in about three weeks ago. Still happy to take this on whenever it works for you both — the scope (uniform tests + docs on both backends, p5.Matrix support in setUniform) is laid out above if useful to revisit. No rush, just wanted to make sure this didn't fall through the cracks. Will be opening a PR after it's approved. thanks!

harshiltewari2004 avatar Sep 18 '26 14:09 harshiltewari2004

Hi! I took a look at your suggestions and they all seem reasonable to me. Adding shortened aliases in the pattern you mentioned would also be good, and ideally would be the variant we primarily document. If you feel like adding p5.Matrix support in setUniform too, feel free to add that too, otherwise we can make a separate issue after.

davepagurek avatar Sep 22 '26 14:09 davepagurek

Thanks @davepagurek! Sounds good — I'll add the shortened aliases as the primarily-documented form, and include p5.Matrix support in setUniform as part of this issue rather than splitting it out. Will get started and open a PR once I have something ready.

harshiltewari2004 avatar Sep 22 '26 14:09 harshiltewari2004