Roger, your implementation looks good to me. As you suspected, you do need to check ctt->getColor() for null before you use it. There might be a <param> or <texture> there instead. The three are mutually exclusive. In theory the <transparency> value should be combined with the <transparent> element regardless of whether or not the <transparent> is a <texture>, <param>, or <color> (<color> is by far the most common), but I'm not sure how feasible that is in fixed-function OpenGL.

What you have should work for the great majority of COLLADA data you'll encounter in the wild.

Roger James wrote:

I have been doing some work on fixing the handling of the “transparent” and “transparency” types in the Collada reader. I have come up with the following piece of code which appears to work reasonably well for the test cases I have. It would be great if someone with a more intimate knowledge of Collada  than mine (hopefully Mike or Marcus) could look this over and see if I have interpreted the remarks in the Collada 1.4.1 release notes and various collada forum threads correctly. I must admit I found it somewhat confusing!

 

I left this post as HTML to try and retain some formatting. (OT – if anyone know how to stop Outlook plain text mode wrapping at column 80 please let me know!)

 

 

osg::StateAttribute *daeReader::processTransparencySettings( domCommon_transparent_type *ctt,  domCommon_float_or_param_type *pTransparency, osg::StateSet *ss )

{

      if (NULL == ctt && NULL == pTransparency)

            return NULL;

 

    if (ctt && ctt->getTexture() != NULL)

    {

            osg::StateAttribute *sa = NULL;

        sa = processTexture( ctt->getTexture() );

        osg::BlendFunc *bf = new osg::BlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

        ss->setAttribute( bf );

        ss->setMode( GL_BLEND, GL_TRUE );

        ss->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );

        ss->setRenderBinDetails( 10, "DepthSortedBin" );

            return sa;

    }

   

      // Fix up defaults acoording to 1.4.1 release notes

      domFloat4 f4;

      domFx_opaque_enum Opaque = FX_OPAQUE_ENUM_A_ONE;

      if (NULL == ctt)

      {

            f4.append(0.0f);

            f4.append(0.0f);

            f4.append(0.0f);

            f4.append(1.0f);

      }

      else

      {

            Opaque = ctt->getOpaque();

            // I wonder if I should do a test like this here DOES ANYBODY KNOW?

            //if (NULL == ctt->getColor().cast())

            f4 = ctt->getColor()->getValue();

      }

 

      domFloat Transparency;

      if (NULL == pTransparency)

            Transparency = 1.0f;

      else

      {

            Transparency = pTransparency->getFloat()->getValue();

            if (m_AuthoringTool == AuthoringTool::GOOGLE_SKETCHUP) // Google back to front support

                  Transparency = 1.0f - Transparency;

      }

 

    osg::BlendColor *bc = new osg::BlendColor();

    bc->setConstantColor(osg::Vec4( f4[0] * Transparency, f4[1] * Transparency, f4[2] * Transparency, f4[3] * Transparency ));

    ss->setAttribute( bc );

      osg::BlendFunc *bf;

      if (FX_OPAQUE_ENUM_A_ONE == Opaque)

            bf = new osg::BlendFunc(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA);

      else

            bf = new osg::BlendFunc(GL_ONE_MINUS_CONSTANT_COLOR, GL_CONSTANT_COLOR);

      ss->setAttribute( bf );

    ss->setMode( GL_BLEND, GL_TRUE );

 

      if (FX_OPAQUE_ENUM_A_ONE == Opaque)

      {

            if (Transparency  * f4[3] > 0.99f)

                  return NULL; // Material is really opaque so dont put it in the transparent bin

      }

      else

      {

            if ((Transparency  * f4[0] < 0.01f) &&

                  (Transparency  * f4[1] < 0.01f) &&

                  (Transparency  * f4[2] < 0.01f) &&

                  (Transparency  * f4[3] < 0.01f))

                  return NULL; // Material is really opaque so dont put it in the transparent bin

      }

 

    ss->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );

    ss->setRenderBinDetails( 10, "DepthSortedBin" );

      return NULL;

}

 


_______________________________________________ osg-users mailing list osg-users@openscenegraph.net http://openscenegraph.net/mailman/listinfo/osg-users http://www.openscenegraph.org/


_______________________________________________
osg-users mailing list
osg-users@openscenegraph.net
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to