From 96f02ab32c4d2fb329f4c382499154673bb56dbb Mon Sep 17 00:00:00 2001 From: unelsson Date: Sat, 11 Sep 2021 17:03:16 +0300 Subject: [PATCH] Per-material alpha testing for collada --- components/resource/scenemanager.cpp | 42 +++++++++++++++++++--------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/components/resource/scenemanager.cpp b/components/resource/scenemanager.cpp index b4a26f0f35..80d8f1ecdc 100644 --- a/components/resource/scenemanager.cpp +++ b/components/resource/scenemanager.cpp @@ -255,31 +255,47 @@ namespace Resource node.getOrCreateStateSet()->setAttributeAndModes(depth, osg::StateAttribute::ON); } + /* Check if the has + correct format for OpenMW: alphatest mode value MaterialName + e.g alphatest GEQUAL 0.8 MyAlphaTestedMaterial */ std::vector descriptions = node.getDescriptions(); for (auto description : descriptions) { - std::vector descriptionParts; + mDescriptions.emplace_back(description); + } + // Iterate each description, and see if the current node uses the specified material for alpha testing + for (auto description : mDescriptions) + { + std::vector descriptionParts; std::istringstream descriptionStringStream(description); for (std::string part; std::getline(descriptionStringStream, part, ' ');) - descriptionParts.emplace_back(part); - - if (descriptionParts.at(0) == "alphatest") { - if (!osgDepthCreated) - { - osg::ref_ptr depth = SceneUtil::createDepth(); - node.getOrCreateStateSet()->setAttributeAndModes(depth, osg::StateAttribute::ON); - } + descriptionParts.emplace_back(part); + } - osg::AlphaFunc::ComparisonFunction mode = getTestMode(descriptionParts.at(1)); - osg::ref_ptr alphaFunc (new osg::AlphaFunc(mode, std::stod(descriptionParts.back()))); - node.getOrCreateStateSet()->setAttributeAndModes(alphaFunc, osg::StateAttribute::ON); - Log(Debug::Info) << "Setting collada alpha test " << description << " for " << node.getName(); + if (descriptionParts.size() > (3) && descriptionParts.at(3) == node.getOrCreateStateSet()->getName()) + { + if (descriptionParts.at(0) == "alphatest") + { + if (!osgDepthCreated) + { + osg::ref_ptr depth = SceneUtil::createDepth(); + node.getOrCreateStateSet()->setAttributeAndModes(depth, osg::StateAttribute::ON); + } + + osg::AlphaFunc::ComparisonFunction mode = getTestMode(descriptionParts.at(1)); + osg::ref_ptr alphaFunc (new osg::AlphaFunc(mode, std::stod(descriptionParts.at(2)))); + node.getOrCreateStateSet()->setAttributeAndModes(alphaFunc, osg::StateAttribute::ON); + Log(Debug::Info) << "Setting collada alpha test for " << node.getName(); + } } } + traverse(node); } + private: + std::vector mDescriptions; }; SceneManager::SceneManager(const VFS::Manager *vfs, Resource::ImageManager* imageManager, Resource::NifFileManager* nifFileManager)