From fdf9184cae5dd92a5eb8e33e096a10630c3ce656 Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Wed, 8 Nov 2023 12:27:12 +0300 Subject: [PATCH] Improve or fix FO76-related definitions --- components/nif/effect.cpp | 4 ++- components/nif/effect.hpp | 3 ++- components/nif/particle.cpp | 6 ++--- components/nif/property.cpp | 52 ++++++++++++++++++------------------- components/nif/property.hpp | 8 +++--- 5 files changed, 38 insertions(+), 35 deletions(-) diff --git a/components/nif/effect.cpp b/components/nif/effect.cpp index ae4c7947cb..47d1863352 100644 --- a/components/nif/effect.cpp +++ b/components/nif/effect.cpp @@ -45,7 +45,9 @@ namespace Nif { NiPointLight::read(nif); - nif->read(mCutoff); + nif->read(mOuterSpotAngle); + if (nif->getVersion() >= NIFStream::generateVersion(20, 2, 0, 5)) + nif->read(mInnerSpotAngle); nif->read(mExponent); } diff --git a/components/nif/effect.hpp b/components/nif/effect.hpp index 906a7fdedf..2dd18d5304 100644 --- a/components/nif/effect.hpp +++ b/components/nif/effect.hpp @@ -58,7 +58,8 @@ namespace Nif struct NiSpotLight : public NiPointLight { - float mCutoff; + float mOuterSpotAngle; + float mInnerSpotAngle{ 0.f }; float mExponent; void read(NIFStream* nif) override; }; diff --git a/components/nif/particle.cpp b/components/nif/particle.cpp index 0581c5a1d1..d81d423fb6 100644 --- a/components/nif/particle.cpp +++ b/components/nif/particle.cpp @@ -231,7 +231,7 @@ namespace Nif info.read(nif); } - if (nif->getBethVersion() >= NIFFile::BethVersion::BETHVER_F76) + if (nif->getBethVersion() > NIFFile::BethVersion::BETHVER_FO4) nif->skip(12); // Unknown if (nif->getVersion() >= NIFStream::generateVersion(20, 0, 0, 2) && nif->get() && hasData) @@ -420,8 +420,8 @@ namespace Nif { nif->read(mRotationSpeedVariation); - if (nif->getBethVersion() >= NIFFile::BethVersion::BETHVER_F76) - nif->skip(5); // Unknown + if (nif->getBethVersion() > NIFFile::BethVersion::BETHVER_FO4) + nif->skip(17); // Unknown nif->read(mRotationAngle); nif->read(mRotationAngleVariation); diff --git a/components/nif/property.cpp b/components/nif/property.cpp index bcc70540c8..2a5f91385d 100644 --- a/components/nif/property.cpp +++ b/components/nif/property.cpp @@ -148,12 +148,6 @@ namespace Nif } else { - uint32_t numShaderFlags1 = 0, numShaderFlags2 = 0; - nif->read(numShaderFlags1); - if (nif->getBethVersion() >= 152) - nif->read(numShaderFlags2); - nif->readVector(mShaderFlags1Hashes, numShaderFlags1); - nif->readVector(mShaderFlags2Hashes, numShaderFlags2); if (nif->getBethVersion() >= NIFFile::BethVersion::BETHVER_F76 && recType == RC_BSLightingShaderProperty) { nif->read(mType); @@ -181,6 +175,13 @@ namespace Nif break; } } + + uint32_t numShaderFlags1 = 0, numShaderFlags2 = 0; + nif->read(numShaderFlags1); + if (nif->getBethVersion() >= 152) + nif->read(numShaderFlags2); + nif->readVector(mShaderFlags1Hashes, numShaderFlags1); + nif->readVector(mShaderFlags2Hashes, numShaderFlags2); } nif->read(mUVOffset); @@ -324,7 +325,7 @@ namespace Nif { nif->read(mSubsurfaceRolloff); nif->read(mRimlightPower); - if (mRimlightPower == std::numeric_limits::max()) + if (nif->getBethVersion() == 130 && mRimlightPower == std::numeric_limits::max()) nif->read(mBacklightPower); } @@ -335,27 +336,27 @@ namespace Nif mWetness.read(nif); } - if (nif->getBethVersion() >= NIFFile::BethVersion::BETHVER_STF) - mLuminance.read(nif); - - if (nif->getBethVersion() == NIFFile::BethVersion::BETHVER_F76) + if (nif->getBethVersion() >= NIFFile::BethVersion::BETHVER_F76) { - nif->read(mDoTranslucency); - if (mDoTranslucency) - mTranslucency.read(nif); - if (nif->get() != 0) + mLuminance.read(nif); + if (nif->getBethVersion() == NIFFile::BethVersion::BETHVER_F76) { - mTextureArrays.resize(nif->get()); - for (std::vector& textureArray : mTextureArrays) - nif->getSizedStrings(textureArray, nif->get()); + nif->read(mDoTranslucency); + if (mDoTranslucency) + mTranslucency.read(nif); + if (nif->get() != 0) + { + mTextureArrays.resize(nif->get()); + for (std::vector& textureArray : mTextureArrays) + nif->getSizedStrings(textureArray, nif->get()); + } + } + if (nif->getBethVersion() >= NIFFile::BethVersion::BETHVER_STF) + { + nif->skip(4); // Unknown + nif->skip(4); // Unknown + nif->skip(2); // Unknown } - } - - if (nif->getBethVersion() >= NIFFile::BethVersion::BETHVER_STF) - { - nif->skip(4); // Unknown - nif->skip(4); // Unknown - nif->skip(2); // Unknown } switch (static_cast(mType)) @@ -439,7 +440,6 @@ namespace Nif if (nif->getBethVersion() >= NIFFile::BethVersion::BETHVER_F76) { - nif->read(mRefractionPower); mReflectanceTexture = nif->getSizedString(); mLightingTexture = nif->getSizedString(); nif->read(mEmittanceColor); diff --git a/components/nif/property.hpp b/components/nif/property.hpp index eaaa972c39..2506633867 100644 --- a/components/nif/property.hpp +++ b/components/nif/property.hpp @@ -295,15 +295,15 @@ namespace Nif { BSShaderTextureSetPtr mTextureSet; osg::Vec3f mEmissive; - float mEmissiveMult; + float mEmissiveMult{ 1.f }; std::string mRootMaterial; - uint32_t mClamp; - float mAlpha; + uint32_t mClamp{ 3 }; + float mAlpha{ 1.f }; float mRefractionStrength; float mGlossiness{ 80.f }; float mSmoothness{ 1.f }; osg::Vec3f mSpecular; - float mSpecStrength; + float mSpecStrength{ 1.f }; std::array mLightingEffects; float mSubsurfaceRolloff; float mRimlightPower;