Luawe All pages

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 instead

The 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

ItemWhat it does
cat.BlendMode.normalDrawn as it is.
cat.BlendMode.dissolveScattered 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.

ItemWhat it does
cat.BlendMode.darkenKeeps the darker of each color part.
cat.BlendMode.multiplyDarkens what is behind, like tinted glass. White does nothing.
cat.BlendMode.colorBurnDarkens hard, with more contrast.
cat.BlendMode.linearBurnDarkens by taking light away.
cat.BlendMode.darkerColorShows whichever color is darker, the thing's or the one behind.

Lighten: each makes what is behind lighter.

ItemWhat it does
cat.BlendMode.lightenKeeps the lighter of each color part.
cat.BlendMode.screenLightens what is behind, like shining a light on it. Black does nothing.
cat.BlendMode.colorDodgeLightens hard, with less contrast.
cat.BlendMode.addAdds its light to what is behind. The editor calls it Additive.
cat.BlendMode.lighterColorShows whichever color is lighter.
cat.BlendMode.reflectIts bright parts make what is behind shine hard.
cat.BlendMode.glowLike Reflect, but led by what is behind.

Contrast: more of both dark and light.

ItemWhat it does
cat.BlendMode.overlayMore contrast, led by what is behind.
cat.BlendMode.softLightGently lightens or darkens.
cat.BlendMode.hardLightStrongly lightens or darkens.
cat.BlendMode.vividLightDarkens or lightens hard, by its color.
cat.BlendMode.linearLightAdds or takes away light, by its color.
cat.BlendMode.pinLightTakes its color where that is much darker or lighter than what is behind.
cat.BlendMode.hardMixOnly full colors: each part is all on or all off.

Compare: how the two colors differ.

ItemWhat it does
cat.BlendMode.differenceHow far apart the two colors are. The same color gives black.
cat.BlendMode.exclusionLike Difference, but softer.
cat.BlendMode.subtractTakes its color away from what is behind.
cat.BlendMode.divideBrightens what is behind: the darker the thing, the more.
cat.BlendMode.negationLike Add (Additive), but too much light turns dark again.
cat.BlendMode.xorMixes the colors' bits: wild patterns.

Color: only a part of the color is taken from the thing.

ItemWhat it does
cat.BlendMode.hueIts hue on what is behind.
cat.BlendMode.saturationIts strength of color on what is behind.
cat.BlendMode.colorIts hue and strength of color; the brightness behind stays.
cat.BlendMode.luminosityIts 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 alpha is how strong the mix is. At half, the way is half as strong. A Dissolve at half has half of its dots. A group's alpha fades 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 strong

Groups

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:

WantedShown as
Normal, Multiply, Screen, Exclusionthe same, always
Darken, Color burn, Linear burn, Darker color, SubtractMultiply
Color dodge, Additive, Reflect, GlowAdditive
Lighten, Lighter colorLighten
Difference, Negation, XORExclusion
DivideScreen
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, and thing.blend.mode = cat.BlendMode.screen changes it.
  • There are 31 ways, in six groups, each an item of cat.BlendMode: Normal, Darken, Lighten, Contrast, Compare, Color.
  • The thing's alpha is 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.