Create filters in Photoshop using Pixel Bender

Jürgen Heiss

Anyone who works in Photoshop knows it comes packed with cool filters which can really create some nice effects. Thanks to the Photoshop Coder who created such sweet tools… if only designers could create their own filters.

Ah ha! But you can.

Creating your own filters can not only help your workflow when designing in Photoshop, but can provide new functions and effects that, normally, you might not be able to execute effectively. You can advance and round out your Photoshop skills by creating your own filters and being familiar with existing ones.

We will demonstrate how to create filters using Adobe’s Pixel Bender Toolkit. First, download and install the Toolkit.

There are 3 interesting parts:

  1. The Preview Window: where you load sample images and apply your filters
  2. The Code Window: where you write code for filters
  3. Information section: the filter’s parameter will appear in this window when you are creating your filter

1. Load an image

Let’s load an example image so we can see the effects of our filter as we develop it. Click on File > Load Image 1, and you can choose from any of the example images you’d like. I went with the YellowFlowers photo:

 

We will create a new filter by clicking on the Create a new kernel button and filling in the appropriate fields:

  • Kernel name: you should try to use a common name for the filter
  • Vendor name: add your name
  • Namespace: Namespace is helpful because Pixel Bender can’t handle two filters with the same name. For example, if I create two filters called SimpleFilter, I fill in different names for Namespace.

After you’re done filling in the appropriate fields, press OK and Pixel Bender will create the minimum filter code.

Not a coder? Have no fear! We will keep this simple and explore it together.

Line 1 is set by Pixel Bender so we will leave it as is.

Lines 3 through 7 incorporate the filter information we entered via the dialog box. This is where you can change the Filter name, Namespace, Vendor or the version of your filter.

And now, where the interesting code starts…

Line 9 input image4 src; — this line of code means we take an input from image4 and we call it src. image4 stands for red, green, blue and alpha.

Line 10 output pixel4 dst; — defines an output of pixel4 (red, green, blue and alpha). We’re going to call it dst.

Lines 13 through 16 evaluates each pixel and output in the variable dst. Pixel Bender defines a function called evaluatePixel().

To run the filter for the first time, press the Build and Run button — make sure that the Combobox near the button is set to GPU (Graphic Processing Unit). The filter will be calculated from the Graphic Processing Unit which will ensure that we get the best possible performance for our filter.

You can see nothing really exciting is happening, but we also haven’t written a single line of code. Now that we have the base for our filter it’s time to write our first line of code.

2. First line of code

We want to write a simple filter which gives us the possibility to brighten a given image. In code editor, add the following on line 16 dst = dst * 2.0;

Tada! We’ve brightened the output image with a simple line of code. You can change the value 2.0 to any other value you’d like — give it a try.

The biggest problem with our filter is that the amount of brightness has a fix amount (2.0). Photoshop solves this problem with their own filters by giving us the possibility to insert values and control a specific filter.

If Photoshop coders can do it then we can do it. Let’s give our filter some parameters.

3. The first parameter

With one simple line of code we can create a parameter in Pixel Bender — parameter float amount;

Notice that a new parameter field called amount (float) has appeared and a value can be entered.

But wait! There is a problem… the preview image stays the same even if we enter a higher or lower value. 🙁

 

The reason the image doesn’t respond to the entered amount is because we didn’t tell Pixel Bender to use this amount. Our code still tells Pixel bender — dst = dst * 2.0;

To make the parameter work, we must change the code line to — dst = dst * amount;

Now, the calculation will work with the entered amount. Hit the Build and Run button (or F5) to check if your filter works correctly.

Woohoo… it works!

We have already created a pretty nice filter with only a few lines of code. However, we still haven’t reached our goal of creating a cool, handy filter because there isn’t a minimum, maximum or default value.

4. Add filter sliders

We defined the amount field before in the code as — parameter float amount;

We will change this line of code to:

parameter float amount
<
minValue: 0.0;
maxValue: 2.0;
defaultValue: 1.0;
>;

It’s like magic! Minimum, maximum and default values have appeared.

Before we finish this tutorial, I want to quickly show you how to add an extra functionality that controls the red, green and blue channels.

The code is pretty self explanatory. We’ve defined three more parameters for red, green and blue similar to the amount parameter.

We gave each parameter a minimum, maximum and default value. Take a look at the completed source code below:

5. Export the filter into Photoshop

Once you have a filter you are happy with, exporting it into Photoshop is quite easy. First, make sure you have installed the Pixel Bender Plugin for Photoshop which you can download on the Adobe website. Once you installed the plugin, you will see the Pixel Bender Filters automatically in Photoshop.

Under Filter > Pixel Bender you can open the Pixel Bender gallery. Some example filters already exist which have some great functionalities. But we want our filter to appear in this gallery also. In Pixel Bender choose File > Save Filter as > and save it to the correct location…

  • Mac: Application > Photoshop CS 5 > Pixel Bender
  • Windows: Program Files > Adobe > Adobe Photoshop CS 5 > Pixel Bender Files

Once the filter is saved in this directory you can access it from the Pixel Bender gallery in Photoshop.

Our Photoshop filter is completed — great job!

 

Any questions about the Pixel Bender Toolkit? Ask us in the comments.

Related articles

How to quickly remove a background in Photoshop

How to quickly remove a background in Photoshop

Photoshop offers many different techniques to remove an unwanted background from an image. For simple backgrounds, using the standard Magic Wand tool to select and delete the background may well be more than adequate. For more complicated backgrounds, you might use the Background Eraser tool. This tool samples the color at the center of the…

Photoshop vs. Illustrator vs. InDesign

Photoshop vs. Illustrator vs. InDesign

From photo editing to typography tools to sound design, the industry-standard Adobe Creative Suite gives creators of all kinds everything they need to create professional work fast—for literally any type of design project. For now, let’s get graphic. Whether it’s creating a logo, designing social media graphics or putting together a brochure, Adobe has created…

3 ways Photoshop Actions can speed up your workflow

3 ways Photoshop Actions can speed up your workflow

Photoshop Actions are a great starting point for graphic designers looking to become more efficient in their workflow. With the help of this computer automation technique, designers can quickly accomplish tasks that would otherwise take countless manual hours. We’ve already walked you through the basics of Photoshop Actions, so now it’s time to teach you some of the effective ways to…

Current Design Contests

Designers, check out these contests so you can start building your career.
0%