Class Shaders

java.lang.Object
org.openpatch.scratch.Shaders

public final class Shaders extends Object
The shaders of a sprite or of the stage. The first one added is used at once; more than one can be active, applied in the order they were added.
Shader waves = this.getShaders().add("waves", "assets/waves.frag");
waves.set("strength", 0.02);
  • Method Details

    • add

      public Shader add(String name, String fragmentPath)
      Adds a shader, or returns the one of that name added before.
      Parameters:
      name - the shader's name
      fragmentPath - the file with the shader's body
      Returns:
      the shader, to set its uniforms
    • get

      public Shader get(String name)
      Parameters:
      name - a shader's name
      Returns:
      the shader, or null
    • switchTo

      public void switchTo(String name)
      Parameters:
      name - the shader to use, alone
    • switchTo

      public void switchTo(double index)
      Parameters:
      index - the shader to use alone, counting from 0; wraps around
    • next

      public void next()
      Uses the next shader alone.
    • reset

      public void reset()
      Uses no shader.
    • activate

      public void activate(String name)
      Parameters:
      name - a shader to use in addition to the active ones
    • deactivate

      public void deactivate(String name)
      Parameters:
      name - a shader to stop using
    • isActive

      public boolean isActive(String name)
      Parameters:
      name - a shader's name
      Returns:
      whether it is in use
    • getActive

      public List<Shader> getActive()
      Returns:
      the shaders in use, in order
    • getCurrent

      public Shader getCurrent()
      Returns:
      the first shader in use, or null
    • getCurrentIndex

      public int getCurrentIndex()
      Returns:
      the number of the first shader in use, or -1
    • getCurrentName

      public String getCurrentName()
      Returns:
      the name of the first shader in use, or null