Hello, everyone!
What I want to achieve is having two differently colored blurred shapes in one PGraphics. The problem is that when copying the latter shape/image into the first one the semi-transparent pixels (blurred edges) are composited with the background color of the first image and don’t keep their original color. In the screenshot below the black border around the white shape is what I want to avoid.
I know this can be done perfectly when drawing one after the other onto the main canvas, but as my actual sketch is a little more complex, I need a solution that doesn’t involve the main canvas.
I tried and read a lot already and have the stupid feeling I’m missing something very basic here, as this is something that comes natural with for example Photoshop.
Any help is appreciated! If this is already solved or explained somewhere else, I’m totally fine with a link.
// PShader taken from Examples->Topics->Shaders->SepBlur
PGraphics pg1, pg2;
PShader blur;
void setup() {
size(500, 500, P2D);
blur = loadShader("blur.glsl");
blur.set("blurSize", 20);
blur.set("sigma", 5f);
pg1 = createPGfx(255);
pg2 = createPGfx(0);
pg2.beginDraw();
pg2.image(pg1, 100, 100);
pg2.endDraw();
}
void draw() {
background(127);
image(pg2, -50, -50);
}
PGraphics createPGfx(color c) {
PGraphics pg = createGraphics(width, height, P2D);
pg.noSmooth();
pg.beginDraw();
pg.noStroke();
pg.fill(c, 255);
pg.background(c, 0);
pg.rectMode(CENTER);
pg.rect(width/2, height/2, width/2, height/2);
blur.set("horizontalPass", 0);
pg.filter(blur);
blur.set("horizontalPass", 1);
pg.filter(blur);
pg.endDraw();
return pg;
}