Add more details about material semantic and samplerState

This commit is contained in:
Jan 2022-04-18 15:26:24 +02:00
parent 2114b761b0
commit ce22a2fea6
2 changed files with 81 additions and 25 deletions

View File

@ -627,6 +627,31 @@ namespace IW4
water_t* water;
};
enum SamplerStateBits_e
{
SAMPLER_FILTER_SHIFT = 0x0,
SAMPLER_FILTER_NEAREST = 0x1,
SAMPLER_FILTER_LINEAR = 0x2,
SAMPLER_FILTER_ANISO2X = 0x3,
SAMPLER_FILTER_ANISO4X = 0x4,
SAMPLER_FILTER_MASK = 0x7,
SAMPLER_MIPMAP_SHIFT = 0x3,
SAMPLER_MIPMAP_DISABLED = 0x0,
SAMPLER_MIPMAP_NEAREST = 0x8,
SAMPLER_MIPMAP_LINEAR = 0x10,
SAMPLER_MIPMAP_COUNT = 0x3,
SAMPLER_MIPMAP_MASK = 0x18,
SAMPLER_CLAMP_U_SHIFT = 0x5,
SAMPLER_CLAMP_V_SHIFT = 0x6,
SAMPLER_CLAMP_W_SHIFT = 0x7,
SAMPLER_CLAMP_U = 0x20,
SAMPLER_CLAMP_V = 0x40,
SAMPLER_CLAMP_W = 0x80,
SAMPLER_CLAMP_MASK = 0xE0,
};
struct MaterialTextureDef
{
unsigned int nameHash;
@ -2247,29 +2272,6 @@ namespace IW4
FxElemDef* elemDefs;
};
enum SamplerStateBits_e
{
SAMPLER_FILTER_SHIFT = 0x0,
SAMPLER_FILTER_NEAREST = 0x1,
SAMPLER_FILTER_LINEAR = 0x2,
SAMPLER_FILTER_ANISO2X = 0x3,
SAMPLER_FILTER_ANISO4X = 0x4,
SAMPLER_FILTER_MASK = 0x7,
SAMPLER_MIPMAP_SHIFT = 0x3,
SAMPLER_MIPMAP_DISABLED = 0x0,
SAMPLER_MIPMAP_NEAREST = 0x8,
SAMPLER_MIPMAP_LINEAR = 0x10,
SAMPLER_MIPMAP_COUNT = 0x3,
SAMPLER_MIPMAP_MASK = 0x18,
SAMPLER_CLAMP_U_SHIFT = 0x5,
SAMPLER_CLAMP_V_SHIFT = 0x6,
SAMPLER_CLAMP_W_SHIFT = 0x7,
SAMPLER_CLAMP_U = 0x20,
SAMPLER_CLAMP_V = 0x40,
SAMPLER_CLAMP_W = 0x80,
SAMPLER_CLAMP_MASK = 0xE0,
};
struct GfxLightImage
{
GfxImage* image;

View File

@ -18,6 +18,16 @@ namespace IW4
return name;
}
template <size_t S>
json ArrayEntry(const char* (&a)[S], const size_t index)
{
assert(index < S);
if (index < S)
return a[index];
return json{};
}
json BuildComplexTableJson(complex_s* complexTable, const size_t count)
{
auto jArray = json::array();
@ -58,8 +68,50 @@ namespace IW4
};
}
json BuildSamplerStateJson(unsigned char samplerState)
{
static const char* samplerFilterNames[]
{
"none",
"nearest",
"linear",
"aniso2x",
"aniso4x"
};
static const char* samplerMipmapNames[]
{
"disabled",
"nearest",
"linear"
};
return json{
{"filter", ArrayEntry(samplerFilterNames, (samplerState & SAMPLER_FILTER_MASK) >> SAMPLER_FILTER_SHIFT)},
{"mipmap", ArrayEntry(samplerMipmapNames, (samplerState & SAMPLER_MIPMAP_MASK) >> SAMPLER_MIPMAP_SHIFT)},
{"clampU", (samplerState & SAMPLER_CLAMP_U) ? true : false},
{"clampV", (samplerState & SAMPLER_CLAMP_V) ? true : false},
{"clampW", (samplerState & SAMPLER_CLAMP_W) ? true : false},
};
}
json BuildTextureTableJson(MaterialTextureDef* textureTable, const size_t count)
{
static const char* semanticNames[]
{
"2d",
"function",
"colorMap",
"detailMap",
"unused2",
"normalMap",
"unused3",
"unused4",
"specularMap",
"unused5",
"unused6",
"waterMap"
};
auto jArray = json::array();
if (textureTable)
@ -67,9 +119,11 @@ namespace IW4
for (auto index = 0u; index < count; index++)
{
const auto& entry = textureTable[index];
assert(entry.semantic < std::extent_v<decltype(semanticNames)>);
json jEntry = {
{"samplerState", entry.samplerState},
{"semantic", entry.semantic}
{"samplerState", BuildSamplerStateJson(entry.samplerState)},
{"semantic", ArrayEntry(semanticNames, entry.semantic)}
};
const auto knownMaterialSourceName = knownMaterialSourceNames.find(entry.nameHash);