Some word on blend modes in Flash Player 8
Blend modes is one of those features who were long thought impossible to do in the Flash Player. And to be frank, it was indeed the most difficult feature I worked on during this release. Something to understand here is that blend modes are not implemented through the bitmap caching feature like the filters, but it's actually part of the core vector renderer. The two main advantages here are that using blend modes will not use excessive amounts of memory and use the shortest path possible in the rendering pipeline making it acceptable speed wise.
Nevertheless there are some things which need to be understood about this feature. It has limitations performance wise. In fact anytime you use a blend mode, all of the vector content in a particular region of your movie will be handled as it was partially transparent. And as you might know using transparent vectors can be a bit slow if used too gratiously. Experiment and see where they are useful, but do not overuse them. Sometimes precompositing or using bitmap caching might help.
The leads me to the list of modes we currently support. Some of them are better understood than others:
There are two special modes here which are f.ex. not part of Photoshop and that are the 'Add' and 'Subtract' modes. These will do exactly what they say and simply add or subtract color values, alpha, red, green and blue color components separately. I think that the 'Add' blend mode will probably be most used one overall since it's the fastest one (even faster than normal alpha compositing!) and will allow great lighting effects which were essentially only possible in OpenGL or Direct3D. In PhotoShop most users use 'Screen' as a replacement which is very similar.
Some of you who have used Director in a past life and maybe now might think that these are simply 'ink' effects. Well, not really. Flash rather followed the path of SVG, Photoshop and other more modern graphics applications. Directors 'ink' effects are IMO rather binary transfer modes that remind me of the QuickDraw era. Sticking to these blend modes is also more in line with what can be easily implemented in graphics hardware.
For those computer scientist out there you might wonder why we did not include a full Porter-Duff compositing model into the Flash Player. Frankly I think this model is pretty much irrelevant for most designers and I had no desire to add a very complex feature which does not bring anything useful to the table. In addition we would have had to implement a JIT for compositing functions just to make it fast enough and that was frankly out of the scope for this release.
There are some 'special' blend modes I should talk about:
The invert blend mode is a special version of the difference blend mode. I added this since a lot of times you simply want to invert an area (for selection f.ex.) without having to fiddle with the color of the top movie clip to get the same effect. It's also a tad faster than the difference mode.
That leaves alpha and erase. If you apply an alpha blend mode on a movie clip it will extract the alpha of that movie clip and try to apply it to the background. The erase mode will invert the alpha before applying it to the background. Now, and that probably the hardest part to understand, you can not change the alpha of the root stage. It's always opaque. In that sense this is very different from FireWorks and Photoshop which will show you a pattern where the transparent areas show through. This means applying an alpha blend mode on a movie clip on the root timeline will have NO effect. Instead you need a movie clip with the layer blend mode set (or any other blend mode) and move your movie clips which should be alpha blended inside it. A movie clip with the layer blend mode set is allowed to have a transparent background as it will be recomposited on the background later. I hope this makes it clear somehow. Our documentation guys certainly had a hard time understanding this, I am still looking for better ways of explaining it...
Nevertheless there are some things which need to be understood about this feature. It has limitations performance wise. In fact anytime you use a blend mode, all of the vector content in a particular region of your movie will be handled as it was partially transparent. And as you might know using transparent vectors can be a bit slow if used too gratiously. Experiment and see where they are useful, but do not overuse them. Sometimes precompositing or using bitmap caching might help.
The leads me to the list of modes we currently support. Some of them are better understood than others:
- Multiply
- Screen
- Darken
- Lighten
- Hardlight
- Overlay
- Difference
- Add
- Subtract
There are two special modes here which are f.ex. not part of Photoshop and that are the 'Add' and 'Subtract' modes. These will do exactly what they say and simply add or subtract color values, alpha, red, green and blue color components separately. I think that the 'Add' blend mode will probably be most used one overall since it's the fastest one (even faster than normal alpha compositing!) and will allow great lighting effects which were essentially only possible in OpenGL or Direct3D. In PhotoShop most users use 'Screen' as a replacement which is very similar.
Some of you who have used Director in a past life and maybe now might think that these are simply 'ink' effects. Well, not really. Flash rather followed the path of SVG, Photoshop and other more modern graphics applications. Directors 'ink' effects are IMO rather binary transfer modes that remind me of the QuickDraw era. Sticking to these blend modes is also more in line with what can be easily implemented in graphics hardware.
For those computer scientist out there you might wonder why we did not include a full Porter-Duff compositing model into the Flash Player. Frankly I think this model is pretty much irrelevant for most designers and I had no desire to add a very complex feature which does not bring anything useful to the table. In addition we would have had to implement a JIT for compositing functions just to make it fast enough and that was frankly out of the scope for this release.
There are some 'special' blend modes I should talk about:
- Layer
- Invert
- Alpha
- Erase
The invert blend mode is a special version of the difference blend mode. I added this since a lot of times you simply want to invert an area (for selection f.ex.) without having to fiddle with the color of the top movie clip to get the same effect. It's also a tad faster than the difference mode.
That leaves alpha and erase. If you apply an alpha blend mode on a movie clip it will extract the alpha of that movie clip and try to apply it to the background. The erase mode will invert the alpha before applying it to the background. Now, and that probably the hardest part to understand, you can not change the alpha of the root stage. It's always opaque. In that sense this is very different from FireWorks and Photoshop which will show you a pattern where the transparent areas show through. This means applying an alpha blend mode on a movie clip on the root timeline will have NO effect. Instead you need a movie clip with the layer blend mode set (or any other blend mode) and move your movie clips which should be alpha blended inside it. A movie clip with the layer blend mode set is allowed to have a transparent background as it will be recomposited on the background later. I hope this makes it clear somehow. Our documentation guys certainly had a hard time understanding this, I am still looking for better ways of explaining it...


