More BGSM cleanup

pull/3235/head
Alexei Kotov 8 months ago
parent 6be2bb70c3
commit 77c3cd4467

@ -38,10 +38,8 @@ namespace Bgsm
} }
stream.read(mGrayscaleToPaletteColor); stream.read(mGrayscaleToPaletteColor);
if (mVersion >= 6) if (mVersion >= 6)
{
stream.read(mMaskWrites); stream.read(mMaskWrites);
} }
}
void BGSMFile::read(BGSMStream& stream) void BGSMFile::read(BGSMStream& stream)
{ {
@ -59,10 +57,8 @@ namespace Bgsm
stream.read(mLightingMap); stream.read(mLightingMap);
stream.read(mFlowMap); stream.read(mFlowMap);
if (mVersion >= 17) if (mVersion >= 17)
{
stream.read(mDistanceFieldAlphaMap); stream.read(mDistanceFieldAlphaMap);
} }
}
else else
{ {
stream.read(mEnvMap); stream.read(mEnvMap);
@ -98,9 +94,7 @@ namespace Bgsm
stream.read(mWetnessControlSpecPowerScale); stream.read(mWetnessControlSpecPowerScale);
stream.read(mWetnessControlSpecMinvar); stream.read(mWetnessControlSpecMinvar);
if (mVersion < 10) if (mVersion < 10)
{
stream.read(mWetnessControlEnvMapScale); stream.read(mWetnessControlEnvMapScale);
}
stream.read(mWetnessControlFresnelPower); stream.read(mWetnessControlFresnelPower);
stream.read(mWetnessControlMetalness); stream.read(mWetnessControlMetalness);
if (mVersion >= 3) if (mVersion >= 3)
@ -116,9 +110,7 @@ namespace Bgsm
stream.read(mAnisoLighting); stream.read(mAnisoLighting);
stream.read(mEmitEnabled); stream.read(mEmitEnabled);
if (mEmitEnabled) if (mEmitEnabled)
{
stream.read(mEmittanceColor); stream.read(mEmittanceColor);
}
stream.read(mEmittanceMult); stream.read(mEmittanceMult);
stream.read(mModelSpaceNormals); stream.read(mModelSpaceNormals);
stream.read(mExternalEmittance); stream.read(mExternalEmittance);
@ -181,14 +173,14 @@ namespace Bgsm
stream.read(mEnvMap); stream.read(mEnvMap);
stream.read(mNormalMap); stream.read(mNormalMap);
stream.read(mEnvMapMask); stream.read(mEnvMapMask);
if (mVersion >= 10)
{
if (mVersion >= 11) if (mVersion >= 11)
{ {
stream.read(mSpecularMap); stream.read(mSpecularMap);
stream.read(mLightingMap); stream.read(mLightingMap);
stream.read(mGlowMap); stream.read(mGlowMap);
} }
if (mVersion >= 10)
{
stream.read(mEnvMapEnabled); stream.read(mEnvMapEnabled);
stream.read(mEnvMapMaskScale); stream.read(mEnvMapMaskScale);
} }
@ -205,20 +197,12 @@ namespace Bgsm
stream.read(mEnvmapMinLOD); stream.read(mEnvmapMinLOD);
stream.read(mSoftDepth); stream.read(mSoftDepth);
if (mVersion >= 11) if (mVersion >= 11)
{
stream.read(mEmittanceColor); stream.read(mEmittanceColor);
if (mVersion >= 15) if (mVersion >= 15)
{
stream.read(mAdaptiveEmissiveExposureParams); stream.read(mAdaptiveEmissiveExposureParams);
if (mVersion >= 16) if (mVersion >= 16)
{
stream.read(mGlowMapEnabled); stream.read(mGlowMapEnabled);
if (mVersion >= 20) if (mVersion >= 20)
{
stream.read(mEffectPbrSpecular); stream.read(mEffectPbrSpecular);
} }
}
}
}
}
} }

@ -50,7 +50,7 @@ namespace Bgsm
MaterialFile() = default; MaterialFile() = default;
virtual void read(BGSMStream& stream); virtual void read(BGSMStream& stream);
virtual ~MaterialFile() {} virtual ~MaterialFile() = default;
}; };
struct BGSMFile : MaterialFile struct BGSMFile : MaterialFile

@ -31,5 +31,4 @@ namespace Bgsm
mFile->read(stream); mFile->read(stream);
} }
} }

@ -2,7 +2,6 @@
namespace Bgsm namespace Bgsm
{ {
template <> template <>
void BGSMStream::read<osg::Vec2f>(osg::Vec2f& vec) void BGSMStream::read<osg::Vec2f>(osg::Vec2f& vec)
{ {
@ -37,5 +36,4 @@ namespace Bgsm
if (end != std::string::npos) if (end != std::string::npos)
str.erase(end); str.erase(end);
} }
} }

