Shader Interface
The operators, their uniforms and the built-in uniforms supplied to every shader are in the
std/visuals reference.
Shader source
Section titled “Shader source”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 esand declares a defaultprecision. - It writes its colour to an
out vec4. - It reads its inputs as
uniform sampler2D iChannel0;,iChannel1, …: the node fed in with>>is alwaysiChannel0, 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.
Bound values
Section titled “Bound values”v.parameter(name) << value arrives in the shader as:
| Value | GLSL declaration |
|---|---|
a number, a signal, a meter feed (.rms, .peak, .fft.band(…)) | uniform float name; |
| an array of 2, 3 or 4 numbers | uniform vec2 name;, vec3, vec4 |
a spectrum feed (.fft, .fft.smooth(…)) | uniform sampler2D name; |
| a visual node | a 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.
Spectrum texture
Section titled “Spectrum texture”| Property | Value |
|---|---|
| Size | 512 bins × 1 row, from a 1024-point FFT |
| Layout | read it at vec2(x, 0.5); x is 0 at the lowest bin and near 1 at the highest, linear in frequency |
| Value | the bin’s magnitude in .r; a full-scale sine reads about 0.5 at its bin |
| Filtering | nearest — no interpolation between bins |
Related
Section titled “Related”- Bind Audio to a Shader — the feeds in use
- MeterFeed and SpectrumFeed — their methods