Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
Creative tools for business
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection / Pixel Bender Technology Center /

Effects with the Pixel Bender Toolkit – Part 9: Integrating multiple image sources with a Pixel Bender kernel

by Kevin Goldsmith

Kevin Goldsmith

Content

  • Creating a Pixel Bender kernel with two inputs
  • Adding a parameter to control the blending
  • Where to go from here

Modified

11 January 2010

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
Flash Professional graphic effects Pixel Bender

Requirements

Prerequisite knowledge

Some familiarity with ActionScript 3.

User level

Beginning

Required products

  • Flash Player 10 and later
  • Flash Professional (Download trial)
  • Pixel Bender Toolkit (Macintosh)
  • Pixel Bender Toolkit (Windows)

Sample files

  • pixel_bender_09.zip (6 KB)

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.

Creating a Pixel Bender kernel with two inputs

To create a Pixel Bender kernel that integrates values from multiple image sources, follow these steps:

  1. Launch the Pixel Bender Toolkit.
  2. Choose File > New Kernel to create a new filter.
  3. Import the YellowFlowers.png image and then update the name of the filter and set the filter metadata as described in Part 1.
  4. Locate the first input line. Add a second line and type the following code:
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()); } }
  1. Click the Run button to run the filter. If you do not encounter any syntax errors, the IDE will prompt you to load a second image.
  2. If the Load Image file dialog box does not default to one of the following locations (depending on the platform), manually browse to the sample images folder at this location:
    • Windows: C:\Program Files (x86)\Adobe\Adobe Utilities\Pixel Bender Toolkit\sample images
    • Mac OS: Mac HD/Applications/Utilities/Adobe Utilities/Pixel Bender Toolkit/sample images
  3. Select the ShrineNearDarjeeling.png image located in the sample images folder, and click Open.

    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.

  4. Locate the line in the code that sets the output value:
dst = sampleNearest(src,outCoord());

Change the line to match the example below:

dst = sampleNearest(src2,outCoord());
  1. Click the Run button to run the filter. The ShrineNearDarjeeling.png image appears instead of the YellowFlowers.png image.
  2. Choose File > Save Filter. Save the Pixel Bender kernel as Exercise9Filter.pbk in the folder named pixel_bender on your desktop.
  3. Locate the line of code that sets the output value:
dst = sampleNearest(src2,outCoord());

Change the line to match the example below:

dst = sampleNearest(src2,outCoord()) + sampleNearest(src, outCoord());
  1. Click the Run button to run the filter. This time, the ShrineNearDarjeeling.png image is added to the YellowFlowers.png image. This effect looks similar to the Photoshop Linear Dodge (Add) blend mode effect (see Figure 1).
  2. Choose File > Save Filter to save the Pixel Bender kernel and preserve your changes.
Two image sources composited on top of each other
Figure 1. Two image sources composited on top of each other

Adding a parameter to control the blending

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:

  1. Locate the following line of code:
output pixel4 dst;
  1. Add a new line immediately following the line above. Add this code on that line:
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()); } }
  1. Locate the line that sets the output pixel value in the code:
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 )
  1. Click the Run button to run the filter.
  2. Interact with the filter by moving the slider back and forth. Notice that the blend effect applied to the images is based on the position of the slider (see Figure 2).
  3. Choose File > Save Filter to save the Pixel Bender kernel.
  4. Choose File > Export Filter for Flash Player. In the Export File dialog box that appears, save the PBJ file as Exercise9Filter.pbj to the folder named pixel_bender on your desktop.
Moving the slider to see the blend effect change
Figure 2. Moving the slider to see the blend effect change

Where to go from here

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:

  • Pixel Bender forum
  • Pixel Bender basics for Flash
  • Pixel Bender basics for Flex and AIR

Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License+Adobe Commercial Rights

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.

More Like This

  • Pixel Bender release notes
  • Effects with the Pixel Bender Toolkit – Part 1: Creating a new filter
  • Effects with the Pixel Bender Toolkit – Part 2: Creating a vintage tone filter
  • Effects with the Pixel Bender Toolkit – Part 3: Adding parameters to filters
  • Effects with the Pixel Bender Toolkit – Part 4: Sampling multiple pixels
  • Effects with the Pixel Bender Toolkit – Part 5: Applying a filter to an image in Flash
  • Effects with the Pixel Bender Toolkit – Part 6: Modifying Pixel Bender parameters in Flash
  • Effects with the Pixel Bender Toolkit – Part 7: Improving the displacement filter
  • Effects with the Pixel Bender Toolkit – Part 8: Controlling the displacement filter with mouse positioning
  • Effects with the Pixel Bender Toolkit – Part 10: Using a multiple-input filter as a blend shader

Tutorials & Samples

Tutorials

  • Animating a particle system
  • Improving the displacement filter in Pixel Bender
  • Controlling the displacement filter in Pixel Bender with mouse positioning

Samples

Pixel Bender Forum

More
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

Pixel Bender Exchange

More
Escher's Droste Effect
4D Quaternion Julia-set Ray Tracer with Ambient Occlusion
Raytracer
Zoom Blur Focus

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps
  • Student and Teacher Editions

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement