11 January 2010
Some familiarity with ActionScript 3.
Beginning
In this article, you'll learn how to create a Pixel Bender kernel that integrates values from multiple image sources. This is the ninth installment in this series of articles about using the Pixel Bender Toolkit to create visual effects with bitmap images.
In the previous section, you learned how to add interactivity by tracking the user's mouse movements. You also updated the code to constrain the filter's parameters based on the minimum and maximum metadata values.
In this section, you'll learn how to create a Pixel Bender kernel that uses two input images to blend them together.
To create a Pixel Bender kernel that integrates values from multiple image sources, follow these steps:
input image4 src2;
After making these changes, the filter code should look like this:
<languageVersion : 1.0;>
kernel blendy
< namespace : "com.adobe.devnet.pixelbender";
vendor : "Kevin's Filters";
version : 1;
description : "mashes two inputs together";
>
{
input image4 src;
input image4 src2;
output pixel4 dst;
void evaluatePixel()
{
dst = sampleNearest(src,outCoord());
}
}
Note: Although you've selected the PNG file, you won't see the second image yet. However, you should see the filename in the status bar of the application. The second image will not appear until your kernel uses pixels from the second image in your filter.
dst = sampleNearest(src,outCoord());
Change the line to match the example below:
dst = sampleNearest(src2,outCoord());
dst = sampleNearest(src2,outCoord());
Change the line to match the example below:
dst = sampleNearest(src2,outCoord()) + sampleNearest(src, outCoord());
Now that you've loaded two images at once and applied the filter to create an effect, you can edit the code to fine-tune the way the two images are blended together:
output pixel4 dst;
parameter float amount;
After making these changes, your kernel should look like this:
<languageVersion : 1.0;>
kernel blendy
< namespace : "com.adobe.devnet.pixelbender";
vendor : "Kevin's Filters";
version : 1;
description : "mashes two inputs together";
>
{
input image4 src;
input image4 src2;
output pixel4 dst;
parameter float amount;
void evaluatePixel()
{
dst = sampleNearest(src2,outCoord()) + sampleNearest(src, outCoord());
}
}
dst = sampleNearest(src2,outCoord()) + sampleNearest(src, outCoord());
Change the line to match the example shown below:
dst = mix( sampleNearest(src2,outCoord()), sampleNearest(src, outCoord()), amount);
Note: The mix function is pre-built into Pixel Bender. This equation:
a = mix( b, c, d )
is equivalent to:
a = ( (1 – d) * b) + ( d * c )
After testing and reviewing the code from the Flash movie, continue with Part 10, the final installment in this series, where you'll learn how to use a multiple-input filter in Flash.
Check out the following resources to learn more about working with the Pixel Bender Toolkit:
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.
Tutorials & Samples |
| 04/10/2012 | Fast Fourier Transform (FFT) in Pixel Bender? |
|---|---|
| 04/19/2012 | Shader works in toolkit, not in Flash |
| 04/12/2012 | Pixel Bender removed from AE CS6 !? |
| 03/22/2012 | Load an HDR image into Pixel Bender Toolkit |