Skip to content

Commit 1d7cedc

Browse files
authored
Merge pull request #5307 from JetStarBlues/improveShaderDocumentation
Improve documentation clarity of shader methods
2 parents 846a082 + 30e1621 commit 1d7cedc

File tree

2 files changed

+40
-24
lines changed

2 files changed

+40
-24
lines changed

src/webgl/material.js

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ import * as constants from '../core/constants';
1010
import './p5.Texture';
1111

1212
/**
13-
* Loads a custom shader from the provided vertex and fragment
14-
* shader paths. The shader files are loaded asynchronously in the
13+
* Creates a new <a href="#/p5.Shader">p5.Shader</a> object
14+
* from the provided vertex and fragment shader files.
15+
*
16+
* The shader files are loaded asynchronously in the
1517
* background, so this method should be used in <a href="#/p5/preload">preload()</a>.
1618
*
17-
* For now, there are three main types of shaders. p5 will automatically
18-
* supply appropriate vertices, normals, colors, and lighting attributes
19-
* if the parameters defined in the shader match the names.
19+
* Note, shaders can only be used in WEBGL mode.
2020
*
2121
* @method loadShader
2222
* @param {String} vertFilename path to file containing vertex shader
2323
* source code
2424
* @param {String} fragFilename path to file containing fragment shader
2525
* source code
2626
* @param {function} [callback] callback to be executed after loadShader
27-
* completes. On success, the Shader object is passed as the first argument.
27+
* completes. On success, the p5.Shader object is passed as the first argument.
2828
* @param {function} [errorCallback] callback to be executed when an error
2929
* occurs inside loadShader. On error, the error is passed as the first
3030
* argument.
@@ -109,6 +109,11 @@ p5.prototype.loadShader = function(
109109
};
110110

111111
/**
112+
* Creates a new <a href="#/p5.Shader">p5.Shader</a> object
113+
* from the provided vertex and fragment shader code.
114+
*
115+
* Note, shaders can only be used in WEBGL mode.
116+
*
112117
* @method createShader
113118
* @param {String} vertSrc source code for the vertex shader
114119
* @param {String} fragSrc source code for the fragment shader
@@ -177,15 +182,22 @@ p5.prototype.createShader = function(vertSrc, fragSrc) {
177182
};
178183

179184
/**
180-
* The <a href="#/p5/shader">shader()</a> function lets the user provide a custom shader
181-
* to fill in shapes in WEBGL mode. Users can create their
182-
* own shaders by loading vertex and fragment shaders with
183-
* <a href="#/p5/loadShader">loadShader()</a>.
185+
* Sets the <a href="#/p5.Shader">p5.Shader</a> object to
186+
* be used to render subsequent shapes.
187+
*
188+
* Custom shaders can be created using the
189+
* <a href="#/p5/createShader">createShader()</a> and
190+
* <a href="#/p5/loadShader">loadShader()</a> functions.
191+
*
192+
* Use <a href="#/p5/resetShader">resetShader()</a> to
193+
* restore the default shaders.
194+
*
195+
* Note, shaders can only be used in WEBGL mode.
184196
*
185197
* @method shader
186198
* @chainable
187-
* @param {p5.Shader} [s] the desired <a href="#/p5.Shader">p5.Shader</a> to use for rendering
188-
* shapes.
199+
* @param {p5.Shader} s the <a href="#/p5.Shader">p5.Shader</a> object
200+
* to use for rendering shapes.
189201
*
190202
* @example
191203
* <div modernizr='webgl'>
@@ -268,9 +280,9 @@ p5.prototype.shader = function(s) {
268280
};
269281

270282
/**
271-
* This function restores the default shaders in WEBGL mode. Code that runs
272-
* after resetShader() will not be affected by previously defined
273-
* shaders. Should be run after <a href="#/p5/shader">shader()</a>.
283+
* Restores the default shaders. Code that runs after resetShader()
284+
* will not be affected by the shader previously set by
285+
* <a href="#/p5/shader">shader()</a>
274286
*
275287
* @method resetShader
276288
* @chainable

src/webgl/p5.Shader.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -294,17 +294,21 @@ p5.Shader.prototype.useProgram = function() {
294294
};
295295

296296
/**
297-
* Wrapper around gl.uniform functions.
298-
* As we store uniform info in the shader we can use that
299-
* to do type checking on the supplied data and call
300-
* the appropriate function.
297+
* Used to set the uniforms of a
298+
* <a href="#/p5.Shader">p5.Shader</a> object.
299+
*
300+
* Uniforms are used as a way to provide shader programs
301+
* (which run on the GPU) with values from a sketch
302+
* (which runs on the CPU).
303+
*
301304
* @method setUniform
302305
* @chainable
303-
* @param {String} uniformName the name of the uniform in the
304-
* shader program
305-
* @param {Object|Number|Boolean|Number[]} data the data to be associated
306-
* with that uniform; type varies (could be a single numerical value, array,
307-
* matrix, or texture / sampler reference)
306+
* @param {String} uniformName the name of the uniform.
307+
* Must correspond to the name used in the vertex and fragment shaders
308+
* @param {Boolean|Number|Number[]|p5.Image|p5.Graphics|p5.MediaElement}
309+
* data the data to associate with the uniform. The type can be
310+
* a boolean (true/false), a number, an array of numbers, or
311+
* an image (p5.Image, p5.Graphics, p5.MediaElement)
308312
*
309313
* @example
310314
* <div modernizr='webgl'>

0 commit comments

Comments
 (0)