Adjust drawable property state changes

Reset shininess and specular strength when specular lighting is supposed to be disabled
Don't add the material redundantly if a sorter is pushed
Don't discard non-default emissive and specular multipliers if there's no sorter or material
pull/3235/head
Alexei Kotov 8 months ago
parent 713e741f9c
commit a513049129

@ -2817,7 +2817,11 @@ namespace NifOsg
// While NetImmerse and Gamebryo support specular lighting, Morrowind has its support disabled. // While NetImmerse and Gamebryo support specular lighting, Morrowind has its support disabled.
if (mVersion <= Nif::NIFFile::VER_MW || !specEnabled) if (mVersion <= Nif::NIFFile::VER_MW || !specEnabled)
{
mat->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4f(0.f, 0.f, 0.f, 0.f)); mat->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4f(0.f, 0.f, 0.f, 0.f));
mat->setShininess(osg::Material::FRONT_AND_BACK, 0.f);
specStrength = 1.f;
}
if (lightmode == Nif::NiVertexColorProperty::LightMode::LightMode_Emissive) if (lightmode == Nif::NiVertexColorProperty::LightMode::LightMode_Emissive)
{ {
@ -2848,32 +2852,31 @@ namespace NifOsg
mat->setColorMode(osg::Material::OFF); mat->setColorMode(osg::Material::OFF);
} }
if (!mPushedSorter && !hasSortAlpha && mHasStencilProperty) if (hasMatCtrl || mat->getColorMode() != osg::Material::OFF
setBin_Traversal(node->getOrCreateStateSet()); || mat->getEmission(osg::Material::FRONT_AND_BACK) != osg::Vec4f(0, 0, 0, 1)
|| mat->getDiffuse(osg::Material::FRONT_AND_BACK) != osg::Vec4f(1, 1, 1, 1)
if (!mPushedSorter && !hasMatCtrl && mat->getColorMode() == osg::Material::OFF || mat->getAmbient(osg::Material::FRONT_AND_BACK) != osg::Vec4f(1, 1, 1, 1)
&& mat->getEmission(osg::Material::FRONT_AND_BACK) == osg::Vec4f(0, 0, 0, 1) || mat->getShininess(osg::Material::FRONT_AND_BACK) != 0
&& mat->getDiffuse(osg::Material::FRONT_AND_BACK) == osg::Vec4f(1, 1, 1, 1) || mat->getSpecular(osg::Material::FRONT_AND_BACK) != osg::Vec4f(0.f, 0.f, 0.f, 0.f))
&& mat->getAmbient(osg::Material::FRONT_AND_BACK) == osg::Vec4f(1, 1, 1, 1)
&& mat->getShininess(osg::Material::FRONT_AND_BACK) == 0
&& mat->getSpecular(osg::Material::FRONT_AND_BACK) == osg::Vec4f(0.f, 0.f, 0.f, 0.f))
{ {
// default state, skip mat = shareAttribute(mat);
return; node->getOrCreateStateSet()->setAttributeAndModes(mat, osg::StateAttribute::ON);
} }
mat = shareAttribute(mat);
osg::StateSet* stateset = node->getOrCreateStateSet();
stateset->setAttributeAndModes(mat, osg::StateAttribute::ON);
if (emissiveMult != 1.f) if (emissiveMult != 1.f)
stateset->addUniform(new osg::Uniform("emissiveMult", emissiveMult)); node->getOrCreateStateSet()->addUniform(new osg::Uniform("emissiveMult", emissiveMult));
if (specStrength != 1.f) if (specStrength != 1.f)
stateset->addUniform(new osg::Uniform("specStrength", specStrength)); node->getOrCreateStateSet()->addUniform(new osg::Uniform("specStrength", specStrength));
if (!mPushedSorter) if (!mPushedSorter)
{
if (!hasSortAlpha && mHasStencilProperty)
setBin_Traversal(node->getOrCreateStateSet());
return; return;
}
osg::StateSet* stateset = node->getOrCreateStateSet();
auto assignBin = [&](Nif::NiSortAdjustNode::SortingMode mode, int type) { auto assignBin = [&](Nif::NiSortAdjustNode::SortingMode mode, int type) {
if (mode == Nif::NiSortAdjustNode::SortingMode::Off) if (mode == Nif::NiSortAdjustNode::SortingMode::Off)
{ {

Loading…
Cancel
Save