Skip to content

Commit cbc4498

Browse files
authored
Merge pull request #7649 from perminder-17/patch-5
fixing-strokeShader() and some minor fixes in shaderHooks-docs
2 parents 8279b97 + 06ddfc9 commit cbc4498

2 files changed

Lines changed: 15 additions & 13 deletions

File tree

src/webgl/material.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2116,7 +2116,7 @@ function material(p5, fn){
21162116
*
21172117
* function draw() {
21182118
* background(255);
2119-
* shader(myShader);
2119+
* strokeShader(myShader);
21202120
* strokeWeight(10);
21212121
* beginShape();
21222122
* for (let i = 0; i <= 50; i++) {

src/webgl/p5.Shader.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -316,22 +316,23 @@ class Shader {
316316
* createCanvas(200, 200, WEBGL);
317317
* myShader = baseMaterialShader().modify({
318318
* uniforms: {
319-
* 'float time': () => millis()
319+
* 'float time': () => millis() // Uniform for time
320320
* },
321-
* 'vec3 getWorldPosition': `(vec3 pos) {
322-
* pos.y += 20. * sin(time * 0.001 + pos.x * 0.05);
323-
* return pos;
321+
* 'Vertex getWorldInputs': `(Vertex inputs) {
322+
* inputs.position.y +=
323+
* 20. * sin(time * 0.001 + inputs.position.x * 0.05);
324+
* return inputs;
324325
* }`
325326
* });
326327
* }
327328
*
328329
* function draw() {
329330
* background(255);
330-
* shader(myShader);
331-
* lights();
332-
* noStroke();
333-
* fill('red');
334-
* sphere(50);
331+
* shader(myShader); // Apply the custom shader
332+
* lights(); // Enable lighting
333+
* noStroke(); // Disable stroke
334+
* fill('red'); // Set fill color to red
335+
* sphere(50); // Draw a sphere with the shader applied
335336
* }
336337
* </code>
337338
* </div>
@@ -346,9 +347,10 @@ class Shader {
346347
* myShader = baseMaterialShader().modify({
347348
* // Manually specifying a uniform
348349
* declarations: 'uniform float time;',
349-
* 'vec3 getWorldPosition': `(vec3 pos) {
350-
* pos.y += 20. * sin(time * 0.001 + pos.x * 0.05);
351-
* return pos;
350+
* 'Vertex getWorldInputs': `(Vertex inputs) {
351+
* inputs.position.y +=
352+
* 20. * sin(time * 0.001 + inputs.position.x * 0.05);
353+
* return inputs;
352354
* }`
353355
* });
354356
* }

0 commit comments

Comments
 (0)