1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-21 08:23:53 +00:00

Glowupdater fix when using shaders

This commit is contained in:
Allofich 2016-08-10 00:43:14 +09:00
parent 9b2cb2fb8c
commit 4b9aff7a03
2 changed files with 38 additions and 38 deletions

View file

@ -571,7 +571,7 @@ namespace MWMechanics
{ {
short effectId = effect.mId; short effectId = effect.mId;
if (target.getClass().canLock(target)) if (target.getClass().canLock(target))
{ {
if (effectId == ESM::MagicEffect::Lock) if (effectId == ESM::MagicEffect::Lock)
{ {
const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore();

View file

@ -1182,8 +1182,8 @@ namespace MWRender
int mLowestUnusedTexUnit; int mLowestUnusedTexUnit;
}; };
void Animation::addSpellCastGlow(const ESM::MagicEffect *effect){ void Animation::addSpellCastGlow(const ESM::MagicEffect *effect)
{
osg::Vec4f glowColor(1,1,1,1); osg::Vec4f glowColor(1,1,1,1);
glowColor.x() = effect->mData.mRed / 255.f; glowColor.x() = effect->mData.mRed / 255.f;
glowColor.y() = effect->mData.mGreen / 255.f; glowColor.y() = effect->mData.mGreen / 255.f;
@ -1197,28 +1197,9 @@ namespace MWRender
} }
void Animation::addGlow(osg::ref_ptr<osg::Node> node, osg::Vec4f glowColor, float glowDuration) void Animation::addGlow(osg::ref_ptr<osg::Node> node, osg::Vec4f glowColor, float glowDuration)
{ {
std::vector<osg::ref_ptr<osg::Texture2D> > textures;
for (int i=0; i<32; ++i)
{
std::stringstream stream;
stream << "textures/magicitem/caust";
stream << std::setw(2);
stream << std::setfill('0');
stream << i;
stream << ".dds";
osg::ref_ptr<osg::Image> image = mResourceSystem->getImageManager()->getImage(stream.str());
osg::ref_ptr<osg::Texture2D> tex (new osg::Texture2D(image));
tex->setName("envMap");
tex->setWrap(osg::Texture::WRAP_S, osg::Texture2D::REPEAT);
tex->setWrap(osg::Texture::WRAP_T, osg::Texture2D::REPEAT);
mResourceSystem->getSceneManager()->applyFilterSettings(tex);
textures.push_back(tex);
}
if (mGlowUpdater && mGlowUpdater->isDone()) if (mGlowUpdater && mGlowUpdater->isDone())
node->removeUpdateCallback(mGlowUpdater); node->removeUpdateCallback(mGlowUpdater);
FindLowestUnusedTexUnitVisitor findLowestUnusedTexUnitVisitor; FindLowestUnusedTexUnitVisitor findLowestUnusedTexUnitVisitor;
node->accept(findLowestUnusedTexUnitVisitor); node->accept(findLowestUnusedTexUnitVisitor);
@ -1230,25 +1211,44 @@ namespace MWRender
mGlowUpdater->setDuration(glowDuration); mGlowUpdater->setDuration(glowDuration);
} }
else else
{ {
std::vector<osg::ref_ptr<osg::Texture2D> > textures;
for (int i=0; i<32; ++i)
{
std::stringstream stream;
stream << "textures/magicitem/caust";
stream << std::setw(2);
stream << std::setfill('0');
stream << i;
stream << ".dds";
osg::ref_ptr<osg::Image> image = mResourceSystem->getImageManager()->getImage(stream.str());
osg::ref_ptr<osg::Texture2D> tex (new osg::Texture2D(image));
tex->setName("envMap");
tex->setWrap(osg::Texture::WRAP_S, osg::Texture2D::REPEAT);
tex->setWrap(osg::Texture::WRAP_T, osg::Texture2D::REPEAT);
mResourceSystem->getSceneManager()->applyFilterSettings(tex);
textures.push_back(tex);
}
osg::ref_ptr<GlowUpdater> glowUpdater = new GlowUpdater(texUnit, glowColor, textures, node, glowDuration, mResourceSystem); osg::ref_ptr<GlowUpdater> glowUpdater = new GlowUpdater(texUnit, glowColor, textures, node, glowDuration, mResourceSystem);
mGlowUpdater = glowUpdater; mGlowUpdater = glowUpdater;
node->addUpdateCallback(glowUpdater); node->addUpdateCallback(glowUpdater);
}
// set a texture now so that the ShaderVisitor can find it // set a texture now so that the ShaderVisitor can find it
osg::ref_ptr<osg::StateSet> writableStateSet = NULL; osg::ref_ptr<osg::StateSet> writableStateSet = NULL;
if (!node->getStateSet()) if (!node->getStateSet())
writableStateSet = node->getOrCreateStateSet(); writableStateSet = node->getOrCreateStateSet();
else else
{ {
writableStateSet = osg::clone(node->getStateSet(), osg::CopyOp::SHALLOW_COPY); writableStateSet = osg::clone(node->getStateSet(), osg::CopyOp::SHALLOW_COPY);
node->setStateSet(writableStateSet); node->setStateSet(writableStateSet);
}
writableStateSet->setTextureAttributeAndModes(texUnit, textures.front(), osg::StateAttribute::ON);
writableStateSet->addUniform(new osg::Uniform("envMapColor", glowColor));
mResourceSystem->getSceneManager()->recreateShaders(node);
} }
writableStateSet->setTextureAttributeAndModes(texUnit, textures.front(), osg::StateAttribute::ON);
writableStateSet->addUniform(new osg::Uniform("envMapColor", glowColor));
mResourceSystem->getSceneManager()->recreateShaders(node);
} }
// TODO: Should not be here // TODO: Should not be here