@@ -343,18 +343,28 @@ function creatingReading(p5, fn){
343343 * }
344344 *
345345 * @example
346- * // Strands: color() inside a modify() callback returns a vec4
347- * // with normalized RGBA (0-1), instead of a p5.Color object.
346+ * let myShader;
348347 * function setup() {
349- * let shader = baseMaterialShader().modify(() => {
350- * p5.getPixelInputs((inputs) => {
348+ * createCanvas(100, 100, WEBGL);
349+ *
350+ * myShader = baseMaterialShader().modify(() => {
351+ * getPixelInputs((inputs) => {
351352 * // Same syntax as regular sketch code...
352353 * let c = color(255, 0, 0);
353- * // ...but c is a vec4 like (1.0, 0.0, 0.0, 1.0), not a p5.Color.
354- * return c;
354+ * // ...but c is a vec4 with normalized RGBA (0-1), not a p5.Color.
355+ * inputs.color = c;
356+ * return inputs;
355357 * });
356358 * });
357359 * }
360+ *
361+ * function draw() {
362+ * shader(myShader);
363+ * noStroke();
364+ * sphere(40);
365+ *
366+ * describe('A red sphere on a gray background.');
367+ * }
358368 */
359369 /**
360370 * @method color
@@ -420,15 +430,27 @@ function creatingReading(p5, fn){
420430 * @return {Number } the red value.
421431 *
422432 * @example
433+ * let myShader;
423434 * function setup() {
424- * let shader = baseMaterialShader().modify(() => {
425- * p5.getPixelInputs((inputs) => {
435+ * createCanvas(100, 100, WEBGL);
436+ *
437+ * myShader = baseMaterialShader().modify(() => {
438+ * getPixelInputs((inputs) => {
426439 * let r = red(inputs.color);
427- * return vec4(r, 0.0, 0.0, 1.0);
440+ * inputs.color = [r, 0, 0, 1];
441+ * return inputs;
428442 * });
429443 * });
430444 * }
431445 *
446+ * function draw() {
447+ * shader(myShader);
448+ * noStroke();
449+ * sphere(40);
450+ *
451+ * describe('A sphere colored using only its red channel.');
452+ * }
453+ *
432454 * @example
433455 * function setup() {
434456 * createCanvas(100, 100);
@@ -555,15 +577,27 @@ function creatingReading(p5, fn){
555577 * @return {Number } the green value.
556578 *
557579 * @example
580+ * let myShader;
558581 * function setup() {
559- * let shader = baseMaterialShader().modify(() => {
560- * p5.getPixelInputs((inputs) => {
582+ * createCanvas(100, 100, WEBGL);
583+ *
584+ * myShader = baseMaterialShader().modify(() => {
585+ * getPixelInputs((inputs) => {
561586 * let g = green(inputs.color);
562- * return vec4(0.0, g, 0.0, 1.0);
587+ * inputs.color = [0, g, 0, 1];
588+ * return inputs;
563589 * });
564590 * });
565591 * }
566592 *
593+ * function draw() {
594+ * shader(myShader);
595+ * noStroke();
596+ * sphere(40);
597+ *
598+ * describe('A sphere colored using only its green channel.');
599+ * }
600+ *
567601 * @example
568602 * function setup() {
569603 * createCanvas(100, 100);
@@ -690,15 +724,27 @@ function creatingReading(p5, fn){
690724 * @return {Number } the blue value.
691725 *
692726 * @example
727+ * let myShader;
693728 * function setup() {
694- * let shader = baseMaterialShader().modify(() => {
695- * p5.getPixelInputs((inputs) => {
729+ * createCanvas(100, 100, WEBGL);
730+ *
731+ * myShader = baseMaterialShader().modify(() => {
732+ * getPixelInputs((inputs) => {
696733 * let b = blue(inputs.color);
697- * return vec4(0.0, 0.0, b, 1.0);
734+ * inputs.color = [0, 0, b, 1];
735+ * return inputs;
698736 * });
699737 * });
700738 * }
701739 *
740+ * function draw() {
741+ * shader(myShader);
742+ * noStroke();
743+ * sphere(40);
744+ *
745+ * describe('A sphere colored using only its blue channel.');
746+ * }
747+ *
702748 * @example
703749 * function setup() {
704750 * createCanvas(100, 100);
@@ -821,15 +867,27 @@ function creatingReading(p5, fn){
821867 * @return {Number } the alpha value.
822868 *
823869 * @example
870+ * let myShader;
824871 * function setup() {
825- * let shader = baseMaterialShader().modify(() => {
826- * p5.getPixelInputs((inputs) => {
872+ * createCanvas(100, 100, WEBGL);
873+ *
874+ * myShader = baseMaterialShader().modify(() => {
875+ * getPixelInputs((inputs) => {
827876 * let a = alpha(inputs.color);
828- * return vec4(inputs.color.rgb, a * 0.5);
877+ * inputs.color = [inputs.color.rgb, a * 0.5];
878+ * return inputs;
829879 * });
830880 * });
831881 * }
832882 *
883+ * function draw() {
884+ * shader(myShader);
885+ * noStroke();
886+ * sphere(40);
887+ *
888+ * describe('A semi-transparent sphere.');
889+ * }
890+ *
833891 * @example
834892 * function setup() {
835893 * createCanvas(100, 100);
@@ -930,15 +988,27 @@ function creatingReading(p5, fn){
930988 * @return {Number } the hue value.
931989 *
932990 * @example
991+ * let myShader;
933992 * function setup() {
934- * let shader = baseMaterialShader().modify(() => {
935- * p5.getPixelInputs((inputs) => {
993+ * createCanvas(100, 100, WEBGL);
994+ *
995+ * myShader = baseMaterialShader().modify(() => {
996+ * getPixelInputs((inputs) => {
936997 * let h = hue(inputs.color);
937- * return vec4(h, h, h, 1.0);
998+ * inputs.color = [h, h, h, 1];
999+ * return inputs;
9381000 * });
9391001 * });
9401002 * }
9411003 *
1004+ * function draw() {
1005+ * shader(myShader);
1006+ * noStroke();
1007+ * sphere(40);
1008+ *
1009+ * describe('A sphere shaded in grayscale based on hue.');
1010+ * }
1011+ *
9421012 * @example
9431013 * function setup() {
9441014 * createCanvas(100, 100);
@@ -1070,15 +1140,27 @@ function creatingReading(p5, fn){
10701140 * @return {Number } the saturation value
10711141 *
10721142 * @example
1143+ * let myShader;
10731144 * function setup() {
1074- * let shader = baseMaterialShader().modify(() => {
1075- * p5.getPixelInputs((inputs) => {
1145+ * createCanvas(100, 100, WEBGL);
1146+ *
1147+ * myShader = baseMaterialShader().modify(() => {
1148+ * getPixelInputs((inputs) => {
10761149 * let s = saturation(inputs.color);
1077- * return vec4(s, s, s, 1.0);
1150+ * inputs.color = [s, s, s, 1];
1151+ * return inputs;
10781152 * });
10791153 * });
10801154 * }
10811155 *
1156+ * function draw() {
1157+ * shader(myShader);
1158+ * noStroke();
1159+ * sphere(40);
1160+ *
1161+ * describe('A sphere shaded in grayscale based on saturation.');
1162+ * }
1163+ *
10821164 * @example
10831165 * function setup() {
10841166 * createCanvas(100, 100);
@@ -1231,6 +1313,7 @@ function creatingReading(p5, fn){
12311313 * By default, `brightness()` returns a color's HSB brightness in the range 0
12321314 * to 100. If the <a href="/reference/p5/colorMode/">colorMode()</a> is set to HSB, it
12331315 * returns the brightness value in the given range.
1316+ *
12341317 * In p5.strands shader callbacks, `brightness()` operates on `vec4` values
12351318 * and returns the brightness as a normalized value in the 0–1 range.
12361319 * `colorMode()` has no effect inside shader callbacks.
@@ -1241,15 +1324,27 @@ function creatingReading(p5, fn){
12411324 * @return {Number } the brightness value.
12421325 *
12431326 * @example
1327+ * let myShader;
12441328 * function setup() {
1245- * let shader = baseMaterialShader().modify(() => {
1246- * p5.getPixelInputs((inputs) => {
1329+ * createCanvas(100, 100, WEBGL);
1330+ *
1331+ * myShader = baseMaterialShader().modify(() => {
1332+ * getPixelInputs((inputs) => {
12471333 * let b = brightness(inputs.color);
1248- * return vec4(b, b, b, 1.0);
1334+ * inputs.color = [b, b, b, 1];
1335+ * return inputs;
12491336 * });
12501337 * });
12511338 * }
12521339 *
1340+ * function draw() {
1341+ * shader(myShader);
1342+ * noStroke();
1343+ * sphere(40);
1344+ *
1345+ * describe('A sphere shaded in grayscale based on brightness.');
1346+ * }
1347+ *
12531348 * @example
12541349 * function setup() {
12551350 * createCanvas(100, 100);
@@ -1374,6 +1469,7 @@ function creatingReading(p5, fn){
13741469 * By default, `lightness()` returns a color's HSL lightness in the range 0
13751470 * to 100. If the <a href="/reference/p5/colorMode/">colorMode()</a> is set to HSL, it
13761471 * returns the lightness value in the given range.
1472+ *
13771473 * In p5.strands shader callbacks, `lightness()` operates on `vec4` values
13781474 * and returns the lightness as a normalized value in the 0–1 range.
13791475 * `colorMode()` has no effect inside shader callbacks.
@@ -1384,15 +1480,27 @@ function creatingReading(p5, fn){
13841480 * @return {Number } the lightness value.
13851481 *
13861482 * @example
1483+ * let myShader;
13871484 * function setup() {
1388- * let shader = baseMaterialShader().modify(() => {
1389- * p5.getPixelInputs((inputs) => {
1485+ * createCanvas(100, 100, WEBGL);
1486+ *
1487+ * myShader = baseMaterialShader().modify(() => {
1488+ * getPixelInputs((inputs) => {
13901489 * let l = lightness(inputs.color);
1391- * return vec4(l, l, l, 1.0);
1490+ * inputs.color = [l, l, l, 1];
1491+ * return inputs;
13921492 * });
13931493 * });
13941494 * }
13951495 *
1496+ * function draw() {
1497+ * shader(myShader);
1498+ * noStroke();
1499+ * sphere(40);
1500+ *
1501+ * describe('A sphere shaded in grayscale based on lightness.');
1502+ * }
1503+ *
13961504 * @example
13971505 * function setup() {
13981506 * createCanvas(100, 100);
@@ -1531,14 +1639,29 @@ function creatingReading(p5, fn){
15311639 * @return {p5.Color } interpolated color.
15321640 *
15331641 * @example
1642+ * let myShader;
15341643 * function setup() {
1535- * let shader = baseMaterialShader().modify(() => {
1536- * let c1 = color('red');
1537- * let c2 = color('blue');
1538- * let mixed = lerpColor(c1, c2, 0.5);
1644+ * createCanvas(100, 100, WEBGL);
1645+ *
1646+ * myShader = baseMaterialShader().modify(() => {
1647+ * getPixelInputs((inputs) => {
1648+ * let c1 = color('red');
1649+ * let c2 = color('blue');
1650+ * let mixed = lerpColor(c1, c2, 0.5);
1651+ * inputs.color = mixed;
1652+ * return inputs;
1653+ * });
15391654 * });
15401655 * }
15411656 *
1657+ * function draw() {
1658+ * shader(myShader);
1659+ * noStroke();
1660+ * sphere(40);
1661+ *
1662+ * describe('A purple sphere, a blend of red and blue.');
1663+ * }
1664+ *
15421665 * @example
15431666 * function setup() {
15441667 * createCanvas(100, 100);
0 commit comments