Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blendmode not respecting alpha in P3D under certain circumstances #843

Open
RectangleWorld opened this issue Jul 2, 2024 · 0 comments
Open

Comments

@RectangleWorld
Copy link

Description

The additive blendmode does not respect alpha under certain circumstances.

When the following code is run, the two circles drawn have 100% alpha, but we should expect them to have 50% alpha (set by 0x80). There are workarounds, explained below.

void setup() {
  size(800, 800, P3D);
  generate();
}

/*
If the draw() function is removed, blending honors alpha, 
whether or not the last line of generate() is included.
*/
void draw() {
  //
}

void generate() {
  blendMode(BLEND);
  background(0xFF000000);
  noStroke();
  blendMode(ADD);
  fill(0x80FF0000);
  circle(300,300,400);
  fill(0x8000FF00);
  circle(500,500,400);
  // If this last line is omitted, blending doesn't honor alpha.
  //blendMode(BLEND);
}

Workarounds

Blending will honor alpha as expected if one of these things is done:

  • Omitting the draw() function
  • Making sure to set the blend mode back to BLEND at the end of the generate() function
  • Drawing into a PGraphics buffer and then drawing this buffer to the screen as in this code:
void generate() {
  PGraphics pg = createGraphics(width, height, P3D);
  pg.beginDraw();
  pg.blendMode(BLEND);
  pg.background(0xFF000000);
  pg.noStroke();
  pg.blendMode(ADD);
  pg.fill(0x80FF0000);
  pg.circle(300,300,400);
  pg.fill(0x8000FF00);
  pg.circle(500,500,400);
  pg.endDraw();
  image(pg, 0, 0);
}

Environment

  • Processing version: 4.3
  • Operating System and OS version: Windows 11, version 22H2
  • Graphics: NVIDIA GeForce RTX 3050 Ti Laptop GPU
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant