コード例 #1
0
void ShaderShadowMapEngine::updateShadowTexBuffers(SSMEngineData *data)
{
    TextureObjChunk *bufTex = data->getShadowTexChunk();

    if(data->getMFShadowTexBuffers()->empty() == true)
    {
        TextureBufferUnrecPtr newBuf = TextureBuffer::createLocal();
        newBuf->setTexture  (bufTex       );
        newBuf->setTexTarget(GL_TEXTURE_2D);

        data->editMFShadowTexBuffers()->push_back(newBuf);
    }
}
コード例 #2
0
void ShaderShadowMapEngine::updatePointLightShadowTexBuffers(
    SSMEngineData *data)
{
    TextureObjChunk *bufTex = data->getShadowTexChunk();

    if(data->getMFShadowTexBuffers()->empty() == true)
    {
        for(UInt16 i = 0; i < 6; ++i)
        {
            TextureBufferUnrecPtr newBuf = TextureBuffer::createLocal();
            newBuf->setTexture  (bufTex             );
            newBuf->setTexTarget(_cubeFaceTargets[i]);

            data->editMFShadowTexBuffers()->push_back(newBuf);
        }
    }
}
コード例 #3
0
void VarianceShadowMapHandler::initShadowMaps(void)
{
    ShadowStageData::ShadowMapStore &vShadowMaps = _pStageData->getShadowMaps();

    const ShadowStageData::LightStore  &vLights  = _pStageData->getLights();


    if(vLights.size() < vShadowMaps.size())
    {
        vShadowMaps.resize(vLights.size());
    }
    else
    {
        Real32 maximumAnistropy;

        glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maximumAnistropy);

        maximumAnistropy = osgMin(maximumAnistropy, Real32(8.0));


        UInt32 uiLSize   =  vLights.size();
        UInt32 uiMapSize = _pStage-> getMapSize ();

        if(vShadowMaps.size() == 0) 
        {
            _uiMapSize = uiMapSize;
        }

        for(UInt32 i = vShadowMaps.size(); i < uiLSize; ++i)
        {
            ShadowStageData::ShadowMapElem tmpElem;

            tmpElem.uiType = ShadowStageData::ShadowMapElem::ColorShadowMap;

            tmpElem.pImage = Image            ::createLocal();
            tmpElem.pTexO  = TextureObjChunk  ::createLocal();
            tmpElem.pTexE  = TextureEnvChunk  ::createLocal();
            tmpElem.pFBO   = FrameBufferObject::createLocal();

            tmpElem.pImage->set(Image::OSG_RGBA_PF, 
                                uiMapSize, uiMapSize, 1,
                                1, 1, 0.f, 
                                NULL,
                                Image::OSG_FLOAT16_IMAGEDATA,
                                false);

            TextureBufferUnrecPtr pDepthTex = TextureBuffer::createLocal();

            pDepthTex->setTexture(tmpElem.pTexO);

            tmpElem.pFBO ->setColorAttachment(pDepthTex, 0);

            tmpElem.pTexO->setImage(tmpElem.pImage);

            tmpElem.pTexO->setInternalFormat(GL_RGBA16F_ARB);
            tmpElem.pTexO->setExternalFormat(GL_RGBA);

            tmpElem.pTexO->setMinFilter     (GL_LINEAR_MIPMAP_LINEAR);
            tmpElem.pTexO->setMagFilter     (GL_LINEAR              );

            tmpElem.pTexO->setAnisotropy    (maximumAnistropy       );

            tmpElem.pTexO->setWrapS         (GL_REPEAT              );
            tmpElem.pTexO->setWrapT         (GL_REPEAT              );

            tmpElem.pTexO->setTarget(GL_TEXTURE_2D);



            RenderBufferUnrecPtr pDepthRB = RenderBuffer::create();
            
            pDepthRB->setInternalFormat(GL_DEPTH_COMPONENT24);

            tmpElem.pFBO->setDepthAttachment(pDepthRB);

            tmpElem.pFBO->setSize(uiMapSize, uiMapSize);


            vShadowMaps.push_back(tmpElem);
        }
    }
}
コード例 #4
0
ファイル: dyndrawing1.cpp プロジェクト: jondo2010/OpenSG
FrameBufferObjectTransitPtr FBOBuilder::operator()(
    UInt32 width, 
    UInt32 height) const
{
    //
    // Setup the FBO
    //
    FrameBufferObjectUnrecPtr fbo = FrameBufferObject::create();
    //
    // multiple color buffers
    //
    for (UINT32 idx = 0; idx < _buffers.size(); ++idx) {
        //
        // use textures?
        //
        if (_buffers[idx].enable) {
            ImageUnrecPtr           texImg = (_buffers[idx].image  == nullptr ? Image::create()           : _buffers[idx].image);
            TextureObjChunkUnrecPtr texObj = (_buffers[idx].texObj == nullptr ? TextureObjChunk::create() : _buffers[idx].texObj);
            TextureBufferUnrecPtr   texBuf = TextureBuffer::create();

            if (_buffers[idx].image == nullptr)
                texImg->set(_buffers[idx].pixel_format, 
                            width, height, 1, 1, 1, 0.f, nullptr,
                            _buffers[idx].type, 
                            _buffers[idx].main_memory);

            texObj->setImage(texImg);
            texBuf->setTexture(texObj);

            fbo->setColorAttachment(texBuf, idx);
        } else 
        //
        // no, then use simple render buffer
        //
        {
            RenderBufferUnrecPtr renBuf = RenderBuffer::create();
            renBuf->setInternalFormat(_buffers[idx].pixel_format);
            fbo->setColorAttachment(renBuf, idx);
        }
        fbo->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT + idx);
    }
    //
    // a sole depth buffer
    //
    if (_depth && !_stencil) {
        //
        // use textures?
        //
        if (_ds_buffer.enable) {
            ImageUnrecPtr           texImg = (_ds_buffer.image  == nullptr ? Image::create()           : _ds_buffer.image);
            TextureObjChunkUnrecPtr texObj = (_ds_buffer.texObj == nullptr ? TextureObjChunk::create() : _ds_buffer.texObj);
            TextureBufferUnrecPtr   texBuf = TextureBuffer::create();

            if (_ds_buffer.image == nullptr)
                texImg->set(_ds_buffer.pixel_format, 
                            width, height, 1, 1, 1, 0.f, nullptr,
                            _ds_buffer.type, 
                            _ds_buffer.main_memory);

            texObj->setImage(texImg);

            if (_ds_buffer.texObj == nullptr) {
                texObj->setInternalFormat(GL_DEPTH_COMPONENT24);
                texObj->setExternalFormat(GL_DEPTH_COMPONENT24);
            }
            texBuf->setTexture(texObj);

            fbo->setDepthAttachment(texBuf);
        } else 
        //
        // no, then use simple render buffer
        //
        {
            RenderBufferUnrecPtr renBuf = RenderBuffer::create();
            renBuf->setInternalFormat(GL_DEPTH_COMPONENT24);
            fbo->setDepthAttachment(renBuf);
        }
    } else
    //
    // or a combined depth/stencil buffer
    //
    if (_depth && _stencil) {
        //
        // use textures?
        //
        if (_ds_buffer.enable) {
            ImageUnrecPtr           texImg = (_ds_buffer.image  == nullptr ? Image::create()           : _ds_buffer.image);
            TextureObjChunkUnrecPtr texObj = (_ds_buffer.texObj == nullptr ? TextureObjChunk::create() : _ds_buffer.texObj);
            TextureBufferUnrecPtr   texBuf = TextureBuffer::create();

            if (_ds_buffer.image == nullptr)
                texImg->set(GL_DEPTH_STENCIL_EXT, 
                            width, height, 1, 1, 1, 0.f, nullptr,
                            GL_UNSIGNED_INT_24_8, 
                            _ds_buffer.main_memory);

            texObj->setImage(texImg);
            texObj->setInternalFormat(GL_DEPTH24_STENCIL8_EXT);
            texObj->setExternalFormat(GL_DEPTH_STENCIL_EXT);
            texBuf->setTexture(texObj);

            fbo->setDepthAttachment(texBuf);
            fbo->setStencilAttachment(texBuf);
        } else 
        //
        // no, then use simple render buffer
        //
        {
            RenderBufferUnrecPtr renBuf = RenderBuffer::create();
            renBuf->setInternalFormat(GL_DEPTH24_STENCIL8);
            fbo->setDepthAttachment(renBuf);
            fbo->setStencilAttachment(renBuf);
        }
    }

    fbo->setWidth (width );
    fbo->setHeight(height);

    return FrameBufferObjectTransitPtr(fbo);
}
コード例 #5
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);
}
コード例 #6
0
DepthPeelingStageDataTransitPtr
    DepthPeelingStage::setupStageData(Int32 iPixelWidth,
                                      Int32 iPixelHeight)
{
    DepthPeelingStageDataTransitPtr returnValue =
        DepthPeelingStageData::createLocal();

    if(returnValue == NULL)
        return returnValue;

    OSG::Thread::setCurrentLocalFlags();

    //Depth, Blend chunks and Background in Data?
    DepthChunkUnrecPtr pDepthOffChunk = DepthChunk::createLocal();
    pDepthOffChunk->setEnable(false);

    DepthChunkUnrecPtr pDepthOnChunk = DepthChunk::createLocal();
    pDepthOnChunk->setEnable(true);

    returnValue->setDepthChunk(pDepthOnChunk);

    ShaderProgramVariableChunkUnrecPtr pSPVChunk1 =
        ShaderProgramVariableChunk::createLocal();
    pSPVChunk1->addUniformVariable("uIsPeelPass", true);

    returnValue->setSpvIsPeelChunk(pSPVChunk1);

    ShaderProgramVariableChunkUnrecPtr pSPVChunk2 =
        ShaderProgramVariableChunk::createLocal();
    pSPVChunk2->addUniformVariable("uIsPeelPass", false);

    returnValue->setSpvIsInitialChunk(pSPVChunk2);

    BlendChunkUnrecPtr pBlendChunk = BlendChunk::createLocal();
    pBlendChunk->setSrcFactor(GL_DST_ALPHA);
    pBlendChunk->setDestFactor(GL_ONE);
    pBlendChunk->setAlphaSrcFactor(GL_ZERO);
    pBlendChunk->setAlphaDestFactor(GL_ONE_MINUS_SRC_ALPHA);
    pBlendChunk->setEquation(GL_FUNC_ADD);

    SolidBackgroundUnrecPtr pSolidBackground = SolidBackground::createLocal();
    pSolidBackground->setColor(Color3f(0.f, 0.f, 0.f));
    pSolidBackground->setAlpha(0.f);
    returnValue->setBackground(pSolidBackground);

    SimpleSHLChunkUnrecPtr pQuadShader = SimpleSHLChunk::createLocal();
    pQuadShader->setFragmentProgram(std::string(blendFS));
    pQuadShader->addUniformVariable("uSampler", 0);

    //2 FBOs (Ping-Pong)
    FrameBufferObjectUnrecPtr pPeelFBOs[2];
    TextureBufferUnrecPtr pPeelColorTexBuffers[2];
    TextureBufferUnrecPtr pPeelDepthTexBuffers[2];

    TextureObjChunkUnrecPtr pColorTexs[2];
    ImageUnrecPtr           pColorImgs[2];

    TextureObjChunkUnrecPtr pDepthTexs[2];
    ImageUnrecPtr           pDepthImgs[2];

    for (int i=0; i<2; ++i)
    {
        //Color textures
        pColorTexs[i]     = TextureObjChunk::createLocal();
        pColorImgs[i]     = Image          ::createLocal();

        pColorImgs[i]->set(Image::OSG_RGBA_PF,
                  iPixelWidth,
                  iPixelHeight,
                  1,
                  1,
                  1,
                  0.0,
                  0,
                  Image::OSG_FLOAT32_IMAGEDATA,
                  false);

        pColorTexs[i]   ->setImage         (pColorImgs[i]   );
        pColorTexs[i]   ->setMinFilter     (GL_NEAREST       );
        pColorTexs[i]   ->setMagFilter     (GL_NEAREST       );
        pColorTexs[i]   ->setWrapS         (GL_CLAMP_TO_EDGE );
        pColorTexs[i]   ->setWrapT         (GL_CLAMP_TO_EDGE );
        pColorTexs[i]   ->setInternalFormat(GL_RGBA8);

        pPeelColorTexBuffers[i]   = TextureBuffer::createLocal();
        pPeelColorTexBuffers[i]->setTexture(pColorTexs[i]);

        //Depth textures
        pDepthTexs[i]      = TextureObjChunk::createLocal();
        pDepthImgs[i]      = Image          ::createLocal();

        pDepthImgs[i]->set(Image::OSG_DEPTH_PF,
                  iPixelWidth,
                  iPixelHeight,
                  1,
                  1,
                  1,
                  0.0,
                  0,
                  Image::OSG_FLOAT32_IMAGEDATA,
                  false);

        pDepthTexs[i]   ->setImage         (pDepthImgs[i]   );
        pDepthTexs[i]   ->setMinFilter     (GL_NEAREST       );
        pDepthTexs[i]   ->setMagFilter     (GL_NEAREST       );
        pDepthTexs[i]   ->setWrapS         (GL_CLAMP_TO_EDGE );
        pDepthTexs[i]   ->setWrapT         (GL_CLAMP_TO_EDGE );
        pDepthTexs[i]   ->setInternalFormat(GL_DEPTH_COMPONENT32F);
        pDepthTexs[i]   ->setExternalFormat(GL_DEPTH_COMPONENT);

        pPeelDepthTexBuffers[i] = TextureBuffer::createLocal();
        pPeelDepthTexBuffers[i]->setTexture(pDepthTexs[i]);

        pPeelFBOs[i] = FrameBufferObject::createLocal();

        pPeelFBOs[i]->setSize(iPixelWidth, iPixelHeight);
        pPeelFBOs[i]->setColorAttachment(pPeelColorTexBuffers[i], 0);
        pPeelFBOs[i]->setDepthAttachment(pPeelDepthTexBuffers[i]);
        pPeelFBOs[i]->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT);

        //Peel material for Quad (!)
        ChunkMaterialUnrecPtr pPeelMat  = ChunkMaterial  ::createLocal();
        pPeelMat->addChunk(pQuadShader, 0);
        pPeelMat->addChunk(pColorTexs[i],     0);
        pPeelMat->addChunk(pDepthOffChunk);
        pPeelMat->addChunk(pBlendChunk);

        if (i == 0)
        {
            returnValue->setPeelPingFBO(pPeelFBOs[i]);
            returnValue->setPeelPingMaterial(pPeelMat);
        }
        else
        {
            returnValue->setPeelPongFBO(pPeelFBOs[i]);
            returnValue->setPeelPongMaterial(pPeelMat);
        }
    }

    // The final color blend target
    FrameBufferObjectUnrecPtr pBlendFBO      = FrameBufferObject::createLocal();

    //Color texture
    TextureObjChunkUnrecPtr   pBlendColorTex = TextureObjChunk::createLocal();
    ImageUnrecPtr             pBlendColorImg = Image          ::createLocal();

    pBlendColorImg->set(Image::OSG_RGBA_PF,
              iPixelWidth,
              iPixelHeight,
              1,
              1,
              1,
              0.0,
              0,
              Image::OSG_FLOAT32_IMAGEDATA,
              false);

    pBlendColorTex->setImage         (pBlendColorImg   );
    pBlendColorTex->setMinFilter     (GL_NEAREST       );
    pBlendColorTex->setMagFilter     (GL_NEAREST       );
    pBlendColorTex->setWrapS         (GL_CLAMP_TO_EDGE );
    pBlendColorTex->setWrapT         (GL_CLAMP_TO_EDGE );
    pBlendColorTex->setInternalFormat(GL_RGBA8);

    TextureBufferUnrecPtr pBlendColorTexBuffer   = TextureBuffer::createLocal();
    pBlendColorTexBuffer->setTexture(pBlendColorTex);

    TextureBufferUnrecPtr pBlendDepthTexBuffer   = TextureBuffer::createLocal();
    pBlendDepthTexBuffer->setTexture(pDepthTexs[0]);

    pBlendFBO->setSize(iPixelWidth, iPixelHeight);
    pBlendFBO->setColorAttachment(pBlendColorTexBuffer, 0);
    pBlendFBO->setDepthAttachment(pBlendDepthTexBuffer);

    pBlendFBO->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT);

    returnValue->setBlendFBO(pBlendFBO);

    // Blend Final Material
    ChunkMaterialUnrecPtr pBlendFinalMat = ChunkMaterial::createLocal();

    pBlendFinalMat->addChunk(pDepthOffChunk);
    pBlendFinalMat->addChunk(pBlendColorTex,     0);

    SimpleSHLChunkUnrecPtr pBlendFinalShader = SimpleSHLChunk::createLocal();
    pBlendFinalShader->setFragmentProgram(std::string(blendFinalFS));
    pBlendFinalShader->addUniformVariable("uSampler", 0);

    pBlendFinalMat->addChunk(pBlendFinalShader, 0);
    returnValue->setBlendFinalMaterial(pBlendFinalMat);

    OSG::Thread::resetCurrentLocalFlags();

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

    return returnValue;
}
コード例 #7
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;
}
コード例 #8
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;
}
コード例 #9
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;
}
コード例 #10
0
void VRShadowEngine::doLightPass(Light         *pLight,
                                        RenderAction  *pAction,
                                        EngineDataPtr  pEngineData)
{
    this->pushPartition(pAction);

    RenderPartition   *pPart   = pAction    ->getActivePartition();
    Viewarea          *pArea   = pAction    ->getViewarea       ();
    Background        *pBack   = pAction    ->getBackground     ();

    FrameBufferObject *pTarget = pEngineData->getRenderTarget();

    if(pTarget == NULL)
    {
        FrameBufferObjectUnrecPtr pFBO = FrameBufferObject::createLocal();

        pFBO->setWidth (this->getWidth ());
        pFBO->setHeight(this->getHeight());

        pEngineData->setRenderTarget(pFBO);

        pTarget = pFBO;
    }

    TextureObjChunk       *pTexChunk  = pEngineData->getTexChunk();


    TextureBufferUnrecPtr  pTexBuffer = pEngineData->getTexBuffer();

    if(pTexBuffer == NULL)
    {
        pTexBuffer = TextureBuffer::createLocal();

        pEngineData->setTexBuffer     (pTexBuffer);

        pTexBuffer->setTexture        (pTexChunk );
        pTarget   ->setDepthAttachment(pTexBuffer);
    }

    PolygonChunkUnrecPtr pPoly = pEngineData->getPolyChunk();

    if(pPoly == NULL)
    {
        pPoly = PolygonChunk::createLocal();

        pPoly->setOffsetBias  (this->getOffsetBias  ());
        pPoly->setOffsetFactor(this->getOffsetFactor());
        pPoly->setOffsetFill  (true                   );

        pEngineData->setPolyChunk(pPoly);
    }

    pPart->setRenderTarget(pTarget);

    if(pArea != NULL)
    {
        Camera *pCam = pEngineData->getCamera();

        pPart->setWindow  (pAction->getWindow());

        pPart->calcViewportDimension(0.f, 0.f, 1.f, 1.f,
                                     pTarget->getWidth    (),
                                     pTarget->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);

        pCam->getViewing(m,
                         pPart->getViewportWidth (),
                         pPart->getViewportHeight());


        pPart->setupViewing(m);

        pPart->setNear     (pCam->getNear());
        pPart->setFar      (pCam->getFar ());

        pPart->calcFrustum ();

        pPart->setBackground(pBack);
    }

    Node *pActNode = pAction->getActNode();

    pAction->overrideMaterial(_pLightPassMat, pActNode);

    pAction->pushState();

    UInt32 uiPolySlot  = pPoly->getClassId();

    pAction->addOverride     (uiPolySlot,     pPoly);

//    lightRenderEnter(pLight, pAction);

    pAction->useNodeList(false);

    this->recurseFrom(pAction, pLight);

    pAction->popState();

    pAction->overrideMaterial(NULL, pActNode);

    this->popPartition(pAction);
}
コード例 #11
0
DisplayFilterStageDataTransitPtr 
    DisplayFilterStage::setupStageData(Int32 iPixelWidth,
                                       Int32 iPixelHeight)
{
    DisplayFilterStageDataTransitPtr returnValue = 
        DisplayFilterStageData::createLocal();

    if(returnValue == NULL)
        return returnValue;

    // Scene Buffer

    FrameBufferObjectUnrecPtr pFBO     = FrameBufferObject::createLocal();
    RenderBufferUnrecPtr      pDBuffer = RenderBuffer     ::createLocal();
    TextureBufferUnrecPtr     pTBuffer = TextureBuffer    ::createLocal();

    TextureObjChunkUnrecPtr   pTex     = TextureObjChunk  ::createLocal();
    ImageUnrecPtr             pImg     = Image            ::createLocal();

    pImg->set(Image::OSG_RGB_PF, 
              iPixelWidth, 
              iPixelHeight,
              1,
              1,
              1,
              0.0,
              0,
              Image::OSG_UINT8_IMAGEDATA,
              false);
    
    pTex    ->setImage         (pImg             ); 
    pTex    ->setMinFilter     (GL_NEAREST       );
    pTex    ->setMagFilter     (GL_NEAREST       );
    pTex    ->setWrapS         (GL_CLAMP_TO_EDGE );
    pTex    ->setWrapT         (GL_CLAMP_TO_EDGE );
    
    pTBuffer->setTexture(pTex);

    pDBuffer->setInternalFormat(GL_DEPTH_COMPONENT24);
 

    pFBO->setSize(iPixelWidth, iPixelHeight);
    
    pFBO->setColorAttachment(pTBuffer, 0);
    pFBO->setDepthAttachment(pDBuffer   );

    pFBO->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT);


    pFBO->setEnableMultiSample  (this->getEnableMultiSample  ());
    pFBO->setColorSamples       (this->getColorSamples       ());
    pFBO->setCoverageSamples    (this->getCoverageSamples    ());
    pFBO->setFixedSampleLocation(this->getFixedSampleLocation());

    returnValue->setTarget(pFBO);


    ChunkMaterialUnrecPtr pCMat = ChunkMaterial::createLocal();

    pCMat->addChunk(pTex);

    returnValue->setBaseMaterial(pCMat);

    returnValue->setWidth (iPixelWidth );
    returnValue->setHeight(iPixelHeight);

    commitChanges();

    return returnValue;
}