MCPcopy Index your code
hub / github.com/processing/p5.js / shader

Function shader

src/webgl/p5.Shader.js:1165–1300  ·  view source on GitHub ↗
(p5, fn)

Source from the content-addressed store, hash-verified

1163};
1164
1165function shader(p5, fn){
1166 /**
1167 * A class to describe a shader program.
1168 *
1169 * Each `p5.Shader` object contains a shader program that runs on the graphics
1170 * processing unit (GPU). Shaders can process many pixels or vertices at the
1171 * same time, making them fast for many graphics tasks. They’re written in a
1172 * language called
1173 * <a href="https://developer.mozilla.org/en-US/docs/Games/Techniques/3D_on_the_web/GLSL_Shaders" target="_blank">GLSL</a>
1174 * and run along with the rest of the code in a sketch.
1175 *
1176 * A shader program consists of two files, a vertex shader and a fragment
1177 * shader. The vertex shader affects where 3D geometry is drawn on the screen
1178 * and the fragment shader affects color. Once the `p5.Shader` object is
1179 * created, it can be used with the <a href="#/p5/shader">shader()</a>
1180 * function, as in `shader(myShader)`.
1181 *
1182 * A shader can optionally describe *hooks,* which are functions in GLSL that
1183 * users may choose to provide to customize the behavior of the shader. For the
1184 * vertex or the fragment shader, users can pass in an object where each key is
1185 * the type and name of a hook function, and each value is a string with the
1186 * parameter list and default implementation of the hook. For example, to let users
1187 * optionally run code at the start of the vertex shader, the options object could
1188 * include:
1189 *
1190 * ```js
1191 * {
1192 * vertex: {
1193 * 'void beforeVertex': '() {}'
1194 * }
1195 * }
1196 * ```
1197 *
1198 * Then, in your vertex shader source, you can run a hook by calling a function
1199 * with the same name prefixed by `HOOK_`:
1200 *
1201 * ```glsl
1202 * void main() {
1203 * HOOK_beforeVertex();
1204 * // Add the rest ofy our shader code here!
1205 * }
1206 * ```
1207 *
1208 * Note: <a href="#/p5/createShader">createShader()</a>,
1209 * <a href="#/p5/createFilterShader">createFilterShader()</a>, and
1210 * <a href="#/p5/loadShader">loadShader()</a> are the recommended ways to
1211 * create an instance of this class.
1212 *
1213 * @class p5.Shader
1214 * @constructor
1215 * @param {p5.RendererGL} renderer WebGL context for this shader.
1216 * @param {String} vertSrc source code for the vertex shader program.
1217 * @param {String} fragSrc source code for the fragment shader program.
1218 * @param {Object} [options] An optional object describing how this shader can
1219 * be augmented with hooks. It can include:
1220 * - `vertex`: An object describing the available vertex shader hooks.
1221 * - `fragment`: An object describing the available frament shader hooks.
1222 *

Callers 8

drawBlobMethod · 0.85
drawFunction · 0.85
drawFunction · 0.85
drawFunction · 0.85
setupFunction · 0.85
drawFunction · 0.85
p5.Shader.jsFile · 0.85
drawFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected