Navigation


RSS : Articles / Comments


Viewport Filters (IX)

7:54 AM, Posted by Jim Foley, 8 Comments

In this chapter I'll discuss how to apply filters to your viewport, in turn, applying the filter across all objects in your scene. For this example I'll use a PV3D generated Sphere and apply the various filters to the viewport.

Drop Shadow Filter

example: Drop Shadow Filter
source: Drop Shadow Filter Source

This is the code for inserting a drop shadow filter on your viewport. The first thing you need to do is import the flash filters API. For simplicity purposes I'm going to import all filters. You can do that by using * at the end of the flash.filters.* directory.

//import filters api
import flash.filters.*;

//datatype your filter variable
public var dropShadowFilter:DropShadowFilter;

//instantiate your dropShadowFilter var with its parameters
//dropShadowFilter = new DropShadowFilter(distance, angle, color, alpha, x blur, y blur,
//strength, quality, inner shadow boolean, knockout boolean, hide object boolean);
dropShadowFilter = new DropShadowFilter(5, 45, 0x000000, 1, 5, 5, 1, 1);

//apply your filter to the viewport
//viewport.filters = [filter1 to apply, filter2 to apply];
viewport.filters = [dropShadowFilter];


Preview the fla and you'll see your filter in action.


Blur Filter

example: Blur Filter
source: Blur Filter Source

This is the code for inserting a blur filter on your viewport.

//import filters api
import flash.filters.*;

//datatype your filter variable
public var blurFilter:BlurFilter;

//instantiate your blurFilter var with its parameters
//blurFilter = new BlurFilter(x blur, y blur, quality);
blurFilter = new BlurFilter(10, 10, 1);

//apply your filter to the viewport
//viewport.filters = [filter1 to apply, filter2 to apply];
viewport.filters = [blurFilter ];


Preview the fla and you'll see your filter in action.


Glow Filter

example: Glow Filter
source: Glow Filter Source

This is the code for inserting a glow filter on your viewport.

//import filters api
import flash.filters.*;

//datatype your filter variable
public var glowFilter:GlowFilter;

//instantiate your glowFilter var with its parameters
//glowFilter = new GlowFilter(color, alpha, x blur, y blur,
//strength, quality, inner glow bloolean, knockout boolean);
glowFilter = new GlowFilter(0xFF0000, 1, 10, 10, 2, 1);

//apply your filter to the viewport
//viewport.filters = [filter1 to apply, filter2 to apply];
viewport.filters = [glowFilter];


Preview the fla and you'll see your filter in action.


Bevel Filter

example: Bevel Filter
source: Bevel Filter Source

This is the code for inserting a bevel filter on your viewport.

//import filters api
import flash.filters.*;

//datatype your filter variable
public var bevelFilter:BevelFilter;

//instantiate your bevelFilter var with its parameters
//bevelFilter = new BevelFilter(distance, angle, highlight color, highlight alpha,
//shadow color, shadow alpha, x blur, y blur, strength, quality,
//bevel type string, knockout boolean);
bevelFilter = new BevelFilter(8, 45, 0xAAAAAA, 1, 0x000000, 1, 4, 4, 1, 1, "inner");

//apply your filter to the viewport
//viewport.filters = [filter1 to apply, filter2 to apply];
viewport.filters = [bevelFilter];


Preview the fla and you'll see your filter in action.

8 Comments

Privatesub @ March 10, 2008 11:31 AM

Thanks Jim!
The blur and shadow effects are great!

Anonymous @ March 11, 2008 9:19 AM

This is great. I did not think about applying a filter to the viewport. If there a way I can only apply the filter, say a dropshadow, to one specific element on the stage?

For example, I have five planes on my stage, I only want one to have a filter applied. Would I need a new viewport for each plane?

Forgive me if I sound ignorant - I am, and I'm trying to learn!!

Much thanks.

Bryan

Jim Foley @ March 12, 2008 3:23 PM

Hey Bryan,
You'd have to use the effects branch for that type of filtering. I haven't tried it yet myself but it is possible.

William @ April 22, 2008 8:06 PM

Gday, how do you go about applying a filter to a cube that needs to be continually rendered as it is reacting to mouse.X and mouse.Y?

Steve Autisn @ May 23, 2008 2:11 AM

This effects are apply only to viewport...but if i want apply dnly at the boject sphere? not to all abject in viewport?

Oliver @ November 4, 2008 1:54 AM

It's possible to apply filter only to one specific DisplayObject3d,use
DisplayObject.useOwnContainter=true;
DisplayObject.filters[yourFilterHere];

Jim Foley @ November 4, 2008 8:59 AM
This post has been removed by the author.
Jim Foley @ November 4, 2008 9:25 AM

@All - If you're looking to apply filters to objects within the scene see this post: http://blog.zupko.info/?p=129