@ -2151,18 +2151,19 @@ namespace NifOsg
handleTextureControllers(texprop, composite, stateset, animflags); handleTextureControllers(texprop, composite, stateset, animflags);
} }
Bgsm::MaterialFilePtr getShaderMaterial(std::string_view path) const static Bgsm::MaterialFilePtr getShaderMaterial(
std::string_view path, Resource::BgsmFileManager* materialManager)
{ {
if (!mMaterialManager) if (!materialManager)
return nullptr; return nullptr;
if (!Misc::StringUtils::ciEndsWith(path, ".bgem") && !Misc::StringUtils::ciEndsWith(path, ".bgsm")) if (!Misc::StringUtils::ciEndsWith(path, ".bgem") && !Misc::StringUtils::ciEndsWith(path, ".bgsm"))
return nullptr; return nullptr;
std::string normalizedPath = Misc::ResourceHelpers::correctMaterialPath(path, mMaterialManager->getVFS()); std::string normalizedPath = Misc::ResourceHelpers::correctMaterialPath(path, materialManager->getVFS());
try try
{ {
return mMaterialManager->get(VFS::Path::Normalized(normalizedPath)); return materialManager->get(VFS::Path::Normalized(normalizedPath));
} }
catch (std::exception& e) catch (std::exception& e)
{ {
@ -2528,7 +2529,7 @@ namespace NifOsg
node->setUserValue("shaderRequired", shaderRequired); node->setUserValue("shaderRequired", shaderRequired);
osg::StateSet* stateset = node->getOrCreateStateSet(); osg::StateSet* stateset = node->getOrCreateStateSet();
clearBoundTextures(stateset, boundTextures); clearBoundTextures(stateset, boundTextures);
if (Bgsm::MaterialFilePtr material = getShaderMaterial(texprop->mName)) if (Bgsm::MaterialFilePtr material = getShaderMaterial(texprop->mName, mMaterialManager))
{ {
handleShaderMaterialNodeProperties(material, stateset, boundTextures); handleShaderMaterialNodeProperties(material, stateset, boundTextures);
break; break;
@ -2557,7 +2558,7 @@ namespace NifOsg
node->setUserValue("shaderRequired", shaderRequired); node->setUserValue("shaderRequired", shaderRequired);
osg::StateSet* stateset = node->getOrCreateStateSet(); osg::StateSet* stateset = node->getOrCreateStateSet();
clearBoundTextures(stateset, boundTextures); clearBoundTextures(stateset, boundTextures);
if (Bgsm::MaterialFilePtr material = getShaderMaterial(texprop->mName)) if (Bgsm::MaterialFilePtr material = getShaderMaterial(texprop->mName, mMaterialManager))
{ {
handleShaderMaterialNodeProperties(material, stateset, boundTextures); handleShaderMaterialNodeProperties(material, stateset, boundTextures);
break; break;
@ -2776,15 +2777,14 @@ namespace NifOsg
case Nif::RC_BSLightingShaderProperty: case Nif::RC_BSLightingShaderProperty:
{ {
auto shaderprop = static_cast<const Nif::BSLightingShaderProperty*>(property); auto shaderprop = static_cast<const Nif::BSLightingShaderProperty*>(property);
if (Bgsm::MaterialFilePtr shaderMat = getShaderMaterial(shaderprop->mName)) if (Bgsm::MaterialFilePtr shaderMat = getShaderMaterial(shaderprop->mName, mMaterialManager))
{ {
handleShaderMaterialDrawableProperties(shaderMat, mat, *node, hasSortAlpha); handleShaderMaterialDrawableProperties(shaderMat, mat, *node, hasSortAlpha);
if (shaderMat->mShaderType == Bgsm::ShaderType::Lighting) if (shaderMat->mShaderType == Bgsm::ShaderType::Lighting)
{ {
auto bgsm = static_cast<const Bgsm::BGSMFile*>(shaderMat.get()); auto bgsm = static_cast<const Bgsm::BGSMFile*>(shaderMat.get());
specEnabled specEnabled = false; // bgsm->mSpecularEnabled; TODO: PBR specular lighting
= false; // bgsm->mSpecularEnabled; disabled until it can be implemented properly specStrength = 1.f; // bgsm->mSpecularMult;
specStrength = bgsm->mSpecularMult;
emissiveMult = bgsm->mEmittanceMult; emissiveMult = bgsm->mEmittanceMult;
} }
break; break;
@ -2803,7 +2803,7 @@ namespace NifOsg
case Nif::RC_BSEffectShaderProperty: case Nif::RC_BSEffectShaderProperty:
{ {
auto shaderprop = static_cast<const Nif::BSEffectShaderProperty*>(property); auto shaderprop = static_cast<const Nif::BSEffectShaderProperty*>(property);
if (Bgsm::MaterialFilePtr shaderMat = getShaderMaterial(shaderprop->mName)) if (Bgsm::MaterialFilePtr shaderMat = getShaderMaterial(shaderprop->mName, mMaterialManager))
{ {
handleShaderMaterialDrawableProperties(shaderMat, mat, *node, hasSortAlpha); handleShaderMaterialDrawableProperties(shaderMat, mat, *node, hasSortAlpha);
break; break;

@ -1,7 +1,5 @@
#include "bgsmfilemanager.hpp" #include "bgsmfilemanager.hpp"
#include <iostream>
#include <osg/Object> #include <osg/Object>
#include <components/bgsm/reader.hpp> #include <components/bgsm/reader.hpp>
@ -36,8 +34,6 @@ namespace Resource
{ {
} }
BgsmFileManager::~BgsmFileManager() = default;
Bgsm::MaterialFilePtr BgsmFileManager::get(VFS::Path::NormalizedView name) Bgsm::MaterialFilePtr BgsmFileManager::get(VFS::Path::NormalizedView name)
{ {
osg::ref_ptr<osg::Object> obj = mCache->getRefFromObjectCache(name); osg::ref_ptr<osg::Object> obj = mCache->getRefFromObjectCache(name);

@ -14,7 +14,7 @@ namespace Resource
{ {
public: public:
BgsmFileManager(const VFS::Manager* vfs, double expiryDelay); BgsmFileManager(const VFS::Manager* vfs, double expiryDelay);
~BgsmFileManager(); ~BgsmFileManager() = default;
/// Retrieve a material file from the cache or load it from the VFS if not cached yet. /// Retrieve a material file from the cache or load it from the VFS if not cached yet.
Bgsm::MaterialFilePtr get(VFS::Path::NormalizedView name); Bgsm::MaterialFilePtr get(VFS::Path::NormalizedView name);

Loading…
Cancel
Save