We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
blend intensity? (Read 1307 times)
blend intensity?
Nov 10th, 2008, 7:03pm
 
Is it possible to modulate the intensity of the blend function, similar to an alpha component? I am trying to blend the screen buffer back in to the sketch window, but I want to control the percentage it blends in at. I am not using a source image, I want to blend the current frame with the previous.
Re: blend intensity?
Reply #1 - Nov 12th, 2008, 7:32pm
 
Is this not possible or do I have to write some lengthy function to do it?
Re: blend intensity?
Reply #2 - Dec 4th, 2008, 3:06am
 
Can anyone help me out here?
Re: blend intensity?
Reply #3 - Dec 4th, 2008, 8:49pm
 
I don't really know the answer to your question, but did you try playing with the other blend modes?  Maybe one of them will be closer to what you want.
Re: blend intensity?
Reply #4 - Dec 5th, 2008, 10:44am
 
I think you have to take the source image (previous frame, for example), loadPixels(), change all pixels[] to set the alpha at the wanted value, updatePixels(), then use blend() with BLEND mode to merge the two images.

Unless somebody comes up with a better/faster method... Smiley
Not a "lengthy" function, but one you have to code yourself. I can try to do it if you cannot do that, it shouldn't be very long.

BTW, by "frame", you mean in a movie (it was my first idea...). If not, I suppose it is draw()'s frames, so you need to do loadPixels before drawing the current frame, so you have a copy of the previous frame.
Re: blend intensity?
Reply #5 - Dec 6th, 2008, 9:33pm
 
Different blend modes can help, but i need the added control of being able to specify the alpha as well.
Thanks for the reply, PhiLho. I will look into what you are suggesting. You are correct, I was referring to the previous frame of draw().
Re: blend intensity?
Reply #6 - Dec 7th, 2008, 12:33am
 
I'm not sure if I get it correctly, but for controling blend intensity I use mask() method with integer array as factor.
Re: blend intensity?
Reply #7 - Dec 7th, 2008, 1:19am
 
Mask() needs a source image as the alpha channel, correct?
I am trying to blend the current draw frame with the previous. Here is an example. Notice how it quickly burns to white. You need to move your mouse around in the window or nothing will happen.

Code:


void setup(){
 background (00);
 size (400,400);
 stroke(100,10,5,50);
}

void draw(){
 line (mouseX, mouseY, pmouseX, pmouseY);
 blend (0,0,width,height,-width/16,-height/16,width+(width/8),height+(height/8),SCREEN);
}

Re: blend intensity?
Reply #8 - Dec 7th, 2008, 12:57pm
 
I have no idea, how to do it without first saving previous frame. I think that the main idea is to manipulate source alpha (to define blend factor) and then blend with destination (which does not affect alpha of destination). As I said I ussualy do it with mask(), but there might be other more effective ways. I would do it like:

 int nrPixels= 400*400;  
 int [] maskArray = new int[nrPixels];
 PImage previousFrame= createImage(400,400,ARGB);
 int blendFactor=85;

void setup(){
 background (0);
 size (400,400);
 stroke(100,10,5,50);
 for (int i=0; i<nrPixels; i++) { maskArray[i]=blendFactor; }
}

void draw(){  
 line (mouseX, mouseY, pmouseX, pmouseY);
 blend (previousFrame,0,0,width,height,-width/16,-height/16,width+(width/8),height+(hei
ght/8) ,SCREEN);
 previousFrame = get(); // save previous frame
 previousFrame.mask(maskArray);    // set blending factor (alpha of src)
}

I use get() to save previous frame then mask() to set alpha or blending factor. I know that solution depends on context of use and share this just as option to consider.
Also I usually use this technique with BLEND mode (not with SCREEN).
Have a nice day!
Re: blend intensity?
Reply #9 - Dec 7th, 2008, 1:08pm
 
Sorry about smileys inside code. It was my copy/paste mistake. But they look cool.
Re: blend intensity?
Reply #10 - Dec 7th, 2008, 7:24pm
 
Thanks DusanLicer. FYI, you can edit your post and check the option to disable smileys (or use code blocks).

I overlooked the mask() function, "hidden" (with reason) in the PImage reference...
I used your technique in a simple sketch I made for the occasion.
I just made two improvements: I use the fast and simple Arrays.fill() call to init the mask, and I use BLEND mode instead of SCREEN.
To show the difference, I made the blend mode conditional, and when blending, I made the steps bigger, so we can see better the previous frame(s).
Code:
static final int DISK_NB = 8;
static final int DISK_DIAMETER = 64;
static final int MIN_RADIUS = 64, MAX_RADIUS = 200;
static final float ANGLE_STEP = TWO_PI / DISK_NB;

int[] maskArray;
static final int blendFactor = 85;
PImage previousFrame;

static final boolean bUseBlend = true;

void setup()
{
size(800, 800);
// frameRate(10);
noFill();
noStroke();

if (bUseBlend)
{
maskArray = new int[width * height];
Arrays.fill(maskArray, blendFactor);
}
}

void draw()
{
if (bUseBlend)
{
previousFrame = get();
previousFrame.mask(maskArray);
}

background(#AAEEFF);
DrawCircles();

if (bUseBlend)
{
blend(previousFrame, 0, 0, width, height, 0, 0, width, height, BLEND);
}
}

void DrawCircles()
{
float step = (PI / (bUseBlend ? 30 : 180)) * frameCount;
float radius = (MAX_RADIUS - MIN_RADIUS) * (1.0 + sin(step)) + MIN_RADIUS;
float angle = 0;
for (int i = 0; i < DISK_NB; i++)
{
angle += ANGLE_STEP;
int cg = 128 + int(32 * (1.0 + cos(angle)));
int cb = 128 + int(32 * (1.0 + sin(angle)));
fill(color(0, cg, cb));
float x = width / 2 + radius * cos(step + angle);
float y = height / 2 + radius * sin(step + angle);
ellipse(x, y, DISK_DIAMETER, DISK_DIAMETER);
}
}
Re: blend intensity?
Reply #11 - Dec 7th, 2008, 11:02pm
 
This is cool PhiLho, your example is very illustrative. It demostrates exacly what I tought and much more.
Re: blend intensity?
Reply #12 - Dec 8th, 2008, 12:57am
 
Thanks for the input, guys. This is pushing me forward to understand more. I will experiment with your contributions and see if I can get what I want. Thanks again for taking the time to respond.
Page Index Toggle Pages: 1