Class Shader
A shader is a small program in GLSL, the language of the graphics card. It is
run once for every pixel and decides the pixel's colour. Processing hands it
the picture being drawn as texture, and where on that picture the
pixel is as vertTexCoord:
#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D texture;
varying vec4 vertTexCoord;
void main(void) {
vec4 color = texture2D(texture, vertTexCoord.st);
float grey = (color.r + color.g + color.b) / 3.0;
gl_FragColor = vec4(grey, grey, grey, color.a);
}
A shader is not made with new but added to a sprite or the stage with
getShaders().add(...), which returns it. Its uniform values
are given from Java with set(String, int).
In the browser the shader is translated for WebGL, which is stricter than a
desktop graphics card: a float has to be written as 1.0, not
1. A vertex shader other than Processing's default one is ignored
there.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetName()Returns the nameprocessing.opengl.PShaderReturns the shadervoidvoidvoidvoidvoidvoidSets auniformof the shader: a value the shader reads but the program decides, such as the time for an animation or a position on the stage.voidvoidvoidvoidvoidSets the name
-
Constructor Details
-
Shader
-
Shader
-
-
Method Details
-
getName
-
setName
-
getPShader
public processing.opengl.PShader getPShader()Returns the shader- Returns:
- the shader
-
set
Sets auniformof the shader: a value the shader reads but the program decides, such as the time for an animation or a position on the stage.The name is the one the shader file declares,
uniform float blocks;is set withset("blocks", 20). There is asetfor one or two numbers or booleans, aVector2, aColor(as avec3), and an array of numbers,ncoordsat a time, for an array uniform likeuniform vec3 lights[10];.A uniform keeps its value until it is set again, so a value that changes is set in
run().- Parameters:
name- the name of the uniform in the shader filex- the value
-
set
-
set
-
set
-
set
-
set
-
set
-
set
-
set
-
set
-