|
|
FEBRUARY 07, 2002 The Complete Guide to Creating Photoshop Filters
Part 4: Conditional Statements and More So we've learned several new functions, and now we're going to look at a few last ones, along with some new variables, and take a look at a whole new way to apply all of them. We can tell Filter Factory to evaluate individual pixels of an image and then do things to them if certain conditions exist. In other words, we're going to be using conditional statements. [an error occurred while processing this directive] Why? It's another way to add depth and variety to the filters you can create in the Filter Factory. It can be used for edge effects and all kinds of other fun stuff that might actually be useful rather than just funky, as has been the case with all of our previous experiments. New functions and variables But before we get to the conditional statements, I'd like to give you a few more functions and variables to work with. Seeing as this is really the last installment of our Filter Factory series (though not the last page of our compendium here), I'd like to cram in as much as possible to give you as many tools as I can for making your own filters. None of these should prove too difficult. They're similar to functions and variables we've learned in the past, except that they produce different results. What up, d? The first one I want to talk about is d. Yes, d. What is this "d" I speak of? d is a variable that returns an angle, rather than a position, for a given channel of a given pixel. It's useful for creating flare and star effects, and it can be used just as any other variable. For example, you can use the src function with the d variable. But instead of blurring the pixels or shifting color channels in an absolute position, it places them at an angle. For example, try doing a sin expression in each of the R, G and B channels, and include "d" in the formula: R: sin(d*ctl(7))-d*ctl(0)/ctl(3) G: sin(d*ctl(7))-d*ctl(1)/ctl(3) B: sin(d*ctl(7))-d*ctl(2)/ctl(3) Here, the first four sliders--ctl(0) through ctl(3)---control the amount of color in the spokes, while the last slider, otherwise known as ctl(7), controls the number of spokes. Setting the first four sliders down to zero should yield you simple black and white spokes, as in the following example.
I'm not going to dwell on d too long. Place it in your other formulas and see what you can come up with. It's a particularly interesting variable when coupled with convolve expressions and conditional statements, seen later in this section. The m variable A far more useful variable in most circumstances is m. This, to put it simply, creates rings on your images. To try it out, write down a simple src formula in each of the R, G and B channels: R: src(x,y,0) G: src(x,y,1) B: src(x,y,2) Now just go in and slowly replace each of the x and y variables with m. For example, for the R channel, input src(m,m,0). You'll quickly see what this can do with your image.
One of the problems with the m expression is that the preview window just doesn't know what to do with it in some cases. In the preview, you might be creating a beautiful radial gradation, but then, when you apply the filter, you wind up with a big circle covering your image. As with all of the problems with the Filter Factory previews, this is just one you'll have to tweak with for a while before it starts looking right. More functions By now you're pretty familiar with functions and how you can mix and match them inside expressions. Here's I'm going to provide you with several more and just give you a brief explanation of what they do. You can use these alone or inside convolve expressions oor any other way you see fit. These are just different ways to generate values that Filter Factory uses to create effects. add(a,b,c): This adds a plus b, then compares the result with c and returns the smaller value. For example: add(ctl(0),ctl(1),ctl(2)). This would add the first two sliders, compare them with the third and then use the smaller of the two results. For another example, inside an expression, it would look like this: src(add(ctl(0),ctl(1),ctl(2)),add(ctl(3),ctl(4),ctl(5)),0). The first add value would become the new x coordinate; the second would become the new y coordinate; and the zero at the end, of course, just represents the red channel. dif(a,b): The subtracts b from a and returns an absolute value. ery simple, this function can be used inside expressions just like the add function. max(a,b): Picks the larger value of a or b. min(a,b): picks the smaller value of a or b. sqr(a): Returns the square root of a. sub(a,b,c): This is the inverse of add(a,b,,c). It subtracts b from a and then compares it with c and returns the larger value. Conditional statements: my funky chicken How a conditional statement works in the Filter Factory, essentially, is that you tell Photoshop to evaluate the numeric value of each channel of a given pixel; if it's x value, then do y; if it's not x value, then do z. For example, we can say, "If the value of the red channel in a given pixel is greater than 120, then change it to 200; if not, change it to 80." Or something like that. It's actually easier to write it out the Filter Factory way: r>120?200:80 g>120?200:80 b>120?200:80 See? The question "Is the red value greater than 120?" is expressed "r>120?" Then you just put in your "then" and "if not then" results. If it is, then change it to 200. If it isn't, change it to 80. This is simply expressed "200:80." Try this out just to see what happens. Well, the problem is that this is just a one-trick effect. So, instead, let's use some controls to add a little flexibility. Instead of 120, 200 and 80, use ctl(0), ctl(1) and ctl(2). So you will have: r>ctl(0)?ctl(1):ctl(2) g>ctl(2)?ctl(3):ctl(4) b>ctl(4)?ctl(5):ctl(6) So, if the value of red is greater than the value of the first slider (ctl(0)), then change it to the value of the second slider(ctl(1)). Otherwise, change it to the third slider (ctl(2)). The kinds of effects you can get from this are pretty slick. Still, you do feel a bit confined by such a small formula, don't you?
No, of course not. You're the adventurous sort. You won't just settle for ctl(1). You want to try sin(ctl(1)). Well, go for it, tiger. Try this one out: r>ctl(0)?sin(ctl(1)):sin(ctl(2)) g>ctl(2)?sin(ctl(3)):sin(ctl(4)) b>ctl(4)?sin(ctl(5)):sin(ctl(6)) It just gets more and more bizarre, doesn't it? Well, let's try adding in a little convolution to make things a little more crazy. If r is greater than ctl(0), then convolve it one way. If not, convolve it another. You can try any old way of convolving it you feel like trying. I'm going to try this one: r>ctl(0)?cnv(ctl(0),ctl(0),ctl(0),ctl(0),ctl(0),ctl(0),ctl(0),ctl(0),ctl(0),ctl(6)) :cnv(ctl(1),ctl(1),ctl(1),ctl(1),ctl(1),ctl(1),ctl(1),ctl(1),ctl(1),ctl(7)) Or, even better yet, get the sin of the "else" convolution for effects with harder softer edges: r>ctl(0)?cnv(ctl(0),ctl(0),ctl(0),ctl(0),ctl(0),ctl(0),ctl(0),ctl(0),ctl(0),ctl(6)) :sin(cnv(ctl(1),ctl(1),ctl(1),ctl(1),ctl(1),ctl(1),ctl(1),ctl(1),ctl(1),ctl(7))) You should wind up with the ability to create something like the images below. Now let's try adding in some of our new variables from this section--d and m. Try out this one: R: r>ctl(0)?src(x-(d/ctl(0)),y-(d/ctl(1)),0):sin(r-d+ctl(3)) G: g>ctl(0)?src(cnv(ctl(2),ctl(2),ctl(2),ctl(2),ctl(2),ctl(2),ctl(2),ctl(2),ctl(2),ctl(6)), cnv(ctl(3),ctl(3),ctl(3),ctl(3),ctl(3),ctl(3),ctl(3),ctl(3),ctl(3),ctl(7)),1):sin(d*ctl(0)) B: b>ctl(7)?src(cnv(ctl(4),ctl(4),ctl(4),ctl(4),ctl(4),ctl(4),ctl(4),ctl(4),ctl(4),ctl(6)), cnv(ctl(5),ctl(5),ctl(5),ctl(5),ctl(5),ctl(5),ctl(5),ctl(5),ctl(5),ctl(7)),2):sin(d)*ctl(6)/cos(d) As with the images below, this should yield you some very weird effects combining spokes and convolutions.
Now just try throwing in your m variable in various parts of these formulas, and you should start to see some interesting--maybe even useful--results. But then again, maybe not. Let me know how it goes. We've covered a lot here, and that about wraps it up for our Filter Factory series. The next two pages deal in depth with some specific applications of the Filter Factory for creating 3D effects. Page 8 covers a method for users to customize the interface of their filters. And the last page simply presents this entire piece on one giant page. (Watch for crashes on systems with low memory!) 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 Related forums: [an error occurred while processing this directive]
|