[−][src]Static p5_sys::global::loadShader
pub static loadShader: LoadShaderInternalType
Loads a custom shader from the provided vertex and fragment shader paths. The shader files are loaded asynchronously in the background, so this method should be used in preload().
For now, there are three main types of shaders. p5 will automatically supply appropriate vertices, normals, colors, and lighting attributes if the parameters defined in the shader match the names.
Examples
let mandel;
function preload() {
// load the shader definitions from files
mandel = loadShader('assets/shader.vert', 'assets/shader.frag');
}
function setup() {
createCanvas(100, 100, WEBGL);
// use the shader
shader(mandel);
noStroke();
mandel.setUniform('p', [-0.74364388703, 0.13182590421]);
}
function draw() {
mandel.setUniform('r', 1.5 * exp(-6.5 * (1 + sin(millis() / 2000))));
quad(-1, -1, 1, -1, 1, 1, -1, 1);
}
Parameters
vertFilename
path to file containing vertex shader
source code
fragFilename
path to file containing fragment shader
source code
callback?
callback to be executed after loadShader
completes. On success, the Shader object is passed as the first argument.
errorCallback?
callback to be executed when an error
occurs inside loadShader. On error, the error is passed as the first
argument.