Shaders · Chapter 4 of 11

Shaders: Colour

Written for version 2.7.0

A colour is three numbers. Make colours, take them apart, mix, ramp, adjust and blend them with the Color, Channels and Blend nodes.

The last chapter bent a single value into edges, bands, curves, waves and repeats, and showed it as a brightness from black to white. This chapter adds colour. The good news is that there is almost nothing new to learn: a colour is three of those values side by side, and every node you have met works on all three at once.

A colour is three numbers

A screen makes every colour out of three lights: red, green and blue. So a colour in the graph is three numbers, one for each light, and each number is a brightness just like the values of the last chapter: 0 is off, 1 is fully on. The three numbers are called channels.

Construct Vector3 packs three values into one colour: X is red, Y is green, Z is blue. Red alone, then red and green together make yellow, then all three make white. Uneven amounts give every colour in between.
  • All three at 0 is black. All three at 1 is white.
  • Three equal numbers are always a grey. That is why a single value showed as black, grey and white in the last chapter: wired into Color, one value fills all three channels with the same number.
  • Red and green make yellow, green and blue make cyan, red and blue make magenta. Light adds up, so mixing more of it gets brighter, not muddier as paint does.
There is no colour port

The graph has no special type for colour. A colour travels as a Vector 3, a bundle of three numbers, and its ports have a yellow dot. The app does not care whether those three numbers mean red, green and blue or something else, which is why a node called Construct Vector3 makes colours and a node called Split Vector takes them apart.

Making a colour

There are two ways to make a colour. The Color node, in the Parameters folder, is the one you pick by eye: tap its colour well in the inspector and choose. Construct Vector3, in the Channels folder, is the one you build by number, and each of its three inputs can take a wire, so a channel can come from any value in the graph.

  • Every Color node is also listed in the material panel under Graph Inputs, as the graph chapter explained, so its colour can be changed without opening the graph. Type a Label to name its row.
  • Use Construct Vector3 when a channel should come from a value: a gradient in red, a wave in blue.
  • The Color node has three outputs. RGB is the colour and is the one you will use nearly every time. Alpha is its opacity as a single value. RGBA is all four numbers together.
  • RGBA is a Vector 4 and will not attach to a colour input, which wants a Vector 3. If a wire from a Color node refuses to land, you have probably dragged from RGBA: use RGB.
  • Typed numbers look brighter than you might expect: 0.5 in all three inputs of Construct Vector3 is a light grey, for the reason given in the last chapter under "Half is not half as bright". The colour you pick in a Color node is the colour you see.

Taking a colour apart

Going the other way is just as useful. Split Vector, in the Channels folder, takes a colour in and hands out its numbers one at a time, on outputs X, Y and Z. Each is a plain value again, ready for any node from the last chapter.

Split Vector shows one channel of the rainbow at a time as a grey picture: X is the red in it, Y the green, Z the blue. Swizzle 3 passes all three on in whatever order its menus say. Set X to Z and Z to X and red trades places with blue.
  • Split Vector has a fourth output, W. A colour has only three numbers, so ignore it. It is there for Vector 4.
  • A single channel wired into Color shows as grey, because one value fills all three channels. White means a lot of that channel, black means none.
  • Swizzle reorders channels without splitting them. Swizzle 3 gives three numbers out and has three menus, X, Y and Z, each choosing which incoming number goes there. Swizzle 1, 2 and 4 give one, two or four numbers out.
  • Split followed by Construct Vector3 is the long way to do what Swizzle does, but it lets you change a channel on the way through: split a colour, put One Minus on X, and build it again.

Mixing two colours

Mix (Lerp) from the last chapter blended between two values. Wire two colours into A and B and it blends between colours, because it does the same sum on each of the three channels. T is still a single value: 0 gives A, 1 gives B.

Two Color nodes go into A and B of Mix (Lerp) and a Gradient into T. The left edge, where T is 0, is colour A and the right edge is colour B. Change either colour and the fade follows.
  • Anything that makes a value can drive T. A Gradient gives a fade, a Wave gives stripes of two colours, a Step gives two flat areas with a hard line between them.
  • This is how every shape in the next chapter gets its colour: the shape is a value of 0 or 1, and it goes into T.
  • The middle of a mix between two strong colours can look dull or grey. If that bothers you, use a Color Ramp with a third colour placed in the middle.

