From 66b62611f38a07399fca945ecdba965c8cef7efb Mon Sep 17 00:00:00 2001 From: Jan Date: Wed, 23 Mar 2022 13:45:01 +0100 Subject: [PATCH] Add basis for iw4 techset dumping --- src/Common/Game/IW4/IW4_Assets.h | 56 +++++++++++ .../AssetDumpers/AssetDumperPixelShader.cpp | 12 +++ .../IW4/AssetDumpers/AssetDumperPixelShader.h | 14 +++ .../AssetDumpers/AssetDumperTechniqueSet.cpp | 99 +++++++++++++++++++ .../AssetDumpers/AssetDumperTechniqueSet.h | 17 ++++ .../AssetDumpers/AssetDumperVertexDecl.cpp | 12 +++ .../IW4/AssetDumpers/AssetDumperVertexDecl.h | 14 +++ .../AssetDumpers/AssetDumperVertexShader.cpp | 12 +++ .../AssetDumpers/AssetDumperVertexShader.h | 14 +++ src/ObjWriting/Game/IW4/ZoneDumperIW4.cpp | 12 ++- 10 files changed, 258 insertions(+), 4 deletions(-) create mode 100644 src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperPixelShader.cpp create mode 100644 src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperPixelShader.h create mode 100644 src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperTechniqueSet.cpp create mode 100644 src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperTechniqueSet.h create mode 100644 src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperVertexDecl.cpp create mode 100644 src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperVertexDecl.h create mode 100644 src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperVertexShader.cpp create mode 100644 src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperVertexShader.h diff --git a/src/Common/Game/IW4/IW4_Assets.h b/src/Common/Game/IW4/IW4_Assets.h index 5027b5b2..bf8dffea 100644 --- a/src/Common/Game/IW4/IW4_Assets.h +++ b/src/Common/Game/IW4/IW4_Assets.h @@ -938,6 +938,62 @@ namespace IW4 MaterialPass passArray[1]; }; + enum MaterialTechniqueType + { + TECHNIQUE_DEPTH_PREPASS = 0x0, + TECHNIQUE_BUILD_FLOAT_Z = 0x1, + TECHNIQUE_BUILD_SHADOWMAP_DEPTH = 0x2, + TECHNIQUE_BUILD_SHADOWMAP_COLOR = 0x3, + TECHNIQUE_UNLIT = 0x4, + TECHNIQUE_EMISSIVE = 0x5, + TECHNIQUE_EMISSIVE_DFOG = 0x6, + TECHNIQUE_EMISSIVE_SHADOW = 0x7, + TECHNIQUE_EMISSIVE_SHADOW_DFOG = 0x8, + TECHNIQUE_LIT_BEGIN = 0x9, + TECHNIQUE_LIT = 0x9, + TECHNIQUE_LIT_DFOG = 0xA, + TECHNIQUE_LIT_SUN = 0xB, + TECHNIQUE_LIT_SUN_DFOG = 0xC, + TECHNIQUE_LIT_SUN_SHADOW = 0xD, + TECHNIQUE_LIT_SUN_SHADOW_DFOG = 0xE, + TECHNIQUE_LIT_SPOT = 0xF, + TECHNIQUE_LIT_SPOT_DFOG = 0x10, + TECHNIQUE_LIT_SPOT_SHADOW = 0x11, + TECHNIQUE_LIT_SPOT_SHADOW_DFOG = 0x12, + TECHNIQUE_LIT_OMNI = 0x13, + TECHNIQUE_LIT_OMNI_DFOG = 0x14, + TECHNIQUE_LIT_OMNI_SHADOW = 0x15, + TECHNIQUE_LIT_OMNI_SHADOW_DFOG = 0x16, + TECHNIQUE_LIT_INSTANCED = 0x17, + TECHNIQUE_LIT_INSTANCED_DFOG = 0x18, + TECHNIQUE_LIT_INSTANCED_SUN = 0x19, + TECHNIQUE_LIT_INSTANCED_SUN_DFOG = 0x1A, + TECHNIQUE_LIT_INSTANCED_SUN_SHADOW = 0x1B, + TECHNIQUE_LIT_INSTANCED_SUN_SHADOW_DFOG = 0x1C, + TECHNIQUE_LIT_INSTANCED_SPOT = 0x1D, + TECHNIQUE_LIT_INSTANCED_SPOT_DFOG = 0x1E, + TECHNIQUE_LIT_INSTANCED_SPOT_SHADOW = 0x1F, + TECHNIQUE_LIT_INSTANCED_SPOT_SHADOW_DFOG = 0x20, + TECHNIQUE_LIT_INSTANCED_OMNI = 0x21, + TECHNIQUE_LIT_INSTANCED_OMNI_DFOG = 0x22, + TECHNIQUE_LIT_INSTANCED_OMNI_SHADOW = 0x23, + TECHNIQUE_LIT_INSTANCED_OMNI_SHADOW_DFOG = 0x24, + TECHNIQUE_LIT_END = 0x25, + TECHNIQUE_LIGHT_SPOT = 0x25, + TECHNIQUE_LIGHT_OMNI = 0x26, + TECHNIQUE_LIGHT_SPOT_SHADOW = 0x27, + TECHNIQUE_FAKELIGHT_NORMAL = 0x28, + TECHNIQUE_FAKELIGHT_VIEW = 0x29, + TECHNIQUE_SUNLIGHT_PREVIEW = 0x2A, + TECHNIQUE_CASE_TEXTURE = 0x2B, + TECHNIQUE_WIREFRAME_SOLID = 0x2C, + TECHNIQUE_WIREFRAME_SHADED = 0x2D, + TECHNIQUE_DEBUG_BUMPMAP = 0x2E, + TECHNIQUE_DEBUG_BUMPMAP_INSTANCED = 0x2F, + + TECHNIQUE_COUNT + }; + struct MaterialTechniqueSet { const char* name; diff --git a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperPixelShader.cpp b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperPixelShader.cpp new file mode 100644 index 00000000..64eebbb4 --- /dev/null +++ b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperPixelShader.cpp @@ -0,0 +1,12 @@ +#include "AssetDumperPixelShader.h" + +using namespace IW4; + +bool AssetDumperPixelShader::ShouldDump(XAssetInfo* asset) +{ + return true; +} + +void AssetDumperPixelShader::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) +{ +} diff --git a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperPixelShader.h b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperPixelShader.h new file mode 100644 index 00000000..a01be4a9 --- /dev/null +++ b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperPixelShader.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Dumping/AbstractAssetDumper.h" +#include "Game/IW4/IW4.h" + +namespace IW4 +{ + class AssetDumperPixelShader final : public AbstractAssetDumper + { + protected: + bool ShouldDump(XAssetInfo* asset) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; + }; +} diff --git a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperTechniqueSet.cpp b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperTechniqueSet.cpp new file mode 100644 index 00000000..e27eb755 --- /dev/null +++ b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperTechniqueSet.cpp @@ -0,0 +1,99 @@ +#include "AssetDumperTechniqueSet.h" + +#include + +#include "Dumping/AbstractTextDumper.h" + +using namespace IW4; + +namespace IW4 +{ + class TechniqueDumpingZoneState final : public IZoneAssetDumperState + { + std::set m_dumped_techniques; + + public: + bool ShouldDumpTechnique(const MaterialTechnique* technique) + { + if (m_dumped_techniques.find(technique) != m_dumped_techniques.end()) + return false; + + m_dumped_techniques.emplace(technique); + return true; + } + }; + + class TechniqueFileWriter : public AbstractTextDumper + { + public: + explicit TechniqueFileWriter(std::ostream& stream) + : AbstractTextDumper(stream) + { + } + + void DumpTechnique(const MaterialTechnique* technique) + { + m_stream << "technique lol"; + } + }; + + class TechsetFileWriter : public AbstractTextDumper + { + public: + explicit TechsetFileWriter(std::ostream& stream) + : AbstractTextDumper(stream) + { + } + + void DumpTechset(const MaterialTechniqueSet* techset) + { + m_stream << "techset lol"; + } + }; +} + +std::string AssetDumperTechniqueSet::GetTechniqueFileName(const MaterialTechnique* technique) +{ + 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) + { + TechsetFileWriter writer(*techsetFile); + writer.DumpTechset(techset); + } + + auto* techniqueState = context.GetZoneAssetDumperState(); + for (const auto* technique : techset->techniques) + { + if (technique && techniqueState->ShouldDumpTechnique(technique)) + { + const auto techniqueFile = context.OpenAssetFile(GetTechniqueFileName(technique)); + if (techniqueFile) + { + TechniqueFileWriter writer(*techniqueFile); + writer.DumpTechnique(technique); + } + } + } +} diff --git a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperTechniqueSet.h b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperTechniqueSet.h new file mode 100644 index 00000000..fc503d4b --- /dev/null +++ b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperTechniqueSet.h @@ -0,0 +1,17 @@ +#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; + }; +} diff --git a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperVertexDecl.cpp b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperVertexDecl.cpp new file mode 100644 index 00000000..4fb57343 --- /dev/null +++ b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperVertexDecl.cpp @@ -0,0 +1,12 @@ +#include "AssetDumperVertexDecl.h" + +using namespace IW4; + +bool AssetDumperVertexDecl::ShouldDump(XAssetInfo* asset) +{ + return true; +} + +void AssetDumperVertexDecl::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) +{ +} diff --git a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperVertexDecl.h b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperVertexDecl.h new file mode 100644 index 00000000..ac89c6c1 --- /dev/null +++ b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperVertexDecl.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Dumping/AbstractAssetDumper.h" +#include "Game/IW4/IW4.h" + +namespace IW4 +{ + class AssetDumperVertexDecl final : public AbstractAssetDumper + { + protected: + bool ShouldDump(XAssetInfo* asset) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; + }; +} diff --git a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperVertexShader.cpp b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperVertexShader.cpp new file mode 100644 index 00000000..09d558fa --- /dev/null +++ b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperVertexShader.cpp @@ -0,0 +1,12 @@ +#include "AssetDumperVertexShader.h" + +using namespace IW4; + +bool AssetDumperVertexShader::ShouldDump(XAssetInfo* asset) +{ + return true; +} + +void AssetDumperVertexShader::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) +{ +} diff --git a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperVertexShader.h b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperVertexShader.h new file mode 100644 index 00000000..c2b63430 --- /dev/null +++ b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperVertexShader.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Dumping/AbstractAssetDumper.h" +#include "Game/IW4/IW4.h" + +namespace IW4 +{ + class AssetDumperVertexShader final : public AbstractAssetDumper + { + protected: + bool ShouldDump(XAssetInfo* asset) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; + }; +} diff --git a/src/ObjWriting/Game/IW4/ZoneDumperIW4.cpp b/src/ObjWriting/Game/IW4/ZoneDumperIW4.cpp index fbb67ea3..b7fafc17 100644 --- a/src/ObjWriting/Game/IW4/ZoneDumperIW4.cpp +++ b/src/ObjWriting/Game/IW4/ZoneDumperIW4.cpp @@ -13,12 +13,16 @@ #include "AssetDumpers/AssetDumperMenuList.h" #include "AssetDumpers/AssetDumperPhysCollmap.h" #include "AssetDumpers/AssetDumperPhysPreset.h" +#include "AssetDumpers/AssetDumperPixelShader.h" #include "AssetDumpers/AssetDumperRawFile.h" #include "AssetDumpers/AssetDumperSndCurve.h" #include "AssetDumpers/AssetDumperStringTable.h" #include "AssetDumpers/AssetDumperStructuredDataDefSet.h" +#include "AssetDumpers/AssetDumperTechniqueSet.h" #include "AssetDumpers/AssetDumperTracer.h" #include "AssetDumpers/AssetDumperVehicle.h" +#include "AssetDumpers/AssetDumperVertexDecl.h" +#include "AssetDumpers/AssetDumperVertexShader.h" #include "AssetDumpers/AssetDumperWeapon.h" #include "AssetDumpers/AssetDumperXModel.h" @@ -45,10 +49,10 @@ bool ZoneDumper::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(AssetDumperMaterial, m_material, ASSET_TYPE_MATERIAL) - // DUMP_ASSET_POOL(AssetDumperMaterialPixelShader, m_material_pixel_shader, ASSET_TYPE_PIXELSHADER) - // DUMP_ASSET_POOL(AssetDumperMaterialVertexShader, m_material_vertex_shader, ASSET_TYPE_VERTEXSHADER) - // DUMP_ASSET_POOL(AssetDumperMaterialVertexDeclaration, m_material_vertex_decl, ASSET_TYPE_VERTEXDECL) - // DUMP_ASSET_POOL(AssetDumperMaterialTechniqueSet, m_technique_set, ASSET_TYPE_TECHNIQUE_SET) + 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(AssetDumperVertexDecl, m_material_vertex_decl, ASSET_TYPE_VERTEXDECL) + DUMP_ASSET_POOL(AssetDumperTechniqueSet, m_technique_set, ASSET_TYPE_TECHNIQUE_SET) DUMP_ASSET_POOL(AssetDumperGfxImage, 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)