mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-10 14:58:10 -05:00
Apply statemaps to materials
This commit is contained in:
@ -12,8 +12,12 @@
|
||||
#include "Game/IW4/IW4.h"
|
||||
#include "Game/IW4/MaterialConstantsIW4.h"
|
||||
#include "Game/IW4/ObjConstantsIW4.h"
|
||||
#include "Game/IW4/TechsetConstantsIW4.h"
|
||||
#include "Math/Vector.h"
|
||||
#include "Pool/GlobalAssetPool.h"
|
||||
#include "StateMap/StateMapFromTechniqueExtractor.h"
|
||||
#include "StateMap/StateMapHandler.h"
|
||||
#include "Techset/TechniqueFileReader.h"
|
||||
|
||||
using namespace IW4;
|
||||
|
||||
@ -26,10 +30,12 @@ namespace IW4
|
||||
class MaterialGdtLoader : AbstractGdtEntryReader
|
||||
{
|
||||
public:
|
||||
MaterialGdtLoader(const GdtEntry& entry, MemoryManager* memory, IAssetLoadingManager* manager)
|
||||
MaterialGdtLoader(const GdtEntry& entry, MemoryManager* memory, ISearchPath* searchPath, IAssetLoadingManager* manager)
|
||||
: AbstractGdtEntryReader(entry),
|
||||
m_memory(memory),
|
||||
m_search_path(searchPath),
|
||||
m_manager(manager),
|
||||
m_state_map_cache(manager->GetAssetLoadingContext()->GetZoneAssetLoaderState<techset::TechniqueStateMapCache>()),
|
||||
m_material(nullptr),
|
||||
m_base_state_bits{}
|
||||
{
|
||||
@ -167,6 +173,9 @@ namespace IW4
|
||||
|
||||
void mtl_effect_template()
|
||||
{
|
||||
// TODO
|
||||
throw SkipMaterialException();
|
||||
|
||||
commonsetup_template();
|
||||
unitlitcommon_template();
|
||||
}
|
||||
@ -847,6 +856,58 @@ namespace IW4
|
||||
}
|
||||
}
|
||||
|
||||
GfxStateBits GetStateBitsForTechnique(const std::string& techniqueName)
|
||||
{
|
||||
const auto* stateMap = GetStateMapForTechnique(techniqueName);
|
||||
if (!stateMap)
|
||||
return m_base_state_bits;
|
||||
|
||||
const auto preCalculatedStateBits = m_state_bits_per_state_map.find(stateMap);
|
||||
if (preCalculatedStateBits != m_state_bits_per_state_map.end())
|
||||
return preCalculatedStateBits->second;
|
||||
|
||||
const auto stateBits = CalculateStateBitsWithStateMap(stateMap);
|
||||
m_state_bits_per_state_map.emplace(stateMap, stateBits);
|
||||
|
||||
return stateBits;
|
||||
}
|
||||
|
||||
_NODISCARD const state_map::StateMapDefinition* GetStateMapForTechnique(const std::string& techniqueName) const
|
||||
{
|
||||
const auto* preloadedStateMap = m_state_map_cache->GetStateMapForTechnique(techniqueName);
|
||||
if (preloadedStateMap)
|
||||
return preloadedStateMap;
|
||||
|
||||
const auto techniqueFileName = AssetLoaderTechniqueSet::GetTechniqueFileName(techniqueName);
|
||||
const auto file = m_search_path->Open(techniqueFileName);
|
||||
if (!file.IsOpen())
|
||||
return nullptr;
|
||||
|
||||
state_map::StateMapFromTechniqueExtractor extractor;
|
||||
const techset::TechniqueFileReader reader(*file.m_stream, techniqueFileName, &extractor);
|
||||
if (!reader.ReadTechniqueDefinition())
|
||||
{
|
||||
m_state_map_cache->SetTechniqueUsesStateMap(techniqueName, nullptr);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const auto stateMapName = extractor.RetrieveStateMap();
|
||||
const auto* loadedStateMap = AssetLoaderTechniqueSet::LoadStateMapDefinition(stateMapName, m_search_path, m_state_map_cache);
|
||||
m_state_map_cache->SetTechniqueUsesStateMap(techniqueName, loadedStateMap);
|
||||
|
||||
return loadedStateMap;
|
||||
}
|
||||
|
||||
GfxStateBits CalculateStateBitsWithStateMap(const state_map::StateMapDefinition* stateMap) const
|
||||
{
|
||||
const state_map::StateMapHandler stateMapHandler(stateMapLayout, *stateMap);
|
||||
|
||||
GfxStateBits outBits{};
|
||||
stateMapHandler.ApplyStateMap(m_base_state_bits.loadBits, outBits.loadBits);
|
||||
|
||||
return outBits;
|
||||
}
|
||||
|
||||
void SetTechniqueSetCameraRegion(const techset::TechsetDefinition* techsetDefinition) const
|
||||
{
|
||||
std::string tempName;
|
||||
@ -867,12 +928,6 @@ namespace IW4
|
||||
}
|
||||
}
|
||||
|
||||
GfxStateBits GetStateBitsForTechnique(const std::string& techniqueName)
|
||||
{
|
||||
// TODO: Use technique statemap to evaluate actual statebits
|
||||
return m_base_state_bits;
|
||||
}
|
||||
|
||||
void AddMapTexture(const std::string& typeName, const TileMode_e tileMode, GdtFilter_e filterMode, const TextureSemantic semantic, const std::string& textureName)
|
||||
{
|
||||
MaterialTextureDef textureDef{};
|
||||
@ -1263,7 +1318,10 @@ namespace IW4
|
||||
}
|
||||
|
||||
MemoryManager* m_memory;
|
||||
ISearchPath* m_search_path;
|
||||
IAssetLoadingManager* m_manager;
|
||||
techset::TechniqueStateMapCache* m_state_map_cache;
|
||||
std::unordered_map<const state_map::StateMapDefinition*, GfxStateBits> m_state_bits_per_state_map;
|
||||
std::vector<XAssetInfoGeneric*> m_dependencies;
|
||||
|
||||
Material* m_material;
|
||||
@ -1293,7 +1351,7 @@ bool AssetLoaderMaterial::LoadFromGdt(const std::string& assetName, IGdtQueryabl
|
||||
if (!entry)
|
||||
return false;
|
||||
|
||||
MaterialGdtLoader loader(*entry, memory, manager);
|
||||
MaterialGdtLoader loader(*entry, memory, manager->GetAssetLoadingContext()->m_raw_search_path, manager);
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -1007,13 +1007,6 @@ namespace IW4
|
||||
ShaderInfoFromFileSystemCacheState* m_shader_info_cache;
|
||||
techset::TechniqueStateMapCache* m_state_map_cache;
|
||||
|
||||
static std::string GetTechniqueFileName(const std::string& techniqueName)
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss << "techniques/" << techniqueName << ".tech";
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
static void UpdateTechniqueFlags(MaterialTechnique& technique)
|
||||
{
|
||||
// This is stupid but that's what the game does for zprepass for sure
|
||||
@ -1200,7 +1193,7 @@ namespace IW4
|
||||
|
||||
MaterialTechnique* LoadTechniqueFromRaw(const std::string& techniqueName, std::vector<XAssetInfoGeneric*>& dependencies) const
|
||||
{
|
||||
const auto techniqueFileName = GetTechniqueFileName(techniqueName);
|
||||
const auto techniqueFileName = AssetLoaderTechniqueSet::GetTechniqueFileName(techniqueName);
|
||||
const auto file = m_search_path->Open(techniqueFileName);
|
||||
if (!file.IsOpen())
|
||||
return nullptr;
|
||||
@ -1255,6 +1248,13 @@ std::string AssetLoaderTechniqueSet::GetTechsetFileName(const std::string& techs
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string AssetLoaderTechniqueSet::GetTechniqueFileName(const std::string& techniqueName)
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss << "techniques/" << techniqueName << ".tech";
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string AssetLoaderTechniqueSet::GetStateMapFileName(const std::string& stateMapName)
|
||||
{
|
||||
std::ostringstream ss;
|
||||
|
@ -12,12 +12,14 @@ namespace IW4
|
||||
{
|
||||
class AssetLoaderTechniqueSet final : public BasicAssetLoader<ASSET_TYPE_TECHNIQUE_SET, MaterialTechniqueSet>
|
||||
{
|
||||
static std::string GetTechsetFileName(const std::string& techsetAssetName);
|
||||
static std::string GetStateMapFileName(const std::string& stateMapName);
|
||||
static bool CreateTechsetFromDefinition(const std::string& assetName, const techset::TechsetDefinition& definition, ISearchPath* searchPath, MemoryManager* memory,
|
||||
IAssetLoadingManager* manager);
|
||||
|
||||
public:
|
||||
static std::string GetTechsetFileName(const std::string& techsetAssetName);
|
||||
static std::string GetTechniqueFileName(const std::string& techniqueName);
|
||||
static std::string GetStateMapFileName(const std::string& stateMapName);
|
||||
|
||||
static techset::TechsetDefinition* LoadTechsetDefinition(const std::string& assetName, ISearchPath* searchPath, techset::TechsetDefinitionCache* definitionCache);
|
||||
static const state_map::StateMapDefinition* LoadStateMapDefinition(const std::string& stateMapName, ISearchPath* searchPath, techset::TechniqueStateMapCache* stateMapCache);
|
||||
|
||||
|
Reference in New Issue
Block a user