From b2cb98d30e62c78470c479f471f622835828299a Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Wed, 16 Sep 2020 23:03:42 +0100 Subject: [PATCH 1/2] Fix NiFlipController NiFlipControllers *always* affect the base texture, even if no base texture is bound. When no base texture is bound, they default to UV set zero and to having wrapped UV coordinates, instead of using the settings for the disabled base texture. --- components/nifosg/controller.cpp | 2 +- components/nifosg/nifloader.cpp | 77 +++++++++++++++++++------------- 2 files changed, 46 insertions(+), 33 deletions(-) diff --git a/components/nifosg/controller.cpp b/components/nifosg/controller.cpp index 58f1c17a74..b6610728ae 100644 --- a/components/nifosg/controller.cpp +++ b/components/nifosg/controller.cpp @@ -449,7 +449,7 @@ void MaterialColorController::apply(osg::StateSet *stateset, osg::NodeVisitor *n } FlipController::FlipController(const Nif::NiFlipController *ctrl, const std::vector >& textures) - : mTexSlot(ctrl->mTexSlot) + : mTexSlot(0) // always affects diffuse , mDelta(ctrl->mDelta) , mTextures(textures) { diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index 21ae49975d..24184f2c84 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -799,22 +799,23 @@ namespace NifOsg { const Nif::NiFlipController* flipctrl = static_cast(ctrl.getPtr()); std::vector > textures; + + // inherit wrap settings from the target slot + osg::Texture2D* inherit = dynamic_cast(stateset->getTextureAttribute(0, osg::StateAttribute::TEXTURE)); + osg::Texture2D::WrapMode wrapS = osg::Texture2D::REPEAT; + osg::Texture2D::WrapMode wrapT = osg::Texture2D::REPEAT; + if (inherit) + { + wrapS = inherit->getWrap(osg::Texture2D::WRAP_S); + wrapT = inherit->getWrap(osg::Texture2D::WRAP_T); + } + for (unsigned int i=0; imSources.length(); ++i) { Nif::NiSourceTexturePtr st = flipctrl->mSources[i]; if (st.empty()) continue; - // inherit wrap settings from the target slot - osg::Texture2D* inherit = dynamic_cast(stateset->getTextureAttribute(flipctrl->mTexSlot, osg::StateAttribute::TEXTURE)); - osg::Texture2D::WrapMode wrapS = osg::Texture2D::CLAMP_TO_EDGE; - osg::Texture2D::WrapMode wrapT = osg::Texture2D::CLAMP_TO_EDGE; - if (inherit) - { - wrapS = inherit->getWrap(osg::Texture2D::WRAP_S); - wrapT = inherit->getWrap(osg::Texture2D::WRAP_T); - } - osg::ref_ptr image (handleSourceTexture(st.getPtr(), imageManager)); osg::ref_ptr texture (new osg::Texture2D(image)); if (image) @@ -1451,7 +1452,7 @@ namespace NifOsg // If this loop is changed such that the base texture isn't guaranteed to end up in texture unit 0, the shadow casting shader will need to be updated accordingly. for (size_t i=0; itextures.size(); ++i) { - if (texprop->textures[i].inUse) + if (texprop->textures[i].inUse || (i == Nif::NiTexturingProperty::BaseTexture && !texprop->controller.empty())) { switch(i) { @@ -1477,32 +1478,44 @@ namespace NifOsg } } - const Nif::NiTexturingProperty::Texture& tex = texprop->textures[i]; - if(tex.texture.empty() && texprop->controller.empty()) - { - if (i == 0) - Log(Debug::Warning) << "Base texture is in use but empty on shape \"" << nodeName << "\" in " << mFilename; - continue; - } - + unsigned int uvSet = 0; // create a new texture, will later attempt to share using the SharedStateManager osg::ref_ptr texture2d; - if (!tex.texture.empty()) + if (texprop->textures[i].inUse) { - const Nif::NiSourceTexture *st = tex.texture.getPtr(); - osg::ref_ptr image = handleSourceTexture(st, imageManager); - texture2d = new osg::Texture2D(image); - if (image) - texture2d->setTextureSize(image->s(), image->t()); + const Nif::NiTexturingProperty::Texture& tex = texprop->textures[i]; + if(tex.texture.empty() && texprop->controller.empty()) + { + if (i == 0) + Log(Debug::Warning) << "Base texture is in use but empty on shape \"" << nodeName << "\" in " << mFilename; + continue; + } + + if (!tex.texture.empty()) + { + const Nif::NiSourceTexture *st = tex.texture.getPtr(); + osg::ref_ptr image = handleSourceTexture(st, imageManager); + texture2d = new osg::Texture2D(image); + if (image) + texture2d->setTextureSize(image->s(), image->t()); + } + else + texture2d = new osg::Texture2D; + + bool wrapT = tex.clamp & 0x1; + bool wrapS = (tex.clamp >> 1) & 0x1; + + texture2d->setWrap(osg::Texture::WRAP_S, wrapS ? osg::Texture::REPEAT : osg::Texture::CLAMP_TO_EDGE); + texture2d->setWrap(osg::Texture::WRAP_T, wrapT ? osg::Texture::REPEAT : osg::Texture::CLAMP_TO_EDGE); } else + { + // Texture only comes from NiFlipController, so tex is ignored, set defaults texture2d = new osg::Texture2D; - - bool wrapT = tex.clamp & 0x1; - bool wrapS = (tex.clamp >> 1) & 0x1; - - texture2d->setWrap(osg::Texture::WRAP_S, wrapS ? osg::Texture::REPEAT : osg::Texture::CLAMP_TO_EDGE); - texture2d->setWrap(osg::Texture::WRAP_T, wrapT ? osg::Texture::REPEAT : osg::Texture::CLAMP_TO_EDGE); + texture2d->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT); + texture2d->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT); + uvSet = 0; + } unsigned int texUnit = boundTextures.size(); @@ -1590,7 +1603,7 @@ namespace NifOsg break; } - boundTextures.push_back(tex.uvSet); + boundTextures.push_back(uvSet); } } handleTextureControllers(texprop, composite, imageManager, stateset, animflags); From f8f72ce4c4c24c5a1691629270fad64ed5eb1240 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Wed, 16 Sep 2020 23:08:01 +0100 Subject: [PATCH 2/2] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00d7f3539b..026a65c240 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Bug #1662: Qt4 and Windows binaries crash if there's a non-ASCII character in a file path/config path Bug #1952: Incorrect particle lighting + Bug #2069: Fireflies in Fireflies invade Morrowind look wrong Bug #2311: Targeted scripts are not properly supported on non-unique RefIDs Bug #3676: NiParticleColorModifier isn't applied properly Bug #3714: Savegame fails to load due to conflict between SpellState and MagicEffects