Hi J-S,

On Thu, 2005-12-08 at 20:18 -0500, Jean-Sebastien Guay wrote:
> Hello Dirk,
> 
> Sorry for coming back with this, but I really can't find why the transparency
> isn't working with the BlendChunk.
> 
> Here's my previous message about this.
> 
> > I used
> >     blendChunk->setAlphaSrcFactor( GL_SRC_ALPHA );
> >     blendChunk->setAlphaDestFactor( GL_ONE_MINUS_SRC_ALPHA );

I just realized that this is wrong. You're setting the alpha blend
function, but not the one for the color components.

> And basically that's it. I've got a ChunkMaterial with at least two chunks: a
> BlendChunk with the above settings, and a MaterialChunk on which I decrease 
> the
> diffuse alpha gradually. What happens is -- nothing. There seems to be no
> effect.
> 
> Is there anything you can think of that would prevent this from working? It
> seems simple enough... And I'm playing with the alpha of some other objects in
> my scene and they work fine.

I've just tried it on the Tie, and the Geometry's material didn't work.
You need to do this on the MaterialGroup's material:

void doMat(MaterialPtr mat)
{
    SimpleMaterialPtr smat = SimpleMaterialPtr::dcast(mat);
    ChunkMaterialPtr  cmat = ChunkMaterialPtr::dcast(mat);

    if(smat != NullFC)
    {
        beginEditCP(smat, SimpleMaterial::TransparencyFieldMask);
        smat->setTransparency(.5);
        endEditCP(smat, SimpleMaterial::TransparencyFieldMask);
    }
    else if(cmat != NullFC)
    {
        MaterialChunkPtr mc;
        BlendChunkPtr bc;

        mc = MaterialChunkPtr::dcast(
                cmat->find(MaterialChunk::getClassType()));
        bc = BlendChunkPtr::dcast(
                cmat->find(BlendChunk::getClassType()));

        if(mc == NullFC)
        {
            FWARNING(("ChunkMaterial has no MaterrialChunk!\n"));
            return;
        }
        beginEditCP(mc, MaterialChunk::DiffuseFieldMask);
        Color4f c = mc->getDiffuse();
        c[3] = 0.5;
        mc->setDiffuse(c);
        endEditCP(mc, MaterialChunk::DiffuseFieldMask);

        if(bc == NullFC)
        {
            bc = BlendChunk::create();
            beginEditCP(cmat);
            cmat->addChunk(bc);
            endEditCP(cmat);                
        }

        beginEditCP(bc);
        bc->setSrcFactor( GL_SRC_ALPHA );
        bc->setDestFactor( GL_ONE_MINUS_SRC_ALPHA );
        endEditCP(bc);
    }
    else
    {
        FWARNING(("Material is not simple or chunk, ignored!\n"));
    }
}

Action::ResultE makeTrans(NodePtr& node)
{   
    GeometryPtr geo = GeometryPtr::dcast(node->getCore());   
    if(geo!=NullFC)
    {        
        doMat(geo->getMaterial());
    }   

    MaterialGroupPtr mg = MaterialGroupPtr::dcast(node->getCore());   
    if(mg!=NullFC)
    {        
        doMat(mg->getMaterial());
    }   
       
    return Action::Continue; 
}

traverse(scene, 
      osgTypedFunctionFunctor1CPtrRef<Action::ResultE,
                                      NodePtr>(makeTrans));

Hope it helps

        Dirk




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to