@@ -730,43 +730,6 @@ p5.prototype.createFilterShader = function (fragSrc) {
730
730
* let vertSrc = `
731
731
* precision highp float;
732
732
* attribute vec3 aPosition;
733
- * void main() {
734
- * gl_Position = vec4(aPosition, 1.0);
735
- * }
736
- * `;
737
- *
738
- * let fragSrc = `
739
- * precision highp float;
740
- * uniform float uMouseX;
741
- * void main() {
742
- * vec3 color = vec3(uMouseX, 0.0, 1.0); // Color based on mouse X
743
- * gl_FragColor = vec4(color, 1.0);
744
- * }
745
- * `;
746
- *
747
- * function setup() {
748
- * createCanvas(100, 100, WEBGL);
749
- * fillShader = createShader(vertSrc, fragSrc);
750
- * shader(fillShader);
751
- * noStroke();
752
- * describe('A square with color changing based on mouse X without lighting.');
753
- * }
754
- *
755
- * function draw() {
756
- * fillShader.setUniform('uMouseX', map(mouseX, 0, width, 0, 1));
757
- * plane(100, 100);
758
- * }
759
- * </code>
760
- * </div>
761
- *
762
- * @example
763
- * <div modernizr='webgl'>
764
- * <code>
765
- * let fillShader;
766
- *
767
- * let vertSrc = `
768
- * precision highp float;
769
- * attribute vec3 aPosition;
770
733
* uniform mat4 uModelViewMatrix;
771
734
* uniform mat4 uProjectionMatrix;
772
735
* varying vec3 vPosition;
@@ -861,7 +824,42 @@ p5.prototype.createFilterShader = function (fragSrc) {
861
824
* }
862
825
* </code>
863
826
* </div>
827
+ *
828
+ * @example
829
+ * <div modernizr='webgl'>
830
+ * <code>
831
+ * let myShader;
832
+ *
833
+ * function setup() {
834
+ * createCanvas(100, 100, WEBGL);
835
+ *
836
+ * myShader = baseMaterialShader().modify({
837
+ * declarations: 'uniform float time;',
838
+ * 'vec4 getFinalColor': `(vec4 color) {
839
+ * float r = 0.2 + 0.5 * abs(sin(time + 0.0));
840
+ * float g = 0.2 + 0.5 * abs(sin(time + 1.0));
841
+ * float b = 0.2 + 0.5 * abs(sin(time + 2.0));
842
+ * color.rgb = vec3(r, g, b);
843
+ * return color;
844
+ * }`
845
+ * });
846
+ *
847
+ * noStroke();
848
+ * describe('A 3D cube with dynamically changing colors on a beige background.');
849
+ * }
850
+ *
851
+ * function draw() {
852
+ * background(245, 245, 220);
853
+ * shader(myShader);
854
+ * myShader.setUniform('time', millis() / 1000.0);
855
+ *
856
+ * box(50);
857
+ * }
858
+ * </code>
859
+ * </div>
860
+ *
864
861
*/
862
+
865
863
p5 . prototype . shader = function ( s ) {
866
864
this . _assert3d ( 'shader' ) ;
867
865
p5 . _validateParameters ( 'shader' , arguments ) ;
@@ -1060,9 +1058,10 @@ p5.prototype.strokeShader = function (s) {
1060
1058
* or dynamic behavior. The shader will be applied to the image drawn using
1061
1059
* the <a href="#/p5/image">image()</a> function.
1062
1060
*
1063
- * The shader will be used for:
1064
- * - Images only, regardless of whether the image is being drawn with
1065
- * <a href="#/p5/texture">texture()</a> or used in other 3D contexts.
1061
+ * The shader will be used exclusively for:
1062
+ * - `image()` calls, applying only when drawing 2D images.
1063
+ * - This shader will NOT apply to images used in <a href="#/p5/texture">texture()</a> or other 3D contexts.
1064
+ * Any attempts to use the imageShader in these cases will be ignored.
1066
1065
*
1067
1066
* @method imageShader
1068
1067
* @chainable
0 commit comments