Jan 13
DisplacementMapFilter applied to MovieClip: Quick and Easy
THE EFFECT:
Of all of the filters that Flash has to offer, the DisplacementMapFilter holds a special place in my heart. If you don’t care about the WHY and only want the HOW scroll to the bottom.
THE STORY:
The following is a piece of history as I understood it while it was happening. You should question anyone else involved for the whole story. Here it goes:
We (ichameleon/group/) once got pulled into a project for HP because the client wasn’t happy with the way things were going with their current vendor. Although time was short, they decided to contact a list of other vendors to see who came up with the best solution. As eloquently as I can state it, the whole thing turned into an elaborate pissing contest between 7 other well known and respected vendors. They shall remain nameless because God forbid, I might need something from one of them one day. We ended up being the crowd favorite and delivered in a timely fashon as we always do.
WHAT I NEEDED:
The project required a streaming effect with images being pulled dynamic from the library and they had to warp like paper as they floated across the screen. We couldn’t use image sequences from AfterEffects because eventually this same stream engine needed to be used in a screensaver application that would pull images from the user’s hard drive and warp them dynamically in the same way. It was pretty kool!
God Bless Macromedia at the time for implementing the use of the DisplacementMapFilter in Flash 8. All filters in general for that matter. You can apply a DisplacementMapFilter to either BitmapData or to MovieClips. Filters applied to Bitmaps alter the Bitmap completely. It is like manipulating an image in PhotoShop and there is no undo. You can apply a filter to a MovieClip and it remains unaltered. The filters Array can be cleared and the MovieClip is the same as before anything was applied to it. The actual code that it takes to apply a filter is minimal yet powerful.
THE CODE – What it is:
DisplacementMapFilter(mapBitmap:BitmapData, mapPoint:Point, componentX:Number, componentY:Number, scaleX:Number, scaleY:Number, [mode:String], [color:Number], [alpha:Number])
The following is the bare minimum of what I use to create something kool:
mapBitmap: This is the BitmapData object that contains the displacement map data.
mapPoint: This is the positioning coordinates of the displacement map when it gets applied. You generally want to keep these points at 0,0 or less. If you use a large positive number like 50,50, you will notice part of the area gets the filter applied to it, and the rest of the area remains unchanged.
componentX/ componentY: These are the color channels that will be modified. The different channels are 1 (red), 2 (green), 4 (blue), and 8 (alpha). I’ve never been able to tell the difference when changing these values. I would leave it at 1.
scaleX/ scaleY: This is where the fun happens. These values determine how far a pixel gets displaced according to displacement map color shade.
Here is what the code looks like for the example:
——————————————————————————-
// Import classes
import flash.filters.DisplacementMapFilter;
import flash.display.BitmapData;
import flash.geom.Point;
// Create a BitmapData instance. The DisplacementMapFilter will need this.
var bpm1:BitmapData = new BitmapData(mcMap._width, mcMap._height, true);
// Create a DisplacementMapFilter instance. Pass the BitmapData instance in as the first parameter.
var dpmFilter:DisplacementMapFilter = new DisplacementMapFilter(bpm1, new Point(0, 0), 2, 2, 10, 10);
// Add the DisplacementMapFilter into the MovieClip’s “filters” Array.
mcClip.filters = [dpmFilter];
// Call the “draw()” method of the BitmapData class to continually update the DisplacementMap on the MovieClip.
mcClip.onEnterFrame = function() {
bpm1.draw(mcMap);
};
——————————————————————————-
PS: The example used an image sequence I created in AfterEffects because it would illustrate the power and koolness of the DisplacementMapFilter. I added the exact Bitmap sequence inside the affected MovieClip, masked it out to the size of the image and gave it a “MULTIPLY” blending mode for shadows and extra fanciness! Let me know what you think.
SIDE NOTES:
- You may want to always make the DisplacementMapFilter larger that the image/movieclip you will be affecting. You will notice a cutoff depending on how much the pixels will be displaced. Take my word for it.
- Anything that has contrasting color values (ex: balck/white) can be used as a displacement map. Images, image sequences, video, vector gradient fills, I would say ANYTHING.
No Comments
Leave a comment
