The game's shaders: world and screen effects, your own post shaders, live GLSL.
The game draws everything with GLSL shaders, and shader opens them to mods (since API 4), on PC and Android, in
both games. The Shaders guide walks through it.
World effects (shader.world): values the port's code inside every game shader uses: colour (exposure,
contrast, saturation, hue ...), style (visions like thermal or night vision, toon bands, posterize, sepia), a fog and
a sonar ring by distance, and shape (waves, world curve, wobble, PS1 vertex snapping). shader.targets says which
groups of shaders they change (the menus and the HUD are off by default).
Screen effects (shader.screen): a pass over the finished picture: blur, pixelate, bloom, outlines, CRT,
scanlines, VHS, kaleidoscope ...
Post shaders (shader.post): your own fragment shader over the picture, after the screen effects, with
uniforms you set from Lua.
Live shaders (shader.setSource): replace a game shader file's GLSL while the game runs. A source that does
not compile or link is refused with the error, and the game keeps the shader it had.
While no mod sets a value the game looks exactly as it always did; the screen pass only runs while a screen effect or a
post shader is on. Everything goes back to the game's own when your mod unloads (F9, Reload scripts, the Mods screen,
quitting), and shader.reset() does it at once. A shader file a mod ships (sh_world_water.fsh in its folder, see
The game's files) that does not compile no longer ends the game: the game's own file is used,
and the log says why.
Adds a fragment shader of your own over the picture, after the screen effects (several run in the order they were added). Before your code it gets uniform sampler2D screen; (the picture so far), varying vec2 uv; (0-1, bottom left), uniform vec2 resolution; (pixels) and uniform float time; (seconds, back to 0 every 10 minutes), and the precision; your line 1 is the first line of source in error messages. Declare more uniforms and set them with fx:set. It stays until removed or your mod unloads (dropping the handle does not remove it).
Parameter
Type
source
string
a GLSL ES 1.00 fragment shader (it gets screen, uv, resolution, time)
Replaces a game shader file while the game runs. The uniform and attribute names the game sets (input_mvp, input_texture ...) must stay. A source that does not compile or link is refused and the game keeps the shader it had. The world effects still work with your source (they wrap its main). Undone when your mod unloads.
Parameter
Type
file
string
a loaded shader file
source
string
its new GLSL
Returns
boolean
true: every program with the file uses it now
string?
the error when it was refused
local file = "sh_world_water.fsh"local src = shader.source(file)
-- redder water: change the last colour the shader writes
src = src:gsub("gl_FragColor = ", "gl_FragColor = vec4(1.3, 0.8, 0.8, 1.0) * ")
local ok, err = shader.setSource(file, src)
ifnot ok thenprint(err) end