@@ -54,6 +54,66 @@ function rendererWebGPU(p5, fn) {
5454 * the same format as the data originally passed to
5555 * <a href="#/p5/createStorage">`createStorage()`</a>.
5656 *
57+ * ```js example
58+ * let particles;
59+ * let computeShader;
60+ * let displayShader;
61+ * let instance;
62+ * const numParticles = 100;
63+ *
64+ * async function setup() {
65+ * await createCanvas(100, 100, WEBGPU);
66+ * particles = createStorage(makeParticles(width / 2, height / 2));
67+ * computeShader = buildComputeShader(simulate);
68+ * displayShader = buildMaterialShader(display);
69+ * instance = buildGeometry(drawParticle);
70+ * describe('100 orange particles shooting outward.');
71+ * }
72+ *
73+ * function makeParticles(x, y) {
74+ * let data = [];
75+ * for (let i = 0; i < numParticles; i++) {
76+ * let angle = (i / numParticles) * TWO_PI;
77+ * let speed = random(0.5, 2);
78+ * data.push({
79+ * position: createVector(x, y),
80+ * velocity: createVector(cos(angle) * speed, sin(angle) * speed),
81+ * });
82+ * }
83+ * return data;
84+ * }
85+ *
86+ * function drawParticle() {
87+ * sphere(2);
88+ * }
89+ *
90+ * function simulate() {
91+ * let data = uniformStorage(particles);
92+ * let idx = index.x;
93+ * data[idx].position = data[idx].position + data[idx].velocity;
94+ * }
95+ *
96+ * function display() {
97+ * let data = uniformStorage(particles);
98+ * worldInputs.begin();
99+ * let pos = data[instanceID()].position;
100+ * worldInputs.position.xy += pos - [width / 2, height / 2];
101+ * worldInputs.end();
102+ * }
103+ *
104+ * function draw() {
105+ * background(30);
106+ * if (frameCount % 60 === 0) {
107+ * particles.update(makeParticles(random(width), random(height)));
108+ * }
109+ * compute(computeShader, numParticles);
110+ * noStroke();
111+ * fill(255, 200, 50);
112+ * shader(displayShader);
113+ * model(instance, numParticles);
114+ * }
115+ * ```
116+ *
57117 * @method update
58118 * @for p5.StorageBuffer
59119 * @beta
@@ -123,66 +183,6 @@ function rendererWebGPU(p5, fn) {
123183 * Note: <a href="#/p5/createStorage">`createStorage()`</a> is the recommended
124184 * way to create an instance of this class.
125185 *
126- * ```js example
127- * let particles;
128- * let computeShader;
129- * let displayShader;
130- * let instance;
131- * const numParticles = 100;
132- *
133- * async function setup() {
134- * await createCanvas(100, 100, WEBGPU);
135- * particles = createStorage(makeParticles(width / 2, height / 2));
136- * computeShader = buildComputeShader(simulate);
137- * displayShader = buildMaterialShader(display);
138- * instance = buildGeometry(drawParticle);
139- * describe('100 orange particles shooting outward.');
140- * }
141- *
142- * function makeParticles(x, y) {
143- * let data = [];
144- * for (let i = 0; i < numParticles; i++) {
145- * let angle = (i / numParticles) * TWO_PI;
146- * let speed = random(0.5, 2);
147- * data.push({
148- * position: createVector(x, y),
149- * velocity: createVector(cos(angle) * speed, sin(angle) * speed),
150- * });
151- * }
152- * return data;
153- * }
154- *
155- * function drawParticle() {
156- * sphere(2);
157- * }
158- *
159- * function simulate() {
160- * let data = uniformStorage(particles);
161- * let idx = index.x;
162- * data[idx].position = data[idx].position + data[idx].velocity;
163- * }
164- *
165- * function display() {
166- * let data = uniformStorage(particles);
167- * worldInputs.begin();
168- * let pos = data[instanceID()].position;
169- * worldInputs.position.xy += pos - [width / 2, height / 2];
170- * worldInputs.end();
171- * }
172- *
173- * function draw() {
174- * background(30);
175- * if (frameCount % 60 === 0) {
176- * particles.update(makeParticles(random(width), random(height)));
177- * }
178- * compute(computeShader, numParticles);
179- * noStroke();
180- * fill(255, 200, 50);
181- * shader(displayShader);
182- * model(instance, numParticles);
183- * }
184- * ```
185- *
186186 * @class p5.StorageBuffer
187187 * @beta
188188 * @webgpu
0 commit comments