Adobe
Products
Creative Suite
Photoshop Family
Acrobat Family
Flash Platform
Digital Marketing Suite
Digital Publishing Suite
More products
Solutions
Digital marketing solutions
Digital media solutions
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Store
Adobe Store for home and home office
Education Store for students, educators, and staff
Business Store for small and medium businesses
Other ways to buy
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections   Search  
Solutions Company
Help Learning
Sign in Welcome, My orders My Adobe
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 3: Adding parameters to filters

by Kevin Goldsmith

Kevin Goldsmith

Content

  • Setting up the files
  • Adding a float parameter
  • Incorporating the parameter into your filter
  • Setting the parameter metadata
  • Using vectors to simplify the math
  • Simplifying the math
  • Where to go from here

Created

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_03.zip (7 KB)

In this article, you will learn how to add a parameter to a kernel so you can animate a Pixel Bender filter or adjust the effects while the filter is running. You will also learn how to use Pixel Bender's vector types to make the math easier to maintain. This is the third 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 manipulate the red, green, and blue color channels to affect the image in the preview window. This section shows you how to leverage a powerful way to control effects: parameters. By adding parameters and metadata to filters you create with the Pixel Bender Toolkit, you can control the amount of the filter effect with a slider interface.

Setting up the files

If you have been following along since the beginning of this series, you can continue working with the same file. Otherwise, download the sample files provided. Open the Exercise3FilterA.pbk file in the Pixel Bender IDE.

The vintage tone filter that you developed in the last part looks something like this:

<languageVersion : 1.0;> kernel Part3Filter < namespace : "com.adobe.devnet.pixelbender"; vendor : "Kevin's Filter Factory"; version : 1; description : "Playing around with pixels"; > { input image4 src; output pixel4 dst; void evaluatePixel() { dst = sampleNearest(src,outCoord()); dst.r += 0.5; dst.b -= 0.4; dst.g -= 0.1; } }

Adding a float parameter

Now that you have loaded the code (either by opening the file you created in Part 2 or by opening the sample file), you are ready to edit the code to add a parameter.

Follow these steps to add a float parameter to the filter:

  1. Locate the following line of code:
output pixel4 dst;
  1. Add a new line immediately following the line above. Add this code:
parameter float amount;
  1. Click the Run button to run the filter. A slider appears in the right side panel (see Figure 1).
  2. Test the slider by moving it.

Notice that the image doesn't change. Although it is present, the slider value is not used in the Pixel Bender kernel yet. You'll hook this up in the next section.

Slider appearing on the right side after editing the code
Figure 1. Slider appearing on the right side after editing the code

Incorporating the parameter into your filter

Now that you've added the slider, the next part involves editing the code to add the parameter to your filter to make the slider adjust the settings of the effect. Follow these steps:

  1. Locate the following line of code:
dst.r += 0.5;
  1. Change the line shown above to match the code example shown below:
dst.r += (0.5 * amount);
  1. Click the Run button to run the filter.
  2. This time, the image in the preview window will change. Experiment by moving the slider and notice how the slider affects the display of the image.
  3. Try modulating the other channels by changing the amount parameter. Make the following changes to make the evaluatePixel function look like this:
dst = sampleNearest(src,outCoord()); dst.r += (0.5*amount); dst.b -= (0.4*amount); dst.g -= (0.1*amount);
  1. Click the Run button to run the filter.

As you move the slider in the right-hand panel, the image changes more significantly as the slider moves. This occurs because all three channels are now modified by the parameter. When the slider is moved to the left, there is no effect applied to the image. When the slider is moved to the right, the effect is fully applied.

Setting the parameter metadata

In this section, you'll add metadata to the new parameter you just created. The completed version of this code is called Exercise3FilterE.pbk in the sample files. Follow these steps:

  1. Locate the following line in the code:
parameter float amount;
  1. Change the float parameter declaration by adding the new code shown below:
parameter float amount < minValue: -1.0; maxValue: 1.0; defaultValue: 0.0; >;
  1. Click the Run button to run the filter.

      The default position of the slider in the right hand panel is now in the middle. If you move the slider to the left, you will see the filter being applied in inverse. If you move the slider to the right, the effect is applied as it was before.

      Note: Adding parameter metadata is not required; the parameter will work without it. However, if you do not set the metadata, each application will use its own default minimum, maximum, and default values. It is a best practice to always set this metadata to control parameters and get consistent results.

  2. Save the filter by choosing File > Export Kernel Filter for Flash Player.
  3. In the dialog box that appears, name the file Exercise3Filter.pbj and save it inside the pixel_bender folder on your desktop.

Using vectors to simplify the math

In this section, you'll learn how to incorporate vectors into the filter. Adding vectors is easy in the Pixel Bender Toolkit:

  1. Locate the following three lines of code:
dst.r += (0.5*amount); dst.b -= (0.4*amount); dst.g -= (0.1*amount);
  1. Replace the three lines shown above with the following line:
dst += float4(0.5*amount, -0.4*amount, -0.1*amount, 0.0);
  1. Click the Run button to run the filter. The filter behaves exactly as before.

Instead of modifying the first three values of the dst vector individually, you are now creating a new vector and adding it to dst. The extra 0.0 float value at the end is because vectors have to be the same size for the arithmetic operation to be legal. Also notice that you must type the value as 0.0 and not 0 in the code. Pixel Bender will not automatically convert types for you; you always have to use the correct types or an error will occur.

Simplifying the math

In this section, you'll learn a strategy to make the math in the equation a bit more manageable. Follow these steps:

  1. Locate the following line in the code window; this is the line that adds the vector:
dst += float4(0.5*amount, -0.4*amount, -0.1*amount, 0.0);
  1. Change the line above to this:
dst += float4(0.5, -0.1, -0.4, 0.0) * amount;
  1. Click the Run button to run the filter.
  2. When you preview the image, the filter behaves exactly as before.
  3. Save the filter.

Note: Multiplying a vector by a number is the same thing as multiplying every element of the vector by that number.

Where to go from here

After familiarizing yourself with the Pixel Bender interface, continue with Part 4 in this series, where you'll learn how to write the code to sample multiple pixels from the same image.

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 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 9: Integrating multiple image sources with a Pixel Bender kernel
  • Effects with the Pixel Bender Toolkit – Part 10: Using a multiple-input filter as a blend shader

Tutorials & Samples

Tutorials

  • Animating a particle system
  • Modifying Pixel Bender parameters in Flash
  • Improving the displacement filter in Pixel Bender

Samples

Pixel Bender Forum

More
01/25/2012 No gallery folder
01/23/2012 Pixel Bender kernel behaves completely different in Flash
01/18/2012 Pixel bender Vignette circle to elepsis
01/17/2012 Cant install Pixel bender

Pixel Bender Exchange

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

Products

  • Creative Suite
  • Photoshop Family
  • Acrobat Family
  • Flash Platform
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Mobile apps

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

  • Adobe Store
  • For students and educators
  • For small and medium businesses
  • For enterprises
  • 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
  • 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
  • Pacific - English
  • 台灣

Southeast Asia

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

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy (updated 07-14-2009).

Ad Choices

Reviewed by TRUSTe: site privacy statement