Skip to content

Shader Interface

The operators, their uniforms and the built-in uniforms supplied to every shader are in the std/visuals reference.

A shader is a .glsl file loaded with gfx.load_shader(name, path), or the same source given as a string to gfx.Visual(name, source). It is a GLSL-ES 3.00 fragment shader:

  • It starts with #version 300 es and declares a default precision.
  • It writes its colour to an out vec4.
  • It reads its inputs as uniform sampler2D iChannel0;, iChannel1, …: the node fed in with >> is always iChannel0, and nodes bound to named inputs take the channels after it.

It is compiled by the renderer when something draws it — an open visuals window, render(screen) or screen.snap() — not when it is loaded.

v.parameter(name) << value arrives in the shader as:

ValueGLSL declaration
a number, a signal, a meter feed (.rms, .peak, .fft.band(…))uniform float name;
an array of 2, 3 or 4 numbersuniform vec2 name;, vec3, vec4
a spectrum feed (.fft, .fft.smooth(…))uniform sampler2D name;
a visual nodea texture input (iChannel1, …)

Binding a name again replaces what it was bound to. The built-in uniforms and the samplers iChannel0, iChannel1, … and iPrev are supplied by the engine; binding one is an error.

PropertyValue
Size512 bins × 1 row, from a 1024-point FFT
Layoutread it at vec2(x, 0.5); x is 0 at the lowest bin and near 1 at the highest, linear in frequency
Valuethe bin’s magnitude in .r; a full-scale sine reads about 0.5 at its bin
Filteringnearest — no interpolation between bins