diff --git a/src/ObjCommon/Shader/ShaderCommon.cpp b/src/ObjCommon/Shader/ShaderCommon.cpp new file mode 100644 index 00000000..e7cb5994 --- /dev/null +++ b/src/ObjCommon/Shader/ShaderCommon.cpp @@ -0,0 +1,16 @@ +#include "ShaderCommon.h" + +#include + +namespace shader +{ + std::string GetFileNameForPixelShaderAssetName(const std::string& assetName) + { + return std::format("shader_bin/ps_{}.cso", assetName); + } + + std::string GetFileNameForVertexShaderAssetName(const std::string& assetName) + { + return std::format("shader_bin/vs_{}.cso", assetName); + } +} // namespace phys_constraints diff --git a/src/ObjCommon/Shader/ShaderCommon.h b/src/ObjCommon/Shader/ShaderCommon.h new file mode 100644 index 00000000..0e3ef878 --- /dev/null +++ b/src/ObjCommon/Shader/ShaderCommon.h @@ -0,0 +1,9 @@ +#pragma once + +#include + +namespace shader +{ + std::string GetFileNameForPixelShaderAssetName(const std::string& assetName); + std::string GetFileNameForVertexShaderAssetName(const std::string& assetName); +} // namespace shader diff --git a/src/ObjCommon/Techset/TechsetCommon.cpp b/src/ObjCommon/Techset/TechsetCommon.cpp new file mode 100644 index 00000000..0deff7f2 --- /dev/null +++ b/src/ObjCommon/Techset/TechsetCommon.cpp @@ -0,0 +1,16 @@ +#include "TechsetCommon.h" + +#include + +namespace techset +{ + std::string GetFileNameForTechniqueName(const std::string& assetName) + { + return std::format("techniques/{}.tech", assetName); + } + + std::string GetFileNameForTechsetName(const std::string& assetName) + { + return std::format("techsets/{}.techset", assetName); + } +} // namespace phys_constraints diff --git a/src/ObjCommon/Techset/TechsetCommon.h b/src/ObjCommon/Techset/TechsetCommon.h new file mode 100644 index 00000000..61e467c0 --- /dev/null +++ b/src/ObjCommon/Techset/TechsetCommon.h @@ -0,0 +1,9 @@ +#pragma once + +#include + +namespace techset +{ + std::string GetFileNameForTechniqueName(const std::string& assetName); + std::string GetFileNameForTechsetName(const std::string& assetName); +} diff --git a/src/ObjWriting/Game/IW4/ObjWriterIW4.cpp b/src/ObjWriting/Game/IW4/ObjWriterIW4.cpp index 6da19f72..9bf0047c 100644 --- a/src/ObjWriting/Game/IW4/ObjWriterIW4.cpp +++ b/src/ObjWriting/Game/IW4/ObjWriterIW4.cpp @@ -21,7 +21,7 @@ #include "Sound/AssetDumperSndCurve.h" #include "StringTable/StringTableDumperIW4.h" #include "StructuredDataDef/AssetDumperStructuredDataDefSet.h" -#include "Techset/AssetDumperTechniqueSet.h" +#include "Techset/TechsetDumperIW4.h" #include "Tracer/AssetDumperTracer.h" #include "Vehicle/AssetDumperVehicle.h" #include "Weapon/AssetDumperWeapon.h" @@ -49,7 +49,7 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const #endif DUMP_ASSET_POOL(AssetDumperPixelShader, m_material_pixel_shader, ASSET_TYPE_PIXELSHADER) DUMP_ASSET_POOL(AssetDumperVertexShader, m_material_vertex_shader, ASSET_TYPE_VERTEXSHADER) - DUMP_ASSET_POOL(AssetDumperTechniqueSet, m_technique_set, ASSET_TYPE_TECHNIQUE_SET) + DUMP_ASSET_POOL(techset::Dumper, m_technique_set, ASSET_TYPE_TECHNIQUE_SET) DUMP_ASSET_POOL(image::Dumper, m_image, ASSET_TYPE_IMAGE) // DUMP_ASSET_POOL(AssetDumpersnd_alias_list_t, m_sound, ASSET_TYPE_SOUND) DUMP_ASSET_POOL(AssetDumperSndCurve, m_sound_curve, ASSET_TYPE_SOUND_CURVE) diff --git a/src/ObjWriting/Game/IW4/Techset/AssetDumperTechniqueSet.h b/src/ObjWriting/Game/IW4/Techset/AssetDumperTechniqueSet.h deleted file mode 100644 index 67495b9b..00000000 --- a/src/ObjWriting/Game/IW4/Techset/AssetDumperTechniqueSet.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "Dumping/AbstractAssetDumper.h" -#include "Game/IW4/IW4.h" - -namespace IW4 -{ - class AssetDumperTechniqueSet final : public AbstractAssetDumper - { - static std::string GetTechniqueFileName(const MaterialTechnique* technique); - static std::string GetTechsetFileName(const MaterialTechniqueSet* techset); - - protected: - bool ShouldDump(XAssetInfo* asset) override; - void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; - }; -} // namespace IW4 diff --git a/src/ObjWriting/Game/IW4/Techset/AssetDumperTechniqueSet.cpp b/src/ObjWriting/Game/IW4/Techset/TechsetDumperIW4.cpp similarity index 94% rename from src/ObjWriting/Game/IW4/Techset/AssetDumperTechniqueSet.cpp rename to src/ObjWriting/Game/IW4/Techset/TechsetDumperIW4.cpp index 101d323d..2fa97986 100644 --- a/src/ObjWriting/Game/IW4/Techset/AssetDumperTechniqueSet.cpp +++ b/src/ObjWriting/Game/IW4/Techset/TechsetDumperIW4.cpp @@ -1,9 +1,10 @@ -#include "AssetDumperTechniqueSet.h" +#include "TechsetDumperIW4.h" #include "Dumping/AbstractTextDumper.h" #include "Game/IW4/TechsetConstantsIW4.h" #include "Pool/GlobalAssetPool.h" #include "Shader/D3D9ShaderAnalyser.h" +#include "Techset/TechsetCommon.h" #include #include @@ -12,6 +13,7 @@ #include using namespace IW4; +using namespace ::techset; namespace IW4 { @@ -531,48 +533,37 @@ namespace IW4 }; } // namespace IW4 -std::string AssetDumperTechniqueSet::GetTechniqueFileName(const MaterialTechnique* technique) +namespace IW4::techset { - std::ostringstream ss; - ss << "techniques/" << technique->name << ".tech"; - return ss.str(); -} - -std::string AssetDumperTechniqueSet::GetTechsetFileName(const MaterialTechniqueSet* techset) -{ - std::ostringstream ss; - ss << "techsets/" << techset->name << ".techset"; - return ss.str(); -} - -bool AssetDumperTechniqueSet::ShouldDump(XAssetInfo* asset) -{ - return true; -} - -void AssetDumperTechniqueSet::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) -{ - const auto* techset = asset->Asset(); - - const auto techsetFile = context.OpenAssetFile(GetTechsetFileName(techset)); - - if (techsetFile) + bool Dumper::ShouldDump(XAssetInfo* asset) { - TechsetFileWriter writer(*techsetFile); - writer.DumpTechset(techset); + return true; } - auto* techniqueState = context.GetZoneAssetDumperState(); - for (const auto* technique : techset->techniques) + void Dumper::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { - if (technique && techniqueState->ShouldDumpTechnique(technique)) + const auto* techset = asset->Asset(); + + const auto techsetFile = context.OpenAssetFile(GetFileNameForTechsetName(techset->name)); + + if (techsetFile) { - const auto techniqueFile = context.OpenAssetFile(GetTechniqueFileName(technique)); - if (techniqueFile) + TechsetFileWriter writer(*techsetFile); + writer.DumpTechset(techset); + } + + auto* techniqueState = context.GetZoneAssetDumperState(); + for (const auto* technique : techset->techniques) + { + if (technique && techniqueState->ShouldDumpTechnique(technique)) { - TechniqueFileWriter writer(*techniqueFile); - writer.DumpTechnique(technique); + const auto techniqueFile = context.OpenAssetFile(GetFileNameForTechniqueName(technique->name)); + if (techniqueFile) + { + TechniqueFileWriter writer(*techniqueFile); + writer.DumpTechnique(technique); + } } } } -} +} // namespace IW4::techset diff --git a/src/ObjWriting/Game/IW4/Techset/TechsetDumperIW4.h b/src/ObjWriting/Game/IW4/Techset/TechsetDumperIW4.h new file mode 100644 index 00000000..97535e3e --- /dev/null +++ b/src/ObjWriting/Game/IW4/Techset/TechsetDumperIW4.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Dumping/AbstractAssetDumper.h" +#include "Game/IW4/IW4.h" + +namespace IW4::techset +{ + class Dumper final : public AbstractAssetDumper + { + protected: + bool ShouldDump(XAssetInfo* asset) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; + }; +} // namespace IW4::techset diff --git a/src/ObjWriting/Game/T6/ObjWriterT6.cpp b/src/ObjWriting/Game/T6/ObjWriterT6.cpp index 4edd49fa..937ea121 100644 --- a/src/ObjWriting/Game/T6/ObjWriterT6.cpp +++ b/src/ObjWriting/Game/T6/ObjWriterT6.cpp @@ -18,7 +18,7 @@ #include "Sound/AssetDumperSndBank.h" #include "Sound/AssetDumperSndDriverGlobals.h" #include "StringTable/StringTableDumperT6.h" -#include "Techset/AssetDumperTechniqueSet.h" +#include "Techset/TechsetDumperT6.h" #include "Tracer/AssetDumperTracer.h" #include "Vehicle/AssetDumperVehicle.h" #include "Weapon/AssetDumperWeapon.h" @@ -52,7 +52,7 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const // DUMP_ASSET_POOL(AssetDumperXAnimParts, m_xanim_parts, ASSET_TYPE_XANIMPARTS) DUMP_ASSET_POOL(AssetDumperXModel, m_xmodel, ASSET_TYPE_XMODEL) DUMP_ASSET_POOL(material::JsonDumper, m_material, ASSET_TYPE_MATERIAL) - DUMP_ASSET_POOL(AssetDumperTechniqueSet, m_technique_set, ASSET_TYPE_TECHNIQUE_SET) + DUMP_ASSET_POOL(techset::Dumper, m_technique_set, ASSET_TYPE_TECHNIQUE_SET) DUMP_ASSET_POOL(image::Dumper, m_image, ASSET_TYPE_IMAGE) DUMP_ASSET_POOL(AssetDumperSndBank, m_sound_bank, ASSET_TYPE_SOUND) // DUMP_ASSET_POOL(AssetDumperSndPatch, m_sound_patch, ASSET_TYPE_SOUND_PATCH) diff --git a/src/ObjWriting/Game/T6/Techset/AssetDumperTechniqueSet.cpp b/src/ObjWriting/Game/T6/Techset/AssetDumperTechniqueSet.cpp deleted file mode 100644 index e5b0b142..00000000 --- a/src/ObjWriting/Game/T6/Techset/AssetDumperTechniqueSet.cpp +++ /dev/null @@ -1,106 +0,0 @@ -#include "AssetDumperTechniqueSet.h" - -#include -#include - -using namespace T6; - -class ShaderZoneState final : public IZoneAssetDumperState -{ -public: - bool ShouldDumpTechnique(const MaterialTechnique* technique) - { - const auto existingTechnique = m_dumped_techniques.find(technique); - if (existingTechnique == m_dumped_techniques.end()) - { - m_dumped_techniques.emplace(technique); - return true; - } - - return false; - } - - bool ShouldDumpPixelShader(const MaterialPixelShader* pixelShader) - { - const auto existingPixelShader = m_dumped_pixel_shaders.find(pixelShader); - if (existingPixelShader == m_dumped_pixel_shaders.end()) - { - m_dumped_pixel_shaders.emplace(pixelShader); - return true; - } - - return false; - } - - bool ShouldDumpVertexShader(const MaterialVertexShader* vertexShader) - { - const auto existingVertexShader = m_dumped_vertex_shaders.find(vertexShader); - if (existingVertexShader == m_dumped_vertex_shaders.end()) - { - m_dumped_vertex_shaders.emplace(vertexShader); - return true; - } - - return false; - } - -private: - std::unordered_set m_dumped_techniques; - std::unordered_set m_dumped_pixel_shaders; - std::unordered_set m_dumped_vertex_shaders; -}; - -bool AssetDumperTechniqueSet::ShouldDump(XAssetInfo* asset) -{ - return true; -} - -void AssetDumperTechniqueSet::DumpPixelShader(const AssetDumpingContext& context, const MaterialPixelShader* pixelShader) -{ - std::ostringstream ss; - ss << "shader_bin/ps_" << pixelShader->name << ".cso"; - - const auto shaderFile = context.OpenAssetFile(ss.str()); - - if (!shaderFile) - return; - - shaderFile->write(pixelShader->prog.loadDef.program, pixelShader->prog.loadDef.programSize); -} - -void AssetDumperTechniqueSet::DumpVertexShader(const AssetDumpingContext& context, const MaterialVertexShader* vertexShader) -{ - std::ostringstream ss; - ss << "shader_bin/vs_" << vertexShader->name << ".cso"; - - const auto shaderFile = context.OpenAssetFile(ss.str()); - - if (!shaderFile) - return; - - shaderFile->write(vertexShader->prog.loadDef.program, vertexShader->prog.loadDef.programSize); -} - -void AssetDumperTechniqueSet::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) -{ - const auto* techniqueSet = asset->Asset(); - auto* shaderState = context.GetZoneAssetDumperState(); - - for (const auto* technique : techniqueSet->techniques) - { - if (!technique || !shaderState->ShouldDumpTechnique(technique)) - continue; - - for (auto passIndex = 0u; passIndex < technique->passCount; passIndex++) - { - const auto* pixelShader = technique->passArray[passIndex].pixelShader; - - if (pixelShader && shaderState->ShouldDumpPixelShader(pixelShader)) - DumpPixelShader(context, pixelShader); - - const auto* vertexShader = technique->passArray[passIndex].vertexShader; - if (vertexShader && shaderState->ShouldDumpVertexShader(vertexShader)) - DumpVertexShader(context, vertexShader); - } - } -} diff --git a/src/ObjWriting/Game/T6/Techset/AssetDumperTechniqueSet.h b/src/ObjWriting/Game/T6/Techset/AssetDumperTechniqueSet.h deleted file mode 100644 index 5a34305e..00000000 --- a/src/ObjWriting/Game/T6/Techset/AssetDumperTechniqueSet.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "Dumping/AbstractAssetDumper.h" -#include "Game/T6/T6.h" - -namespace T6 -{ - class AssetDumperTechniqueSet final : public AbstractAssetDumper - { - static void DumpPixelShader(const AssetDumpingContext& context, const MaterialPixelShader* pixelShader); - static void DumpVertexShader(const AssetDumpingContext& context, const MaterialVertexShader* vertexShader); - - protected: - bool ShouldDump(XAssetInfo* asset) override; - void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; - }; -} // namespace T6 diff --git a/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.cpp b/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.cpp new file mode 100644 index 00000000..abbb953a --- /dev/null +++ b/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.cpp @@ -0,0 +1,107 @@ +#include "TechsetDumperT6.h" + +#include "Shader/ShaderCommon.h" + +#include +#include + +using namespace T6; + +namespace +{ + class ShaderZoneState final : public IZoneAssetDumperState + { + public: + bool ShouldDumpTechnique(const MaterialTechnique* technique) + { + const auto existingTechnique = m_dumped_techniques.find(technique); + if (existingTechnique == m_dumped_techniques.end()) + { + m_dumped_techniques.emplace(technique); + return true; + } + + return false; + } + + bool ShouldDumpPixelShader(const MaterialPixelShader* pixelShader) + { + const auto existingPixelShader = m_dumped_pixel_shaders.find(pixelShader); + if (existingPixelShader == m_dumped_pixel_shaders.end()) + { + m_dumped_pixel_shaders.emplace(pixelShader); + return true; + } + + return false; + } + + bool ShouldDumpVertexShader(const MaterialVertexShader* vertexShader) + { + const auto existingVertexShader = m_dumped_vertex_shaders.find(vertexShader); + if (existingVertexShader == m_dumped_vertex_shaders.end()) + { + m_dumped_vertex_shaders.emplace(vertexShader); + return true; + } + + return false; + } + + private: + std::unordered_set m_dumped_techniques; + std::unordered_set m_dumped_pixel_shaders; + std::unordered_set m_dumped_vertex_shaders; + }; + + void DumpPixelShader(const AssetDumpingContext& context, const MaterialPixelShader& pixelShader) + { + const auto shaderFile = context.OpenAssetFile(shader::GetFileNameForPixelShaderAssetName(pixelShader.name)); + + if (!shaderFile) + return; + + shaderFile->write(pixelShader.prog.loadDef.program, pixelShader.prog.loadDef.programSize); + } + + void DumpVertexShader(const AssetDumpingContext& context, const MaterialVertexShader& vertexShader) + { + const auto shaderFile = context.OpenAssetFile(shader::GetFileNameForVertexShaderAssetName(vertexShader.name)); + + if (!shaderFile) + return; + + shaderFile->write(vertexShader.prog.loadDef.program, vertexShader.prog.loadDef.programSize); + } +} // namespace + +namespace T6::techset +{ + bool Dumper::ShouldDump(XAssetInfo* asset) + { + return true; + } + + void Dumper::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) + { + const auto* techniqueSet = asset->Asset(); + auto* shaderState = context.GetZoneAssetDumperState(); + + for (const auto* technique : techniqueSet->techniques) + { + if (!technique || !shaderState->ShouldDumpTechnique(technique)) + continue; + + for (auto passIndex = 0u; passIndex < technique->passCount; passIndex++) + { + const auto* pixelShader = technique->passArray[passIndex].pixelShader; + if (pixelShader && shaderState->ShouldDumpPixelShader(pixelShader)) + DumpPixelShader(context, *pixelShader); + + const auto* vertexShader = technique->passArray[passIndex].vertexShader; + if (vertexShader && shaderState->ShouldDumpVertexShader(vertexShader)) + DumpVertexShader(context, *vertexShader); + } + } + } +} // namespace T6::techset diff --git a/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.h b/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.h new file mode 100644 index 00000000..885be6c2 --- /dev/null +++ b/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Dumping/AbstractAssetDumper.h" +#include "Game/T6/T6.h" + +namespace T6::techset +{ + class Dumper final : public AbstractAssetDumper + { + protected: + bool ShouldDump(XAssetInfo* asset) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; + }; +} // namespace T6::techset