Multiply and add

Multiply and Add also work channel by channel: red with red, green with green, blue with blue. They do opposite things to brightness. Multiplying colours whose channels are between 0 and 1 can only darken, which suits shadows, tints and masks. Adding can only lighten, which suits glows and highlights.

A rainbow goes into A of both nodes and one Color into B. Multiply by white changes nothing, by a red keeps only the red in each colour, by a grey darkens everything. Add lifts everything towards white instead, and adding black changes nothing.
You do thisAnd get this
Multiply by whiteNo change. White is 1 in every channel
Multiply by a greyA darker picture. Every channel is scaled down by the same amount
Multiply by a colourA tint. Each channel is scaled by a different amount, like looking through coloured glass
Multiply by blackBlack
Add blackNo change. Black is 0 in every channel
Add a greyA lighter, more washed out picture
Add a colourA lighter picture pushed towards that colour, like shining a coloured light on it
A typed number only changes red

When Multiply is working on a colour, the single number you can type into B in the inspector fills only the first channel. Type 0.5, expecting a picture half as bright, and only red is halved while green and blue stay as they were, so the picture turns blue-green. The same goes for Add, Subtract and the other Math nodes. To change all three channels by the same amount, add a Float node from the Parameters folder, set its Value, and wire it into B. A wired value fills every channel.

Colours can go past white

Add two bright colours and a channel can end up above 1. The screen shows that as fully on, so bright areas flatten out and shift towards white or yellow. The next node still gets the real number. Follow with Saturate to hold every channel between 0 and 1.

Color Ramp: many colours from one value

Mix blends two colours. Color Ramp, in the Color folder, blends as many as eight. It takes one value in, called Fac, and looks it up along a row of colour stops. Each stop is a colour and a position from 0 to 1. Between two stops the colours blend smoothly.

A Gradient goes into Fac. Two stops give a plain fade, a third adds orange, a fourth makes a sunset. Switch the Gradient to Spherical and the same colours run out from the centre: a ramp colours any value.
  • Select the node to see its stops in the inspector. Each row is a colour well and a Pos, the position of that stop.
  • Add Stop adds one, up to eight. The red minus removes one. A ramp always keeps at least two.
  • Move two stops close together for a sharp change of colour, or far apart for a slow one.
  • Fac is held between 0 and 1. A value below 0 gets the first colour and a value above 1 gets the last.
  • The second output, Alpha, is the opacity of the stops, blended the same way.

Color Ramp is the workhorse of colour in a graph. Every trick from the last chapter makes a value, and a ramp turns any value into colours of your choosing: fire from a gradient, marble from noise, a striped flag from a ramp with stops pushed together. When you are not sure how to colour something, build it in grey first and finish with a Color Ramp.

Hue, saturation and value

Red, green and blue are how a screen thinks. People find it easier to describe a colour in three other terms, and the graph can work in those too.

  • Hue is which colour it is, as a position round the colour wheel from 0 to 1. Red is 0, green is a third of the way round, blue two thirds, and 1 is red again. It wraps round: a hue of 1.25 is the same colour as 0.25, so a value that keeps growing runs through the rainbow again and again.
  • Saturation is how vivid it is. 0 is grey and 1 is the pure colour.
  • Value is how bright it is. 0 is black whatever the other two say.
Construct Vector3 packs a hue in X, a saturation in Y and a value in Z, and HSV to RGB turns them into a colour. The Gradient drives the hue, so the square shows every hue in order. Lowering Y washes it out towards white. Lowering Z dims it towards black.
NodeWhat it does
HSV to RGBReads a Vector 3 as hue, saturation and value and gives the colour
RGB to HSVThe other way. Follow it with Split Vector: X is the hue, Y the saturation, Z the value
Hue to RGBOne value in, a fully vivid, fully bright colour out. A rainbow in a single node

Adjusting a finished colour

To change one of the three on a colour you already have, you could convert it with RGB to HSV, split it, change a number, pack it again and convert back. Hue/Saturation/Value, in the Color folder, does all of that in one node. Reach for it when a picture is right but its colours are not.

