void DeferredShadingStage::scheduleShadingPass(RenderAction *ract)
{
#if 0
    RenderPartition *parentPart = ract->getActivePartition    (            );
#endif
    DSStageData     *data       = ract->getData<DSStageData *>(_iDataSlotId);

    this->pushPartition(ract,
                        (RenderPartition::CopyWindow      |
                         RenderPartition::CopyViewportSize) );
    {
        RenderPartition *part = ract->getActivePartition();

#ifdef OSG_DEBUG
        part->setDebugString("DeferredShadingStage::ShadingPartition");
#endif
        setupShadingPartition(part, ract, data);

        RenderPartition::DrawFunctor f =
            boost::bind(&DeferredShadingStage::executeShadingPass, this, _1);

        DSStageData::MFShadingStatesType::const_iterator sIt  =
            data->getMFShadingStates()->begin();
        DSStageData::MFShadingStatesType::const_iterator sEnd =
            data->getMFShadingStates()->end();

        for(UInt32 i = 0; sIt != sEnd; ++sIt, ++i)
        {
            if((i > 0) &&  (getLights(i-1)->getOn() == false))
                continue;
          
            part->dropFunctor(f, *sIt, (*sIt)->getSortKey());
        }
    }
    this->popPartition(ract);
}
ActionBase::ResultE TestMultiPartitionStage::renderEnter(Action *action)
{
#ifdef OSG_DUMP_TRAVERSAL
    FDEBUG_GV(("Enter TestMultiPartStage %p\n", &(*pCore)));
#endif

    RenderAction *a = dynamic_cast<RenderAction *>(action);

#ifdef OSG_DEBUGX
    if(this != NULL && this->getMessage().size() != 0)
    {
        fprintf(stderr, "StartEnter MPTS %s\n",
                this->getMessage().c_str());
    }
#endif

    TraversalValidator::ValidationStatus eStatus = this->validateOnEnter(a);

    if(eStatus == TraversalValidator::Run)
    {
        if(this->getUseGroup() == true)
        {
            this->beginPartitionGroup(a);
        }
        else
        {
            this->beginPartitions(a);
        }

        for(Int32 i = 0; i < this->getNumPartitions(); ++i)
        {
            this->pushPartition(a);
            {
#ifdef OSG_DEBUG
                RenderPartition *pPart  = a->getActivePartition();
            
                if(this != NULL && this->getMessage().size() != 0)
                {
                    char szNum[16];
                    
                    std::string szMessage = this->getMessage();
                    
                    sprintf(szNum, "%d", i);
                    
                    szMessage += " | Partition ";
                    szMessage += szNum;
                    
                    pPart->setDebugString(szMessage);
                }
#endif

                this->recurseFromThis(a);
            }
            this->popPartition(a);
        }
        
        if(this->getUseGroup() == true)
        {
            this->endPartitionGroup(a);
        }
        else
        {
            this->endPartitions(a);
        }
    }

#ifdef OSG_DEBUGX
    if(this != NULL && this->getMessage().size() != 0)
    {
        fprintf(stderr, "FinishedEnter MPTS %s\n",
                this->getMessage().c_str());
    }
#endif

    return ActionBase::Continue;
}
Exemplo n.º 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::scheduleGBufferPass(RenderAction *ract)
{
#if 0
    RenderPartition    *parentPart  = ract->getActivePartition();
#endif
    DSStageData        *data        = ract->getData<DSStageData *>(_iDataSlotId);
    ShaderProgramChunk *shader      = this->getGBufferProgram();
#if 0
    UInt32              bufferCount = osgMin(getMFPixelFormats()->size(),
                                             getMFPixelTypes  ()->size() );
#endif

    // create shadow maps
    MFLightsType::const_iterator lIt         = _mfLights.begin();
    MFLightsType::const_iterator lEnd        = _mfLights.end  ();

    for(UInt32 i = 0; lIt != lEnd; ++lIt, ++i)
    {
        (*lIt)->callLightEngineEnter(ract);

        ShaderProgramChunk    *spc   = data->getShadingProgramChunks(1+i);
        State                 *state = data->getShadingStates       (1+i);
        ShaderShadowMapEngine *sme   = dynamic_cast<ShaderShadowMapEngine *>(
            (*lIt)->getLightEngine());

        if(sme != NULL)
        {
//             ShaderProgram *shadowVP = sme->getShadowVertexProgram  ();
            ShaderProgram *shadowFP = sme->getShadowFragmentProgram();

//             if(shadowVP                                      != NULL &&
//                spc->getMFVertexShader()->findIndex(shadowVP) == -1     )
//             {
//                 spc->addShader(shadowVP);
//             }

            if(shadowFP                                        != NULL &&
               spc->getMFFragmentShader()->findIndex(shadowFP) == -1     )
            {
                spc->addShader(shadowFP);
            }

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

            if(sme->getEnabled() == true)
            {
                state->addChunk(sme->getShadowTexChunk(),
                                shadowTexUnit            );
            }
            else
            {
                state->subChunk(TextureObjChunk::getStaticClassId(),
                                shadowTexUnit                       );
            }
        }
    }

    this->pushPartition(ract);
    {
        RenderPartition *part = ract->getActivePartition();

#ifdef OSG_DEBUG
        part->setDebugString("DeferredShadingStage::GBufferPartition");
#endif
        setupGBufferPartition(part, ract, data);

        if(shader != NULL)
        {
            part->pushState  (                            );
            part->addOverride(shader->getClassId(), shader);
        }

        this->recurseFromThis(ract);

        if(shader != NULL)
            part->popState();
    }
    this->popPartition(ract);

    // create shadow maps
    lIt  = _mfLights.begin();
    lEnd = _mfLights.end  ();

    for(; lIt != lEnd; ++lIt)
    {
        (*lIt)->callLightEngineLeave(ract);
    }
}
Exemplo n.º 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;
}
ActionBase::ResultE CubeMapGenerator::renderEnter(Action *action)
{
    static Matrix transforms[] = 
    { 
        Matrix( 1,  0,  0,  0,
                0, -1,  0,  0,
                0,  0, -1,  0,
                0,  0,  0,  1),
        
        Matrix(-1,  0,  0,  0,
                0, -1,  0,  0,
                0,  0,  1,  0,
                0,  0,  0,  1),
        
        Matrix( 1,  0,  0,  0,
                0,  0, -1,  0,
                0,  1,  0,  0,
                0,  0,  0,  1),
        
        Matrix( 1,  0,  0,  0,
                0,  0,  1,  0,
                0, -1,  0,  0,
                0,  0,  0,  1),
        
        Matrix( 0,  0, -1,  0,
                0, -1,  0,  0,
               -1,  0,  0,  0,
                0,  0,  0,  1),
        
        Matrix( 0,  0,  1,  0,
                0, -1,  0,  0,
                1,  0,  0,  0,
                0,  0,  0,  1)
    };

    RenderAction *a = dynamic_cast<RenderAction *>(action);

    Action::ResultE  returnValue = Action::Continue;

    Background      *pBack    = a->getBackground();

    Viewport        *pPort    = a->getViewport();

    Node            *pActNode = a->getActNode();

    CubeMapGeneratorStageData *pData = 
        a->getData<CubeMapGeneratorStageData *>(_iDataSlotId);

    if(pData == NULL)
    {
        pData = this->initData(a);
    }

    TraversalValidator::ValidationStatus eStatus = this->validateOnEnter(a);

    if(eStatus == TraversalValidator::Run)
    {
        this->beginPartitionGroup(a);
        {
            FrameBufferObject *pTarget  = this->getRenderTarget();
                
            if(pTarget == NULL)
            {
                pTarget  = pData->getRenderTarget();
            }

            Pnt3f oOrigin;

            if(this->getOriginMode() == CubeMapGenerator::UseStoredValue)
            {
                oOrigin = this->getOrigin();
            }
            else if(this->getOriginMode() == CubeMapGenerator::UseBeacon)
            {
                fprintf(stderr, "CubemapGen::UseBeacon NYI\n");
            }
            else if(this->getOriginMode() == 
                                       CubeMapGenerator::UseCurrentVolumeCenter)
            {
                BoxVolume oWorldVol;

                commitChanges();

                pActNode->updateVolume();
                
                pActNode->getWorldVolume(oWorldVol);
                
                oWorldVol.getCenter(oOrigin);
            }
            else if(this->getOriginMode() == 
                                       CubeMapGenerator::UseParentsVolumeCenter)
            {
                fprintf(stderr, "CubemapGen::UseParentsCenter NYI\n");
            }

            Camera *pCam = pData->getCamera();

            pActNode->setTravMask(0);

            for(UInt32 i = 0; i < 6; ++i)
            {
                this->pushPartition(a);
                {
                    RenderPartition   *pPart    = a->getActivePartition();
                
                    pPart->setVolumeDrawing(false);

                    pPart->setRenderTarget(pTarget       );
                    pPart->setWindow      (a->getWindow());

                    pPart->calcViewportDimension(0,
                                                 0,
                                                 1,
                                                 1,
                                                 this->getWidth (),
                                                 this->getHeight());
                
                    Matrix m, t;
            
                    // set the projection
                    pCam->getProjection          (m, 
                                                  pPart->getViewportWidth (), 
                                                  pPart->getViewportHeight());
                
                    pCam->getProjectionTranslation(t, 
                                                   pPart->getViewportWidth (), 
                                                   pPart->getViewportHeight());
                
                    pPart->setupProjection(m, t);
            
                    m = transforms[i];
            
                    m[3][0] = oOrigin[0];
                    m[3][1] = oOrigin[1];
                    m[3][2] = oOrigin[2];

                    m.invert();

                    pPart->setupViewing(m);
            
                    pPart->setNear     (pCam->getNear());
                    pPart->setFar      (pCam->getFar ());
                    
                    pPart->calcFrustum();
                
                    if(this->getBackground() == NULL)
                    {
                        pPart->setBackground(pBack);
                    }
                    else
                    {
                        pPart->setBackground(this->getBackground());
                    }
                
                    if(this->getRoot() != NULL)
                    {
                        this->recurse(a, this->getRoot());
                    }
                    else
                    {
                        this->recurse(a, pPort->getRoot());
                    }

                    pPart->setDrawBuffer(GL_COLOR_ATTACHMENT0_EXT + i);

#ifdef OSG_DEBUGX
                    std::string szMessage("CubeX\n");
                    pPart->setDebugString(szMessage          );
#endif
                }
                this->popPartition(a);
            }

            pActNode->setTravMask(~0);
        }
        this->endPartitionGroup(a);
    }

    OSG_ASSERT(pActNode == a->getActNode());

    returnValue = Inherited::renderEnter(action);

    action->useNodeList(false);

    return returnValue;
}