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.
Exemplo n.º 1
0
 override protected void CreatePrograms()
 {
     if (_program == null)
     {
         string programName = "_test_emptyFilterProgram";
         _program = SparrowSharpApp.GetProgram(programName);
         if (_program == null)
         {
             _program = new Program(FragmentFilter.StandardVertexShader(), FragmentFilter.StandardFragmentShader());
             SparrowSharpApp.RegisterProgram(programName, _program);
         }
     }
     VertexPosID = _program.Attributes["aPosition"];
     TexCoordsID = _program.Attributes["aTexCoords"];
 }
Exemplo n.º 2
0
        override protected void CreatePrograms()
        {
            if (_shaderProgram == null)
            {
                _shaderProgram = SparrowSharpApp.GetProgram(ColorMatrixProgram);

                if (_shaderProgram == null)
                {
                    _shaderProgram = new Program(FragmentFilter.StandardVertexShader(), GetFragmentShader());

                    SparrowSharpApp.RegisterProgram(ColorMatrixProgram, _shaderProgram);
                }

                VertexPosID = _shaderProgram.Attributes["aPosition"];
                TexCoordsID = _shaderProgram.Attributes["aTexCoords"];

                _uColorMatrix = _shaderProgram.Uniforms["uColorMatrix"];
                _uColorOffset = _shaderProgram.Uniforms["uColorOffset"];
                _uMvpMatrix   = _shaderProgram.Uniforms["uMvpMatrix"];
            }
        }