12 Comments:
Thank you for this excellent explanation - I really appreciate the technical insights and details you give us here!
If I understand you correct it is possible to group MovieClips by using the blendMode "layer".
Now my question: Is it possible to create a parent clip (like a layer) which has some childs inside and apply to all theese childs the same blendMode by only one call?
I agree with Mario,thanks for all this valuable Info,heavily appreciated!
Next to the actual blendmode explanation,this was interesting,too:"In addition we would have had to implement a JIT for compositing functions just to make it fast enough and that was frankly out of the scope for this release."
Sooo.. is that in the scope for a future release? ;) :)
Thank you!
You just Rock, Tinic!!
Your blog is great, thanks for all that brilliant insights - pls go on like that!
thanks for info
how invert,alpha & erase blend mode work mathematically ?
I'm seeing a strange hair-line rendering bug around a clip using the alpha mode when it's set to cacheAsBitmap (or a color filter is applied). The hair-line edge appears or disappears depending on the scaling of the overall clip.
If I set the movie to low quality, the edge goes away, but all the text and shapes look terrible.
Any advice on how to work around this?
Hi thanks for the explanation. I am having a bit of a problem though. I used the difference blend mode and created a application in which you make a screen shot of the cam image and after that you can walk into the cam and the background will be filterd. But when i scale my cam image to 400 x 300 it doenst work anymore. Any explanation?
daniel@gomotion.nl
Hi Tinic,
I have been having some problems with the blendmodes and PNGs (with alpha) in Flash 8.
Essentially, I have 2 "holder" movieclips created through actionscript, on level 9 and 10. Each has 3 child movieclips: image, imagetint, imagemask. holder.image has a PNG loaded into it through an mcl object. holder.imagetint has a color fill on it. imagemask has a copy of the PNG image (created through BitmapData), with the transparency preserved.
Below are the blendmode settings:
holder.blendMode = "layer"
holder.image.blendMode = "normal"
holder.imagetint.blendMode = "overlay"
holder.imagemask.blendMode = "alpha"
This creates the effect I want: the PNG image is tinted with a color, and that tint is masked by the visible areas of the PNG image (imagine a product color chooser).
The problem is if I layer 2 or more "holders" ontop of each other. Eventually, after about 8 times in changing the imagetint fill, the PNG data vanishes, except for the contour; I'm left with the contour of the PNG with a solid fill in it, instead of the blendMode overlay.
I can send you an FLA if it would make more sense, but this seems like a bug to me...
Have you heard of this problem?
Thanks!
E
BlendMode.LAYER is not applied to sub-children. Any workaround or fix?
CS3 - I have a terrible time using blends and movie clips.. For example if i create button as a movie clip and then lay another movie clip inside that movie clip with a layer blend, the action script treats the nested movie clip as a separate button. I have tried this. and target. Experts Exchange is clueless.
Post a Comment
<< Home