- JavaDoc documentation for the Tile class.
- JavaDoc documentation for the GraphicTile class.
- JavaDoc documentation for the Shader class.
- JavaDoc documentation for the CharShader class.
- A guide that includes a section on how to add/remove shaders to/from tiles.
How Shaders Work
Shaders, when working with VTerminal, are subclasses of either the Shader or CharShader classes. Because Tile and GraphicTile objects are rendered differently, there had to be a way to distinguish shaders that are only for Tile objects and shaders that are for both Tile and GraphicTile objects. This is why subclasses of CharShader can only be added to Tile objects, while subclasses of Shader can be added to both Tile and GraphicTile objects.
Within implementing a shader, there are two functions that must be overridden.
- The run(BufferedImage) function is used, by VTerminal, to run the shader on the sprite of a Tile or GraphicTile.
- The copy() function is used to create a deep copy of the shader.
The order in which shaders are added to a Tile, or GraphicTile, is important. If you were to add a CharBoldShader before a CharShadowShader, then the sprite of the tile is first run through the CharBoldShader and then through the CharShadowShader.
Whenever a shader is added, or removed, from a Tile or GraphicTile, the sprite of the tile must be re-generated and all of it's shaders must be re-applied to it. Because some shaders may be computationally expensive, this could result in noticable lag if enough tiles are altered before a screen redraw. If tile shader changes are spread across multiple screen redraws, or if only a handful of tiles are altered, then the potential for noticable lag can be minimized.
The following image shows a number of the shaders included with VTerminal.
Creating a Shader
In order to create a new shader, you must create a new class that implements the Shader class.
The following example shows a shader that is capable of adding a colored border around the edges of a Tile or GraphicTile.
Creating a CharShader
In order to create a new character shader, you must create a new class that implements the CharShader class.
The following example shows a character shader that is capable of adding a black drop-shadow below the displayed character of a Tile.