Overlay blendMode in Processing

I need to use OVERLAY in blendMode() for a project I’m working on.

From reading the documentation I know that OVERLAY (as well as a number of other blend modes) is no longer supported. Yet, overlay is the blend mode I need.

What are my options? Can I make my own custom blend mode to use when drawing shapes? Or do I need to manually pixel-per-pixel apply an image to themain canvas using an overlay blend formula?

Did you try blend() with OVERLAY

Yes. I tried blend() and got somewhat close to the results I’m loooking for. However, blend() requires a PImage as source, and I would like to skip this. Ideally, I want to be able to draw shapes like circle(), square(), triangle() directly on to the main canvas using a function that emulates the look of blendMode(OVERLAY).

PImage is the parent class for subclass PGraphics.

And also for other subclasses from some addon libraries, like Movie, Capture, etc.

That’s why we can pass variables of those subclasses’ datatype as an argument for functions like image(), set(), background(), etc.

Appreciate your input @GoToLoop. Please help me understand it in relation to my initial question. Is it the fact that PImage is a parent class that is somehow preventing the use of OVERLAY in blendMode()?

Not much experience w/ Processing blending, sorry.

But as far as I can understand from the reference docs, blend() is a filter copy operation which applies to all pixels from some selected area; while blendMode() modifies how new pixels are blended in existing pixels for future drawings/copies.

Thanks for clarifying. I get the same understanding from reading the reference as you do @GoToLoop.

It puzzles me how certain blend modes are supported while others - seemingly very related - blend modes somehow doesn’t work anymore (I can see in my earlier sketches that OVERLAY was indeed supported).

Bet it traces down to the way Processing’s different renderers work. Can somebody with more in-depth knowlegde shed some light on this?

Here’s a code snippet to help troubleshoot:

PGraphics brush;

void setup() {
  size(800, 800);
  brush = createGraphics(400, 400);
  brush.beginDraw();
  brush.background(255, 255, 0);
  brush.endDraw();
}

void draw() {
  background(255);
  fill(255, 0, 0);
  noStroke();
  rect(0, 0, 400, 400);
  //blend(brush, 0, 0, brush.width, brush.height, mouseX, mouseY, brush.width, brush.height, BLEND);
  blend(brush, 0, 0, brush.width, brush.height, mouseX, mouseY, brush.width, brush.height, OVERLAY);
}

In setup() I’m filling a PGraphics with a yellow background. In draw() I’m drawing a red square and using blend() to add that yellow image using OVERLAY as blend mode but nothing happens? The yellow image isn’t even showing?

To test if blend() is indeed working, I tried to use BLEND as the blend mode (see the commented line) and the yellow image appears as expected.

OVERLAY is such an important blend mode for anyone who want to simulate the behaviour of pigment based ink on paper. I’m really hoping someone can help me shed some light on this.

(I’m on a Mac 12.6.7 using Processing 4.2)