Hi! I have a circle on a PGraphics. I want reduce the opacity of parts of it. Imagine painting with your mouse on the PGraphics and instead of adding paint, it becomes more transparent under the mouse.
By using blendMode(REPLACE);
I can make it fully transparent, but is it possible to apply say 50% transparency?
PGraphics pg;
void setup() {
size(300, 300, P2D);
pg = createGraphics(width, height, P2D);
pg.beginDraw();
pg.background(255, 0);
// draw white circle
pg.noStroke();
pg.ellipse(width/2, height/2, 200, 200);
// bite the circle, reduce opacity
pg.blendMode(REPLACE);
pg.fill(255, 0);
pg.ellipse(width/3, height/3, 200, 200);
pg.endDraw();
}
void draw() {
background(#DDDDDD);
line(0, 0, width, height);
image(pg, 0, 0);
}
produces
I try reducing opacity like this
// bite the circle, reduce opacity
pg.blendMode(SUBTRACT);
pg.fill(0, 100);
pg.ellipse(width/3, height/3, 200, 200);
but this is what I get:
The opacity of the white circle is not reduced, and for some reason the transparent area becomes partially opaque.
MULTIPLY gives me a similar result, so it seems like the alpha is not multiplied.
I know how to do it with a shader, but I was wondering if it’s possible to achieve with blendMode
? Is this related to those pre-multiplied alpha issues?