Hi Antonin,

Sounds like your issue might be related to GL_LIGHTING or GL_MATERIAL_COLOR mode usage. GL_COLOR_MATERIAL selects source of diffuse/ambient/emissive/specular term. Its either taken from material or from color set in geometries. This fixed pipeline attribute is not passed to Vertex Shaders as an uniform so shader coders may need to make workarounds for it.

We had such problem with bunch of models using GL_COLOR_MATERIAL set to AMBIENT_AND_DIFFUSE in which case actual ambient and diffuse material values where not set in material but assumed tio be taken from glColor. If they were not set in material they often were quite random so they were causing the issues. We overcame this by approach similar to your option number 2. We ran a visitor which found if material set per drawable used GL_COLOR_MATERIAL with colors from drawable and we cloned such material replacing its colors with these from drawable color array. There should be a problem with drawables with more than one color (colors set per vertex or per primitive) but fortunately we did not have such cases. Below is source of the function used by this visitor. Its inputs are drawable StateSet and Color taken from drawable color array.

bool SubstituteColorMaterial( osg::StateSet * ss, osg::Vec4 color )
{
   if( !ss ) return false;

   osg::Material * material =
       dynamic_cast<osg::Material*>
           ( ss->getAttribute( osg::StateAttribute::MATERIAL ) );

if ( !material || material->getColorMode() == osg::Material::OFF ) return false;

   osg::ref_ptr< osg::Material >
       newOsgMaterial = dynamic_cast<osg::Material*>
           ( material->clone(osg::CopyOp::SHALLOW_COPY) );

   switch( newOsgMaterial->getColorMode() )
   {
       case osg::Material::AMBIENT_AND_DIFFUSE:
newOsgMaterial->setAmbient( osg::Material::FRONT_AND_BACK, color ); newOsgMaterial->setDiffuse( osg::Material::FRONT_AND_BACK, color );
           break;
       case osg::Material::AMBIENT:
newOsgMaterial->setAmbient( osg::Material::FRONT_AND_BACK, color );
           break;
       case osg::Material::DIFFUSE:
newOsgMaterial->setDiffuse( osg::Material::FRONT_AND_BACK, color );
           break;
       case osg::Material::SPECULAR:
newOsgMaterial->setSpecular( osg::Material::FRONT_AND_BACK, color );
           break;
       case osg::Material::EMISSION:
newOsgMaterial->setEmission( osg::Material::FRONT_AND_BACK, color );
           break;
   }

   newOsgMaterial->setColorMode( osg::Material::OFF );

   ss->setAttribute(  newOsgMaterial.get()  );

   return true;
}

Maybe this helps a little,
Wojtek

----- Original Message ----- From: "Antonin Linares" <antonin.lina...@onera.fr>
To: "OpenSceneGraph Users" <osg-users@lists.openscenegraph.org>
Sent: Tuesday, May 05, 2009 4:23 PM
Subject: Re: [osg-users] ViewDependentShadow and Lod


Hi Wojtek,
Thanks for the vertex shader trick, but in this way i gate pure black
shadow and terrible artifact on my shadow caster model.
Actually i can see two way to solve my lighting problem.

-Make a vertex shader who can compute lighting with glMaterial and
glColor both.
   but it's seem to me that it's impossible without using an uniform
switch.

-Use a nodeVisitor to replace vertex color attribute by a similar material.
   But here i dont now how to check actual color mode:

void setMatNodeVisitor::apply(osg::Node& node)
{
   osg::Geode* geode = node.asGeode();
   if(geode)
   {
       for(int i =0; i < geode->getNumDrawable(); i++)
       {
           osg::Material* mat = (osg::Matrial*)
geode->getDrawable(i)->getStateSet();
            if(mat){
              if(mat.getColorMode() == osg::Material::OFF)
                  //no material off in my scene ...

           }
       }
   }
}


Wojciech Lewandowski a écrit :
Hi Antonin,

I am glad you had this sorted it out. You may try to replace shaders with yours. Its possible to set only fragment shaders and use fixed pipeline for vertices by setting MainVertexShader and ShadowVertexShader to NULL.

Cheers,
Wojtek

----- Original Message ----- From: "Antonin Linares" <antonin.lina...@onera.fr>
To: "OpenSceneGraph Users" <osg-users@lists.openscenegraph.org>
Sent: Monday, May 04, 2009 4:11 PM
Subject: Re: [osg-users] ViewDependentShadow and Lod


Again,

Please don't care of my previous message, i'm wrong.

Some part of my terrain database use pure glColor(), so the shader miss compute this part of database.

Sorry all.

_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to