From 8e76f05d051f08aecbc56f088d065be02c785a09 Mon Sep 17 00:00:00 2001 From: Jan Date: Wed, 23 Mar 2022 16:46:49 +0100 Subject: [PATCH] Skeleton for IW4 MaterialTechnique dumping --- src/Common/Game/IW4/IW4_Assets.h | 36 ++++++++++ .../AssetDumpers/AssetDumperTechniqueSet.cpp | 69 ++++++++++++++++++- 2 files changed, 104 insertions(+), 1 deletion(-) diff --git a/src/Common/Game/IW4/IW4_Assets.h b/src/Common/Game/IW4/IW4_Assets.h index bf8dffea..cefa073e 100644 --- a/src/Common/Game/IW4/IW4_Assets.h +++ b/src/Common/Game/IW4/IW4_Assets.h @@ -837,6 +837,42 @@ namespace IW4 uint16_t loadForRenderer; }; + enum MaterialStreamStreamSource_e + { + STREAM_SRC_POSITION = 0x0, + STREAM_SRC_COLOR = 0x1, + STREAM_SRC_TEXCOORD_0 = 0x2, + STREAM_SRC_NORMAL = 0x3, + STREAM_SRC_TANGENT = 0x4, + STREAM_SRC_OPTIONAL_BEGIN = 0x5, + STREAM_SRC_PRE_OPTIONAL_BEGIN = 0x4, + STREAM_SRC_TEXCOORD_1 = 0x5, + STREAM_SRC_TEXCOORD_2 = 0x6, + STREAM_SRC_NORMAL_TRANSFORM_0 = 0x7, + STREAM_SRC_NORMAL_TRANSFORM_1 = 0x8, + + STREAM_SRC_COUNT + }; + + enum MaterialStreamDestination_e + { + STREAM_DST_POSITION = 0x0, + STREAM_DST_NORMAL = 0x1, + STREAM_DST_COLOR_0 = 0x2, + STREAM_DST_COLOR_1 = 0x3, + STREAM_DST_DEPTH = 0x4, + STREAM_DST_TEXCOORD_0 = 0x5, + STREAM_DST_TEXCOORD_1 = 0x6, + STREAM_DST_TEXCOORD_2 = 0x7, + STREAM_DST_TEXCOORD_3 = 0x8, + STREAM_DST_TEXCOORD_4 = 0x9, + STREAM_DST_TEXCOORD_5 = 0xA, + STREAM_DST_TEXCOORD_6 = 0xB, + STREAM_DST_TEXCOORD_7 = 0xC, + + STREAM_DST_COUNT + }; + struct MaterialStreamRouting { char source; diff --git a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperTechniqueSet.cpp b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperTechniqueSet.cpp index d8bcd53a..b3cd5cd0 100644 --- a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperTechniqueSet.cpp +++ b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperTechniqueSet.cpp @@ -28,6 +28,72 @@ namespace IW4 class TechniqueFileWriter : public AbstractTextDumper { + void DumpStateMap() const + { + Indent(); + // TODO: Actual statemap: Maybe find all materials using this techset and try to make out rules for the flags based on the statebitstable + m_stream << "stateMap \"\"; // TODO\n"; + } + + void DumpVertexShader(const MaterialPass& pass) + { + if (pass.vertexShader == nullptr) + return; + + m_stream << "\n"; + Indent(); + // TODO: Actually find out which version this shader uses + m_stream << "vertexShader 1.0 \"" << pass.vertexShader->name << "\"\n"; + Indent(); + m_stream << "{\n"; + IncIndent(); + + // TODO: Dump vertex shader args + + DecIndent(); + Indent(); + m_stream << "}\n"; + } + + void DumpPixelShader(const MaterialPass& pass) + { + if (pass.pixelShader == nullptr) + return; + + m_stream << "\n"; + Indent(); + // TODO: Actually find out which version this shader uses + m_stream << "pixelShader 1.0 \"" << pass.pixelShader->name << "\"\n"; + Indent(); + m_stream << "{\n"; + IncIndent(); + + // TODO: Dump pixel shader args + + DecIndent(); + Indent(); + m_stream << "}\n"; + } + + void DumpVertexDecl(const MaterialPass& pass) + { + // TODO + } + + void DumpPass(const MaterialPass& pass) + { + m_stream << "{\n"; + IncIndent(); + + DumpStateMap(); + DumpVertexShader(pass); + DumpPixelShader(pass); + DumpVertexDecl(pass); + + DecIndent(); + m_stream << "}\n"; + } + public: explicit TechniqueFileWriter(std::ostream& stream) : AbstractTextDumper(stream) @@ -36,7 +102,8 @@ namespace IW4 void DumpTechnique(const MaterialTechnique* technique) { - m_stream << "technique lol"; + for (auto i = 0u; i < technique->passCount; i++) + DumpPass(technique->passArray[i]); } };