Skip to content

color

unreviewed draft

Scales each RGBA channel of the image; negative values invert a channel before scaling it.

color is a color function: it runs per pixel after the earlier part of the chain has produced a color xx (one of red, green, blue or alpha), with argument cc for that channel:

x′={c⋅xc≥0∣c∣⋅(1−x)c<0x' = \begin{cases} c \cdot x & c \ge 0 \\ |c| \cdot (1 - x) & c < 0 \end{cases}

So positive values are a plain gain (tint/dim/brighten) and negative values are a scaled inversion. color(-1, -1, -1) is the same as invert(). Each channel is independent, so color(1, -1, 1) inverts green only.

All four arguments default to 1, so any you leave out are untouched: color(0.5) halves red only, which tints the image cyan.

The result is not clamped inside the chain, but every output buffer stores 0–1 per channel, so gains above 1 saturate when written out.

color source in glsl-functions.js (hydra-synth 1.4.0) ↗
Tint: keep red, dim green and blue
osc(20, 0.1, 0).color(1, 0.4, 0.2).out()
Open in hydra ↗
Invert one channel
osc(20, 0.1, 1.5).color(1, -1, 1).out()
Open in hydra ↗
Pulsing brightness with a function
osc(10, 0.1, 1).color(() => 1 + Math.sin(time), () => 1 + Math.sin(time), () => 1 + Math.sin(time)).out()
Open in hydra ↗

Multiplies each channel by its argument; a negative argument multiplies the inverted channel by its absolute value.

ParameterDefaultUseful rangeUnitsNo-op at
r1-2 … 2multiplier (unitless)1
g1-2 … 2multiplier (unitless)1
b1-2 … 2multiplier (unitless)1
a1-1 … 1multiplier (unitless)1

r= 1

Red multiplier. Negative values use the inverted red channel, 1−red1 - \text{red}.

Useful range
-2 … 2
Units
multiplier (unitless)
No-op at
1
Negative values
∣r∣⋅(1−red)|r| \cdot (1 - \text{red}): -1 is a pure inversion of red, -0.5 an inverted and dimmed red
Accepts
number · array · function

Values above 1 brighten, but anything past 1.0 is clipped when the result is written to an output, so a channel that is already bright saturates to full. 0 and -0 give the same result (black in that channel) — both formulas multiply by ∣r∣=0|r| = 0.

r = 11
r = 0.50.5
r = 00
r = -0.5-0.5
r = -1-1
r = 22
Sweep of r (still at time = 0): s0.initImage("https://hydra-ref.audiodude.xyz/cards/color-chart.png") src(s0).color({r}, 1, 1, 1).out() · outlined tile = default

g= 1

Green multiplier; same rules as r.

Useful range
-2 … 2
Units
multiplier (unitless)
No-op at
1
Negative values
∣g∣⋅(1−green)|g| \cdot (1 - \text{green})
Accepts
number · array · function
g = 11
g = 0.50.5
g = 00
g = -0.5-0.5
g = -1-1
g = 22
Sweep of g (still at time = 0): s0.initImage("https://hydra-ref.audiodude.xyz/cards/color-chart.png") src(s0).color(1, {g}, 1, 1).out() · outlined tile = default

b= 1

Blue multiplier; same rules as r.

Useful range
-2 … 2
Units
multiplier (unitless)
No-op at
1
Negative values
∣b∣⋅(1−blue)|b| \cdot (1 - \text{blue})
Accepts
number · array · function
b = 11
b = 0.50.5
b = 00
b = -0.5-0.5
b = -1-1
b = 22
Sweep of b (still at time = 0): s0.initImage("https://hydra-ref.audiodude.xyz/cards/color-chart.png") src(s0).color(1, 1, {b}, 1).out() · outlined tile = default

a= 1

Alpha multiplier; same rules applied to the alpha channel.

Useful range
-1 … 1
Units
multiplier (unitless)
No-op at
1
Negative values
∣a∣⋅(1−alpha)|a| \cdot (1 - \text{alpha}); on an opaque image any negative a gives alpha 0
Accepts
number · array · function

Alpha matters when this result is combined with another texture (e.g. layer, blend, mask). Displayed directly, the browser composites the canvas over whatever page is behind it, so what a lowered a looks like on its own depends on that page.

a = 11
a = 0.50.5
a = 00
Sweep of a (still at time = 0): s0.initImage("https://hydra-ref.audiodude.xyz/cards/color-chart.png") src(s0).color(1, 1, 1, {a}).out() · outlined tile = default
  • Gains above 1 clip at the output, so color(2, 2, 2) blows highlights out to white rather than stretching contrast. Use contrast/brightness for that.
  • 0 and -0 behave identically (both zero the channel).
  • Arguments & time: animating the channels with arrays and functions.
  • modulate: uses red/green of another texture as displacement, so color on the modulator changes the direction of the warp.

Documents hydra-synth 1.4.0 (AGPL-3.0; this site runs it unmodified). Annotations drafted by Claude (Anthropic) from the hydra-synth source and checked against rendered output — see about. Site code AGPL-3.0, prose CC BY 4.0,source.