Sub topic 4
Blend modes as simple per-channel math
This chapter assumes you can work with layers and masks in Photoshop and know brightness, hue and saturation. It also assumes you can read a short Python function. No calculus is needed, only multiplication and subtraction.
A blend mode can look like a menu of unrelated effects. Most of them are short arithmetic formulas, and once you know the formulas you can predict what a mode will do before you try it.
The model: one channel at a time
Photoshop applies a blend mode to each pixel, and within each pixel to each channel separately. In an RGB image, the red value of the top layer combines only with the red value beneath it. Green combines with green, and blue with blue. The channels never mix during this step.
Two names are used throughout the rest of this tutorial:
- Base is the value already present beneath the layer. It is the composite of everything under the active layer.
- Blend is the value on the layer that carries the blend mode.
The formula takes one base value and one blend value. It returns one result value.
To keep the math readable, treat channel values as numbers from 0 to 1. Black is 0 and white is 1. Photoshop stores 8-bit values from 0 to 255, so divide by 255 to convert. For example, 128 becomes about 0.502, and 64 becomes about 0.251.
Because each channel is independent, a mode can change hue even when you only meant to change brightness. If the blend layer is orange, its red, green and blue values differ, so each channel is pushed by a different amount. That shift in the balance of channels is a color shift.
Normal: the baseline
Normal is the simplest formula. The result equals the blend value.
def normal(base, blend):
return blendWith Normal at 100% opacity, the top layer replaces what is beneath it wherever the layer is opaque. Every other mode does something different with the base, and Normal is the reference for comparison.
Multiply, Screen, Overlay and Hard Light
Four formulas cover the core of the Darken and Lighten groups and the Contrast group. These groups get their own chapters. Here they serve as worked examples of the model.
def multiply(base, blend):
return base * blend
def screen(base, blend):
return 1 - (1 - base) * (1 - blend)
def overlay(base, blend):
if base < 0.5:
return 2 * base * blend
return 1 - 2 * (1 - base) * (1 - blend)
def hard_light(base, blend):
return overlay(blend, base)
print(multiply(0.5, 0.5)) # 0.25 (darker)
print(screen(0.5, 0.5)) # 0.75 (lighter)
print(overlay(0.5, 0.5)) # 0.5 (a 50% gray blend leaves the base value unchanged)Why Multiply darkens
Multiplying two numbers between 0 and 1 gives a number no larger than either one. A value of 1 (white) leaves the other number unchanged, and a value of 0 (black) forces the result to 0. Every blend value except white therefore pulls the result down. That is why Multiply can only darken or keep the same tone.
Why Screen lightens
Screen is Multiply applied to the inverted values, then inverted again. Inverting a value means computing 1 - value. So Screen darkens the "darkness" and the picture gets lighter. Black (0) leaves the base unchanged, and white (1) forces the result to 1.
Screen is the mirror of Multiply. The two formulas pivot around the same idea, which is why they appear as a pair.
Why Overlay depends on the base
Overlay checks the base value first. If the base is below 0.5, it behaves like a doubled Multiply. If the base is 0.5 or higher, it behaves like a doubled Screen. Dark areas get darker and light areas get lighter, so contrast increases. A blend value of 0.5 leaves the base unchanged in both branches.
Check this with the base at 0.25 and the blend at 0.5. The base is below 0.5, so the result is 2 * 0.25 * 0.5 = 0.25. The value did not change.
Why Hard Light is Overlay with the layers swapped
hard_light(base, blend) calls overlay(blend, base). The roles are reversed, so the blend layer decides whether the formula multiplies or screens. Where the top layer is dark, it multiplies. Where the top layer is light, it screens.
This difference matters when you choose between the two. With Overlay, the image beneath controls the effect. With Hard Light, the layer you are adding controls it.
Soft Light is a gentler relative of Overlay. Photoshop's exact formula is more involved and is not a single simple expression, so this chapter does not reproduce it. It uses the same pivot idea around 0.5 with a softer curve.
Running the numbers on a full pixel
The functions above work on one channel. To apply a mode to a pixel, call the function once per channel. The following code adds opacity as well.
def mix_opacity(base, result, opacity):
return base + (result - base) * opacity
def blend_pixel(base_rgb, blend_rgb, mode, opacity=1.0):
out = []
for base, blend in zip(base_rgb, blend_rgb):
result = mode(base, blend)
out.append(round(mix_opacity(base, result, opacity), 3))
return tuple(out)
def multiply(base, blend):
return base * blend
skin = (0.8, 0.4, 0.2)
gray = (0.5, 0.5, 0.5)
print(blend_pixel(skin, gray, multiply)) # (0.4, 0.2, 0.1)
print(blend_pixel(skin, gray, multiply, 0.5)) # (0.6, 0.3, 0.15)A 50% gray multiplied over the pixel halves each channel. The orange tone stays orange, only darker, because all three channels were scaled by the same factor. A colored blend layer would scale them by different factors and change the hue.
Opacity as a mix
Opacity does not change the formula. It controls how far the result moves away from the base. The expression is:
final = base + (result - base) * opacityAt 100% the final value equals the mode result. At 0% it equals the base. At 50% it sits halfway between them.
Here is one worked case. Take a base of 0.8 and a Multiply blend of 0.2. The mode result is 0.8 * 0.2 = 0.16. At 50% opacity, the final value is 0.8 + (0.16 - 0.8) * 0.5 = 0.48.
If the layer has transparent areas, the layer's own alpha multiplies with the opacity. A pixel that is 50% transparent on a layer at 50% opacity contributes at about 25% strength. A layer mask works the same way, as a per-pixel multiplier on the strength of the effect.
Opacity is a straight mix for every mode. The Fill slider is related, but it does not affect layer styles, and in a few modes (such as Linear Dodge and Color Dodge) the two sliders produce visibly different strength. The previous chapter covers that difference.
What the math tells you in practice
Once you know the formulas, several behaviors stop being surprises.
| Formula behavior | What you will see |
|---|---|
| Multiply can only keep or lower a value | A Multiply layer never brightens, so white on it is invisible |
| Screen can only keep or raise a value | A Screen layer never darkens, so black on it is invisible |
| Overlay pivots on the base at 0.5 | Midtones in the image move the most, and the extremes move less |
| Hard Light pivots on the blend at 0.5 | The top layer's tones decide the result |
| Opacity mixes toward the base | Lowering opacity never adds any new effect, it only weakens the one you have |
The Multiply and Screen rows describe the neutral colors (white for Multiply, black for Screen). The next chapter returns to this idea for every mode.
Limits of the simple model
The formulas above are accurate for the modes shown, but real files bring a few complications.
- Gamma. The numbers Photoshop blends are normally the encoded values stored in the file, not linear light. A 50% value in the file is not 50% of the physical light. Color Settings has an advanced option to blend RGB colors using a gamma of 1.0, which changes results noticeably. Leave it at its default unless you have a reason to change it, because files shared with other people may look different if you change it.
- Rounding. Photoshop works in 8-bit, 16-bit or 32-bit float. In 8-bit, each operation rounds to a whole number between 0 and 255. Stacking many blend layers can produce banding in smooth gradients. A 16-bit file avoids most of it.
- Clipping. Some formulas can produce values below 0 or above 1. In 8-bit and 16-bit modes Photoshop clamps them to the range, and the detail is lost. This is the source of blown highlights, covered later in the pitfalls chapter.
- Complex modes. Modes such as Soft Light, Vivid Light and the Component modes use formulas that are longer than the four above, or that work on hue, saturation and luminosity instead of straight RGB channels.
Practice
Exercise
A base channel is 0.6 and the blend channel is 0.5. Calculate the result for Multiply, Screen and Overlay. Which of the three leaves the base unchanged, and why?
Show answer
Multiply gives 0.6 0.5 = 0.3. Screen gives 1 - (1 - 0.6) (1 - 0.5) = 1 - 0.4 0.5 = 0.8. Overlay uses the second branch because the base is 0.5 or higher: 1 - 2 (1 - 0.6) (1 - 0.5) = 1 - 2 0.4 * 0.5 = 0.6. Overlay leaves the base unchanged because a blend value of 0.5 is its neutral value.
Exercise
The base is 0.25 and the blend is 0.8. Calculate overlay(0.25, 0.8) and hard_light(0.25, 0.8). Why are the answers different?
Show answer
overlay(0.25, 0.8): the base is below 0.5, so the result is 2 0.25 0.8 = 0.4. hard_light(0.25, 0.8) calls overlay(0.8, 0.25). Now the first argument is 0.8, which is 0.5 or higher, so the result is 1 - 2 (1 - 0.8) (1 - 0.25) = 1 - 2 0.2 0.75 = 0.7. The answers differ because Overlay branches on the base value, while Hard Light branches on the blend value.
Exercise
A layer set to Multiply produces a mode result of 0.16 over a base of 0.8. What is the final value at 25% opacity?
Show answer
final = base + (result - base) opacity = 0.8 + (0.16 - 0.8) 0.25 = 0.8 - 0.16 = 0.64.