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

Function material

src/webgl/material.js:28–3840  ·  view source on GitHub ↗
(p5, fn)

Source from the content-addressed store, hash-verified

26}
27
28function material(p5, fn) {
29 /**
30 * Loads vertex and fragment shaders to create a
31 * <a href="#/p5.Shader">p5.Shader</a> object.
32 *
33 * Shaders are programs that run on the graphics processing unit (GPU). They
34 * can process many pixels at the same time, making them fast for many
35 * graphics tasks. They’re written in a language called
36 * <a href="https://developer.mozilla.org/en-US/docs/Games/Techniques/3D_on_the_web/GLSL_Shaders" target="_blank">GLSL</a>
37 * and run along with the rest of the code in a sketch.
38 *
39 * Once the <a href="#/p5.Shader">p5.Shader</a> object is created, it can be
40 * used with the <a href="#/p5/shader">shader()</a> function, as in
41 * `shader(myShader)`. A shader program consists of two files, a vertex shader
42 * and a fragment shader. The vertex shader affects where 3D geometry is drawn
43 * on the screen and the fragment shader affects color.
44 *
45 * `loadShader()` loads the vertex and fragment shaders from their `.vert` and
46 * `.frag` files. For example, calling
47 * `loadShader('assets/shader.vert', 'assets/shader.frag')` loads both
48 * required shaders and returns a <a href="#/p5.Shader">p5.Shader</a> object.
49 *
50 * The third parameter, `successCallback`, is optional. If a function is
51 * passed, it will be called once the shader has loaded. The callback function
52 * can use the new <a href="#/p5.Shader">p5.Shader</a> object as its
53 * parameter. The return value of the `successCallback()` function will be used
54 * as the final return value of `loadShader()`.
55 *
56 * The fourth parameter, `failureCallback`, is also optional. If a function is
57 * passed, it will be called if the shader fails to load. The callback
58 * function can use the event error as its parameter. The return value of the `
59 * failureCallback()` function will be used as the final return value of `loadShader()`.
60 *
61 * This function returns a `Promise` and should be used in an `async` setup with
62 * `await`. See the examples for the usage syntax.
63 *
64 * Note: Shaders can only be used in WebGL mode.
65 *
66 * @method loadShader
67 * @param {String|Request} vertFilename path of the vertex shader to be loaded.
68 * @param {String|Request} fragFilename path of the fragment shader to be loaded.
69 * @param {Function} [successCallback] function to call once the shader is loaded. Can be passed the
70 * <a href="#/p5.Shader">p5.Shader</a> object.
71 * @param {Function} [failureCallback] function to call if the shader fails to load. Can be passed an
72 * `Error` event object.
73 * @return {Promise<p5.Shader>} new shader created from the vertex and fragment shader files.
74 *
75 * @example
76 * // Note: A "uniform" is a global variable within a shader program.
77 *
78 * let mandelbrot;
79 *
80 * // Load the shader and create a p5.Shader object.
81 * async function setup() {
82 * mandelbrot = await loadShader('assets/shader.vert', 'assets/shader.frag');
83 *
84 * createCanvas(100, 100, WEBGL);
85 *

Callers 2

loadShader.jsFile · 0.85
graphicsFunction · 0.85

Calls 15

requestFunction · 0.90
withGlobalStrandsFunction · 0.85
urlToStrandsCallbackFunction · 0.85
modifyMethod · 0.80
_assert3dMethod · 0.80
baseNormalShaderMethod · 0.80
baseColorShaderMethod · 0.80
baseStrokeShaderMethod · 0.80
_animateGifMethod · 0.80
setWrapModeMethod · 0.80
setDefaultUniformsMethod · 0.80

Tested by

no test coverage detected