diff --git a/src/Common/Game/IW4/IW4_Assets.h b/src/Common/Game/IW4/IW4_Assets.h index 471d7efe..75f4c755 100644 --- a/src/Common/Game/IW4/IW4_Assets.h +++ b/src/Common/Game/IW4/IW4_Assets.h @@ -950,6 +950,15 @@ namespace IW4 TEXTURE_SRC_CODE_COUNT }; + enum CustomSamplers + { + CUSTOM_SAMPLER_REFLECTION_PROBE = 0x0, + CUSTOM_SAMPLER_LIGHTMAP_PRIMARY = 0x1, + CUSTOM_SAMPLER_LIGHTMAP_SECONDARY = 0x2, + + CUSTOM_SAMPLER_COUNT + }; + struct CodeSamplerSource { const char* name; diff --git a/src/ObjCommon/Game/IW4/TechsetConstantsIW4.h b/src/ObjCommon/Game/IW4/TechsetConstantsIW4.h index ce281988..c8f5069e 100644 --- a/src/ObjCommon/Game/IW4/TechsetConstantsIW4.h +++ b/src/ObjCommon/Game/IW4/TechsetConstantsIW4.h @@ -507,6 +507,14 @@ namespace IW4 }; static_assert(std::extent_v == TEXTURE_SRC_CODE_COUNT); + inline MaterialTextureSource g_customSamplerSrc[] + { + TEXTURE_SRC_CODE_REFLECTION_PROBE, // CUSTOM_SAMPLER_REFLECTION_PROBE + TEXTURE_SRC_CODE_LIGHTMAP_PRIMARY, // CUSTOM_SAMPLER_LIGHTMAP_PRIMARY + TEXTURE_SRC_CODE_LIGHTMAP_SECONDARY // CUSTOM_SAMPLER_LIGHTMAP_SECONDARY + }; + static_assert(std::extent_v == CUSTOM_SAMPLER_COUNT); + static constexpr std::pair KnownMaterialSource(const char* name) { return std::make_pair(Common::R_HashString(name, 0u), name); diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderTechniqueSet.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderTechniqueSet.cpp index b4319f90..95e64030 100644 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderTechniqueSet.cpp +++ b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderTechniqueSet.cpp @@ -131,7 +131,7 @@ namespace IW4 static MaterialUpdateFrequency GetUpdateFrequencyForArg(MaterialShaderArgument arg) { - switch(arg.type) + switch (arg.type) { case MTL_ARG_CODE_VERTEX_CONST: case MTL_ARG_CODE_PIXEL_CONST: @@ -143,7 +143,7 @@ namespace IW4 return s_codeConstUpdateFreq[arg.u.codeConst.index]; case MTL_ARG_CODE_PIXEL_SAMPLER: - if(arg.u.codeSampler >= std::extent_v) + if (arg.u.codeSampler >= std::extent_v) { assert(false); return MTL_UPDATE_RARELY; @@ -1011,9 +1011,23 @@ namespace IW4 stableArgCount++; break; case MTL_UPDATE_CUSTOM: + { + assert(arg.m_arg.type == MTL_ARG_CODE_PIXEL_SAMPLER); + if (arg.m_arg.type == MTL_ARG_CODE_PIXEL_SAMPLER) + { + const auto customSampler = std::find(std::begin(g_customSamplerSrc), std::end(g_customSamplerSrc), arg.m_arg.u.codeSampler); + assert(customSampler != std::end(g_customSamplerSrc)); + if (customSampler != std::end(g_customSamplerSrc)) + { + const auto customSamplerIndex = customSampler - std::begin(g_customSamplerSrc); + out.customSamplerFlags |= 1 << customSamplerIndex; + } + } + } + continue; default: assert(false); - break; + continue; } out.args[argIndex++] = arg.m_arg;