Hi all,

I'm using vertex colors on my models to save on memory in a CAD-style
application, as one color per geometry is more than sufficient for my needs.


However, is it possible to have specular highlights when using vertex
colors?

For instance, I'm adding a color as follows

///////////////////////
osg::Geometry * coneBodyGeometry = new osg::Geometry();

...

// Set the Colour to the entire object
osg::ref_ptr<osg::Vec4Array> colourArray = new osg::Vec4Array();
colourArray->push_back(osg::Vec4(1.0f, 0.5f, 0.5f, 1.0f));
coneBodyGeometry->setColorArray(colourArray.get());
coneBodyGeometry->setColorBinding(osg::Geometry::BIND_OVERALL);
///////////////////////

However so far I can see the only way to add specular is via a StateSet. I
previously had one stateset per object, but this consumed too much memory,
so now have a shared stateset

///////////////////////
sharedState = new osg::StateSet();

// Create a material
osg::ref_ptr<osg::Material> mat = new osg::Material();

// Set specular attribute
mat->setDiffuse(osg::Material::Face::FRONT_AND_BACK, osg::Vec4(0,0,0,0));
mat->setSpecular(osg::Material::FRONT, osg::Vec4f(1.0f, 1.0f, 1.0f, 1.0f));
mat->setShininess(osg::Material::FRONT, 12.0f);
mat->setColorMode(osg::Material::ColorMode::SPECULAR);
sharedState->setAttribute(mat.get(), osg::StateAttribute::Values::ON);
sharedState->setMode(GL_COLOR_MATERIAL, osg::StateAttribute::ON);
///////////////////////

Of course, the material then mixes its color with the vertex color, despite
the fact that its transparent.

Does anyone know a way to have specular on objects but either sharing
stateset, or without a stateset?

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

Reply via email to