Further adjust FO3+ shader properties based on nifly definitions

macos_ci_fix
Alexei Kotov 1 year ago
parent 4db994cda9
commit 82eed09604

@ -124,22 +124,74 @@ namespace Nif
void BSShaderProperty::read(NIFStream* nif)
{
if (nif->getBethVersion() < NIFFile::BethVersion::BETHVER_F76 && recType == RC_BSLightingShaderProperty)
nif->read(mType);
NiShadeProperty::read(nif);
if (nif->getBethVersion() <= NIFFile::BethVersion::BETHVER_FO3)
if (nif->getUserVersion() <= 11)
{
nif->read(mType);
nif->read(mShaderFlags1);
nif->read(mShaderFlags2);
nif->read(mEnvMapScale);
return;
}
if (!mName.empty() && nif->getBethVersion() >= NIFFile::BethVersion::BETHVER_F76)
return;
if (nif->getBethVersion() <= 131)
{
nif->read(mShaderFlags1);
nif->read(mShaderFlags2);
}
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);
// Remap FO76+ shader types to FO4 system so that we can actually use them
// TODO: NifTools spec doesn't do anything about the misplaced EyeEnvmap. Bug or feature?
switch (mType)
{
case 3:
mType = static_cast<uint32_t>(BSLightingShaderType::ShaderType_FaceTint);
break;
case 4:
mType = static_cast<uint32_t>(BSLightingShaderType::ShaderType_SkinTint);
break;
case 5:
mType = static_cast<uint32_t>(BSLightingShaderType::ShaderType_HairTint);
break;
case 12:
mType = static_cast<uint32_t>(BSLightingShaderType::ShaderType_EyeEnvmap);
break;
case 17:
mType = static_cast<uint32_t>(BSLightingShaderType::ShaderType_Terrain);
break;
default:
break;
}
}
}
nif->read(mUVOffset);
nif->read(mUVScale);
}
void BSShaderLightingProperty::read(NIFStream* nif)
{
BSShaderProperty::read(nif);
if (nif->getBethVersion() <= NIFFile::BethVersion::BETHVER_FO3)
if (nif->getUserVersion() <= 11)
nif->read(mClamp);
}
@ -148,10 +200,15 @@ namespace Nif
BSShaderLightingProperty::read(nif);
mTextureSet.read(nif);
if (nif->getBethVersion() >= 15)
mRefraction.read(nif);
if (nif->getBethVersion() >= 25)
mParallax.read(nif);
if (nif->getUserVersion() == 11)
{
if (nif->getBethVersion() >= 15)
mRefraction.read(nif);
if (nif->getBethVersion() >= 25)
mParallax.read(nif);
}
else if (nif->getUserVersion() >= 12)
nif->read(mEmissiveColor);
}
void BSShaderPPLightingProperty::post(Reader& nif)
@ -212,31 +269,11 @@ namespace Nif
void BSLightingShaderProperty::read(NIFStream* nif)
{
if (nif->getBethVersion() <= 139)
nif->read(mType);
BSShaderProperty::read(nif);
if (nif->getBethVersion() <= 130)
{
nif->read(mShaderFlags1);
nif->read(mShaderFlags2);
}
else if (nif->getBethVersion() >= 132)
{
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)
nif->read(mType);
if (!mName.empty() && nif->getBethVersion() >= NIFFile::BethVersion::BETHVER_F76)
return;
nif->read(mUVOffset);
nif->read(mUVScale);
mTextureSet.read(nif);
nif->read(mEmissive);
nif->read(mEmissiveMult);
@ -299,32 +336,6 @@ namespace Nif
nif->skip(2); // Unknown
}
if (nif->getBethVersion() >= NIFFile::BethVersion::BETHVER_F76)
{
// Remap FO76+ shader types to FO4 system so that we can actually use them
// TODO: NifTools spec doesn't do anything about the misplaced EyeEnvmap. Bug or feature?
switch (static_cast<BSLightingShaderType>(mType))
{
case BSLightingShaderType::ShaderType_Parallax:
mType = static_cast<uint32_t>(BSLightingShaderType::ShaderType_FaceTint);
break;
case BSLightingShaderType::ShaderType_FaceTint:
mType = static_cast<uint32_t>(BSLightingShaderType::ShaderType_SkinTint);
break;
case BSLightingShaderType::ShaderType_SkinTint:
mType = static_cast<uint32_t>(BSLightingShaderType::ShaderType_HairTint);
break;
case BSLightingShaderType::ShaderType_TreeAnim:
mType = static_cast<uint32_t>(BSLightingShaderType::ShaderType_EyeEnvmap);
break;
case BSLightingShaderType::ShaderType_Cloud:
mType = static_cast<uint32_t>(BSLightingShaderType::ShaderType_Terrain);
break;
default:
break;
}
}
switch (static_cast<BSLightingShaderType>(mType))
{
case BSLightingShaderType::ShaderType_EnvMap:
@ -337,10 +348,9 @@ namespace Nif
}
break;
case BSLightingShaderType::ShaderType_SkinTint:
if (nif->getBethVersion() <= NIFFile::BethVersion::BETHVER_FO4)
mSkinTintColor = { nif->get<osg::Vec3f>(), 1.f };
else
nif->read(mSkinTintColor);
nif->read(mSkinTintColor);
if (nif->getBethVersion() > NIFFile::BethVersion::BETHVER_FO4)
nif->read(mSkinTintAlpha);
break;
case BSLightingShaderType::ShaderType_HairTint:
nif->read(mHairTintColor);
@ -375,23 +385,9 @@ namespace Nif
{
BSShaderProperty::read(nif);
if (nif->getBethVersion() <= 130)
{
nif->read(mShaderFlags1);
nif->read(mShaderFlags2);
}
else if (nif->getBethVersion() >= 132)
{
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 (!mName.empty() && nif->getBethVersion() >= NIFFile::BethVersion::BETHVER_F76)
return;
nif->read(mUVOffset);
nif->read(mUVScale);
mSourceTexture = nif->getSizedString();
if (nif->getBethVersion() >= NIFFile::BethVersion::BETHVER_STF)

@ -113,16 +113,16 @@ namespace Nif
struct BSSPParallaxParams
{
float mMaxPasses;
float mScale;
float mMaxPasses{ 4.f };
float mScale{ 1.f };
void read(NIFStream* nif);
};
struct BSSPRefractionParams
{
float mStrength;
int32_t mPeriod;
float mStrength{ 0.f };
int32_t mPeriod{ 0 };
void read(NIFStream* nif);
};
@ -131,6 +131,8 @@ namespace Nif
{
uint32_t mType{ 0u }, mShaderFlags1{ 0u }, mShaderFlags2{ 0u };
float mEnvMapScale{ 0.f };
std::vector<uint32_t> mShaderFlags1Hashes, mShaderFlags2Hashes;
osg::Vec2f mUVOffset, mUVScale;
void read(NIFStream* nif) override;
@ -142,7 +144,7 @@ namespace Nif
struct BSShaderLightingProperty : BSShaderProperty
{
unsigned int mClamp{ 0u };
uint32_t mClamp{ 3 };
void read(NIFStream* nif) override;
@ -155,6 +157,7 @@ namespace Nif
BSShaderTextureSetPtr mTextureSet;
BSSPRefractionParams mRefraction;
BSSPParallaxParams mParallax;
osg::Vec4f mEmissiveColor;
void read(NIFStream* nif) override;
void post(Reader& nif) override;
@ -249,8 +252,6 @@ namespace Nif
struct BSLightingShaderProperty : BSShaderProperty
{
std::vector<uint32_t> mShaderFlags1Hashes, mShaderFlags2Hashes;
osg::Vec2f mUVOffset, mUVScale;
BSShaderTextureSetPtr mTextureSet;
osg::Vec3f mEmissive;
float mEmissiveMult;
@ -277,7 +278,8 @@ namespace Nif
bool mUseSSR;
bool mWetnessUseSSR;
osg::Vec4f mSkinTintColor;
osg::Vec3f mSkinTintColor;
float mSkinTintAlpha{ 1.f };
osg::Vec3f mHairTintColor;
BSSPParallaxParams mParallax;
@ -297,8 +299,6 @@ namespace Nif
struct BSEffectShaderProperty : BSShaderProperty
{
std::vector<uint32_t> mShaderFlags1Hashes, mShaderFlags2Hashes;
osg::Vec2f mUVOffset, mUVScale;
std::string mSourceTexture;
uint8_t mClamp;
uint8_t mLightingInfluence;

Loading…
Cancel
Save