Screen shaders
A screen shader is a fragment shader that post-processes an output's final image (colour grading, a night light, scanlines). Set it in an output rule:
outputs:
- match: "*"
shader: ~/.config/lys-wm/grayscale.fragThe path is absolute, starts with ~/, or is relative to the config file. lys-wmctl reload rereads it with the rest of the config. An output without a shader has no extra pass and scans out fullscreen windows directly.
The language
One source runs on both renderers. It is a subset of GLSL ES 1.00 (#version 100), parsed and checked by lys-wm itself:
| Renderer | Runs |
|---|---|
| Vulkan | SPIR-V generated by lys-wm |
| Software | Interpreted on the CPU per pixel, one thread per core |
precision mediump float;
uniform sampler2D tex;
varying vec2 v_texcoord;
void main() {
gl_FragColor = vec4(1.0 - texture2D(tex, v_texcoord).rgb, 1.0);
}Inputs, each declared before use; no other uniform or varying exists:
| Input | Is |
|---|---|
uniform sampler2D tex | The output's final image, bilinear, clamped at the edges. Read only through texture2D(tex, uv) |
varying vec2 v_texcoord | The pixel's position, (0, 0) top left to (1, 1) bottom right |
uniform vec2 resolution | Output size in device pixels |
uniform float time | Seconds, wrapping every hour. Using it redraws the output every frame |
gl_FragCoord | Pixel centre in device pixels, y down |
gl_FragColor | The result; must be written. Alpha is ignored, values clamp to 0–1 |
Supported:
- Types
float,int,bool,vec2–vec4,mat2–mat4; constructors, swizzles, constant indices. constglobals and locals; functions defined before use, withinparameters.if/else,?:,break,continue,return, and the GLSL ES 1.00 operators.forloops of constant length (GLSL ES 1.00 appendix A form,for (int i = 0; i < 8; i++)), index not assignable, at most 1024 iterations per pixel in total, including called functions.- Built-ins
radians,degrees,sin,cos,tan,asin,acos,atan,pow,exp,log,exp2,log2,sqrt,inversesqrt,abs,sign,floor,ceil,fract,mod,min,max,clamp,mix,step,smoothstep,length,distance,dot,cross,normalize,faceforward,reflect,refract,matrixCompMult,texture2D.
Not supported: implicit conversions (write 2.0 or float(n)), while, recursion, any directive other than #version 100 (so no #define and no #version 300 es), struct, arrays, ivec/bvec, mutable globals, out and inout parameters, prototypes, overloads, discard, derivatives, other textures. Sources are at most 64 KiB.
Errors
A shader that fails to compile, in lys-wm or the driver, leaves the output unshaded. The log names file, line and column, and lys-wmctl outputs shows it as shader_error until a reload fixes it.
What is shaded
Only the display. Screen capture (wlr-screencopy, ext-image-copy-capture and everything built on them) sees the unshaded image. While the session is locked, outputs draw without their shader.
Cost
On a shaded output:
- The scene renders into an intermediate image; the shader then redraws the whole output on any damage. With no damage it does not run, unless it reads
time. - The cursor is drawn into the image instead of a hardware plane, and fullscreen windows do not scan out directly.
- A 10-bit output composes in 8 bits.
A shader too heavy for the GPU slows the output, and one that stalls the GPU for seconds can trigger a driver reset that ends the session. On the software renderer the shader runs on the compositor thread and is slow at full HD.
Examples
Tested on all three renderers:
grayscale.frag: luminance onlynightlight.frag: a warm tintsharpen.frag: an unsharp mask over the eight neighboursscanlines.frag: moving scanlines and a vignette, readingtime