< Previous | Contents | Next >
The Math of the Matrix
The ‘ColorMatrix’ is a 4x4 matrix, so you can use it to affect RGB. The ‘ColorMatrixFull’ is a 5x5 matrix, which adds Alpha to the RGB color channels.
In the terminology of Matrix mathematics, an "identity matrix" is one that doesn’t change anything. A 4x4 identity matrix would look like:
r g b
R 1 0 0 0
G 0 1 0 0
B 0 0 1 0
0 0 0 1
We could say that uppercase R, G and B are going to be the results, and lowercase r, g and b are the source/input values. You can completely ignore the bottom row, but not the right column.
So just looking at the first row, it says the R result will contain 1 of r, 0 of g and 0 of b (or 1 * r + 0 * g + 0 * b). And the second row says the R result will contain 0 of r, 1 of g and 0 of b. And similar for the 3rd row.
So far we just ignored the right column, but you can consider the source/input value for the right column to be 1.0. So that would make the first row of the matrix produce results for R = 1 * r + 0 * g + 0 * b + 0 * 1.0.
With that, we can do "brightness" by increasing or decreasing how much of the 1.0 input value is included in the result. Let’s say we wanted a brightness of 0.5 in the R result. That would make the R row of the matrix:
R | r 1 | g 0 | b 1.0 0 0.5 | ||
R | = = | 1 1 | * * | r + 0 * g + 0 * b + 0.5 * 1.0 r + 0.5 * 1.0 | |
= | r | + | 0.5 | ||
If instead we wanted a "gain" of 2.0 (so we want the R result to have 2 times r), that would make the R row of the matrix:
r g b 1.0
R 2 0 0 0
= 2 * r

r g b 1.0 R 0 1 0 0
B = 0 * r + 1 * g + 0 * b + 0 * 1.0
= 1 * g
= g
R = 2 * r + 0 * g + 0 * b + 0 * 1.0
Say we wanted to put g into the resulting R, (copying the green channel into the Red channel of the output) then the first row of the matrix would be:

R = 0.299 * r + 0.587 * g + 0.114 * b + 0.0 * 1.0
= 0.299 * r + 0.587 * g + 0.114 * b
If you wanted R to be the "luminance" of rgb, the first row of the matrix would be:
r | g | b | 1.0 | |
R | 0.299 | 0.587 | 0.114 | 0 |
r g b 1.0
R -1 0 0 1

= -r + 1
= 1 - r
R = -1 * r + 0 * g + 0 * b + 1 * 1.0
= -1 * r + 1 * 1.0
If we want R to be an inverted version of r, we want to do "1.0 - r", which means we want to make r negative (gain of -1.0) and then add 1.0 (brightness of 1.0), so the first row of the matrix would be: