Package processing.opengl
Class PShader
java.lang.Object
processing.opengl.PShader
- All Implemented Interfaces:
PConstants
This class encapsulates a GLSL shader program, including a vertex
and a fragment shader. It is compatible with P2D and P3D, but not
with the default renderer.
Use the loadShader() function to load your shader code.
Note: It's strongly encouraged to use loadShader() to create
a PShader object, rather than calling the PShader
constructor manually.
-
Field Summary
FieldsFields inherited from interface processing.core.PConstants
ADD, ALPHA, ALT, AMBIENT, ARC, ARGB, ARROW, BACKSPACE, BASELINE, BEVEL, BEZIER_VERTEX, BICUBIC, BILINEAR, BLEND, BLUR, BOTTOM, BOX, BREAK, BURN, CENTER, CHATTER, CHORD, CLAMP, CLOSE, CODED, COMPLAINT, CONTROL, CORNER, CORNERS, CROSS, CURVE_VERTEX, CUSTOM, DARKEST, DEG_TO_RAD, DELETE, DIAMETER, DIFFERENCE, DILATE, DIRECTIONAL, DISABLE_ASYNC_SAVEFRAME, DISABLE_BUFFER_READING, DISABLE_DEPTH_MASK, DISABLE_DEPTH_SORT, DISABLE_DEPTH_TEST, DISABLE_KEY_REPEAT, DISABLE_NATIVE_FONTS, DISABLE_OPENGL_ERRORS, DISABLE_OPTIMIZED_STROKE, DISABLE_STROKE_PERSPECTIVE, DISABLE_STROKE_PURE, DISABLE_TEXTURE_MIPMAPS, DODGE, DOWN, DXF, ELLIPSE, ENABLE_ASYNC_SAVEFRAME, ENABLE_BUFFER_READING, ENABLE_DEPTH_MASK, ENABLE_DEPTH_SORT, ENABLE_DEPTH_TEST, ENABLE_KEY_REPEAT, ENABLE_NATIVE_FONTS, ENABLE_OPENGL_ERRORS, ENABLE_OPTIMIZED_STROKE, ENABLE_STROKE_PERSPECTIVE, ENABLE_STROKE_PURE, ENABLE_TEXTURE_MIPMAPS, ENTER, EPSILON, ERODE, ESC, EXCLUSION, FX2D, GIF, GRAY, GROUP, HALF_PI, HAND, HARD_LIGHT, HINT_COUNT, HSB, IMAGE, INVERT, JAVA2D, JPEG, LANDSCAPE, LEFT, LIGHTEST, LINE_LOOP, LINE_STRIP, LINES, LINUX, MACOS, MACOSX, MAX_FLOAT, MAX_INT, MIN_FLOAT, MIN_INT, MITER, MODEL, MODELVIEW, MOVE, MULTIPLY, NEAREST_NEIGHBOR, NORMAL, OPAQUE, OPEN, OPENGL, ORTHOGRAPHIC, OTHER, OVERLAY, P2D, P3D, PATH, PDF, PERSPECTIVE, PI, PIE, platformNames, POINTS, POLYGON, PORTRAIT, POSTERIZE, PROBLEM, PROJECT, PROJECTION, QUAD, QUAD_BEZIER_VERTEX, QUAD_STRIP, QUADRATIC_VERTEX, QUADS, QUARTER_PI, RAD_TO_DEG, RADIUS, RECT, REPEAT, REPLACE, RETURN, RGB, RIGHT, ROUND, SCREEN, SHAPE, SHIFT, SOFT_LIGHT, SPAN, SPHERE, SPOT, SQUARE, SUBTRACT, SVG, TAB, TARGA, TAU, TEXT, THIRD_PI, THRESHOLD, TIFF, TOP, TRIANGLE, TRIANGLE_FAN, TRIANGLE_STRIP, TRIANGLES, TWO_PI, UP, VERTEX, WAIT, WHITESPACE, WINDOWS, X, Y, Z -
Constructor Summary
ConstructorsConstructorDescriptionPShader()Creates a shader program using the specified vertex and fragment shaders. -
Method Summary
Modifier and TypeMethodDescriptionvoidbind()Initializes (if needed) and binds the shader program.booleanbound()Returns true if the shader is bound, false otherwise.voidinit()voidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidSets the uniform variables inside the shader to modify the effect while the program is running.voidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidsetFragmentShader(String fragFilename) voidsetFragmentShader(String[] fragSource) voidsetFragmentShader(URL fragURL) voidsetVertexShader(String vertFilename) voidsetVertexShader(String[] vertSource) voidsetVertexShader(URL vertURL) voidunbind()Unbinds the shader program.
-
Field Details
-
glProgram
public int glProgram -
glVertex
public int glVertex -
glFragment
public int glFragment
-
-
Constructor Details
-
PShader
public PShader() -
PShader
-
PShader
Creates a shader program using the specified vertex and fragment shaders.- Parameters:
parent- the parent programvertFilename- name of the vertex shaderfragFilename- name of the fragment shader
-
PShader
- Parameters:
vertURL- network location of the vertex shaderfragURL- network location of the fragment shader
-
PShader
-
-
Method Details
-
setVertexShader
-
setVertexShader
-
setVertexShader
-
setFragmentShader
-
setFragmentShader
-
setFragmentShader
-
bind
public void bind()Initializes (if needed) and binds the shader program. -
unbind
public void unbind()Unbinds the shader program. -
bound
public boolean bound()Returns true if the shader is bound, false otherwise. -
set
Sets the uniform variables inside the shader to modify the effect while the program is running.- Parameters:
name- the name of the uniform variable to modifyx- first component of the variable to modify
-
set
- Parameters:
y- second component of the variable to modify. The variable has to be declared with an array/vector type in the shader (i.e.: int[2], vec2)
-
set
- Parameters:
z- third component of the variable to modify. The variable has to be declared with an array/vector type in the shader (i.e.: int[3], vec3)
-
set
- Parameters:
w- fourth component of the variable to modify. The variable has to be declared with an array/vector type in the shader (i.e.: int[4], vec4)
-
set
-
set
-
set
-
set
-
set
- Parameters:
vec- modifies all the components of an array/vector uniform variable. PVector can only be used if the type of the variable is vec3.
-
set
-
set
-
set
-
set
-
set
-
set
- Parameters:
ncoords- number of coordinates per element, max 4
-
set
-
set
-
set
-
set
-
set
- Parameters:
mat- matrix of values
-
set
-
set
- Parameters:
use3x3- enforces the matrix is 3 x 3
-
set
- Parameters:
tex- sets the sampler uniform variable to read from this image texture
-
init
public void init()
-