Hue starts at 0.5, which changes nothing. Moving it either way turns every colour round the wheel together. Saturation multiplies how vivid the colours are and Value how bright.
Hue 0.5 means no change

On this node the neutral setting for Hue is 0.5, not 0. Setting Hue to 0 or to 1 swaps every colour for its opposite on the wheel. Saturation and Value are neutral at 1.

Grey and vivid

Saturation at Amount 1 leaves the picture alone. At 0 it is the grey version, and above 1 the colours get stronger. Luminance gives the same grey as a single value.

The Saturation node blends each colour with its own brightness. Luminance works that brightness out and gives it as one value, with green counting for the most and blue for the least, the way the eye sees them. Use Luminance when you want to forget the colours of something and treat it as a value again: to cut it with Step, or to colour it afresh with a Color Ramp.

Brightness, contrast and gamma

Three small nodes in the Color folder do the everyday adjustments. They are shown here on a grey ramp so that the plot can show what each does to the numbers. On a colour they do the same to all three channels.

Brightness slides the whole line up. Contrast tilts it about the middle, so darks get darker and lights lighter. Gamma bends the line and leaves both ends where they were. Invert Color turns it round.
NodeSettingsWhat it does
Brightness/ContrastBrightness, Contrast, both 0 for no changeBrightness is added to every channel. Contrast pushes each channel away from the middle value of 0.5, or towards it when negative
GammaGamma, 1 for no changeAbove 1 lifts the middle and keeps black and white fixed. Below 1 darkens the middle
Invert ColorFac, from 0 to 1Gives the opposite colour: each channel taken away from 1. Fac at 0 leaves the colour alone
RGB CurvesThree lists of points, headed R, G and BFloat Curve from the last chapter, once for each channel. Raise the middle of the blue list for a cooler picture, or lower the end of the red one to calm a hot highlight

The Blend node

Blend, in the Blend & Compositing folder, combines two colours the way layers combine in a painting app. Base is the picture underneath, Blend is the layer on top, and the Mode menu picks the sum. Opacity fades the result back towards the base. Order matters in most modes: if the result looks wrong, swap the wires going into Base and Blend.

The sunset is the Base and grey rings are the Blend layer. Normal covers the base. Multiply keeps the dark rings, Screen the light ones, Overlay does both, and Difference shows where the two disagree. Opacity turns the effect down.
What the mode doesModesIn short
CoversNormalShows the Blend layer over the base
DarkensMultiply, Darken, Burn, SubtractWhite in the Blend layer changes nothing in Multiply, Darken and Burn. Darken keeps whichever is darker
LightensAdd, Screen, Lighten, Dodge, DivideBlack in the Blend layer changes nothing in Add, Screen, Lighten and Dodge. Lighten keeps whichever is lighter
Adds contrastOverlay, Soft Light, Linear LightA Blend layer darker than middle grey darkens and a lighter one lightens. Soft Light is the gentlest
ComparesDifferenceBlack where the two match, brighter the more they differ

Multiply and Add here are the same sums as the Math nodes. Blend adds the Mode menu and Opacity, so you can try one mode after another without rewiring. Screen is a softer Add that never goes past white.

Now you try

  1. A sun. Gradient with Type set to Spherical, into a Color Ramp with three stops: pale yellow at 0, orange at about 0.4, deep blue at 0.6. Wire the ramp into Surface Output.
  2. Two-colour stripes. A Wave into T of a Mix (Lerp), with two Color nodes in A and B. Change the Wave Profile and Scale.
  3. A pastel rainbow. Gradient into Hue to RGB, then Saturation with Amount at 0.4.
  4. A duotone. Take the sun from the first exercise, follow its Color Ramp with Luminance, and feed that into a second Color Ramp with only two stops. Any picture can be recoloured this way.
  5. A darker picture, done properly. Put Multiply after any of the above, add a Float node set to 0.5 and wire it into B. Then pull the wire off, type 0.5 into B, and see the difference.
Something unclear?

Tell us which node or picture confused you, what you built, and what colour the square showed instead of the one you expected.

Send Feedback