void ColorDisplayFilter::process(DisplayFilterStageData *pData)
{
    SimpleSHLChunk *pShader = pData->getColorFilterShader();

    if(pShader == NULL || this->getFilterShader() != pShader)
    {
        pShader = this->getFilterShader();

        OSG_ASSERT(pShader != NULL);
        
        ChunkMaterial *pCMat = pData->getBaseMaterial();

        OSG_ASSERT(pCMat != NULL);

        pCMat->addChunk(pShader);

        commitChanges();

        pData->setColorFilterShader(pShader);
    }



    TextureObjChunk *pColTex = pData->getColorFilterTexture();

    if(pData->getInitColTableFrom() != this)
    {
        if(pColTex == NULL)
        {
            TextureObjChunkUnrecPtr pTex = TextureObjChunk::createLocal();

            pTex->setMinFilter(GL_LINEAR            );
            pTex->setMagFilter(GL_LINEAR            );
            pTex->setWrapS    (GL_CLAMP_TO_EDGE     );
            pTex->setWrapT    (GL_CLAMP_TO_EDGE     );
            pTex->setWrapR    (GL_CLAMP_TO_EDGE     );

            pData->setColorFilterTexture(pTex);

            ChunkMaterial *pCMat = pData->getBaseMaterial();
            
            OSG_ASSERT(pCMat != NULL);
            
            pCMat->addChunk(pTex, 1);

            pColTex = pTex;
        }

        pData->setInitColTableFrom(this);

        pColTex->setImage(this->getTableImage());

        commitChanges();
    }

    OSG_ASSERT(pShader != NULL);
    OSG_ASSERT(pColTex != NULL);

    pShader->setIgnore(false);
    pColTex->setIgnore(false);
}
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;
}