diff --git a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperTechniqueSet.cpp b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperTechniqueSet.cpp index 7dca71df..8b0896bd 100644 --- a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperTechniqueSet.cpp +++ b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperTechniqueSet.cpp @@ -76,6 +76,45 @@ namespace IW4 return false; } + static bool FindCodeSamplerSourceAccessor(const MaterialTextureSource sourceIndexToFind, const CodeSamplerSource* codeSamplerTable, std::string& codeSourceAccessor) + { + const auto* currentCodeConst = codeSamplerTable; + while(currentCodeConst->name != nullptr) + { + if(currentCodeConst->subtable != nullptr) + { + std::string accessorInSubTable; + if(FindCodeSamplerSourceAccessor(sourceIndexToFind, currentCodeConst->subtable, accessorInSubTable)) + { + std::ostringstream ss; + ss << currentCodeConst->name << '.' << accessorInSubTable; + codeSourceAccessor = ss.str(); + return true; + } + } + else if(currentCodeConst->arrayCount > 0) + { + if(currentCodeConst->source <= static_cast(sourceIndexToFind) + && static_cast(currentCodeConst->source) + currentCodeConst->arrayCount > static_cast(sourceIndexToFind)) + { + std::ostringstream ss; + ss << currentCodeConst->name << '[' << (static_cast(sourceIndexToFind) - static_cast(currentCodeConst->source)) << ']'; + codeSourceAccessor = ss.str(); + return true; + } + } + else if(currentCodeConst->source == sourceIndexToFind) + { + codeSourceAccessor = currentCodeConst->name; + return true; + } + + currentCodeConst++; + } + + return false; + } + void DumpShaderArg(const MaterialShaderArgument& arg, const d3d9::ShaderInfo& shaderInfo) const { const auto targetShaderArg = std::find_if(shaderInfo.m_constants.begin(), shaderInfo.m_constants.end(), [arg](const d3d9::ShaderConstant& constant) @@ -117,6 +156,33 @@ namespace IW4 #ifdef TECHSET_DEBUG Indent(); m_stream << "// Omitted due to matching accessors: " << codeDestAccessor << " = code." << codeSourceAccessor << ";\n"; +#endif + } + } + else + { + assert(false); + Indent(); + m_stream << codeDestAccessor << " = UNKNOWN;\n"; + } + } + else if(arg.type == MTL_ARG_CODE_PIXEL_SAMPLER) + { + const auto sourceIndex = static_cast(arg.u.codeSampler); + std::string codeSourceAccessor; + if (FindCodeSamplerSourceAccessor(sourceIndex, s_codeSamplers, codeSourceAccessor) + || FindCodeSamplerSourceAccessor(sourceIndex, s_defaultCodeSamplers, codeSourceAccessor)) + { + if (codeDestAccessor != codeSourceAccessor) + { + Indent(); + m_stream << codeDestAccessor << " = code." << codeSourceAccessor << ";\n"; + } + else + { +#ifdef TECHSET_DEBUG + Indent(); + m_stream << "// Omitted due to matching accessors: " << codeDestAccessor << " = code." << codeSourceAccessor << ";\n"; #endif } }