FEBRUARY 07, 2002
The Complete Guide to Creating Photoshop Filters
Part 1: Introduction to Basic Operations in Filter Factory
So what is this "Filter Factory" thing? Photoshop's Filter Factory provides you with a plugin interface for creating your own filters using formulas containing functions, operators and variables. Now, I know I've already scared the beejeepers out of half of you. "What do you mean by 'formulas?' 'Variables?' 'Operators?' Damn it, I'm a designer, not a mathematician. What's going on here?" [an error occurred while processing this directive] Now don't you worry your pretty little artistic head about those big, bad words. Ol' Davey's here to protect you from them. I know you're a designer, and all you really want to do is create custom effects and be able to show off to your friends the fact that you can make your own Photoshop plugins. There's no programming at all; there's just a specific way you need to write what you want your filters to do. And I'm going to show you how.
We're going to start off with some basic Filter Factory functions and how they work. Over the course of the next several weeks, we'll get into it more, and I'll even show you how to create a custom interface for each one of the filters you create--again, no programming required.
If you haven't already, make sure that you have Filter Factory installed in your Photoshop "Plug-Ins" folder. If it's not there, you'll find it somewhere on your Photoshop CD. Just drop it into your Photoshop "Plug-Ins" folder, and relaunch Photoshop. Once it's there, you'll find it under Filter > Synthetic > Filter Factory.
For the purposes of this tutorial, you should have an image open in Photoshop that contains transparency. And you should not work on a "Background" layer. If your image is just a Background layer, double-click it in the Layer palette to convert it into a layer.
The reason you want to do this is that Filter Factory provides you with options for modifying each channel in your image. If your image contains no transparency, then you will only have R, G and B channels available for modification. With transparency, you will also be able to write filters that mess around with an image's alpha channel (if you so desire).
What am I looking at?
Now that we have our image all ready to go, let's go ahead and open up FIlter Factory (Filter > Synthetic > Filter Factory). What you're faced with right away is a very daunting-looking interface, just the kind of thing a designer doesn't like to see when he or she is in the middle of compositing.
You know what the image in the interface is. That's your preview window. But what does the rest of it mean? You see those sliders labeled "Map 0," "Map 1," "Map 2" and "Map 3?" Those are simply value sliders that we'll be using in the filters that we create. I'll show you an example of how they work in a few minutes.
Next you see four data entry fields labeled R, G, B and A. I bet you can figure out what those mean. That's right! They stand for red, green, blue and alpha--the three color channels in your image, plus the transparency channel. Inside each one of those fields you see a small r, g, b and a. These are simply the default values for those fields. They just mean that the Red channel, for example, should stick with its current value, which is r. Makes sense, right? If R=r, then your image remains unchanged. If you modify the field to read R=r+100, then your image will become more red, as you have just told the red channel to adjust itself 100 points higher.
In fact, go ahead and do this right now. In the field labeled R, change the data input area to read r+100. You will see the change immediately in your little preview window. (After you see what it does, go ahead and change that field back to its default "r" setting.)
Finally, at the bottom, you see a bunch of buttons. "Load" just let's you load previously saved settings. "Save" lets you save your settings. "Make" lets you actually turn your settings into a self-contained Photoshop plugin. And the "Cancel" and "OK" buttons let you cancel or apply the effect to your image.
Those are all of the things you'll have to worry about for now.
Now, I mentioned that I would show you how the sliders work, so we'll just try something simple right now so that there's no confusion later on. There are eight sliders there. Each slider has its own name, these names being "control 0" through "control 7." In shorthand, that's ctl(0) through ctl(7). Just to see what these controls do, place "ctl(0)" in the A data entry field, as in the following picture.
Instantly you will see your picture vanish in the preview window. But now slide the first slider (called "ctl(0)") back and forth from 0 to 255, and you'll see the transparency change. See? Now the A channel takes on the value of whatever position the slider is at. It's the same thing for all the channels.
But there are tons of ways to interact with the sliders. Obviously, if the only thing you could do with this thing were to change the absolute values of your four channels, it would be pretty useless. So we'll kick things off by showing you how you can change the way the sliders affect your image.
A little arithmetic
To this point, we've just been looking at how the sliders control channels as simple numeric values. Nothing too troublesome. But all we've been able to do is to create solid colors. Hardly worth the effort of writing a filter, right? Right.
So now we're going to start adding a little complexity to the whole thing so that we can actually generate some useful effects.
By writing formulas in the data entry fields.
Settle down, settle down. I know this sounds like it's not fun, but it's really easy. Suppose, for example, you want to use more than one slider in each channel, or you want the value of the slider in the green channel to affect the value of the red channel. No problem.
In Filter Factory, we can add, subtract, multiply and divide the values of the sliders. For example, instead of writing "ctl(0)" in the A channel, you can write "ctl(0)+ctl(1)" so that the value of the alpha channel is now the value of the first slider plus the second slider.
Why would you want to do this? Well, some of our effects might require you to use values higher than the 255 maximum available to any individual slider. With "ctl(0)+ctl(1)" you can go as low as zero (0+0) or as high as 510 (255+255). With multiplication, you can go even higher.
Another reason for this is that you might want to have the value of one channel affect the value of another channel. For example, if I use "ctl(1)+ctl(0)" in my red channel and just "ctl(1)" in my green channel, then I will change the value of my red channel at the same time that I change the value of my green channel. At the same time, my red channel maintains some independence because I can offset any changes made with "ctl(1)" by adding "ctl(0)" to it.
Go ahead and try this out, as in the illustration below. Adjust the first and second sliders to see what happens. (Remember, the first slider is ctl(0), and the second slider is ctl(1).)
In addition to adding, you can also subtract, multiply and divide slider values. The plus (+) and minus (-) symbols represent addition and subtraction. The asterisk (*) and slash (/) characters represent multiplication and division. In practice, these would look like the following:
These four things (+, -, * and /) are called operators. There are no other operators that you will have to worry about. So we're all set to move on to the next phase.
Working with individual pixels
As you've probably guessed, adding and subtracting the values of color channels isn't our aim here. Our aim is to produce effects, and we do this in the Filter Factory by adding functions to the operators we learned above. Today we're going to deal with two of these functions. In future installments, we'll take this much further. But the two that I'm about to give you will allow you to create some pretty cool effects, provided you play around with them on your own and experiment with the operators we learned above.
For both of the functions we'll be learning about today, we are going to be affecting the positions of individual pixels in our image. Pixels in a Photoshop image have both absolute and relative values. In terms of absolute values, Photoshop uses Cartesian coordinate, otherwise known as x and y. Lowercase x represents the horizontal position of any given pixel. Lowercase y represents the vertical position of any given pixel.
Look at the little red dot in the image below.
This red dot is a single pixel that's 30 pixels over from the left edge (x) and 20 pixels down from the top edge (y) of the image. It's x,y position, therefore is expressed as 30,20.
We, however, are not going to be speaking to any one particular pixel. Rather, we want to affect pixels in general--all of them--but also affect them individually. Of course, we don't want to go in and manually write all of the coordinates for all of our pixels in a given image. Instead, we simply refer to all pixels "source" and their coordinates as x and y. The shorthand for "source" in the Filter Factory is "src" simply enough. So any given pixel is referred to as src(x,y). This simple statement accounts for every pixel in your image, regardless of coordinate.
Each pixel must also have a channel assigned to it in the Filter Factory. The channels for red, green, blue and alpha are referred to as 0, 1, 2 and 3, respectively. So now each pixel looks like this:
To get an idea of what I'm talking about, follow along with this exercise. It will be very simple.
First, create a new image that's 400 pixels x 400 pixels (with a transparent background). Fill in the background white, and then use the Pencil tool to create a red dot in the dead center of your image. Use a 45 pixel brush so that you'll be able to see what's going on.
Now open up Filter Factory and set all the sliders to 0. Enter the following into each one of the data entry fields.
Notice what happened? That's right, nothing. All we've done is told Filter Factory that all of the pixels should remain at their current positions. But now add "ctl(0)" to each of the x and y coordinates of your R, G and B channels, like this:
Now move the first slider around, and you should see the big red dot moving up and to the left. This is because we've told Filter Factory to move each channel of every pixel a number of pixels up and down equal to the current x,y position plus the first slider, otherwise known as "ctl(0)."
(One thing you might have noticed when playing around with the slider is that the preview in Filter Factory is not accurate. If we move the first slider to a value of 60 or more, the red dot seems to slide off the canvas. But, in fact, if we apply the filter, the red dot will still be somewhere on the canvas. This is just something you have to live with. An inaccurate preview is the price we pay for being able to make our own filters.)
Now, as you've probably guessed, you can change things up a bit for each individual channel by assigning a separate slider to to each color. So, instead of the above formula, let's try this one:
Now move around the first three sliders, and you'll see the individual channels of the red dot moving separately, as if they were separate dots, where only the overlap maintains its original red color. Of course, on an image that's composed of something other than just a red dot, the effect will look different. You can experiment with this on your own.
But what if you don't just want to move channels diagonally up and to the left? That's where your subtraction operator comes in. The expression "src(x-ctl(0),y-ctl(0),0)" moves the pixels down and to the right. And you can use any variation in between. Here you can also combine sliders to allow you to move pixels up and down and right and left. The expression "x+(ctl(0)-ctl(1)" will allow you to do this because you can wind up with either a positive or negative value, depending upon the values of the first and second sliders. It would look like this:
This will allow you to move the dot diagonally up or down, lef or right, depending on where you place the first and second sliders.
But what's the deal with all of those parentheses? This is simple. It's just part of the organization of the formulas we're using. You have to keep expressions together with opening and closing parentheses for each expression, as in 1+(2*3)=7. Without the parentheses, 1+2*3=6. Get it? Good.
REMEMBER: The basic structure of any "src" function is src(x,y,0) for the R channel, src(x,y,1) for the G channel, src(x,y,2) for the B channel or src(x,y,3) for the A channel. You can add any expressions you wish these this basic structure as long as everything appears in a way that is logical to Filter Factory. You accomplish this by keeping everything within parentheses, just as you would in an algebra formula. If you get an error in Filter Factory (indicated by a little exclamation point in a yellow triangle), chances are that you are missing parentheses somewhere.
Three final notes on this. First, you can use your image's r, g, b and a values as a part of your formulas. Every pixel in your image has a numeric value for r, g, b and a. This numeric value can then be used in your expressions simply by using the letter of the channel. For example, "src(x+r,y+r,0)" or "src(x+(r+g+b+a),y+(r+g+b+a),0)."
Second, you remember the number at the end of each one of our "src" expressions? "0" means red; "1" means green; "2" means blue; and "3" means alpha. You can actually move these around to give channels the characteristics of other channels. For example, if you place "src(x,y,0)" in the first three color channels (R, G and B), you'll wind up with a black and white image. Just something to keep in mind.
Third, to this point we've been using the lowercase x and y for our coordinates. But you can also use capital X and capital Y for different effects. Why different? Lowercase x and y represent the coordinates of your individual pixels. Capital X and Y represent the actual static edges of your image. Try substituting capital X and Y for lowercase x and y in some of the formulas you've already experimented with.
Variations on a theme
So now we know the basics of moving around source pixels. Obviously, the whole thing would be pretty pointless if we stopped here. What you need to understand is that moving pixels up, down, left and right can produce a whole variety of effects, depending upon the formulas that you use. Essentially, you can produce any effect you want and then vary that effect with the use of the sliders.
Just stick to the basic structure, and make sure you enclose your individual expressions within the proper opening and closing parentheses.
Here are some examples. Play around with these to create your own variations.
Dave's Funky Wet Duo
This produces a very cool, but static, effect based upon the red value of each of the pixels in your image.
Can you think of a way to add some variety to this effect? Here's one way:
Dave's Fresh Wet Duo
It's the same thing as the previous formula, but I've introduced our sliders into the equation, allowing us to customize the look of our new filter each time we use it. Keep in mid that you don't have to use r in this formula. You could also use g, b or a or any combination of these.
This one will simply allow you to stretch an image. It also illustrates an important point about Filter Factory's math. Namely, Filter Factory outputs whole numbers. So, if you're going to do any division, you might want to throw in some multipliers as well. In the above example, I have multiplied x by 100 before dividing it by ctl(0). Try removing the "*100" portion of the formula to see what happens to the filter's capabilities.
Bring on da noise
So we've now discovered what the sliders do, what the channels do, what the operators do and what the "src" function does. Now we're going to move on to a new function that you can use with your addition, subtraction, multiplication and division operators. This one is used to generate noise effects and is used in conjunction with the "src" function. It's called the random function, and its shorthand is "rnd."
When you use the "rnd" function, you're asking the Filter Factory to generate a random number between two numbers. So the expression "rnd(1,10)" will generate a random number between 1 and 10. But what's the point?
When we're dealing with the "src" function and the coordinates of individual pixels, the "rnd" function will allow us to shift our pixels by a certain value plus a random number, giving us a noise effect.. Our sliders can determine how much noise appears in our image, and we can control the noise on a channel by channel basis. Here's how it looks:
In the above formulas, we're telling Filter Factory to shift the pixels on the horizontal axis (x) by a number of pixels equal to the value of the first slider (ctl(0)) minus a random number between 1 and 35. This does not allow you to control the amount of noise in your image, but rather the position of the noise. To control the amount of noise, try this instead:
Here we're asking Filter Factory to move our pixels up and to the left by a random number between the value of ctl(0) and ctl(1). See how that happened? Instead of assigning a static value to our random number, as in "rnd(1,35)," we're letting our first two sliders determine the range of randomness. If the first slider is set to 1 and the second slider is set to 35, then, indeed, we get a random number between 1 and 35. But, if we move the second slider to 255, then we get a random number between 1 and 255 and, hence, more noise.
(I should note for the sticklers out there that, no, Filter Factory's "random" function isn't truly random, but it's random enough for our purposes here.)
Now, this noise isn't particularly pretty. You can doll it up considerably in a number of ways, most of which we'll get to in a future installment. (The concepts are a little too complex to introduce here.) For now, try using the values of r, g, b and a to generate some "less ugly" noise, as in the following example.
You can also achieve a nice effect by applying this formula only to the R channel and leaving the others alone.
Remember, "src(x,y,1)" is the same as "g." Similarly, "src(x,y,2)" is the same as "b." And "src(x,y,3)" is the same as "a."
You can also generate some interesting noise by randomly changing the values of the colors in the image rather than the positions of the pixels. Here we won't use the "src" function at all.
Now the brightness of your image will be controlled by the values of the first and second slider, which the noise will be determined by the difference between the two (making sure to keep the second slider ("ctl(1)") at a higher value than the first slider ("ctl(0)").
Making your filter
You now have enough information to start experimenting on your own. We will get into some new functions next time around that will greatly enhance your Filter Factory experience. In the meantime, of course, you want to use Filter Factory to make your own plugins that you can use again in the future.
In order to create your filter, all you have to do is click the "Make" button in the Filter Factory interface after you have entered in your formulas as you like them.
Once you click this button, you will see an interface asking you to enter in some information about your plugin. The "Copyright" and "Author" fields are pretty self-explanatory. "Title" is the actual name of the filter as it will appear in Photoshop. "Category" is the menu item that Filter Factory will create so that each of the filters you make in a given "category" will appear in the same submenu in Photoshop's Filter menu.
Following this, you see your controls listed. Check any controls that you have used in your formula, and give them a name that describes what each attribute each slider will control. For now, keep the names short, or they'll get all clumped in with the slider in the interface.
As for the "maps," don't worry about them. Just leave them unchecked. They don't do anything.
When you're done naming your controls, click OK to save the filter. Save it into your Photoshop "Plug-Ins" folder. You can now quit and relaunch Photoshop and select your filter from the Filter menu. This will not call up the Filter Factory interface, but rather a new interface with the sliders you've created and a small, inaccurate preview window.
Part 1: Introduction to Basic Operations in Filter Factory
Part 2: Convolving Pixels
Part 3: Geometric Expressions
Part 4: Conditional Statements
Appendix 1: 3D Effects in the Filter Factory
Appendix 2: More on 3D Effects
Appendix 3: Customizing Your Filter Interface
Complete: The Whole Thing on One Giant Page!
Further Resources: I've tried to make this series as accessible as possible for you folks without any programming background. If you'd like to take the Filter Factory even further or just learn more about the guts of Photoshop, there is a highly technical instructional document that you can find at http://www.thepluginsite.com/knowhow/ffpg/ffpg.htm. I highly recommend it. For me, it's been a great source for experimentation, even if, at first, I didn't understand everything that the author was talking about.
Prev 1 2 3 4 5 6 7 8 9 Next
Related sites: Animation Artist AV Video Creative Mac Digital Media Designer Digital Post Production Digital Producer Digital Webcast Presentation Master The WWUG
[an error occurred while processing this directive]