Class PShader

java.lang.Object
processing.opengl.PShader
All Implemented Interfaces:
PConstants

public class PShader extends Object implements 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 Details

    • glProgram

      public int glProgram
    • glVertex

      public int glVertex
    • glFragment

      public int glFragment
  • Constructor Details

    • PShader

      public PShader()
    • PShader

      public PShader(PApplet parent)
    • PShader

      public PShader(PApplet parent, String vertFilename, String fragFilename)
      Creates a shader program using the specified vertex and fragment shaders.
      Parameters:
      parent - the parent program
      vertFilename - name of the vertex shader
      fragFilename - name of the fragment shader
    • PShader

      public PShader(PApplet parent, URL vertURL, URL fragURL)
      Parameters:
      vertURL - network location of the vertex shader
      fragURL - network location of the fragment shader
    • PShader

      public PShader(PApplet parent, String[] vertSource, String[] fragSource)
  • Method Details

    • setVertexShader

      public void setVertexShader(String vertFilename)
    • setVertexShader

      public void setVertexShader(URL vertURL)
    • setVertexShader

      public void setVertexShader(String[] vertSource)
    • setFragmentShader

      public void setFragmentShader(String fragFilename)
    • setFragmentShader

      public void setFragmentShader(URL fragURL)
    • setFragmentShader

      public void setFragmentShader(String[] fragSource)
    • 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

      public void set(String name, int x)
      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 modify
      x - first component of the variable to modify
    • set

      public void set(String name, int x, int y)
      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

      public void set(String name, int x, int y, int z)
      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

      public void set(String name, int x, int y, int z, int w)
      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

      public void set(String name, float x)
    • set

      public void set(String name, float x, float y)
    • set

      public void set(String name, float x, float y, float z)
    • set

      public void set(String name, float x, float y, float z, float w)
    • set

      public void set(String name, PVector vec)
      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

      public void set(String name, boolean x)
    • set

      public void set(String name, boolean x, boolean y)
    • set

      public void set(String name, boolean x, boolean y, boolean z)
    • set

      public void set(String name, boolean x, boolean y, boolean z, boolean w)
    • set

      public void set(String name, int[] vec)
    • set

      public void set(String name, int[] vec, int ncoords)
      Parameters:
      ncoords - number of coordinates per element, max 4
    • set

      public void set(String name, float[] vec)
    • set

      public void set(String name, float[] vec, int ncoords)
    • set

      public void set(String name, boolean[] vec)
    • set

      public void set(String name, boolean[] boolvec, int ncoords)
    • set

      public void set(String name, PMatrix2D mat)
      Parameters:
      mat - matrix of values
    • set

      public void set(String name, PMatrix3D mat)
    • set

      public void set(String name, PMatrix3D mat, boolean use3x3)
      Parameters:
      use3x3 - enforces the matrix is 3 x 3
    • set

      public void set(String name, PImage tex)
      Parameters:
      tex - sets the sampler uniform variable to read from this image texture
    • init

      public void init()