Adobe
Products

Top destinations

  • Adobe Creative Cloud
  • Creative Suite 6
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • SiteCatalyst
  • Students
  • Elements family

Adobe Creative Cloud

  • What is Adobe Creative Cloud?
  • Design
  • Web
  • Photography
  • Video
  • Students
  • Teams
  • Enterprise
  • Educational institutions
  • Government

Design and photography

  • Photoshop
  • Illustrator
  • InDesign
  • Adobe Muse
  • Lightroom

Video

  • Adobe Premiere
  • After Effects

Web development and HTML5

  • Edge Tools & Services [opens in a new window]
  • Dreamweaver
  • Gaming [opens in a new window]

Adobe Marketing Cloud

  • What is Adobe Marketing Cloud?
  • Digital analytics
  • Social marketing
  • Web experience management
  • Testing and targeting
  • Media optimization

Analytics

  • SiteCatalyst
  • Adobe Discover
  • Insight

Social

  • Adobe Social

Experience Manager

  • CQ
  • Scene7

Target

  • Test&Target
  • Recommendations
  • Search&Promote

Media Optimizer

  • AdLens
  • AudienceManager
  • AudienceResearch

Document services

  • Acrobat
  • EchoSign [opens in a new window]
  • FormsCentral [opens in a new window]
  • SendNow [opens in a new window]
  • Acrobat.com [opens in a new window]

Publishing

  • Digital Publishing Suite

  • See all products
Business solutions

By business need

  • Digital analytics
  • Digital publishing
  • Document management
  • Media optimization
  • Social marketing
  • Testing and targeting
  • Video editing and serving
  • Web development [opens in a new window]
  • Web experience management
  • See all business needs

By industry

  • Broadcast
  • Education
  • Financial services
  • Government
  • Publishing
  • Retail
  • See all industries
Support & Learning

I need help

  • Products
  • Adobe Creative Cloud
  • Adobe Marketing Cloud
  • Forums [opens in a new window]

I want to learn

  • Training and tutorials
  • Certification [opens in a new window]
  • Adobe Developer Connection
  • Adobe Design Center
  • Adobe TV [opens in a new window]
  • Adobe Marketing Center
  • Adobe Labs [opens in a new window]
Download
  • Product trials
  • Adobe Flash Player
  • Adobe Reader
  • Adobe AIR
  • See all downloads
Company
  • Careers at Adobe
  • Investor Relations
  • Newsroom
  • Privacy
  • Corporate Social Responsibility
  • Customer Showcase
  • Contact us
  • More company info
Buy
  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers
  • Adobe Marketing Cloud sales [opens in a new window]
Search
 
Info Sign in
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Welcome,
My Adobe
My orders
My information
My preferences
My products and services
Sign out
My cart
Privacy My Adobe
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out Privacy 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
Promotions
Estimated shipping
Tax
Calculated at checkout
Total
Review and Checkout
Adobe Developer Connection / Pixel Bender Technology Center /

Effects with the Pixel Bender Toolkit – Part 4: Sampling multiple pixels

by Kevin Goldsmith

Kevin Goldsmith

Content

  • Setting up the files
  • Adding a float parameter
  • Sampling a second pixel
  • Scaling back the pixel values
  • Where to go from here

Created

11 January 2010

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
Flash Professional CCgraphic effectsPixel Bender
Was this helpful?
Yes   No

By clicking Submit, you accept the Adobe Terms of Use.

 
Thanks for your feedback.

Requirements

Prerequisite knowledge

Some familiarity with ActionScript 3.

User level

Beginning

Required products

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

Sample files

  • pixel_bender_04.zip (5 KB)

In this article, you'll learn how to write a Pixel Bender kernel that combines multiple pixels from the same image. If you've been following along with the instructions provided since the beginning of this series, you've been building on the same file with each subsequent section. This time, we're going to start by creating a brand new filter, using the steps provided in the first article in this series.

This is the fourth 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 parameters to create a slider interface that affects the display of the image in the preview window. You also learned how to add metadata to the parameters to ensure consistency when the effects are displayed. In this section, you'll learn how to sample multiple pixels from the same input image.

Setting up the files

If you'd like to follow along by reviewing the code in the working copy, download the sample files provided. To get started, follow these steps:

  1. Choose File > New Kernel to create a new filter.
  2. Load the YellowFlowers.png image and modify the kernel metadata as described in the first article in this series.
  3. Click the Run button to run the filter.
  4. After verifying that there are no syntax errors, choose File > Save Filter.
  5. Name the file Exercise4.pbk and save it in the folder named pixel_bender on your desktop.

Adding a float parameter

In this part, you'll update the code using the syntax you learned in Part 3 of this article series. Follow these steps:

  1. Find this line of code:
output pixel4 dst;
  1. Immediately following that line, add a float parameter called amount:
parameter float amount;
  1. Immediately following the line above, set the parameter's metadata as follows:
< minValue: -5.0; maxValue: 5.0; defaultValue: 0.0; >;

    Note: Open the sample file named Exercise4FilterB.pbk to see the working example of adding the metadata described above to a float parameter.

  1. After editing the code, make sure your code looks like this:
