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

q5-webgpu: User defined uniform data

Open quinton-ashley opened this issue 7 months ago • 0 comments

Support user defined uniform data in custom shaders.

https://p5js.org/reference/p5.Shader/setUniform/

In p5, setting uniform data is typically a necessity, as p5 doesn't provide any instance data such as width, height, mouseX, etc.

q5 does provide uniform data about the q5 instance by default though. So in q5, shader.setUniform would just be for custom data that users want to feed into the shader each frame. Pretty advanced stuff.

If q5 were to support this, I think the assumption would be the user's data is just f32 floats. q5 would make a struct for the data behind the scenes. It'd be put in a buffer each frame just like q5's default uniform data.

In q5, it'd be nice for users to be able to set uniform data in a JS object when they apply a shader, instead of having to use setUniform multiple times.

shader(myCustomShader, {
  myUniform0: 1000,
  myUniform1: 2000
});

quinton-ashley avatar Mar 05 '25 19:03 quinton-ashley