Additive vs Over compositing/rendering

Hey there

How does one go about making colours additive in the graphics context?

That is to say if I were to layer up a three identical strokes, eg red, green, and blue, all with alpha = 1, I would expect, and do get, the top colour to be the only one you see. This is totally appropriate for Over compositing.

However, if one were to use Additive compositing the result would be white, as in red + green + blue. And this visual result would be the same irrespective of layer order.

It would be great to be able to switch g.setCompositingMode between standard Over, and Additive for, glows, overlays, and other niceties. Sometimes it might be appropriate to combine and express all your visual data in this way for say a multi band eq display or something.

I did see the vf layer effects thing from 9 years ago. It seems like it could be outdated though, and also perhaps overkill for what I’m considering.

Any thoughts or suggestions are much appreciated!


The problem is, by drawing with a graphic context, you draw into an unspecified target. It could be a software renderer image, stored in memory. Or an OpenGL image, stored in a GL texture on your GPU, which needs a CPU<->GPU synchronization. Or it could be an OS surface. Different for every platform.

Additionally to that you need per pixel blending with source and destination to emulate the blend equation for each colour component

It’s not as obvious as one might think. You have to perform a per pixel iteration. This needs additional state for every kind of drawing operation. Paths, fill, and so on. It’s probably better to just write some kind of specialization for software images. A layer composition engine. So you don’t have to use a graphics context at all, but directly operate on BitmapData or juce::Image.

1 Like

Thanks for the reply @parawave. My visual effects background privilege is showing. Lol.

Although conceptually it’s a really obvious ask, thanks for explaining how an implementation that satisfies all targets is not as straightforward. Also thanks for suggesting how you might approach the problem.

All that said, having such ease of visual flexibility would have been really cool :slight_smile:

You might be interested that the Gin library implements a bunch of blend modes for juce::Image. This won’t be as easy as what you described (just set a blend mode and paint). You will have to create an image for each layer you want to draw in a different blend mode, then combine them. But depending on what you want to do, it might get you some of the way.


@widdershins thanks for your suggestion, and that link. Looks like a very interesting project!