Utility: Rework MaterialData
This commit is contained in:
parent
1eb72af57e
commit
7ae76b32b0
|
|
@ -12,8 +12,9 @@ namespace Nz
|
|||
struct MaterialData
|
||||
{
|
||||
static constexpr const char* AlphaTest = "MatAlphaTest";
|
||||
static constexpr const char* AlphaTextureFilter = "MatAlphaTextureFilter";
|
||||
static constexpr const char* AlphaTexturePath = "MatAlphaTexturePath";
|
||||
static constexpr const char* AlphaWrap = "MatAlphaWrap";
|
||||
static constexpr const char* AlphaTextureWrap = "MatAlphaWTexturerap";
|
||||
static constexpr const char* AlphaThreshold = "MatAlphaThreshold";
|
||||
static constexpr const char* AmbientColor = "MatAmbientColor";
|
||||
static constexpr const char* BackFaceStencilCompare = "MatBackFaceStencilCompare";
|
||||
|
|
@ -23,8 +24,9 @@ namespace Nz
|
|||
static constexpr const char* BackFaceStencilReference = "MatBackFaceStencilReference";
|
||||
static constexpr const char* BackFaceStencilZFail = "MatBackFaceStencilZFail";
|
||||
static constexpr const char* BaseColor = "MatBaseColor";
|
||||
static constexpr const char* BaseColorTextureFilter = "MatBaseColorTextureFilter";
|
||||
static constexpr const char* BaseColorTexturePath = "MatBaseColorTexturePath";
|
||||
static constexpr const char* BaseColorWrap = "MatBaseColorWrap";
|
||||
static constexpr const char* BaseColorTextureWrap = "MatBaseColorTextureWrap";
|
||||
static constexpr const char* Blending = "MatBlending";
|
||||
static constexpr const char* BlendModeAlpha = "MatBlendModeAlpha";
|
||||
static constexpr const char* BlendModeColor = "MatBlendModeColor";
|
||||
|
|
@ -38,32 +40,34 @@ namespace Nz
|
|||
static constexpr const char* DepthFunc = "MatDepthfunc";
|
||||
static constexpr const char* DepthSorting = "MatDepthSorting";
|
||||
static constexpr const char* DepthWrite = "MatDepthWrite";
|
||||
static constexpr const char* DiffuseAnisotropyLevel = "MatDiffuseAnisotropyLevel";
|
||||
static constexpr const char* DiffuseFilter = "MatDiffuseFilter";
|
||||
static constexpr const char* EmissiveTextureFilter = "MatEmissiveTextureFilter";
|
||||
static constexpr const char* EmissiveTexturePath = "MatEmissiveTexturePath";
|
||||
static constexpr const char* EmissiveWrap = "MatEmissiveWrap";
|
||||
static constexpr const char* EmissiveTextureWrap = "MatEmissiveTextureWrap";
|
||||
static constexpr const char* FaceCulling = "MatFaceCulling";
|
||||
static constexpr const char* FaceFilling = "MatFaceFilling";
|
||||
static constexpr const char* FilePath = "MatFilePath";
|
||||
static constexpr const char* HeightTextureFilter = "MatHeightTextureFilter";
|
||||
static constexpr const char* HeightTexturePath = "MatHeightTexturePath";
|
||||
static constexpr const char* HeightWrap = "MatHeightWrap";
|
||||
static constexpr const char* Lighting = "MatLighting";
|
||||
static constexpr const char* HeightTextureWrap = "MatHeightTextureWrap";
|
||||
static constexpr const char* LineWidth = "MatLineWidth";
|
||||
static constexpr const char* MetallicTextureFilter = "MatMetallicTextureFilter";
|
||||
static constexpr const char* MetallicTexturePath = "MatMetallicTexturePath";
|
||||
static constexpr const char* MetallicWrap = "MatMetallicWrap";
|
||||
static constexpr const char* MetallicTextureWrap = "MatMetallicTextureWrap";
|
||||
static constexpr const char* Name = "MatName";
|
||||
static constexpr const char* NormalTextureFilter = "MatNormalTextureFilter";
|
||||
static constexpr const char* NormalTexturePath = "MatNormalTexturePath";
|
||||
static constexpr const char* NormalWrap = "MatNormalTextureWrap";
|
||||
static constexpr const char* NormalTextureWrap = "MatNormalTextureWrap";
|
||||
static constexpr const char* PointSize = "MatPointSize";
|
||||
static constexpr const char* RoughnessTextureFilter = "MatRoughnessTextureFilter";
|
||||
static constexpr const char* RoughnessTexturePath = "MatRoughnessTexturePath";
|
||||
static constexpr const char* RoughnessWrap = "MatRoughnessWrap";
|
||||
static constexpr const char* RoughnessTextureWrap = "MatRoughnessTextureWrap";
|
||||
static constexpr const char* ScissorTest = "MatScissorTest";
|
||||
static constexpr const char* Shininess = "MatShininess";
|
||||
static constexpr const char* SpecularAnisotropyLevel = "MatSpecularAnisotropyLevel";
|
||||
static constexpr const char* SpecularColor = "MatSpecularColor";
|
||||
static constexpr const char* SpecularFilter = "MatSpecularFilter";
|
||||
static constexpr const char* SpecularTextureFilter = "MatSpecularTextureFilter";
|
||||
static constexpr const char* SpecularTexturePath = "MatSpecularTexturePath";
|
||||
static constexpr const char* SpecularWrap = "MatSpecularWrap";
|
||||
static constexpr const char* SpecularTextureWrap = "MatSpecularTextureWrap";
|
||||
static constexpr const char* StencilCompare = "MatStencilCompare";
|
||||
static constexpr const char* StencilFail = "MatStencilFail";
|
||||
static constexpr const char* StencilMask = "MatStencilMask";
|
||||
|
|
@ -72,6 +76,7 @@ namespace Nz
|
|||
static constexpr const char* StencilTest = "MatStencilTest";
|
||||
static constexpr const char* StencilZFail = "MatStencilZFail";
|
||||
static constexpr const char* Transform = "MatTransform";
|
||||
static constexpr const char* Type = "MatType";
|
||||
static constexpr const char* VertexColor = "MatVertexColor";
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -739,25 +739,48 @@ std::shared_ptr<Nz::SubMesh> ProcessSubMesh(const std::filesystem::path& originP
|
|||
|
||||
ConvertColor(AI_MATKEY_COLOR_SPECULAR, Nz::MaterialData::SpecularColor);
|
||||
|
||||
if (!ConvertTexture(aiTextureType_BASE_COLOR, Nz::MaterialData::BaseColorTexturePath, Nz::MaterialData::BaseColorWrap))
|
||||
ConvertTexture(aiTextureType_DIFFUSE, Nz::MaterialData::BaseColorTexturePath, Nz::MaterialData::BaseColorWrap);
|
||||
if (!ConvertTexture(aiTextureType_BASE_COLOR, Nz::MaterialData::BaseColorTexturePath, Nz::MaterialData::BaseColorTextureWrap))
|
||||
ConvertTexture(aiTextureType_DIFFUSE, Nz::MaterialData::BaseColorTexturePath, Nz::MaterialData::BaseColorTextureWrap);
|
||||
|
||||
ConvertTexture(aiTextureType_DIFFUSE_ROUGHNESS, Nz::MaterialData::RoughnessTexturePath, Nz::MaterialData::RoughnessWrap);
|
||||
ConvertTexture(aiTextureType_EMISSIVE, Nz::MaterialData::EmissiveTexturePath, Nz::MaterialData::EmissiveWrap);
|
||||
ConvertTexture(aiTextureType_HEIGHT, Nz::MaterialData::HeightTexturePath, Nz::MaterialData::HeightWrap);
|
||||
ConvertTexture(aiTextureType_METALNESS, Nz::MaterialData::MetallicTexturePath, Nz::MaterialData::MetallicWrap);
|
||||
ConvertTexture(aiTextureType_NORMALS, Nz::MaterialData::NormalTexturePath, Nz::MaterialData::NormalWrap);
|
||||
ConvertTexture(aiTextureType_OPACITY, Nz::MaterialData::AlphaTexturePath, Nz::MaterialData::AlphaWrap);
|
||||
ConvertTexture(aiTextureType_SPECULAR, Nz::MaterialData::SpecularTexturePath, Nz::MaterialData::SpecularWrap);
|
||||
ConvertTexture(aiTextureType_DIFFUSE_ROUGHNESS, Nz::MaterialData::RoughnessTexturePath, Nz::MaterialData::RoughnessTextureWrap);
|
||||
ConvertTexture(aiTextureType_EMISSIVE, Nz::MaterialData::EmissiveTexturePath, Nz::MaterialData::EmissiveTextureWrap);
|
||||
ConvertTexture(aiTextureType_HEIGHT, Nz::MaterialData::HeightTexturePath, Nz::MaterialData::HeightTextureWrap);
|
||||
ConvertTexture(aiTextureType_METALNESS, Nz::MaterialData::MetallicTexturePath, Nz::MaterialData::MetallicTextureWrap);
|
||||
ConvertTexture(aiTextureType_NORMALS, Nz::MaterialData::NormalTexturePath, Nz::MaterialData::NormalTextureWrap);
|
||||
ConvertTexture(aiTextureType_OPACITY, Nz::MaterialData::AlphaTexturePath, Nz::MaterialData::AlphaTextureWrap);
|
||||
ConvertTexture(aiTextureType_SPECULAR, Nz::MaterialData::SpecularTexturePath, Nz::MaterialData::SpecularTextureWrap);
|
||||
|
||||
aiString name;
|
||||
if (aiGetMaterialString(aiMat, AI_MATKEY_NAME, &name) == aiReturn_SUCCESS)
|
||||
if (aiString name; aiGetMaterialString(aiMat, AI_MATKEY_NAME, &name) == aiReturn_SUCCESS)
|
||||
matData.SetParameter(Nz::MaterialData::Name, std::string(name.data, name.length));
|
||||
|
||||
int iValue;
|
||||
if (aiGetMaterialInteger(aiMat, AI_MATKEY_TWOSIDED, &iValue) == aiReturn_SUCCESS)
|
||||
if (int iValue; aiGetMaterialInteger(aiMat, AI_MATKEY_TWOSIDED, &iValue) == aiReturn_SUCCESS)
|
||||
matData.SetParameter(Nz::MaterialData::FaceCulling, !iValue);
|
||||
|
||||
if (int shadingMode; aiGetMaterialInteger(aiMat, AI_MATKEY_SHADING_MODEL, &shadingMode) == aiReturn_SUCCESS)
|
||||
{
|
||||
switch (shadingMode)
|
||||
{
|
||||
case aiShadingMode_Flat:
|
||||
case aiShadingMode_Gouraud:
|
||||
case aiShadingMode_Phong:
|
||||
case aiShadingMode_Blinn:
|
||||
matData.SetParameter(Nz::MaterialData::Type, "Phong");
|
||||
break;
|
||||
|
||||
case aiShadingMode_CookTorrance:
|
||||
case aiShadingMode_PBR_BRDF:
|
||||
matData.SetParameter(Nz::MaterialData::Type, "PhysicallyBased");
|
||||
break;
|
||||
|
||||
case aiShadingMode_NoShading:
|
||||
default:
|
||||
matData.SetParameter(Nz::MaterialData::Type, "Basic");
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
matData.SetParameter(Nz::MaterialData::Type, "Phong");
|
||||
|
||||
matIt = materialData.insert(std::make_pair(meshData->mMaterialIndex, std::make_pair(Nz::UInt32(materialData.size()), std::move(matData)))).first;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -90,6 +90,7 @@ namespace Nz
|
|||
|
||||
ParameterList matData;
|
||||
matData.SetParameter(MaterialData::BaseColorTexturePath, PathToString(baseDir / skin));
|
||||
matData.SetParameter(MaterialData::Type, "Phong");
|
||||
|
||||
mesh->SetMaterialData(i, std::move(matData));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -213,6 +213,7 @@ namespace Nz
|
|||
// Material
|
||||
ParameterList matData;
|
||||
matData.SetParameter(MaterialData::BaseColorTexturePath, PathToString(baseDir / md5Mesh.shader));
|
||||
matData.SetParameter(MaterialData::Type, "Phong");
|
||||
|
||||
mesh->SetMaterialData(i, std::move(matData));
|
||||
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ namespace Nz
|
|||
baseColor.a = alphaValue;
|
||||
specularColor.a = alphaValue;
|
||||
|
||||
data.SetParameter(MaterialData::Type, "Phong");
|
||||
data.SetParameter(MaterialData::AmbientColor, ambientColor);
|
||||
data.SetParameter(MaterialData::BaseColor, baseColor);
|
||||
data.SetParameter(MaterialData::Shininess, mtlMat->shininess);
|
||||
|
|
|
|||
Loading…
Reference in New Issue