Reference
The whole shader language, on one page.
The block
SHADER "name"
USE NUMBER name [DEFAULT number]
USE COLOR name [DEFAULT RGB(r, g, b)]
USE IMAGE name
WHEN DRAWING
name = expression
SET COLOR = expression
END WHEN
END SHADER
| Line | Means |
|---|---|
SHADER "name" … END SHADER | Defines a shader called name, or replaces the one already called that. |
USE NUMBER name [DEFAULT n] | A number setting. Without DEFAULT it’s 0. n is a plain number, with no minus. |
USE COLOR name [DEFAULT RGBA(r, g, b, a)] | A color setting, four numbers; RGB(r, g, b) for an opaque one. Without DEFAULT it’s opaque black. Given as three or four numbers from 0 to 1: (1.0, 0.5, 0.0) or a list. |
USE IMAGE name | A picture setting, given by its name in shader_params, read with SAMPLE(name, uv). Up to 4. |
WHEN DRAWING … END WHEN | The code, run once for every pixel. |
name = expression | Makes or changes a variable. |
SET COLOR = expression | The pixel’s color: four parts, 0 to 1. The last one wins; with none, the pixel keeps IMAGE. |
' comment | To the end of the line. |
What a pixel knows
| Word | Parts | Is |
|---|---|---|
IMAGE | 4 | The color the pixel was going to be. |
UV | 2 | Where it is on what’s being drawn: (0, 0) top left, (1, 1) bottom right. On an animated sprite, on the frame. |
SCREEN | 2 | Where it is on the screen, in the game’s pixels, from (0, 0) at the game’s top left. |
SCREEN_SIZE | 2 | The game’s size, in its own pixels, as SCREEN set it. |
TIME | 1 | Seconds since the renderer started. |
TICK | 1 | Frames drawn since this shader went on this layer or sprite. |
Functions
| Function | Gives |
|---|---|
RGBA(r, g, b, a) | A color. |
RGB(r, g, b) | A solid color. |
VEC2(x, y), VEC3(x, y, z), VEC4(x, y, z, w) | A vector. |
OWNTEXTURE(uv) | The color of the shader’s own picture at uv. |
SAMPLE(name, uv) | The color of a USE IMAGE picture at uv. |
PX(x, y) | x pixels across and y down, as a UV, in the picture’s own pixels. |
RND(x), RND(x, y) | A number from 0 to 1 that looks random, the same every time for the same numbers. |
ABS(x) | x without its minus. |
FLOOR(x) | x rounded down to a whole number. |
FRACT(x) | What comes after the point: x - FLOOR(x). |
SIN(x), COS(x) | Sine and cosine, in radians. |
SQRT(x) | Square root. |
POW(x, y) | x to the power y. |
MIN(a, b), MAX(a, b) | The smaller, the bigger. |
CLAMP(x, low, high) | x, kept from low to high. |
MIX(a, b, t) | a at 0, b at 1, between in between. |
STEP(edge, x) | 0 if x is under edge, otherwise 1. |
SMOOTHSTEP(low, high, x) | 0 to 1, smoothly, as x goes from low to high. |
LENGTH(v) | How long a vector is. |
DOT(a, b) | Parts multiplied in pairs, added up. |
NORMALIZE(v) | v, 1 long. |
Every function but RGBA, RGB, the VECs, OWNTEXTURE, SAMPLE, PX,
RND, LENGTH and DOT works on a vector part by part, as well as on a
number. When it takes more than one value, they’re all the same size, except
the last of MIX, which can be a number.
Sums
+ - * /, with * and / first, brackets before both, and - in front to
turn a number around. Vector and vector, of the same size, part by part;
vector and number, the number in every part.
Swizzles
.r .g .b .a or .x .y .z .w, one to four of them, in any order, on a
name, a word, or brackets: c.bgr, UV.yx, (UV * 2.0).x.
Putting a shader on
| On | Settings | Off | |
|---|---|---|---|
| A layer | SET LAYER n !! shader("name") | !! shader_params({...}), with shader or by itself | !! clear_shader |
| A sprite | SET SPRITE n !! shader("name") | !! shader_params({...}), with shader | !! clear_shader |
A shape, with a texture | SET POLYGON n !! shader("name") | !! shader_params({...}), with shader | !! clear_shader |
| A behavior | USE SHADER "name" | !! param("name") start(a) to(b) duration(ticks) [loop] | when the behavior ends |
| A transition | CLS [color] !! effect_shader("name") [speed(n)] | progress, target_r, target_g, target_b, target_a, filled in | when it’s done |
In shader_params, a number goes to a USE NUMBER setting, three or four
numbers in brackets or a list to a USE COLOR one, and a picture’s name, as a
string, to a USE IMAGE one. A name the shader doesn’t have, or a value of
the wrong kind, stops the program and says which settings the shader takes.