void
DepthPeelingStage::setupPostProcess(RenderAction* a, bool isFinal, bool isPing)
{
    this->pushPartition(a,
                        (RenderPartition::CopyWindow      |
                         RenderPartition::CopyViewportSize),
                         RenderPartition::SimpleCallback    );
    {
        RenderPartition *pPart  = a->getActivePartition();

        Matrix m, t;

        m.setIdentity();
        t.setIdentity();

        MatrixOrthogonal( m,
                            0.f, 1.f,
                            0.f, 1.f,
                            -1.f, 1.f);

        pPart->setupProjection(m, t);

        RenderPartition::SimpleDrawCallback f;

        if (!isFinal)
            f = boost::bind(&DepthPeelingStage::postProcess, this, _1, isPing);
        else
            f = boost::bind(&DepthPeelingStage::postProcessFinal, this, _1);

        pPart->dropFunctor(f);
    }
    this->popPartition(a);
}
void ShaderShadowMapEngine::handleDirectionalLightEnter(
    DirectionalLight *dirL, RenderAction *ract, SSMEngineData *data)
{
    RenderPartition *parentPart = ract      ->getActivePartition();
    FrustumVolume    camFrust   = parentPart->getFrustum        ();

    Matrix matEyeToWorld  (parentPart->getCameraToWorld());
    Matrix matWorldToLight;
    Matrix matEyeToLight;

    calcDirectionalLightMatrices(matWorldToLight, matEyeToLight,
                                 dirL,            matEyeToWorld );

    // place light camera outside the scene bounding box:
    //  - project camera frustum and scene bounding box into a
    //    coordinate system where the directional light shines
    //    along the -z axis.
    //  - compute 2 AABBs that contain the projected frustum and
    //    scene BB
    //  - width and height of the ortho projection are determined from
    //    the frustum AABB, while near and far are determined by the
    //    scene AABB (offscreen objects cast shadows into the view volume)
          Pnt3f      camVerts  [10];
          Pnt3f      sceneVerts[10];
    const Matrix    &matSceneToWorld = ract->topMatrix ();
          BoxVolume  sceneBB         = ract->getActNode()->getVolume();

    camFrust.getCorners(camVerts  [0], camVerts  [1],
                        camVerts  [2], camVerts  [3],
                        camVerts  [4], camVerts  [5],
                        camVerts  [6], camVerts  [7] );
    sceneBB .getCorners(sceneVerts[0], sceneVerts[1],
                        sceneVerts[2], sceneVerts[3],
                        sceneVerts[4], sceneVerts[5],
                        sceneVerts[6], sceneVerts[7] );

    camVerts  [8].setValues(TypeTraits<Real32>::getMax(),
                            TypeTraits<Real32>::getMax(),
                            TypeTraits<Real32>::getMax() );
    camVerts  [9].setValues(TypeTraits<Real32>::getMin(),
                            TypeTraits<Real32>::getMin(),
                            TypeTraits<Real32>::getMin() );
    sceneVerts[8].setValues(TypeTraits<Real32>::getMax(),
                            TypeTraits<Real32>::getMax(),
                            TypeTraits<Real32>::getMax() );
    sceneVerts[9].setValues(TypeTraits<Real32>::getMin(),
                            TypeTraits<Real32>::getMin(),
                            TypeTraits<Real32>::getMin() );

    for(UInt32 i = 0; i < 8; ++i)
    {
        matWorldToLight.mult(camVerts  [i], camVerts  [i]);

        matSceneToWorld.mult(sceneVerts[i], sceneVerts[i]);
        matWorldToLight.mult(sceneVerts[i], sceneVerts[i]);

        camVerts  [8][0] = osgMin(camVerts  [8][0], camVerts  [i][0]);
        camVerts  [9][0] = osgMax(camVerts  [9][0], camVerts  [i][0]);
        camVerts  [8][1] = osgMin(camVerts  [8][1], camVerts  [i][1]);
        camVerts  [9][1] = osgMax(camVerts  [9][1], camVerts  [i][1]);

        sceneVerts[8][0] = osgMin(sceneVerts[8][0], sceneVerts[i][0]);
        sceneVerts[9][0] = osgMax(sceneVerts[9][0], sceneVerts[i][0]);
        sceneVerts[8][1] = osgMin(sceneVerts[8][1], sceneVerts[i][1]);
        sceneVerts[9][1] = osgMax(sceneVerts[9][1], sceneVerts[i][1]);
        sceneVerts[8][2] = osgMin(sceneVerts[8][2], sceneVerts[i][2]);
        sceneVerts[9][2] = osgMax(sceneVerts[9][2], sceneVerts[i][2]);
    }

    // these points are the corners of the ortho shadow view volume
    Pnt3f lightMin(osgMax(camVerts[8][0], sceneVerts[8][0]),
                   osgMax(camVerts[8][1], sceneVerts[8][1]),
                   -sceneVerts[9][2]);
    
    Pnt3f lightMax(osgMin(camVerts[9][0], sceneVerts[9][0]),
                   osgMin(camVerts[9][1], sceneVerts[9][1]),
                   -sceneVerts[8][2]);

    // enlarge by 2% in x, y, z direction
    lightMin[0] -= (lightMax[0] - lightMin[0]) * 0.01f;
    lightMin[1] -= (lightMax[1] - lightMin[1]) * 0.01f; 
    lightMin[2] -= (lightMax[2] - lightMin[2]) * 0.01f;

    lightMax[0] += (lightMax[0] - lightMin[0]) * 0.01f;
    lightMax[1] += (lightMax[1] - lightMin[1]) * 0.01f;
    lightMax[2] += (lightMax[2] - lightMin[2]) * 0.01f;

    Matrix matLightProj;
    Matrix matLightProjTrans;

    MatrixOrthogonal(matLightProj,
                     lightMin[0], lightMax[0],
                     lightMin[1], lightMax[1],
                     lightMin[2], lightMax[2] );

    updateShadowTexImage  (data);
    updateShadowTexBuffers(data);
    updateRenderTargets   (data);

    Int32 shadowTexUnit = (this->getForceTextureUnit() > 0) ?
                           this->getForceTextureUnit()      : 7;

    ShaderProgram *shadowFP = this->getShadowFragmentProgram();

    if(shadowFP == NULL)
    {
        ShaderProgramUnrecPtr newShadowFP = ShaderProgram::createLocal();
        newShadowFP->setShaderType(GL_FRAGMENT_SHADER);
        newShadowFP->setProgram   (_dirFPCode        );

        newShadowFP->addUniformVariable("SSME_matEyeToLight", matEyeToLight);
        newShadowFP->addUniformVariable("SSME_matLightProj",  matLightProj );
        newShadowFP->addUniformVariable("SSME_texShadow",     shadowTexUnit);

        this->setShadowFragmentProgram(newShadowFP);
        shadowFP = newShadowFP;
    }
    else
    {
        shadowFP->updateUniformVariable("SSME_matEyeToLight", matEyeToLight);
        shadowFP->updateUniformVariable("SSME_matLightProj",  matLightProj );
    }

    commitChanges();

    this->pushPartition(ract);
    {
        RenderPartition   *part   = ract->getActivePartition( );
        Window            *win    = ract->getWindow         ( );
        FrameBufferObject *target = data->getRenderTargets  (0);
        Background        *back   = data->getBackground     ( );

        part->setRenderTarget(target);
        part->setWindow      (win   );

        part->calcViewportDimension(0.f, 0.f, 1.f, 1.f,
                                    target->getWidth (),
                                    target->getHeight() );

        part->setupProjection(matLightProj, matLightProjTrans);
        part->setupViewing   (matWorldToLight                );

        part->setNear        (parentPart->getNear());
        part->setFar         (parentPart->getFar ());

        part->calcFrustum    (                     );

        part->setBackground  (back                 );

        // force material for shadow map generation
        part->overrideMaterial(data->getLightPassMaterials(0),
                               ract->getActNode           ( ) );

        this->recurseFrom(ract, dirL);
        ract->useNodeList(false     );

        // undo override
        part->overrideMaterial(NULL,
                               ract->getActNode           ( ) );
    }
    this->popPartition(ract);
}
Пример #3
0
Action::ResultE PostShaderStage::renderEnter(Action *action)
{
    RenderAction *a = dynamic_cast<RenderAction *>(action);

    a->disableDefaultPartition();

    this->beginPartitionGroup(a);
    {
        this->pushPartition(a);
        {
            RenderPartition   *pPart    = a->getActivePartition();
            FrameBufferObject *pTarget  = this->getRenderTarget();
            Viewarea          *pArea    = a->getViewarea();
            Camera            *pCam     = a->getCamera  ();
            Background        *pBack    = a->getBackground();
            
            if(pTarget == NULL)
            {
                this->initData(a);

                pTarget  = this->getRenderTarget();
            }

            pPart->setRenderTarget(pTarget);
            
#ifdef OSG_DEBUGX
            std::string szMessage("RenderPartition\n");
            pPart->setDebugString(szMessage          );
#endif

            if(pArea != NULL)
            {
//                pPart->setViewport(pPort         );
                pPart->setWindow  (a->getWindow());
                
                if(pTarget != NULL)
                {
#if 0
                    pPart->calcViewportDimension(pArea->getLeft  (),
                                                 pArea->getBottom(),
                                                 pArea->getRight (),
                                                 pArea->getTop   (),
                                                 
                                                 pTarget->getWidth    (),
                                                 pTarget->getHeight   ());

#endif
                    pPart->calcViewportDimension(0.f,
                                                 0.f,
                                                 1.f,
                                                 1.f,
                                                 
                                                 pTarget->getWidth    (),
                                                 pTarget->getHeight   ());

                }
                else
                {
                    pPart->calcViewportDimension(pArea->getLeft  (),
                                                 pArea->getBottom(),
                                                 pArea->getRight (),
                                                 pArea->getTop   (),
                                                 
                                                 a->getWindow()->getWidth (),
                                                 a->getWindow()->getHeight());
                }
                
                if(pCam != NULL)
                {
                    Matrix m, t;
                    
                    // set the projection
                    pCam->getProjection          (m, 
                                                  pPart->getViewportWidth (), 
                                                  pPart->getViewportHeight());
                    
                    pCam->getProjectionTranslation(t, 
                                                   pPart->getViewportWidth (), 
                                                   pPart->getViewportHeight());
                    
                    pPart->setupProjection(m, t);
                    
                    pCam->getViewing(m, 
                                     pPart->getViewportWidth (),
                                     pPart->getViewportHeight());
                    
                    
                    pPart->setupViewing(m);
                    
                    pPart->setNear     (pCam->getNear());
                    pPart->setFar      (pCam->getFar ());
                    
                    pPart->calcFrustum();
                }
                
                pPart->setBackground(pBack);
            }
            
            this->recurseFromThis(a);
        }
        this->popPartition(a);
        
        this->pushPartition(a,
                            (RenderPartition::CopyWindow      |
                             RenderPartition::CopyViewportSize),
                            RenderPartition::SimpleCallback    );
        {
            RenderPartition *pPart  = a->getActivePartition();

#ifdef OSG_DEBUGX
            std::string szMessage("PostProcessPartition\n");
            pPart->setDebugString(szMessage          );
#endif
           
            Matrix m, t;
                
            m.setIdentity();
            t.setIdentity();
                
            MatrixOrthogonal( m,
                              0.f, 1.f,
                              0.f, 1.f,
                             -1.f, 1.f);
            
            pPart->setupProjection(m, t);
                
            RenderPartition::SimpleDrawCallback f;
                
            f = boost::bind(&PostShaderStage::postProcess, this, _1);
                
            pPart->dropFunctor(f);
        }
        this->popPartition(a);
    }
    this->endPartitionGroup(a);

    RenderPassVector::iterator passIt = _vPostProcessPasses.begin();

    //Update the uniform parameters to the shader
    for(; passIt != _vPostProcessPasses.end(); ++passIt)
    {
        (*passIt)->updateUniformVariables(a);
    }

    return Action::Skip;
}
void DeferredShadingStage::setupShadingPartition(
    RenderPartition *part, RenderAction *ract, DSStageData *data)
{
    Window            *win    = ract->getWindow           ();
    FrameBufferObject *target = data->getShadingTarget    ();
    Camera            *cam    = this->getCamera           ();
    Background        *back   = this->getBackground       ();

    part->setRenderTarget(target);
    part->setWindow      (win   );

    if(target != NULL)
    {
        part->calcViewportDimension(this->getLeft    (),
                                    this->getBottom  (),
                                    this->getRight   (),
                                    this->getTop     (),

                                    target->getWidth (),
                                    target->getHeight() );
    }
    else if(win != NULL)
    {
        part->calcViewportDimension(this->getLeft  (),
                                    this->getBottom(),
                                    this->getRight (),
                                    this->getTop   (),

                                    win->getWidth  (),
                                    win->getHeight () );
    }
    else
    {
        SWARNING << "DeferredShadingStage::setupShadingPartition: "
                 << "No target or window." << std::endl;
    }

    // setup ortho projection
    Matrix matProjection;
    Matrix matProjectionTranslation;
    Matrix matViewing;

    matProjectionTranslation.setIdentity();
    matViewing              .setIdentity();

    MatrixOrthogonal(matProjection,
                     -1.f, 1.f,
                     -1.f, 1.f,
                     -1.f, 1.f );

    part->setupProjection(matProjection, matProjectionTranslation);
    part->setupViewing   (matViewing                             );

    part->setNear(-1.f);
    part->setFar ( 1.f);

    // setup VPCamera matrices to original projection -- TODO copy from GBuffer pass?
    cam->getProjection           (matProjection,
                                  part->getViewportWidth (),
                                  part->getViewportHeight() );
    cam->getProjectionTranslation(matProjectionTranslation,
                                  part->getViewportWidth (),
                                  part->getViewportHeight() );

    Matrix matProjectionFull = matProjection;
    matProjectionFull.mult(matProjectionTranslation);

    Matrix matToWorld;
    Matrix matWorldToScreen;

    cam->getViewing(matViewing, part->getViewportWidth (),
                                part->getViewportHeight() );
    matToWorld.invertFrom(matViewing);

    matWorldToScreen = matProjectionFull;
    matWorldToScreen.mult(matToWorld);

    part->setVPCameraMatrices(matProjectionFull,
                              matProjection,
                              matProjectionTranslation,
                              matViewing,
                              matToWorld,
                              matWorldToScreen          );

    part->setBackground(back);

    part->setSetupMode(RenderPartition::ProjectionSetup |
                       RenderPartition::BackgroundSetup  );
}
Пример #5
0
Action::ResultE HDRStage::renderEnter(Action *action)
{
    RenderAction *a = dynamic_cast<RenderAction *>(action);

    a->disableDefaultPartition();

    Int32 iVPWidth  = a->getActivePartition()->getViewportWidth ();
    Int32 iVPHeight = a->getActivePartition()->getViewportHeight();

    this->beginPartitionGroup(a);
    {
        this->pushPartition(a);
        {
            RenderPartition   *pPart    = a   ->getActivePartition();
            FrameBufferObject *pTarget  = this->getRenderTarget   ();
            Viewarea          *pArea    = a   ->getViewarea       ();
            Camera            *pCam     = a   ->getCamera         ();
            Background        *pBack    = a   ->getBackground     ();
            
            if(pTarget == NULL)
            {
                this->initData(a, iVPWidth, iVPHeight);

                pTarget  = this->getRenderTarget();
            }
            else
            {
                this->updateData(a, iVPWidth, iVPHeight);
            }

            pPart->setRenderTarget(pTarget);
            pPart->getDrawEnv().setTargetBufferFormat(this->getBufferFormat());

#ifdef OSG_DEBUGX
            std::string szMessage("HDR: RenderPartition\n");
            pPart->setDebugString(szMessage          );
#endif

            if(pArea != NULL)
            {
                pPart->setWindow  (a->getWindow());
                
                if(pTarget != NULL)
                {
#if 0
                    pPart->calcViewportDimension(pArea->getLeft  (),
                                                 pArea->getBottom(),
                                                 pArea->getRight (),
                                                 pArea->getTop   (),
                                                 
                                                 pTarget->getWidth    (),
                                                 pTarget->getHeight   ());
#endif
                    pPart->calcViewportDimension(0.f,
                                                 0.f,
                                                 1.f,
                                                 1.f,
                                                 
                                                 pTarget->getWidth    (),
                                                 pTarget->getHeight   ());

                }
                else
                {
                    pPart->calcViewportDimension(pArea->getLeft  (),
                                                 pArea->getBottom(),
                                                 pArea->getRight (),
                                                 pArea->getTop   (),
                                                 
                                                 a->getWindow()->getWidth (),
                                                 a->getWindow()->getHeight());
                }

                if(pCam != NULL)
                {
                    Matrix m, t;
                    
                    // set the projection
                    pCam->getProjection          (m, 
                                                  pPart->getViewportWidth (), 
                                                  pPart->getViewportHeight());
                    
                    pCam->getProjectionTranslation(t, 
                                                   pPart->getViewportWidth (), 
                                                   pPart->getViewportHeight());
                    
                    pPart->setupProjection(m, t);
                    
                    pCam->getViewing(m, 
                                     pPart->getViewportWidth (),
                                     pPart->getViewportHeight());
                    
                    
                    pPart->setupViewing(m);
                    
                    pPart->setNear     (pCam->getNear());
                    pPart->setFar      (pCam->getFar ());
                    
                    pPart->calcFrustum();
                }
                
                pPart->setBackground(pBack);
            }
            
            this->recurseFromThis(a);
        }
        this->popPartition(a);

        a->getActivePartition()->disable();

        this->pushPartition(a,
                            (RenderPartition::CopyWindow       |
                             RenderPartition::CopyViewportSize |
                             RenderPartition::CopyTarget       ),
                            RenderPartition::SimpleCallback    );
        {
            RenderPartition *pPart  = a->getActivePartition();

#ifdef OSG_DEBUGX
            std::string szMessage("HDR: PostProcessPartition\n");
            pPart->setDebugString(szMessage          );
#endif

            Matrix m, t;
                
            m.setIdentity();
            t.setIdentity();
                
            MatrixOrthogonal( m,
                              0.f, 1.f,
                              0.f, 1.f,
                             -1.f, 1.f);
            
            pPart->setupProjection(m, t);
                
            RenderPartition::SimpleDrawCallback f;
                
            f = boost::bind(&HDRStage::postProcess, this, _1);
                
            pPart->dropFunctor(f);
        }
        this->popPartition(a);
    }
    this->endPartitionGroup(a);

    return Action::Skip;
}
Пример #6
0
void VRShadowEngine::setupCamera(Light         *pLight,
                                        LightTypeE     eType,
                                        RenderAction  *pAction,
                                        EngineDataPtr  pEngineData)
{
    if(eType == Directional)
    {
        DirectionalLight *pDLight =
            dynamic_cast<DirectionalLight *>(pLight);

        MatrixCameraUnrecPtr pCam =
            dynamic_cast<MatrixCamera *>(pEngineData->getCamera());

        if(pCam == NULL)
        {
            pCam = MatrixCamera::createLocal();

            pEngineData->setCamera(pCam);
        }


        Vec3f   diff;
        Pnt3f   center;
        Matrix  transMatrix;
        Node   *pNode = pAction->getActNode();

//        tmpDir = DirectionalLightPtr::dcast(_lights[i]);

        diff = (pNode->getVolume().getMax() -
                pNode->getVolume().getMin());

        Real32 sceneWidth = diff.length() * 0.5f;
        // Not final values. May get tweaked in the future

        Real32 sceneHeight = diff.length() * 0.5f;

        pNode->getVolume().getCenter(center);

        Vec3f lightdir = pDLight->getDirection();

        if(pLight->getBeacon() != NULL)
        {
            Matrix m = pLight->getBeacon()->getToWorld();

            m.mult(lightdir, lightdir);
        }

        MatrixLookAt(transMatrix,
                     center + lightdir,
                     center,
                     Vec3f(0,1,0));

        transMatrix.invert();

        Matrix proMatrix;

        proMatrix.setIdentity();

        MatrixOrthogonal( proMatrix,
                         -sceneWidth,   sceneWidth, -sceneHeight,
                          sceneHeight, -sceneWidth,  sceneWidth);


        pCam->setProjectionMatrix(proMatrix  );
        pCam->setModelviewMatrix (transMatrix);
    }
    else if(eType == Point)
    {
        PointLight *pPLight = dynamic_cast<PointLight *>(pLight);

        MatrixCameraUnrecPtr pCam =
            dynamic_cast<MatrixCamera *>(pEngineData->getCamera());

        if(pCam == NULL)
        {
            pCam = MatrixCamera::createLocal();

            pEngineData->setCamera(pCam);
        }

        Real32  angle;
        Vec3f   dist;
        Pnt3f   center;
        Vec3f   diff;

        Matrix  transMatrix;

        Node   *pNode = pAction->getActNode();


        pNode->getVolume().getCenter(center);

        Pnt3f lightpos = pPLight->getPosition();

        if(pLight->getBeacon() != NULL)
        {
            Matrix m = pLight->getBeacon()->getToWorld();

            m.mult(lightpos, lightpos);
        }


        MatrixLookAt(transMatrix,
                     lightpos,
                     center,
                     Vec3f(0,1,0));

        transMatrix.invert();


        diff = (pNode->getVolume().getMax() -
                pNode->getVolume().getMin());

        dist  = lightpos - center;

        angle = atan((diff.length() * 0.5) / dist.length());

        Matrix proMatrix;

        proMatrix.setIdentity();

        MatrixPerspective( proMatrix,
                           2.f * angle,
                           1,
                           pAction->getActivePartition()->getNear(),
                           pAction->getActivePartition()->getFar ());


        pCam->setProjectionMatrix(proMatrix  );
        pCam->setModelviewMatrix (transMatrix);
    }
}
Action::ResultE DisplayFilterStage::renderEnter(Action *action)
{
    RenderAction *ract = dynamic_cast<RenderAction *>(action);

    if(ract == NULL)
        return Action::Continue;

    DisplayFilterStageDataUnrecPtr pData = 
        ract->getData<DisplayFilterStageData *>(_iDataSlotId);

    DrawEnv &oEnv = ract->getActivePartition()->getDrawEnv();

    bool                      bFilterActive = false;
    RenderPartition::Mode     partMode      = RenderPartition::StateSorting;

    CalibrationPatternFilter *pCalibFilter  = NULL;
    ResolutionDisplayFilter  *pResFilter    = NULL;
    DistortionDisplayFilter  *pDistFilter   = NULL;
    ColorDisplayFilter       *pColFilter    = NULL;
    bool                      bDoDraw       = true;

    if(_mfFilterGroups.size() == 0)
    {
        pCalibFilter = this->getCalibrationPatternFilter();

        pResFilter   = this->getResolutionFilter();

        pColFilter   = this->getColorFilter();

        pDistFilter  = this->getDistortionFilter();

    }
    else
    {
        // Linear search, optimize of needed

        MFFilterGroupsType::const_iterator gIt  = _mfFilterGroups.begin();
        MFFilterGroupsType::const_iterator gEnd = _mfFilterGroups.end  ();

        for(; gIt != gEnd; ++gIt)
        {
            if((*gIt)->matches(oEnv.getDrawerId(),
                               oEnv.getDrawableId()) == true)
            {
                pCalibFilter = (*gIt)->getCalibrationPatternFilter();

                pResFilter   = (*gIt)->getResolutionFilter();

                pColFilter   = (*gIt)->getColorFilter();

                pDistFilter  = (*gIt)->getDistortionFilter();
                
                bDoDraw = 
                    ((*gIt)->matches(this->getActiveGroup(),
                                     oEnv. getDrawableId ()) == true) ||
                     (this->getActiveGroup()                == -1   )  ;

                break;
            }
        }
    }


    if(pCalibFilter != NULL && pCalibFilter->getEnabled() == true)
    {
        if(pData != NULL)
            pData->setCalibFilter(pCalibFilter);
            
        bFilterActive = true;
        partMode      = RenderPartition::SimpleCallback;
    }
    else
    {
        if(pData != NULL)
            pData->setCalibFilter(NULL);
    }

    if(pColFilter               != NULL &&
       pColFilter->getEnabled() == true  )
    {
        if(pData != NULL)
            pData->setColFilter(pColFilter);
        
        bFilterActive = true;
    }
    else
    {
        if(pData != NULL)
        {
            pData->setColFilter(NULL);
            
            ColorDisplayFilter::deactivate(pData);
        }
    }        
    if(pDistFilter               != NULL &&
       pDistFilter->getEnabled() == true  )
    {
        if(pData != NULL)
            pData->setDistFilter(pDistFilter);

        bFilterActive = true;
    }
    else
    {
        if(pData != NULL)
            pData->setDistFilter(NULL);
    }

    
    UInt32 uiTargetWidth  = oEnv.getPixelWidth ();
    UInt32 uiTargetHeight = oEnv.getPixelHeight();

    Int32 iLeft   = oEnv.getPixelLeft  ();
    Int32 iRight  = oEnv.getPixelRight ();
    Int32 iBottom = oEnv.getPixelBottom();
    Int32 iTop    = oEnv.getPixelTop   ();

    if(pResFilter               != NULL &&
       pResFilter->getEnabled() == true  )
    {
        bFilterActive = true;
        
        uiTargetWidth  = UInt32(uiTargetWidth  * pResFilter->getDownScale());
        uiTargetHeight = UInt32(uiTargetHeight * pResFilter->getDownScale());

        iLeft   = Int32(iLeft   * pResFilter->getDownScale());
        iRight  = Int32(iRight  * pResFilter->getDownScale());
        iBottom = Int32(iBottom * pResFilter->getDownScale());
        iTop    = Int32(iTop    * pResFilter->getDownScale());
        
    }

    if(pData == NULL)
    {
        pData = setupStageData(uiTargetWidth,
                               uiTargetHeight);

        if(pData == NULL)
            return Action::Continue;

        this->setData(pData, _iDataSlotId, ract);

        pData->setColFilter  (pColFilter  );
        pData->setDistFilter (pDistFilter );
        pData->setCalibFilter(pCalibFilter);
    }


    if((pData->getWidth () != uiTargetWidth ) ||
       (pData->getHeight() != uiTargetHeight)  )
    {
        resizeStageData(pData, uiTargetWidth, uiTargetHeight);
    }

   


    if(bFilterActive == false)
        return Action::Continue;

    ract->disableDefaultPartition();

    this->beginPartitionGroup(ract);
    {
        this->pushPartition(ract, 0x0000, partMode);
        {
            RenderPartition   *pPart    = ract ->getActivePartition();
            FrameBufferObject *pTarget  = pData->getTarget();
            Viewarea          *pArea    = ract ->getViewarea();
            Camera            *pCam     = ract ->getCamera  ();
            Background        *pBack    = ract ->getBackground();
            

            pPart->setRenderTarget(pTarget);
            
            if(pArea != NULL)
            {
                pPart->setWindow(ract->getWindow());
                
                if(pTarget != NULL)
                {
                    pPart->calcViewportDimension(iLeft  ,
                                                 iBottom,
                                                 iRight ,
                                                 iTop   ,
                                                 
                                                 pTarget->getWidth    (),
                                                 pTarget->getHeight   ());
                }
                else
                {
                    pPart->calcViewportDimension(
                        pArea->getLeft  (),
                        pArea->getBottom(),
                        pArea->getRight (),
                        pArea->getTop   (),
                        
                        ract->getWindow()->getWidth (),
                        ract->getWindow()->getHeight());
                }
                
                if(pCam != NULL)
                {
                    Matrix m, t;
                    
                    // set the projection
                    pCam->getProjection          (m, 
                                                  pPart->getViewportWidth (), 
                                                  pPart->getViewportHeight());
                    
                    pCam->getProjectionTranslation(t, 
                                                   pPart->getViewportWidth (), 
                                                   pPart->getViewportHeight());
                    
                    pPart->setupProjection(m, t);
                    
                    pCam->getViewing(m, 
                                     pPart->getViewportWidth (),
                                     pPart->getViewportHeight());
                    
                    
                    pPart->setupViewing(m);
                    
                    pPart->setNear     (pCam->getNear());
                    pPart->setFar      (pCam->getFar ());
                    
                    pPart->calcFrustum();
                }
                
                pPart->setBackground(pBack);
            }

            if(pCalibFilter != NULL && pCalibFilter->getEnabled() == true)
            {
                RenderPartition::SimpleDrawCallback f;

                if(bDoDraw == true)
                {
                    f = boost::bind(&DisplayFilterStage::processCalibActive, 
                                    this, _1);
                }
                else
                {
                    f = boost::bind(&DisplayFilterStage::processCalibInactive, 
                                    this, _1);
                }

                pPart->dropFunctor(f);
            }
            else
            {
                MFForegroundsType::const_iterator fIt = 
                    this->getMFForegrounds()->begin();
                MFForegroundsType::const_iterator fEnd = 
                    this->getMFForegrounds()->end  ();

                for(; fIt != fEnd; ++fIt)
                {
                    pPart->pushToForegrounds(*fIt);
                }

                this->recurseFromThis(ract);
            }
        }
        this->popPartition(ract);
        
        this->pushPartition(ract,
                            (RenderPartition::CopyWindow      |
                             RenderPartition::CopyViewportSize),
                            RenderPartition::SimpleCallback);
        {
            RenderPartition *pPart  = ract->getActivePartition();

            Matrix m, t;
                
            m.setIdentity();
            t.setIdentity();
                
            MatrixOrthogonal( m,
                              0.f, 1.f,
                              0.f, 1.f,
                             -1.f, 1.f);
            
            pPart->setupProjection(m, t);
                
            RenderPartition::SimpleDrawCallback f;
                
            f = boost::bind(&DisplayFilterStage::postProcess, this, _1);
                
            pPart->dropFunctor(f);
        }
        this->popPartition(ract);
    }
    this->endPartitionGroup(ract);

    return Action::Skip;
}