<languageVersion : 1.0;> kernel Part4Filter < namespace : "com.adobe.devnet.pixelbender"; vendor : "Kevin's Filter Factory"; version : 2; description : "Playing around with pixels"; > { input image4 src; output pixel4 dst; parameter float amount < minValue: -5.0; maxValue: 5.0; defaultValue: 0.0; >; void evaluatePixel() { dst = sampleNearest(src,outCoord()); } }
  1. If you encounter any errors, compare your code to the example above. Make any necessary changes.

Sampling a second pixel

In this part, you'll learn how to write the code to sample the second pixel and store its value in a new variable that you'll declare. Follow these steps:

  1. Locate the line of code that samples the input pixel:
dst = sampleNearest(src,outCoord());
  1. Add a new line after the line above, and enter the following code:
pixel4 dst2 = sampleNearest(src, outCoord()+float2(amount, amount));
  1. Click the Run button to run the filter. If syntax errors occur, return to the code and compare it to the code shown above. The image will not change; at this point, you haven't made any modifications to the output pixel, stored in the variable named dst.
  2. If you do not encounter syntax errors, choose File > Save Filter to save the filter.

    Note: dst2 is a new variable. It is storing the value of a second pixel in the image offset in both x and y axes by the value in the parameter named amount.

  3. Add the following line of code to the end of the evaluatePixel function:
dst += dst2;
  1. After making these changes, examine your code to make sure it looks like this:
Dst Void evaluatePixel() { dst = sampleNearest(src, outCoord()); pixel4 dst2 = sampleNearest(src, outCoord()+float2(amount, amount)); dst += dst2; }
  1. Click the Run button to run the filter.
  2. After verifying that there are no syntax errors, choose File > Save Filter.
  3. When you leave the slider in its default position, the image looks twice as bright. When you move the slider, it causes the image to appear offset (see Figure 1).

The dark borders around two edges of the image appear when running this filter because the returned color is a transparent black when sampling pixels off the end of the image.

Oversaturated output image in the preview
Figure 1. Oversaturated output image in the preview

Scaling back the pixel values

The current implementation of the filter causes the colors to be oversaturated because the code is adding two pixel values together. In this section, you'll learn how to remedy this issue and make the saturation level return to normal.

Follow these steps:

  1. Locate this line in the code:
dst += dst2;
  1. Immediately following the line above, add this line of code:
dst /= 2.0;
  1. Click the Run button to run the filter.
  2. If there are no syntax errors, choose File > Save Filter to save the filter.

Notice that if you leave the slider in its default position, the image appears unchanged. This occurs because you updated the code to add each pixel to itself and then divide the resulting value by 2.0 (restoring it to normal saturation).

If you move the slider, the offset effect is now displayed without making the colors seem too bright (see Figure 2).

Offset effect applied to the image
Figure 2. Offset effect applied to the image

Use the instructions provided in Part 2 of this article series to export the Pixel Bender code so that you can use it in Flash. Follow these steps:

  1. Choose Build > Turn on Flash Player Warnings and Errors. This option enables filter validation for Flash Player when running filters, to help you perform troubleshooting.
  2. Click the Run button to run the filter.
  3. Verify that the filter runs successfully without generating any errors.
  4. Choose File > Export Kernel Filter for Flash Player.

In the Export dialog box that appears, enter the name for the filter: Exercise4Filter.pbj. Save the exported file to the desktop, in the folder named pixel_bender.

Where to go from here

After experimenting with sampling multiple pixels from the same image, continue with Part 5 in this series, where you'll learn how to apply a Pixel Bender filter to an image 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

  • Effects with the Pixel Bender Toolkit – Part 10: Using a multiple-input filter as a blend shader
  • Effects with the Pixel Bender Toolkit – Part 8: Controlling the displacement filter with mouse positioning
  • Effects with the Pixel Bender Toolkit – Part 2: Creating a vintage tone filter
  • Pixel Bender release notes
  • Effects with the Pixel Bender Toolkit – Part 3: Adding parameters to filters
  • Effects with the Pixel Bender Toolkit – Part 6: Modifying Pixel Bender parameters in Flash
  • Animating a particle system using Pixel Bender
  • Effects with the Pixel Bender Toolkit – Part 9: Integrating multiple image sources with a Pixel Bender kernel
  • Effects with the Pixel Bender Toolkit – Part 5: Applying a filter to an image in Flash
  • Effects with the Pixel Bender Toolkit – Part 7: Improving the displacement filter

Tutorials & Samples

Tutorials

  • Animating a particle system
  • Using a multiple-input filter in Pixel Bender as a blend shader
  • Controlling the displacement filter in Pixel Bender with mouse positioning

Samples

Pixel Bender Forum

More
05/09/2013 Pixel Bender Installation
02/10/2012 I Cannot get pixel bender to show in PS
05/31/2009 White Hat PBJ Decompiling
01/19/2013 Multiple Image inputs in Blendmode Shader

Pixel Bender Exchange

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

Products

  • Adobe Creative Cloud
  • Creative Suite 6
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • Digital Publishing Suite
  • Elements family
  • SiteCatalyst
  • For education

Download

  • Product trials
  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR

Support & Learning

  • Product help
  • Forums

Buy

  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers

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 © 2013 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy (Updated) | Cookies

Ad Choices