Handle custom samplers

This commit is contained in:
Jan 2022-04-15 16:34:44 +02:00
parent 65c9267b06
commit 9990338130
3 changed files with 34 additions and 3 deletions

View File

@ -950,6 +950,15 @@ namespace IW4
TEXTURE_SRC_CODE_COUNT 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 struct CodeSamplerSource
{ {
const char* name; const char* name;

View File

@ -507,6 +507,14 @@ namespace IW4
}; };
static_assert(std::extent_v<decltype(s_codeSamplerUpdateFreq)> == TEXTURE_SRC_CODE_COUNT); static_assert(std::extent_v<decltype(s_codeSamplerUpdateFreq)> == 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<decltype(g_customSamplerSrc)> == CUSTOM_SAMPLER_COUNT);
static constexpr std::pair<uint32_t, const char*> KnownMaterialSource(const char* name) static constexpr std::pair<uint32_t, const char*> KnownMaterialSource(const char* name)
{ {
return std::make_pair(Common::R_HashString(name, 0u), name); return std::make_pair(Common::R_HashString(name, 0u), name);

View File

@ -1011,9 +1011,23 @@ namespace IW4
stableArgCount++; stableArgCount++;
break; break;
case MTL_UPDATE_CUSTOM: 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: default:
assert(false); assert(false);
break; continue;
} }
out.args[argIndex++] = arg.m_arg; out.args[argIndex++] = arg.m_arg;