C# (CSharp) SparrowSharp.Filters Namespace

Classes

Name Description
BlurFilter

The BlurFilter applies a gaussian blur to an object. The strength of the blur can be set for x- and y-axis separately (always relative to the stage).

A blur filter can also be set up as a drop shadow or glow filter. Use FilterFactory to create such a filter.

For each blur direction, the number of required passes is ceil(blur).

blur = 0.5: 1 pass

blur = 1.0: 1 pass

blur = 1.5: 2 passes

blur = 2.0: 2 passes

etc.

BlurProgram Shader used by BlurFilter
ColorMatrix A color matrix class containing an array of 20 floats arranged as a 4x5 matrix.
ColorMatrixFilter
EmptyFilter Empty filter that does nothing. Used for testing; you can use its code to make custom filters.
FilterFactory Helper class that allows quick creation Sparrow's built in filters.
FragmentFilter The FragmentFilter class is the base class for all filter effects in Sparrow.

All other filters of this package extend this class. You can attach them to any display object through the 'filter' property.

A fragment filter works in the following way:

* The object that is filtered is rendered into a texture (in stage coordinates).

* That texture is passed to the first filter pass.

* Each pass processes the texture using a fragment shader (and optionally a vertex shader) to achieve a certain effect.

* The output of each pass is used as the input for the next pass; if it's the final pass, it will be rendered directly to the back buffer.

All of this is set up by the abstract FragmentFilter class. Concrete subclasses just need to override the protected methods 'createPrograms', 'activateWithPass' and (optionally) 'deactivateWithPass' to create and execute its custom shader code. Each filter can be configured to either replace the original object, or be drawn below or above it. This can be done through the 'mode' property, which accepts one of the enums defined in the 'SPFragmentFilterMode' enum.

Beware that each filter should be used only on one object at a time. Otherwise, it will get slower and require more resources; and caching will lead to undefined results.