コード例 #1
0
PostShaderStage::RenderPassData::RenderPassData(
    const std::string         &       szVertexProgram,
    const std::string         &       szFragmentProgram,
          bool                        isLastPass,
          UInt32                      uiIndex,
          Int32                       iPixelWidth,
          Int32                       iPixelHeight,
          PostShaderStageData *       pStageData,
    const Vec2f               &       vFBOSize,
          TextureObjChunk     * const pSceneColorTex,
          TextureObjChunk     * const pSceneDepthTex,
    const RenderPassVector    &       vPasses,
          FrameBufferObject   * const pSceneFBO) : 

    _pShader                (NULL      ),
    _pFBO                   (NULL      ),
    _pOutputTexture         (NULL      ),
    _bIsLassPass            (isLastPass),
    _uiIndex                (uiIndex   ),
    _vFBOSize               (vFBOSize  ),
    _vWidthRefs             (          ),
    _vHeightRefs            (          ),

    _bShaderHasSceneColorTex(false     ),
    _bShaderHasSceneDepthTex(false     ),
    _bShaderHasFBOWidth     (false     ),
    _bShaderHasFBOHeight    (false     ),
    _bShaderHasCameraNear   (false     ),
    _bShaderHasCameraFar    (false     )
{
    //If this pass is not the last
    if(!_bIsLassPass)
    {
        _pFBO = FrameBufferObject::createLocal();

        _pOutputTexture                  = TextureObjChunk::createLocal();
        TextureEnvChunkUnrecPtr pTexEnv  = TextureEnvChunk::createLocal();
        ImageUnrecPtr           pImg     = Image          ::createLocal();
        
        pImg->set(Image::OSG_RGB_PF, 
                  static_cast<Real32>(iPixelWidth)  * _vFBOSize.x() , 
                  static_cast<Real32>(iPixelHeight) * _vFBOSize.y(),
                  1,
                  1,
                  1,
                  0.0,
                  0,
                  Image::OSG_UINT8_IMAGEDATA,
                  false);
        
        _pOutputTexture   ->setImage         (pImg             ); 
        _pOutputTexture   ->setMinFilter     (GL_LINEAR        );
        _pOutputTexture   ->setMagFilter     (GL_LINEAR        );
        _pOutputTexture   ->setWrapS         (GL_CLAMP_TO_EDGE );
        _pOutputTexture   ->setWrapT         (GL_CLAMP_TO_EDGE );
        _pOutputTexture   ->setInternalFormat(GL_RGB           );

        pTexEnv->setEnvMode       (GL_REPLACE       );
        
        TextureBufferUnrecPtr pTexBuffer   = TextureBuffer::createLocal();
        
        pTexBuffer->setTexture(_pOutputTexture);
        
        _pFBO->setSize(static_cast<Real32>(iPixelWidth)  * _vFBOSize.x(),
                       static_cast<Real32>(iPixelHeight) * _vFBOSize.y());
        _pFBO->setColorAttachment(pTexBuffer, 0);
        _pFBO->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT);

        pStageData->pushToRenderTargets(_pFBO);

        OSG_ASSERT(pStageData->getMFRenderTargets()->size() == _uiIndex + 1);
    }
    else
    {
        _pFBO = pSceneFBO;
    }

    //Update the flags on what uniforms are present
    _bShaderHasSceneColorTex = 
        ((szFragmentProgram.find(
              PostShaderStage::ShaderSceneColorTexName) != std::string::npos) ||
         (szVertexProgram  .find(
              PostShaderStage::ShaderSceneColorTexName) != std::string::npos));

    _bShaderHasSceneDepthTex = 
        ((szFragmentProgram.find(
              PostShaderStage::ShaderSceneDepthTexName) != std::string::npos) ||
         (szVertexProgram  .find(
              PostShaderStage::ShaderSceneDepthTexName) != std::string::npos));

    _bShaderHasFBOWidth = 
        ((szFragmentProgram.find(
              PostShaderStage::ShaderFBOWidthName) != std::string::npos) ||
         (szVertexProgram  .find(
              PostShaderStage::ShaderFBOWidthName) != std::string::npos));

    _bShaderHasFBOHeight = 
        ((szFragmentProgram.find(
              PostShaderStage::ShaderFBOHeightName) != std::string::npos) ||
         (szVertexProgram  .find(
              PostShaderStage::ShaderFBOHeightName) != std::string::npos));

    _bShaderHasCameraNear = 
        ((szFragmentProgram.find(
              PostShaderStage::ShaderCameraNearName) != std::string::npos) ||
         (szVertexProgram  .find(
              PostShaderStage::ShaderCameraNearName) != std::string::npos));

    _bShaderHasCameraFar = 
        ((szFragmentProgram.find(
              PostShaderStage::ShaderCameraFarName) != std::string::npos) ||
         (szVertexProgram  .find(
              PostShaderStage::ShaderCameraFarName) != std::string::npos));

    //Create the material used by this pass
    ChunkMaterialUnrecPtr pPostShaderMat = ChunkMaterial::createLocal();

    UInt16 uiTextureId = 0;

    _pShader = SimpleSHLChunk::createLocal();

    TextureEnvChunkUnrecPtr pGenericTexEnv  = TextureEnvChunk::createLocal();

    pGenericTexEnv->setEnvMode(GL_REPLACE);

    //Scene Color Texture
    if(_bShaderHasSceneColorTex)
    {
         pPostShaderMat->addChunk(pSceneColorTex,  uiTextureId);
         pPostShaderMat->addChunk(pGenericTexEnv,  uiTextureId);

        _pShader->addUniformVariable(
            PostShaderStage::ShaderSceneColorTexName.c_str(), uiTextureId);

        ++uiTextureId;
    }
    //Scene Depth Texture
    if(_bShaderHasSceneDepthTex)
    {
         pPostShaderMat->addChunk(pSceneDepthTex, uiTextureId);
         pPostShaderMat->addChunk(pGenericTexEnv, uiTextureId);

        _pShader->addUniformVariable(
            PostShaderStage::ShaderSceneDepthTexName.c_str(), uiTextureId);

        ++uiTextureId;
    }

    _vHeightRefs.clear();
    _vWidthRefs .clear();

    //Preceding passes variables
    std::string szVariableName;

    RenderPassVector::const_iterator passIt = vPasses.begin();

    for(; passIt != vPasses.end(); ++passIt)
    {
        szVariableName = (*passIt)->getOutputTextureName();

        if((szFragmentProgram.find(szVariableName) != std::string::npos) ||
           (szVertexProgram  .find(szVariableName) != std::string::npos)  )
        {
             pPostShaderMat->addChunk((*passIt)->getOutputTexture(), 
                                      uiTextureId);

             pPostShaderMat->addChunk(pGenericTexEnv, uiTextureId);

            _pShader->addUniformVariable(szVariableName.c_str(), uiTextureId);

            ++uiTextureId;
        }

        szVariableName = (*passIt)->getWidthName();

        if((szFragmentProgram.find(szVariableName) != std::string::npos) ||
           (szVertexProgram  .find(szVariableName) != std::string::npos)  )
        {
            _pShader->addUniformVariable<Real32>(
                szVariableName.c_str(),
                (*passIt)->getOutputTexture()->getImage()->getWidth());

            _vWidthRefs.push_back((*passIt)->getIndex());
        }

        szVariableName = (*passIt)->getHeightName();

        if((szFragmentProgram.find(szVariableName) != std::string::npos) ||
           (szVertexProgram  .find(szVariableName) != std::string::npos)  )
        {
            _pShader->addUniformVariable<Real32>(
                szVariableName.c_str(),
                (*passIt)->getOutputTexture()->getImage()->getHeight());

            _vHeightRefs.push_back((*passIt)->getIndex());
        }
    }

    MaterialChunkUnrecPtr pMatChunk = MaterialChunk::createLocal();

    pMatChunk     ->setLit(false);
    pPostShaderMat->addChunk(pMatChunk);

    _pShader->setVertexProgram  (szVertexProgram);
    _pShader->setFragmentProgram(szFragmentProgram);
    
    //Add the uniform parameters
    _pShader->addUniformVariable(ShaderFBOWidthName  .c_str(), 0.0f);
    _pShader->addUniformVariable(ShaderFBOHeightName .c_str(), 0.0f);
    _pShader->addUniformVariable(ShaderCameraNearName.c_str(), 0.0f);
    _pShader->addUniformVariable(ShaderCameraFarName .c_str(), 1.0f);
    
    pPostShaderMat->addChunk(_pShader, 0);
    
    pStageData->pushToShaderMaterials(pPostShaderMat);

    OSG_ASSERT(pStageData->getMFShaderMaterials()->size() == _uiIndex + 1);
}
コード例 #2
0
PostShaderStageDataTransitPtr 
    PostShaderStage::setupStageData(Int32 iPixelWidth,
                                    Int32 iPixelHeight)
{
    PostShaderStageDataTransitPtr returnValue = 
        PostShaderStageData::createLocal();

    if(returnValue == NULL)
        return returnValue;

    OSG::Thread::setCurrentLocalFlags();

    // Scene Target
    FrameBufferObjectUnrecPtr pSceneFBO = FrameBufferObject::createLocal();
        
    //Depth texture
                            _pSceneDepthTex    = TextureObjChunk::createLocal();
    TextureEnvChunkUnrecPtr  pSceneDepthTexEnv = TextureEnvChunk::createLocal();
    ImageUnrecPtr            pDepthImg         = Image          ::createLocal();

    pDepthImg->set(Image::OSG_L_PF, 
                   iPixelWidth, 
                   iPixelHeight,
                   1,
                   1,
                   1,
                   0.0,
                   NULL,
                   Image::OSG_UINT8_IMAGEDATA,
                   false);

    _pSceneDepthTex  ->setImage         (pDepthImg         ); 
    _pSceneDepthTex  ->setMinFilter     (GL_LINEAR         );
    _pSceneDepthTex  ->setMagFilter     (GL_LINEAR         );
    _pSceneDepthTex  ->setWrapS         (GL_CLAMP_TO_EDGE  );
    _pSceneDepthTex  ->setWrapT         (GL_CLAMP_TO_EDGE  );
    _pSceneDepthTex  ->setInternalFormat(GL_DEPTH_COMPONENT);
    _pSceneDepthTex  ->setExternalFormat(GL_DEPTH_COMPONENT);

    pSceneDepthTexEnv->setEnvMode       (GL_REPLACE        );
    
    TextureBufferUnrecPtr pDepthBuffer = TextureBuffer::createLocal();
    //pDepthBuffer->setInternalFormat(GL_DEPTH_COMPONENT24   );
    
    pDepthBuffer->setTexture(_pSceneDepthTex);

        
    //Color Buffer
                            _pSceneTex     = TextureObjChunk::createLocal();
    TextureEnvChunkUnrecPtr  pSceneTexEnv  = TextureEnvChunk::createLocal();
    ImageUnrecPtr            pImg          = Image          ::createLocal();
    
    pImg->set(Image::OSG_RGB_PF, 
              iPixelWidth, 
              iPixelHeight,
              1,
              1,
              1,
              0.0,
              0,
              Image::OSG_UINT8_IMAGEDATA,
              false);
    
    _pSceneTex  ->setImage         (pImg                  ); 
    _pSceneTex  ->setMinFilter     (GL_LINEAR             );
    _pSceneTex  ->setMagFilter     (GL_LINEAR             );
    _pSceneTex  ->setWrapS         (GL_CLAMP_TO_EDGE      );
    _pSceneTex  ->setWrapT         (GL_CLAMP_TO_EDGE      );
    _pSceneTex  ->setInternalFormat(getColorBufferFormat());

    pSceneTexEnv->setEnvMode       (GL_REPLACE            );
    
    TextureBufferUnrecPtr pSceneTexBuffer   = TextureBuffer::createLocal();
    
    pSceneTexBuffer->setTexture(_pSceneTex);
    

    
    pSceneFBO->setSize(iPixelWidth, iPixelHeight);
    
    pSceneFBO->setColorAttachment(pSceneTexBuffer, 0);
    pSceneFBO->setDepthAttachment(pDepthBuffer      );
    
    pSceneFBO->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT);
    
    setRenderTarget(pSceneFBO);
    
    // general mat chunk

    //Init all of the render passes
    _vPostProcessPasses.clear();

    UInt32 NumPasses = getNumPasses();

    for(UInt32 i =0; i != NumPasses ; ++i)
    {
        _vPostProcessPasses.push_back(
            RenderPassData::create( getVertexShaders(i),
                                    getFragmentShaders(i),
                                    (i == NumPasses-1),
                                    i,
                                    iPixelWidth,
                                    iPixelHeight,
                                    returnValue.get(),
                                    getPassSizes(i),
                                   _pSceneTex,
                                   _pSceneDepthTex,
                                   _vPostProcessPasses,
                                    pSceneFBO));
    }
    
    OSG::Thread::resetCurrentLocalFlags();

    Thread::getCurrentChangeList()->commitChanges();

    return returnValue;
}
コード例 #3
0
static Action::ResultE modifyMaterial(Node * const node)
{   
    MaterialGroup *mg = dynamic_cast<MaterialGroup *>(node->getCore());
    
    if(mg == NULL)
        return Action::Continue; 
    
    ChunkMaterial *cmat = dynamic_cast<ChunkMaterial *>(mg->getMaterial());
    
    if(cmat == NULL)
        return Action::Continue; 
    
    TextureObjChunk *texc = 
        dynamic_cast<TextureObjChunk *>(
            cmat->find(TextureObjChunk::getClassType()));
    
    if(texc == NULL)
        return Action::Continue;
    
    MaterialChunk *matc = 
        dynamic_cast<MaterialChunk *>(
            cmat->find(MaterialChunk::getClassType()));

    TextureEnvChunkUnrecPtr texe = 
        dynamic_cast<TextureEnvChunk *>(
            cmat->find(TextureEnvChunk::getClassType()));
    
    if(texe == NULL)
    {
        texe = TextureEnvChunk::create();
        cmat->addChunk(texe);
    }

    if(matc == NULL)
    {
        // no material chunk so we use the replace mode.
        texe->setEnvMode(GL_REPLACE);
        return Action::Continue;
    }
    
    if(matc != NULL)
    {
        Image *img = texc->getImage();

        texe->setEnvMode(GL_MODULATE);

        if(img != NULL && img->getBpp() > 2)
        {
            // for color textures the texture replaces only the diffuse part.
            matc->setDiffuse(Color4f(1.0f, 1.0f, 1.0f, 1.0f));
        }
        
        
        // check for textures with alpha
        if(!matc->isTransparent()         && 
            img                   != NULL &&
            img->getBpp()         ==    4   )
        {
            BlendChunkUnrecPtr blendc = 
                dynamic_cast<BlendChunk *>(
                    cmat->find(BlendChunk::getClassType()));

            if(blendc == NULL)
            {
                blendc = OSG::BlendChunk::create();

                blendc->setSrcFactor (GL_SRC_ALPHA);
                blendc->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
    
                cmat->addChunk(blendc);
            }
        }
    }

    return Action::Continue;
}
コード例 #4
0
HDRStageDataTransitPtr HDRStage::setupStageData(Int32 iPixelWidth,
                                                Int32 iPixelHeight)
{
    HDRStageDataTransitPtr returnValue = HDRStageData::createLocal();

    if(returnValue == NULL)
        return returnValue;

    OSG::Thread::setCurrentLocalFlags();

    // Scene Target

    FrameBufferObjectUnrecPtr pSceneFBO    = FrameBufferObject::createLocal();

    RenderBufferUnrecPtr      pDepthBuffer = RenderBuffer     ::createLocal();

    pDepthBuffer->setInternalFormat(GL_DEPTH_COMPONENT24   );

        
    TextureObjChunkUnrecPtr pSceneTex     = TextureObjChunk::createLocal();
    TextureEnvChunkUnrecPtr pSceneTexEnv  = TextureEnvChunk::createLocal();
    ImageUnrecPtr           pImg          = Image          ::createLocal();
    
    pImg->set(Image::OSG_RGB_PF, 
              iPixelWidth, 
              iPixelHeight,
              1,
              1,
              1,
              0.0,
              0,
              Image::OSG_FLOAT32_IMAGEDATA,
              false);
    
    pSceneTex   ->setImage         (pImg             ); 
    pSceneTex   ->setMinFilter     (GL_LINEAR        );
    pSceneTex   ->setMagFilter     (GL_LINEAR        );
    pSceneTex   ->setWrapS         (GL_CLAMP_TO_EDGE );
    pSceneTex   ->setWrapT         (GL_CLAMP_TO_EDGE );
    pSceneTex   ->setInternalFormat(getBufferFormat());

    pSceneTexEnv->setEnvMode       (GL_REPLACE       );
    
    TextureBufferUnrecPtr pSceneTexBuffer   = TextureBuffer::createLocal();
    
    pSceneTexBuffer->setTexture(pSceneTex);
    

    
    pSceneFBO->setSize(iPixelWidth, iPixelHeight);
    
    pSceneFBO->setColorAttachment(pSceneTexBuffer, 0);
    pSceneFBO->setDepthAttachment(pDepthBuffer      );
    
    pSceneFBO->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT);
    
    setRenderTarget(pSceneFBO);
    



    // Shrink Target (w/2, h/2)

    FrameBufferObjectUnrecPtr pShrinkFBO     = FrameBufferObject::createLocal();

    TextureObjChunkUnrecPtr   pShrinkTex     = TextureObjChunk::createLocal();
    TextureEnvChunkUnrecPtr   pShrinkTexEnv  = TextureEnvChunk::createLocal();
                              pImg           = Image          ::createLocal();
    
    pImg->set(Image::OSG_RGB_PF, 
              iPixelWidth  / 2, 
              iPixelHeight / 2,
              1,
              1,
              1,
              0.0,
              0,
              Image::OSG_FLOAT32_IMAGEDATA,
              false);
    
    pShrinkTex   ->setImage         (pImg             ); 
    pShrinkTex   ->setMinFilter     (GL_LINEAR        );
    pShrinkTex   ->setMagFilter     (GL_LINEAR        );
    pShrinkTex   ->setWrapS         (GL_CLAMP_TO_EDGE );
    pShrinkTex   ->setWrapT         (GL_CLAMP_TO_EDGE );
    pShrinkTex   ->setInternalFormat(getBufferFormat());

    pShrinkTexEnv->setEnvMode       (GL_REPLACE       );
    
    TextureBufferUnrecPtr pShrinkTexBuffer   = TextureBuffer::createLocal();
    
    pShrinkTexBuffer->setTexture(pShrinkTex);
    

    
    pShrinkFBO->setSize(iPixelWidth / 2, iPixelHeight / 2);
    
    pShrinkFBO->setColorAttachment(pShrinkTexBuffer, 0);
    
    pShrinkFBO->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT);
    
    returnValue->setShrinkRenderTarget(pShrinkFBO);





    // blur (w/4, h/4)


    FrameBufferObjectUnrecPtr pBlurFBO     = FrameBufferObject::createLocal();

    TextureObjChunkUnrecPtr   pBlurTex1    = TextureObjChunk  ::createLocal();
    TextureEnvChunkUnrecPtr   pBlurTex1Env = TextureEnvChunk  ::createLocal();
    
    
    pImg = Image::createLocal();
    
    pImg->set(Image::OSG_RGB_PF, 
              iPixelWidth  / 4,
              iPixelHeight / 4,
              1,
              1,
              1,
              0.0,
              0,
              Image::OSG_FLOAT32_IMAGEDATA,
              false);
    
    pBlurTex1   ->setImage         (pImg             ); 
    pBlurTex1   ->setMinFilter     (GL_LINEAR        );
    pBlurTex1   ->setMagFilter     (GL_LINEAR        );
    pBlurTex1   ->setWrapS         (GL_CLAMP_TO_EDGE );
    pBlurTex1   ->setWrapT         (GL_CLAMP_TO_EDGE );
    pBlurTex1   ->setInternalFormat(getBufferFormat());

    pBlurTex1Env->setEnvMode       (GL_REPLACE       );
    
    TextureBufferUnrecPtr pBlurTexBuffer1 = TextureBuffer::createLocal();
    
    pBlurTexBuffer1->setTexture(pBlurTex1);
    
    
    
    TextureObjChunkUnrecPtr pBlurTex2    = TextureObjChunk::createLocal();
    TextureEnvChunkUnrecPtr pBlurTex2Env = TextureEnvChunk::createLocal();
    
    
    pImg = Image::createLocal();

    pImg->set(Image::OSG_RGB_PF, 
              iPixelWidth  / 4,
              iPixelHeight / 4,
              1,
              1,
              1,
              0.0,
              0,
              Image::OSG_FLOAT32_IMAGEDATA,
              false);
    
    pBlurTex2   ->setImage         (pImg             ); 
    pBlurTex2   ->setMinFilter     (GL_LINEAR        );
    pBlurTex2   ->setMagFilter     (GL_LINEAR        );
    pBlurTex2   ->setWrapS         (GL_CLAMP_TO_EDGE );
    pBlurTex2   ->setWrapT         (GL_CLAMP_TO_EDGE );
    pBlurTex2   ->setInternalFormat(getBufferFormat());

    pBlurTex2Env->setEnvMode       (GL_REPLACE       );
    
    TextureBufferUnrecPtr pBlurTexBuffer2 = TextureBuffer::createLocal();

    pBlurTexBuffer2->setTexture(pBlurTex2);


    pBlurFBO->setSize(iPixelWidth  / 4,
                      iPixelHeight / 4);
    
    pBlurFBO->setColorAttachment(pBlurTexBuffer1,  0);
    pBlurFBO->setColorAttachment(pBlurTexBuffer2,  1);
    
    returnValue->setBlurRenderTarget(pBlurFBO);


    // general mat chunk


    MaterialChunkUnrecPtr pMatChunk = MaterialChunk::createLocal();
        
    pMatChunk->setLit(false);




    // tone map material

    ChunkMaterialUnrecPtr    pTonemapMat  = ChunkMaterial  ::createLocal();
    
    pTonemapMat->addChunk(pMatChunk         );
    pTonemapMat->addChunk(pSceneTex,       0);
    pTonemapMat->addChunk(pSceneTexEnv,    0);
    pTonemapMat->addChunk(pBlurTex1,       1);
    pTonemapMat->addChunk(pBlurTex1Env,    1);

    SimpleSHLChunkUnrecPtr pTonemapShader = generateHDRFragmentProgram();
    
    pTonemapShader->addUniformVariable("sceneTex",     0);
    pTonemapShader->addUniformVariable("blurTex",      1);
    pTonemapShader->addUniformVariable("blurAmount",   getBlurAmount  ());
    pTonemapShader->addUniformVariable("exposure",     getExposure    ());
    pTonemapShader->addUniformVariable("effectAmount", getEffectAmount());
    pTonemapShader->addUniformVariable("gamma",        getGamma       ());
    
    pTonemapMat->addChunk(pTonemapShader, 0);
    
    returnValue->setToneMappingMaterial(pTonemapMat);




    // Shrink material

    ChunkMaterialUnrecPtr pShrinkMat = ChunkMaterial::createLocal();
    
    pShrinkMat->addChunk(pMatChunk   );
    
    pShrinkMat->addChunk(pSceneTex,     0);
    pShrinkMat->addChunk(pSceneTexEnv,  0);

    SimpleSHLChunkUnrecPtr pShrinkShader = generate2DShrinkHalfFilterFP();
        
    pShrinkShader->addUniformVariable("inputTex", 0);
    
    pShrinkMat->addChunk(pShrinkShader, 0);
    
    returnValue->setShrinkMaterial(pShrinkMat);




    // Blur material

    ChunkMaterialUnrecPtr pBlurMat = ChunkMaterial::createLocal();
    
    pBlurMat->addChunk(pMatChunk   );
    
    pBlurMat->addChunk(pShrinkTex,    0);
    pBlurMat->addChunk(pShrinkTexEnv, 0);
    pBlurMat->addChunk(pBlurTex1,     1);
    pBlurMat->addChunk(pBlurTex1Env,  1);
    pBlurMat->addChunk(pBlurTex2,     2);
    pBlurMat->addChunk(pBlurTex2Env,  2);

    pBlurMat->addChunk(pShrinkShader, 0);
    
    returnValue->setBlurMaterial(pBlurMat);


    // generate blur fragment programs
    SimpleSHLChunkUnrecPtr pHBlurShader = 
        generate1DConvolutionFilterFP(getBlurWidth(), 
                                      false, 
                                      true, 
                                      iPixelWidth  / 2, 
                                      iPixelHeight / 2);
    
   
    pHBlurShader->addUniformVariable("inputTex", 0);

    returnValue->setHBlurShader(pHBlurShader);

    
    
    // VBlur Override


    SimpleSHLChunkUnrecPtr pVBlurShader = 
        generate1DConvolutionFilterFP(getBlurWidth(),  
                                      true, 
                                      true, 
                                      iPixelWidth  / 2, 
                                      iPixelHeight / 2);
    
    pVBlurShader->addUniformVariable("inputTex", 1);
    
    returnValue->setVBlurShader(pVBlurShader);

    OSG::Thread::resetCurrentLocalFlags();

    Thread::getCurrentChangeList()->commitChanges();

    return returnValue;
}
コード例 #5
0
CubeMapGeneratorStageDataTransitPtr CubeMapGenerator::setupStageData(
    RenderActionBase *pAction)
{
    CubeMapGeneratorStageDataTransitPtr returnValue = 
        CubeMapGeneratorStageData::createLocal();
    
    if(returnValue == NULL)
        return returnValue;

    FrameBufferObjectUnrecPtr pCubeTarget  = NULL;
    RenderBufferUnrecPtr      pDepthBuffer = NULL;

    if(this->getRenderTarget() == NULL)
    {
        pCubeTarget  = FrameBufferObject::createLocal();
        pDepthBuffer = RenderBuffer     ::createLocal();

        pDepthBuffer->setInternalFormat (GL_DEPTH_COMPONENT24);

        pCubeTarget ->setDepthAttachment(pDepthBuffer        );

        returnValue ->setRenderTarget   (pCubeTarget         );
    }
    else
    {
        pCubeTarget = this->getRenderTarget();
    }

    TextureObjChunkUnrecPtr   pCubeTex     = NULL;

    if(0x0000 != (_sfSetupMode.getValue() & SetupTexture))
    {
        pCubeTex = TextureObjChunk::createLocal();

        ImageUnrecPtr pImg = Image::createLocal();
    
        pImg->set(Image::OSG_RGB_PF, 
                  getWidth (), 
                  getHeight(),
                  1,
                  1,
                  1,
                  0.0,
                  0,
                  Image::OSG_UINT8_IMAGEDATA,
                  false,
                  6);
        
        pCubeTex   ->setImage         (pImg              ); 
        pCubeTex   ->setMinFilter     (GL_LINEAR         );
        pCubeTex   ->setMagFilter     (GL_LINEAR         );
        pCubeTex   ->setWrapS         (GL_CLAMP_TO_EDGE  );
        pCubeTex   ->setWrapT         (GL_CLAMP_TO_EDGE  );
        pCubeTex   ->setWrapR         (GL_CLAMP_TO_EDGE  );
        pCubeTex   ->setInternalFormat(getTextureFormat());
    }
    else
    {
        pCubeTex = _sfTexture.getValue();
    }

    TextureEnvChunkUnrecPtr pCubeTexEnv  = NULL;

    if(0x0000 != (_sfSetupMode.getValue() & SetupTexEnv))
    {
        pCubeTexEnv = TextureEnvChunk::createLocal();
        
        pCubeTexEnv->setEnvMode       (GL_REPLACE       );
    }

    TexGenChunkUnrecPtr           pCubeTexGen   = NULL;
    TextureTransformChunkUnrecPtr pCubeTexTrans = NULL;

    if(0x0000 != (_sfSetupMode.getValue() & SetupTexGen))
    {
        pCubeTexGen = TexGenChunk::createLocal();

        pCubeTexGen->setGenFuncS(GL_REFLECTION_MAP);
        pCubeTexGen->setGenFuncT(GL_REFLECTION_MAP);
        pCubeTexGen->setGenFuncR(GL_REFLECTION_MAP);

        pCubeTexTrans = TextureTransformChunk::createLocal();

        pCubeTexTrans->setUseCameraBeacon(true);
    }


    static GLenum targets[6] = 
    {
        GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
        GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB,
        GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,
        GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
        GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
        GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
    };

    for(UInt32 i = 0; i < 6; ++i)
    {
        TextureBufferUnrecPtr pCubeTexBuffer = TextureBuffer::createLocal();
    
        pCubeTexBuffer->setTexture  (pCubeTex  );
        pCubeTexBuffer->setTexTarget(targets[i]);

        pCubeTarget->setColorAttachment(pCubeTexBuffer,    i);
    }

    pCubeTarget->setSize(getWidth (),
                         getHeight());

    if(0x0000 != (_sfSetupMode.getValue() & OverrideTex))
    {
        returnValue->addChunk(pCubeTex,
                              getTexUnit());
    }

    if(0x0000 != (_sfSetupMode.getValue() & SetupTexEnv))
    {
        returnValue->addChunk(pCubeTexEnv,
                              getTexUnit());
    }

    if(0x0000 != (_sfSetupMode.getValue() & SetupTexGen))
    {
        returnValue->addChunk(pCubeTexGen,
                              getTexUnit());
        returnValue->addChunk(pCubeTexTrans,
                              getTexUnit());

        returnValue->setTexTransform(pCubeTexTrans);
    }

    if(this->getCamera() == NULL)
    {
        PerspectiveCameraUnrecPtr pCam = PerspectiveCamera::createLocal();

        pCam->setNear(pAction->getCamera()->getNear());
        pCam->setFar (pAction->getCamera()->getFar ());
        
        pCam->setFov (osgDegree2Rad(90.f));

        returnValue->setCamera(pCam);
    }

    return returnValue;
}