Blend modes
A Blend mode child decides how a thing mixes with whatever is behind it. Without one, a thing just covers what is behind it. With one, it can darken it like tinted glass, light it up like a lamp, turn its colors round, or take only its brightness.
local glass = things.find("glass")
glass:addChild(cat.Child.blendMode, { mode = cat.BlendMode.multiply }) -- darkens what is behind it
glass.blend.mode = cat.BlendMode.screen -- now it lights it up insteadThe child is cat.Child.blendMode, and it has one property: mode, the way it mixes, an item of cat.BlendMode. A child that is added with no mode is cat.BlendMode.normal: nothing changes until the script sets another.
What it works on
A Blend mode child can be put on floor, objects, texts and groups, and it works on whatever they show: a color, a picture, a text with its outline and shadow, the particles a thing gives off.
A script can add the child to an object or a text (thing:addChild(cat.Child.blendMode)), and it can change the mode of any thing that has one, group or not. What a script cannot do is add a blend mode to a group, because it turns the whole group into one picture. Put it on in the editor; afterwards group.blend.mode = cat.BlendMode.difference works like it does for anything else.
The ways
There are 31, and each is an item of the category cat.BlendMode: cat.BlendMode.multiply, cat.BlendMode.colorBurn. The editor's list gathers them in six groups, and the tables below follow it. (cat.BlendMode has one more item, grain, that only the camera's noise effect uses.)
Normal
| Item | What it does |
|---|---|
cat.BlendMode.normal | Drawn as it is. |
cat.BlendMode.dissolve | Scattered dots: more of them where the thing is more solid. Lower its alpha to see them; a solid thing shows no gaps. The dots stay on the thing as it moves, turns or zooms. |
Darken: each makes what is behind darker.
| Item | What it does |
|---|---|
cat.BlendMode.darken | Keeps the darker of each color part. |
cat.BlendMode.multiply | Darkens what is behind, like tinted glass. White does nothing. |
cat.BlendMode.colorBurn | Darkens hard, with more contrast. |
cat.BlendMode.linearBurn | Darkens by taking light away. |
cat.BlendMode.darkerColor | Shows whichever color is darker, the thing's or the one behind. |
Lighten: each makes what is behind lighter.
| Item | What it does |
|---|---|
cat.BlendMode.lighten | Keeps the lighter of each color part. |
cat.BlendMode.screen | Lightens what is behind, like shining a light on it. Black does nothing. |
cat.BlendMode.colorDodge | Lightens hard, with less contrast. |
cat.BlendMode.add | Adds its light to what is behind. The editor calls it Additive. |
cat.BlendMode.lighterColor | Shows whichever color is lighter. |
cat.BlendMode.reflect | Its bright parts make what is behind shine hard. |
cat.BlendMode.glow | Like Reflect, but led by what is behind. |
Contrast: more of both dark and light.
| Item | What it does |
|---|---|
cat.BlendMode.overlay | More contrast, led by what is behind. |
cat.BlendMode.softLight | Gently lightens or darkens. |
cat.BlendMode.hardLight | Strongly lightens or darkens. |
cat.BlendMode.vividLight | Darkens or lightens hard, by its color. |
cat.BlendMode.linearLight | Adds or takes away light, by its color. |
cat.BlendMode.pinLight | Takes its color where that is much darker or lighter than what is behind. |
cat.BlendMode.hardMix | Only full colors: each part is all on or all off. |
Compare: how the two colors differ.
| Item | What it does |
|---|---|
cat.BlendMode.difference | How far apart the two colors are. The same color gives black. |
cat.BlendMode.exclusion | Like Difference, but softer. |
cat.BlendMode.subtract | Takes its color away from what is behind. |
cat.BlendMode.divide | Brightens what is behind: the darker the thing, the more. |
cat.BlendMode.negation | Like Add (Additive), but too much light turns dark again. |
cat.BlendMode.xor | Mixes the colors' bits: wild patterns. |
Color: only a part of the color is taken from the thing.
| Item | What it does |
|---|---|
cat.BlendMode.hue | Its hue on what is behind. |
cat.BlendMode.saturation | Its strength of color on what is behind. |
cat.BlendMode.color | Its hue and strength of color; the brightness behind stays. |
cat.BlendMode.luminosity | Its brightness; the colors behind stay. |
Reading thing.blend.mode gives the item. thing:get("blend.mode") does the same, and thing:set("blend.mode", cat.BlendMode.hue) sets it, as for any property. A word in quotes, or a number, is not an item, and stops the script. A name that is none of the ways is a mistake, and the message suggests the nearest one: cat.BlendMode has no 'multipl': normal, dissolve, darken... (did you mean 'multiply'?).
Together with the other children
The thing is drawn first, with all its other children, and the finished picture is then mixed in the way you chose. So:
- The thing's
alphais how strong the mix is. At half, the way is half as strong. A Dissolve at half has half of its dots. A group'salphafades the whole group as one picture. - Gradient and Mask shape the picture before it is mixed: a gradient that fades the thing out fades the mix out, and a mask only lets the mix through where it lets the thing through.
- Picture: a thing with a picture mixes the picture, not the color under it.
- Blur blurs the thing, and the blurred thing is mixed.
- Effects act on the thing as before. If the Effects child hides the thing, there is nothing of it left to mix.
- Particles (their page) follow the mode, except those with Glow at 1: they always add their light, whatever the mode. A thing with several copies (
repeat) mixes all its copies as one picture. - Visible off, a hidden thing, or one off the screen: nothing is mixed, and it costs nothing.
- A hazard that hurts still hurts, however it mixes.
Everything above is the same when a script adds, changes or tweens the child, or a Make node does, and for keys. A mode is one of the things that is never "in between": a glide or a tween keeps the old way until it arrives and then switches.
local lamp = things.find("lamp")
lamp:addChild(cat.Child.blendMode, { mode = cat.BlendMode.add })
lamp.alpha = 0.6 -- not so strongGroups
A thing in a group mixes with what is behind the group. A group with a Blend mode child is one drawn as one picture: its things are put together first, and the whole picture then mixes with what is behind it. The things inside it mix only with each other.
This is also the way to mix touching pieces as one. Two touching blocks, each with a blend mode, mix twice where they meet. Put them in a group and give the group the blend mode, and the meeting is mixed once.
Groups drawn as one can sit inside each other, four deep. A group drawn as one deeper than that is drawn as a plain group: its blend mode does not show, and the editor says so.
Older computers
On most computers every way looks as it should. On older ones a few ways cannot be drawn, and the game draws the nearest one that it can:
| Wanted | Shown as |
|---|---|
| Normal, Multiply, Screen, Exclusion | the same, always |
| Darken, Color burn, Linear burn, Darker color, Subtract | Multiply |
| Color dodge, Additive, Reflect, Glow | Additive |
| Lighten, Lighter color | Lighten |
| Difference, Negation, XOR | Exclusion |
| Divide | Screen |
| everything else (Dissolve, the Contrast group, the Color group) | Normal |
The editor tells you when a way you picked is shown as another on this computer. A level should look right with a stand-in, so a script that depends on one exact way for something that matters (a hint that must be seen) should not be the only thing that shows it.
A level can have a lot of blended things, but the screen has a budget: at most 32 mixes by the full method in a frame (12 on a phone), over at most 6 screens' worth of pixels. A thing past the budget is shown with its stand-in for that frame. Many small blended things (a hundred sparkles) are better as one thing with particles.
What you have used
thing:addChild(cat.Child.blendMode, { mode = cat.BlendMode.multiply })puts the child on, andthing.blend.mode = cat.BlendMode.screenchanges it.- There are 31 ways, in six groups, each an item of
cat.BlendMode: Normal, Darken, Lighten, Contrast, Compare, Color. - The thing's
alphais how strong it is; a group with the child is mixed as one picture. - A group's blend mode is put on in the editor; a script can change it.
- A mode never glides: when a key, a Set property node or a tween changes it, it switches at once (at the end of a glide).
Next: shaders, for looks the editor has no child for.