Loading...
Logo
Processing Forum
Is this a bug? Or just a basic color math concept I'm missing?

I have a PImage with a mask that draws correctly.
When I change the blendMode the mask disappears, except for ADD.
This holds true when I'm using P2D, P3D, and even when the PImage is mapped onto 3D geometry.

Is there any way to combine masks and blendingModes?

Thanks,
--David

Here's my code.  I've used loadImage, but it works the same way with generated PImages:
Copy code
  1. PImage image, mask;
    boolean bMask = false;
     
    void setup() {
      size(800, 800, P2D);
      image = loadImage("fibers.jpg");
      mask = loadImage("zebra.jpg");
    }

    void draw() {
      background(128);
      blendMode(ADD);
      image(image, 0, 0);
    }

    void keyPressed()
      {
          if(key == 'm') {
              if(!bMask) {
                image.mask(mask);
                bMask = true;
                print(bMask);
              }
              else {
                  image = loadImage("fibers.jpg");
                  bMask = false;
                  print(bMask);
              }
          }

      }

Replies(5)

yes, I have the same question, for example, I want to assign a mask to an image then blend it on another image in SCREEN mode, 
Reset the blend mode before doing the mask:
Copy code
  1. PImage image, mask, masked;
  2. boolean bMask = false;
  3.  
  4. void setup()
  5. {
  6.   size(800, 800);
  7.   image = loadImage("G:/Images/map.png");
  8.   masked = image.get();
  9.   mask = loadImage("G:/Images/mapMask1.png");
  10. }
  11.  
  12. void draw()
  13. {
  14.   background(128);
  15.   scale(8);
  16.   blendMode(ADD);
  17.   image(masked, 0, 0);
  18. }
  19.  
  20. void keyPressed()
  21. {
  22.   if (key == 'm')
  23.   {
  24.     blendMode(BLEND);
  25.     if (!bMask)
  26.     {
  27.       masked.mask(mask);
  28.     }
  29.     else
  30.     {
  31.       masked = image.get();
  32.     }
  33.     bMask = !bMask;
  34.   }
  35. }

Copy code
  1. PImage desert; 
  2. PImage redp; 
  3. PImage maskp; 
  4. PImage masked;
  5. void setup() { 
  6.   background(0); 
  7.   size(400, 400, P2D); 
  8.   desert=loadImage("Desert.jpg"); 
  9.   redp=loadImage("red.jpg"); 
  10.   masked=redp.get();
  11.   maskp=loadImage("mask.jpg");

  12. void draw() { 
  13.   image (desert, 0, 0); 
  14.   //blendMode(ADD); 
  15.   blendMode(SCREEN); 
  16.   image (masked, 0, 0); 
  17.   masked.mask(maskp);
Hi PhiLho,
I add get() before the mask but  no lucky, there is no mask in SCREEN mode, any problem in my code? thank you very much!!


Fantastic,  I'll be needing to do this a lot on my next project - so thanks!
Copy code

  1. PImage desert;
  2. PImage redp;
  3. PImage maskp;
  4. PImage comp;
  5. void setup(){
  6.   size(400,400,P2D);
  7.   desert=loadImage("Desert.jpg"); 
  8.   redp=loadImage("red.jpg"); 
  9.   maskp=loadImage("mask.jpg");
  10.   redp.mask(maskp);
  11. }
  12. void draw(){
  13. image(desert,0,0);
  14. blend(redp,0,0,400,400,0,0,400,400,MULTIPLY);

  15. }
aha, I figured it out, blend() works fine in this case!!