Creates a new p5.Shader object.
Shaders are programs that run on the graphics processing unit (GPU). They can process many pixels at the same time, making them fast for many graphics tasks. They’re written in a language called GLSL and run along with the rest of the code in a sketch.
Once the p5.Shader object is created, it can be used with the shader() function, as in shader(myShader)
. A shader program consists of two parts, a vertex shader and a fragment shader. The vertex shader affects where 3D geometry is drawn on the screen and the fragment shader affects color.
The first parameter, vertSrc
, sets the vertex shader. It’s a string that contains the vertex shader program written in GLSL.
The second parameter, fragSrc
, sets the fragment shader. It’s a string that contains the fragment shader program written in GLSL.
Note: Only filter shaders can be used in 2D mode. All shaders can be used in WebGL mode.
Examples
Syntax
createShader(vertSrc, fragSrc)
Parameters
source code for the vertex shader.
source code for the fragment shader.