[osg-users] Per vertex colors with different front and back intensity

OpenSceneGraph Users osg-users at lists.openscenegraph.org
Thu May 7 08:42:35 PDT 2020


Hello,

I have a triangle geometry and I'm displaying it in various material modes.
The standard is just a texture. What I want is the backside of the geometry 
to be slightly darker than the front.

So I configure my lighting like this

osg::ref_ptr<osg::LightModel> lm = new osg::LightModel;
lm->setTwoSided(true);
m_geometry->getOrCreateStateSet()->setAttributeAndModes(lm);

and then I set up my material like this, in addition to setting a texture.

m_material->setAmbient(osg::Material::FRONT_AND_BACK, xmx::osg::black);
m_material->setDiffuse(osg::Material::FRONT_AND_BACK, xmx::osg::black);
m_material->setEmission(osg::Material::FRONT, osg::Vec4(ff, ff, ff, 1.0f));
m_material->setEmission(osg::Material::BACK, osg::Vec4(fb, fb, fb, 1.0f));
m_material->setColorMode(osg::Material::ColorMode::OFF);

ff and fb here are two different values, ff usually being just 1 and fb 
something less than 1 to make the backside darker.
This works great for me.

Now I also have a mode where I can set per-vertex colors in addition to a 
texture, and I want to combine it.
This works if I just drop the material and set a color array with the 
provided colors,
but then I loose the feature of different front and back lighting, or 
generally the possibility to dampen front and back
intensity separately.

Is there any way to achieve this without writing my own shader?

I tried to set the color mode of the material to AMBIENT_AND_DIFFUSE or 
to EMISSION and added the material,
which resulted in no spectacular changes.
How could I combine the material with the texture and color array?

Thank you in advance,
Phil

-- 
You received this message because you are subscribed to the Google Groups "OpenSceneGraph Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osg-users+unsubscribe at googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/osg-users/109aa9e5-0fa3-4dda-bbd7-e6aff3e11131%40googlegroups.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20200507/e1e53279/attachment.html>


More information about the osg-users mailing list