Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated documentation for shaders. #6497

Merged
merged 15 commits into from
Oct 30, 2023
28 changes: 24 additions & 4 deletions src/webgl/material.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import './p5.Texture';
* The shader files are loaded asynchronously in the
* background, so this method should be used in <a href="#/p5/preload">preload()</a>.
*
* Shaders can alter the positioning of shapes drawn with them.
* To ensure consistency in rendering, it's recommended to use the vertex shader in the <a href="#/p5/createShader">createShader example</a>
deveshidwivedi marked this conversation as resolved.
Show resolved Hide resolved
*
* Note, shaders can only be used in WEBGL mode.
*
* @method loadShader
Expand Down Expand Up @@ -127,11 +130,25 @@ p5.prototype.loadShader = function(
* // the 'varying's are shared between both vertex & fragment shaders
* let varying = 'precision highp float; varying vec2 vPos;';
deveshidwivedi marked this conversation as resolved.
Show resolved Hide resolved
*
* Shaders can alter the positioning of shapes drawn with them.
deveshidwivedi marked this conversation as resolved.
Show resolved Hide resolved
* To ensure consistency in rendering, it's recommended to use the vertex shader, as in the example below.
deveshidwivedi marked this conversation as resolved.
Show resolved Hide resolved
*
* // the vertex shader is called for each vertex
* let vs =
* varying +
* 'attribute vec3 aPosition;' +
* 'void main() { vPos = (gl_Position = vec4(aPosition,1.0)).xy; }';
*let vs = `
deveshidwivedi marked this conversation as resolved.
Show resolved Hide resolved
* uniform mat4 uModelViewMatrix;
deveshidwivedi marked this conversation as resolved.
Show resolved Hide resolved
* uniform mat4 uProjectionMatrix;
*
* attribute vec3 aPosition;
* attribute vec2 aTexCoord;
* varying vec2 vTexCoord;
*
* void main() {
* vTexCoord = aTexCoord;
* vec4 positionVec4 = vec4(aPosition, 1.0);
* gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;
* }
*`;
deveshidwivedi marked this conversation as resolved.
Show resolved Hide resolved
*
*
* // the fragment shader is called for each pixel
* let fs =
deveshidwivedi marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -313,6 +330,9 @@ p5.prototype.createFilterShader = function(fragSrc) {
* Sets the <a href="#/p5.Shader">p5.Shader</a> object to
* be used to render subsequent shapes.
*
* Shaders can alter the positioning of shapes drawn with them.
* To ensure consistency in rendering, it's recommended to use the vertex shader in the <a href="#/p5/createShader">createShader example</a>
deveshidwivedi marked this conversation as resolved.
Show resolved Hide resolved
*
* Custom shaders can be created using the
* <a href="#/p5/createShader">createShader()</a> and
* <a href="#/p5/loadShader">loadShader()</a> functions.
Expand Down