Rename Diffuse to BaseColor

This commit is contained in:
Lynix 2022-07-19 20:02:01 +02:00
parent 994ebd869a
commit ad8b46db38
26 changed files with 169 additions and 158 deletions

View File

@ -4,7 +4,7 @@ module;
import InstanceData from Engine.InstanceData;
import ViewerData from Engine.ViewerData;
option HasDiffuseTexture: bool = false;
option HasBaseColorTexture: bool = false;
option HasAlphaTexture: bool = false;
option AlphaTest: bool = false;
@ -12,13 +12,13 @@ option AlphaTest: bool = false;
struct BasicSettings
{
AlphaThreshold: f32,
DiffuseColor: vec4[f32]
BaseColor: vec4[f32]
}
external
{
[binding(0)] settings: uniform[BasicSettings],
[binding(1)] MaterialDiffuseMap: sampler2D[f32],
[binding(1)] MaterialBaseColorMap: sampler2D[f32],
[binding(2)] MaterialAlphaMap: sampler2D[f32],
[binding(3)] TextureOverlay: sampler2D[f32],
[binding(4)] instanceData: uniform[InstanceData],
@ -34,7 +34,7 @@ struct InputData
struct OutputData
{
[location(0)] diffuseMap: vec4[f32],
[location(0)] baseColorMap: vec4[f32],
[location(1)] normalMap: vec4[f32],
[location(2)] positionMap: vec4[f32]
}
@ -42,21 +42,21 @@ struct OutputData
[entry(frag)]
fn main(input: InputData) -> OutputData
{
let diffuseColor = settings.DiffuseColor;
const if (HasDiffuseTexture)
diffuseColor *= MaterialDiffuseMap.Sample(input.uv);
let color = settings.BaseColor;
const if (HasBaseColorTexture)
color *= MaterialBaseColorMap.Sample(input.uv);
const if (HasAlphaTexture)
diffuseColor.w *= MaterialAlphaMap.Sample(input.uv).x;
color.w *= MaterialAlphaMap.Sample(input.uv).x;
const if (AlphaTest)
{
if (diffuseColor.w < settings.AlphaThreshold)
if (color.w < settings.AlphaThreshold)
discard;
}
let output: OutputData;
output.diffuseMap = diffuseColor;
output.baseColorMap = color;
output.normalMap = vec4[f32]((vec3[f32](1.0, 1.0, 1.0) + input.normal) * 0.5, 1.0);
output.positionMap = vec4[f32](input.pos, 1.0);
return output;

View File

@ -8,7 +8,7 @@ import ViewerData from Engine.ViewerData;
struct BasicSettings
{
AlphaThreshold: f32,
DiffuseColor: vec4[f32]
BaseColor: vec4[f32]
}
external

View File

@ -206,7 +206,7 @@ int main()
Nz::BasicMaterial basicMat(*spaceshipMatPass);
basicMat.EnableAlphaTest(false);
basicMat.SetAlphaMap(Nz::Texture::LoadFromFile(resourceDir / "alphatile.png", texParams));
basicMat.SetDiffuseMap(Nz::Texture::LoadFromFile(resourceDir / "Spaceship/Texture/diffuse.png", texParams));
basicMat.SetBaseColorMap(Nz::Texture::LoadFromFile(resourceDir / "Spaceship/Texture/diffuse.png", texParams));
}
spaceshipMat->AddPass("ForwardPass", spaceshipMatPass);
@ -225,7 +225,7 @@ int main()
flareMaterialPass->SetBlendFunc(Nz::BlendFunc::SrcAlpha, Nz::BlendFunc::InvSrcAlpha, Nz::BlendFunc::One, Nz::BlendFunc::Zero);
Nz::BasicMaterial Osef(*flareMaterialPass);
Osef.SetDiffuseMap(Nz::Texture::LoadFromFile(resourceDir / "flare1.png", texParams));
Osef.SetBaseColorMap(Nz::Texture::LoadFromFile(resourceDir / "flare1.png", texParams));
flareMaterial->AddPass("ForwardPass", flareMaterialPass);
}
@ -236,13 +236,13 @@ int main()
planeMatPass->EnableDepthBuffer(true);
{
Nz::BasicMaterial basicMat(*planeMatPass);
basicMat.SetDiffuseMap(Nz::Texture::LoadFromFile(resourceDir / "dev_grey.png", texParams));
basicMat.SetBaseColorMap(Nz::Texture::LoadFromFile(resourceDir / "dev_grey.png", texParams));
Nz::TextureSamplerInfo planeSampler;
planeSampler.anisotropyLevel = 16;
planeSampler.wrapModeU = Nz::SamplerWrap::Repeat;
planeSampler.wrapModeV = Nz::SamplerWrap::Repeat;
basicMat.SetDiffuseSampler(planeSampler);
basicMat.SetBaseColorSampler(planeSampler);
}
planeMat->AddPass("ForwardPass", planeMatPass);

View File

@ -73,7 +73,7 @@ int main()
Nz::PhongLightingMaterial phongMat(*forwardPass);
phongMat.EnableAlphaTest(false);
phongMat.SetAlphaMap(Nz::Texture::LoadFromFile(resourceDir / "alphatile.png", texParams));
phongMat.SetDiffuseMap(Nz::Texture::LoadFromFile(resourceDir / "Spaceship/Texture/diffuse.png", texParams));
phongMat.SetBaseColorMap(Nz::Texture::LoadFromFile(resourceDir / "Spaceship/Texture/diffuse.png", texParams));
phongMat.SetNormalMap(Nz::Texture::LoadFromFile(resourceDir / "Spaceship/Texture/normal.png", texParams));
Nz::Model model(std::move(gfxMesh), spaceshipMesh->GetAABB());

View File

@ -67,7 +67,7 @@ int main()
Nz::PhysicallyBasedMaterial pbrMat(*forwardPass);
pbrMat.EnableAlphaTest(false);
pbrMat.SetAlphaMap(Nz::Texture::LoadFromFile(resourceDir / "alphatile.png", texParams));
pbrMat.SetDiffuseMap(Nz::Texture::LoadFromFile(resourceDir / "Rusty/rustediron2_basecolor.png", srgbTexParams));
pbrMat.SetBaseColorMap(Nz::Texture::LoadFromFile(resourceDir / "Rusty/rustediron2_basecolor.png", srgbTexParams));
pbrMat.SetMetallicMap(Nz::Texture::LoadFromFile(resourceDir / "Rusty/rustediron2_metallic.png", texParams));
pbrMat.SetRoughnessMap(Nz::Texture::LoadFromFile(resourceDir / "Rusty/rustediron2_roughness.png", texParams));
pbrMat.SetNormalMap(normalMap);

View File

@ -75,8 +75,8 @@ int main()
texParams.loadFormat = Nz::PixelFormat::RGBA8_SRGB;
Nz::BasicMaterial basicMat(*materialPass);
basicMat.SetDiffuseMap(Nz::Texture::LoadFromFile(resourceDir / "Spaceship/Texture/diffuse.png", texParams));
basicMat.SetDiffuseSampler(samplerInfo);
basicMat.SetBaseColorMap(Nz::Texture::LoadFromFile(resourceDir / "Spaceship/Texture/diffuse.png", texParams));
basicMat.SetBaseColorSampler(samplerInfo);
for (std::size_t y = 0; y < 10; ++y)
{

View File

@ -81,8 +81,8 @@ int main()
Nz::BasicMaterial basicMat(*materialPass);
basicMat.EnableAlphaTest(false);
basicMat.SetAlphaMap(Nz::Texture::LoadFromFile(resourceDir / "alphatile.png", texParams));
basicMat.SetDiffuseMap(Nz::Texture::LoadFromFile(resourceDir / "Spaceship/Texture/diffuse.png", texParams));
basicMat.SetDiffuseSampler(samplerInfo);
basicMat.SetBaseColorMap(Nz::Texture::LoadFromFile(resourceDir / "Spaceship/Texture/diffuse.png", texParams));
basicMat.SetBaseColorSampler(samplerInfo);
Nz::DepthMaterial basicMatDepth(*depthPass);
basicMatDepth.SetAlphaMap(Nz::Texture::LoadFromFile(resourceDir / "alphatile.png", texParams));
@ -142,7 +142,7 @@ int main()
colliderMat->AddPass("ForwardPass", colliderMatPass);
Nz::BasicMaterial colliderBasicMat(*colliderMatPass);
colliderBasicMat.SetDiffuseColor(Nz::Color::Green);
colliderBasicMat.SetBaseColor(Nz::Color::Green);
std::shared_ptr<Nz::Model> colliderModel;
{

View File

@ -77,8 +77,8 @@ int main()
texParams.loadFormat = Nz::PixelFormat::RGBA8_SRGB;
Nz::BasicMaterial basicMat(*materialPass);
basicMat.SetDiffuseMap(Nz::Texture::LoadFromFile(resourceDir / "Spaceship/Texture/diffuse.png", texParams));
basicMat.SetDiffuseSampler(samplerInfo);
basicMat.SetBaseColorMap(Nz::Texture::LoadFromFile(resourceDir / "Spaceship/Texture/diffuse.png", texParams));
basicMat.SetBaseColorSampler(samplerInfo);
Nz::ImageWidget* imageWidget = canvas2D.Add<Nz::ImageWidget>();
imageWidget->SetPosition(1200.f, 200.f);

View File

@ -32,24 +32,24 @@ namespace Nz
inline const std::shared_ptr<Texture>& GetAlphaMap() const;
inline const TextureSamplerInfo& GetAlphaSampler() const;
float GetAlphaTestThreshold() const;
Color GetDiffuseColor() const;
inline const std::shared_ptr<Texture>& GetDiffuseMap() const;
inline const TextureSamplerInfo& GetDiffuseSampler() const;
Color GetBaseColor() const;
inline const std::shared_ptr<Texture>& GetBaseColorMap() const;
inline const TextureSamplerInfo& GetBaseColorSampler() const;
inline bool IsAlphaTestEnabled() const;
inline bool HasAlphaMap() const;
inline bool HasAlphaTest() const;
inline bool HasAlphaTestThreshold() const;
inline bool HasDiffuseColor() const;
inline bool HasDiffuseMap() const;
inline bool HasBaseColor() const;
inline bool HasBaseColorMap() const;
inline void SetAlphaMap(std::shared_ptr<Texture> alphaMap);
inline void SetAlphaSampler(TextureSamplerInfo alphaSampler);
void SetAlphaTestThreshold(float alphaThreshold);
void SetDiffuseColor(const Color& diffuse);
inline void SetDiffuseMap(std::shared_ptr<Texture> diffuseMap);
inline void SetDiffuseSampler(TextureSamplerInfo diffuseSampler);
void SetBaseColor(const Color& baseColor);
inline void SetBaseColorMap(std::shared_ptr<Texture> baseColorMap);
inline void SetBaseColorSampler(TextureSamplerInfo baseColorSampler);
static inline const BasicUniformOffsets& GetOffsets();
static inline const std::shared_ptr<MaterialSettings>& GetSettings();
@ -57,7 +57,7 @@ namespace Nz
struct BasicUniformOffsets
{
std::size_t alphaThreshold;
std::size_t diffuseColor;
std::size_t baseColor;
std::size_t totalSize;
};
@ -70,13 +70,13 @@ namespace Nz
{
std::size_t alphaTest;
std::size_t hasAlphaMap;
std::size_t hasDiffuseMap;
std::size_t hasBaseColorMap;
};
struct BasicTextureIndexes
{
std::size_t alpha;
std::size_t diffuse;
std::size_t baseColor;
};
struct BasicBuildOptions

View File

@ -46,16 +46,16 @@ namespace Nz
return m_material.GetTextureSampler(m_basicTextureIndexes.alpha);
}
inline const std::shared_ptr<Texture>& BasicMaterial::GetDiffuseMap() const
inline const std::shared_ptr<Texture>& BasicMaterial::GetBaseColorMap() const
{
NazaraAssert(HasDiffuseMap(), "Material has no alpha texture slot");
return m_material.GetTexture(m_basicTextureIndexes.diffuse);
NazaraAssert(HasBaseColorMap(), "Material has no alpha texture slot");
return m_material.GetTexture(m_basicTextureIndexes.baseColor);
}
inline const TextureSamplerInfo& BasicMaterial::GetDiffuseSampler() const
inline const TextureSamplerInfo& BasicMaterial::GetBaseColorSampler() const
{
NazaraAssert(HasDiffuseMap(), "Material has no alpha texture slot");
return m_material.GetTextureSampler(m_basicTextureIndexes.diffuse);
NazaraAssert(HasBaseColorMap(), "Material has no alpha texture slot");
return m_material.GetTextureSampler(m_basicTextureIndexes.baseColor);
}
inline bool BasicMaterial::IsAlphaTestEnabled() const
@ -83,14 +83,14 @@ namespace Nz
return m_basicUniformOffsets.alphaThreshold != MaterialSettings::InvalidIndex;
}
inline bool BasicMaterial::HasDiffuseColor() const
inline bool BasicMaterial::HasBaseColor() const
{
return m_basicUniformOffsets.diffuseColor != MaterialSettings::InvalidIndex;
return m_basicUniformOffsets.baseColor != MaterialSettings::InvalidIndex;
}
inline bool BasicMaterial::HasDiffuseMap() const
inline bool BasicMaterial::HasBaseColorMap() const
{
return m_basicTextureIndexes.diffuse != MaterialSettings::InvalidIndex;
return m_basicTextureIndexes.baseColor != MaterialSettings::InvalidIndex;
}
inline void BasicMaterial::SetAlphaMap(std::shared_ptr<Texture> alphaMap)
@ -99,7 +99,7 @@ namespace Nz
bool hasAlphaMap = (alphaMap != nullptr);
m_material.SetTexture(m_basicTextureIndexes.alpha, std::move(alphaMap));
if (m_basicOptionIndexes.hasDiffuseMap != MaterialSettings::InvalidIndex)
if (m_basicOptionIndexes.hasBaseColorMap != MaterialSettings::InvalidIndex)
m_material.SetOptionValue(m_basicOptionIndexes.hasAlphaMap, hasAlphaMap);
}
@ -109,20 +109,20 @@ namespace Nz
m_material.SetTextureSampler(m_basicTextureIndexes.alpha, std::move(alphaSampler));
}
inline void BasicMaterial::SetDiffuseMap(std::shared_ptr<Texture> diffuseMap)
inline void BasicMaterial::SetBaseColorMap(std::shared_ptr<Texture> baseColorMap)
{
NazaraAssert(HasDiffuseMap(), "Material has no diffuse map slot");
bool hasDiffuseMap = (diffuseMap != nullptr);
m_material.SetTexture(m_basicTextureIndexes.diffuse, std::move(diffuseMap));
NazaraAssert(HasBaseColorMap(), "Material has no diffuse map slot");
bool hasBaseColorMap = (baseColorMap != nullptr);
m_material.SetTexture(m_basicTextureIndexes.baseColor, std::move(baseColorMap));
if (m_basicOptionIndexes.hasDiffuseMap != MaterialSettings::InvalidIndex)
m_material.SetOptionValue(m_basicOptionIndexes.hasDiffuseMap, hasDiffuseMap);
if (m_basicOptionIndexes.hasBaseColorMap != MaterialSettings::InvalidIndex)
m_material.SetOptionValue(m_basicOptionIndexes.hasBaseColorMap, hasBaseColorMap);
}
inline void BasicMaterial::SetDiffuseSampler(TextureSamplerInfo diffuseSampler)
inline void BasicMaterial::SetBaseColorSampler(TextureSamplerInfo diffuseSampler)
{
NazaraAssert(HasDiffuseMap(), "Material has no diffuse map slot");
m_material.SetTextureSampler(m_basicTextureIndexes.diffuse, std::move(diffuseSampler));
NazaraAssert(HasBaseColorMap(), "Material has no diffuse map slot");
m_material.SetTextureSampler(m_basicTextureIndexes.baseColor, std::move(diffuseSampler));
}
inline MaterialPass& BasicMaterial::GetMaterial()

View File

@ -21,6 +21,9 @@ namespace Nz
static constexpr const char* BackFaceStencilPass = "MatBackFaceStencilPass";
static constexpr const char* BackFaceStencilReference = "MatBackFaceStencilReference";
static constexpr const char* BackFaceStencilZFail = "MatBackFaceStencilZFail";
static constexpr const char* BaseColor = "MatBaseColor";
static constexpr const char* BaseColorTexturePath = "MatBaseColorTexturePath";
static constexpr const char* BaseColorWrap = "MatBaseColorWrap";
static constexpr const char* Blending = "MatBlending";
static constexpr const char* BlendModeAlpha = "MatBlendModeAlpha";
static constexpr const char* BlendModeColor = "MatBlendModeColor";
@ -35,10 +38,7 @@ namespace Nz
static constexpr const char* DepthSorting = "MatDepthSorting";
static constexpr const char* DepthWrite = "MatDepthWrite";
static constexpr const char* DiffuseAnisotropyLevel = "MatDiffuseAnisotropyLevel";
static constexpr const char* DiffuseColor = "MatDiffuseColor";
static constexpr const char* DiffuseFilter = "MatDiffuseFilter";
static constexpr const char* DiffuseTexturePath = "MatDiffuseTexturePath";
static constexpr const char* DiffuseWrap = "MatDiffuseWrap";
static constexpr const char* EmissiveTexturePath = "MatEmissiveTexturePath";
static constexpr const char* FaceCulling = "MatFaceCulling";
static constexpr const char* FaceFilling = "MatFaceFilling";

View File

@ -377,7 +377,10 @@ std::shared_ptr<Mesh> LoadMesh(Stream& stream, const MeshParams& parameters)
if (aiGetMaterialColor(aiMat, aiKey, aiType, aiIndex, &color) == aiReturn_SUCCESS)
{
matData.SetParameter(colorKey, Color(color.r, color.g, color.b, color.a));
return true;
}
return false;
};
auto ConvertTexture = [&](aiTextureType aiType, const char* textureKey, const char* wrapKey = nullptr)
@ -413,19 +416,27 @@ std::shared_ptr<Mesh> LoadMesh(Stream& stream, const MeshParams& parameters)
matData.SetParameter(wrapKey, static_cast<long long>(wrap));
}
return true;
}
return false;
};
ConvertColor(AI_MATKEY_COLOR_AMBIENT, MaterialData::AmbientColor);
ConvertColor(AI_MATKEY_COLOR_DIFFUSE, MaterialData::DiffuseColor);
if (!ConvertColor(AI_MATKEY_BASE_COLOR, MaterialData::BaseColor))
ConvertColor(AI_MATKEY_COLOR_DIFFUSE, MaterialData::BaseColor);
ConvertColor(AI_MATKEY_COLOR_SPECULAR, MaterialData::SpecularColor);
ConvertTexture(aiTextureType_DIFFUSE, MaterialData::DiffuseTexturePath, MaterialData::DiffuseWrap);
ConvertTexture(aiTextureType_EMISSIVE, MaterialData::EmissiveTexturePath);
ConvertTexture(aiTextureType_HEIGHT, MaterialData::HeightTexturePath);
ConvertTexture(aiTextureType_NORMALS, MaterialData::NormalTexturePath);
ConvertTexture(aiTextureType_OPACITY, MaterialData::AlphaTexturePath);
ConvertTexture(aiTextureType_SPECULAR, MaterialData::SpecularTexturePath, MaterialData::SpecularWrap);
if (!ConvertTexture(aiTextureType_BASE_COLOR, MaterialData::BaseColorTexturePath, MaterialData::BaseColorWrap))
ConvertTexture(aiTextureType_DIFFUSE, MaterialData::BaseColorTexturePath, MaterialData::BaseColorWrap);
aiString name;
if (aiGetMaterialString(aiMat, AI_MATKEY_NAME, &name) == aiReturn_SUCCESS)
@ -627,10 +638,10 @@ std::shared_ptr<Mesh> LoadMesh(Stream& stream, const MeshParams& parameters)
};
ConvertColor(AI_MATKEY_COLOR_AMBIENT, MaterialData::AmbientColor);
ConvertColor(AI_MATKEY_COLOR_DIFFUSE, MaterialData::DiffuseColor);
ConvertColor(AI_MATKEY_COLOR_DIFFUSE, MaterialData::BaseColor);
ConvertColor(AI_MATKEY_COLOR_SPECULAR, MaterialData::SpecularColor);
ConvertTexture(aiTextureType_DIFFUSE, MaterialData::DiffuseTexturePath, MaterialData::DiffuseWrap);
ConvertTexture(aiTextureType_DIFFUSE, MaterialData::BaseColorTexturePath, MaterialData::BaseColorWrap);
ConvertTexture(aiTextureType_EMISSIVE, MaterialData::EmissiveTexturePath);
ConvertTexture(aiTextureType_HEIGHT, MaterialData::HeightTexturePath);
ConvertTexture(aiTextureType_NORMALS, MaterialData::NormalTexturePath);

View File

@ -33,21 +33,21 @@ namespace Nz
{
m_basicOptionIndexes.alphaTest = materialSettings->GetOptionIndex("AlphaTest");
m_basicOptionIndexes.hasAlphaMap = materialSettings->GetOptionIndex("HasAlphaMap");
m_basicOptionIndexes.hasDiffuseMap = materialSettings->GetOptionIndex("HasDiffuseMap");
m_basicOptionIndexes.hasBaseColorMap = materialSettings->GetOptionIndex("HasBaseColorMap");
m_basicTextureIndexes.alpha = materialSettings->GetTextureIndex("Alpha");
m_basicTextureIndexes.diffuse = materialSettings->GetTextureIndex("Diffuse");
m_basicTextureIndexes.baseColor = materialSettings->GetTextureIndex("BaseColor");
m_uniformBlockIndex = materialSettings->GetUniformBlockIndex("MaterialSettings");
if (m_uniformBlockIndex != MaterialSettings::InvalidIndex)
{
m_basicUniformOffsets.alphaThreshold = materialSettings->GetUniformBlockVariableOffset(m_uniformBlockIndex, "AlphaThreshold");
m_basicUniformOffsets.diffuseColor = materialSettings->GetUniformBlockVariableOffset(m_uniformBlockIndex, "DiffuseColor");
m_basicUniformOffsets.baseColor = materialSettings->GetUniformBlockVariableOffset(m_uniformBlockIndex, "BaseColor");
}
else
{
m_basicUniformOffsets.alphaThreshold = MaterialSettings::InvalidIndex;
m_basicUniformOffsets.diffuseColor = MaterialSettings::InvalidIndex;
m_basicUniformOffsets.baseColor = MaterialSettings::InvalidIndex;
}
}
}
@ -61,13 +61,13 @@ namespace Nz
return AccessByOffset<const float&>(bufferData.data(), m_basicUniformOffsets.alphaThreshold);
}
Color BasicMaterial::GetDiffuseColor() const
Color BasicMaterial::GetBaseColor() const
{
NazaraAssert(HasDiffuseColor(), "Material has no diffuse color uniform");
NazaraAssert(HasBaseColor(), "Material has no base color uniform");
const std::vector<UInt8>& bufferData = m_material.GetUniformBufferConstData(m_uniformBlockIndex);
const float* colorPtr = AccessByOffset<const float*>(bufferData.data(), m_basicUniformOffsets.diffuseColor);
const float* colorPtr = AccessByOffset<const float*>(bufferData.data(), m_basicUniformOffsets.baseColor);
return Color(colorPtr[0], colorPtr[1], colorPtr[2], colorPtr[3]);
}
@ -79,17 +79,17 @@ namespace Nz
AccessByOffset<float&>(bufferData.data(), m_basicUniformOffsets.alphaThreshold) = alphaThreshold;
}
void BasicMaterial::SetDiffuseColor(const Color& diffuse)
void BasicMaterial::SetBaseColor(const Color& baseColor)
{
NazaraAssert(HasDiffuseColor(), "Material has no diffuse color uniform");
NazaraAssert(HasBaseColor(), "Material has no base color uniform");
std::vector<UInt8>& bufferData = m_material.GetUniformBufferData(m_uniformBlockIndex);
float* colorPtr = AccessByOffset<float*>(bufferData.data(), m_basicUniformOffsets.diffuseColor);
colorPtr[0] = diffuse.r;
colorPtr[1] = diffuse.g;
colorPtr[2] = diffuse.b;
colorPtr[3] = diffuse.a;
float* colorPtr = AccessByOffset<float*>(bufferData.data(), m_basicUniformOffsets.baseColor);
colorPtr[0] = baseColor.r;
colorPtr[1] = baseColor.g;
colorPtr[2] = baseColor.b;
colorPtr[3] = baseColor.a;
}
MaterialSettings::Builder BasicMaterial::Build(BasicBuildOptions& options)
@ -105,11 +105,11 @@ namespace Nz
});
}
if (options.basicOffsets.diffuseColor != std::numeric_limits<std::size_t>::max())
if (options.basicOffsets.baseColor != std::numeric_limits<std::size_t>::max())
{
variables.push_back({
"DiffuseColor",
options.basicOffsets.diffuseColor
"BaseColor",
options.basicOffsets.baseColor
});
}
@ -118,8 +118,8 @@ namespace Nz
if (options.basicOffsets.alphaThreshold != std::numeric_limits<std::size_t>::max())
AccessByOffset<float&>(options.defaultValues.data(), options.basicOffsets.alphaThreshold) = 0.2f;
if (options.basicOffsets.diffuseColor != std::numeric_limits<std::size_t>::max())
AccessByOffset<Vector4f&>(options.defaultValues.data(), options.basicOffsets.diffuseColor) = Vector4f(1.f, 1.f, 1.f, 1.f);
if (options.basicOffsets.baseColor != std::numeric_limits<std::size_t>::max())
AccessByOffset<Vector4f&>(options.defaultValues.data(), options.basicOffsets.baseColor) = Vector4f(1.f, 1.f, 1.f, 1.f);
// Textures
if (options.basicTextureIndexes)
@ -132,11 +132,11 @@ namespace Nz
});
if (options.basicTextureIndexes)
options.basicTextureIndexes->diffuse = settings.textures.size();
options.basicTextureIndexes->baseColor = settings.textures.size();
settings.textures.push_back({
1,
"Diffuse",
"BaseColor",
ImageType::E2D
});
@ -206,11 +206,11 @@ namespace Nz
// Options
// HasDiffuseMap
// HasBaseColorMap
if (options.basicOptionIndexes)
options.basicOptionIndexes->hasDiffuseMap = settings.options.size();
options.basicOptionIndexes->hasBaseColorMap = settings.options.size();
MaterialSettings::BuildOption(settings.options, "HasDiffuseMap", "HasDiffuseTexture");
MaterialSettings::BuildOption(settings.options, "HasBaseColorMap", "HasBaseColorTexture");
// HasAlphaMap
if (options.basicOptionIndexes)
@ -240,7 +240,7 @@ namespace Nz
BasicUniformOffsets uniformOffsets;
uniformOffsets.alphaThreshold = fieldOffsets.AddField(nzsl::StructFieldType::Float1);
uniformOffsets.diffuseColor = fieldOffsets.AddField(nzsl::StructFieldType::Float4);
uniformOffsets.baseColor = fieldOffsets.AddField(nzsl::StructFieldType::Float4);
uniformOffsets.totalSize = fieldOffsets.GetAlignedSize();
return std::make_pair(std::move(uniformOffsets), std::move(fieldOffsets));

View File

@ -66,10 +66,10 @@ namespace Nz
if (const auto& material = m_material->FindPass("ForwardPass"))
{
BasicMaterial mat(*material);
if (mat.HasDiffuseMap())
if (mat.HasBaseColorMap())
{
// Material should always have textures but we're better safe than sorry
if (const auto& texture = mat.GetDiffuseMap())
if (const auto& texture = mat.GetBaseColorMap())
return texture->GetSize();
}
}

View File

@ -36,7 +36,7 @@ namespace Nz
{
m_basicOptionIndexes.alphaTest = materialSettings->GetOptionIndex("AlphaTest");
m_basicOptionIndexes.hasAlphaMap = materialSettings->GetOptionIndex("HasAlphaMap");
m_basicOptionIndexes.hasDiffuseMap = materialSettings->GetOptionIndex("HasDiffuseMap");
m_basicOptionIndexes.hasBaseColorMap = materialSettings->GetOptionIndex("HasBaseColorMap");
m_phongOptionIndexes.hasEmissiveMap = materialSettings->GetOptionIndex("HasEmissiveMap");
m_phongOptionIndexes.hasHeightMap = materialSettings->GetOptionIndex("HasHeightMap");
@ -44,7 +44,7 @@ namespace Nz
m_phongOptionIndexes.hasSpecularMap = materialSettings->GetOptionIndex("HasSpecularMap");
m_basicTextureIndexes.alpha = materialSettings->GetTextureIndex("Alpha");
m_basicTextureIndexes.diffuse = materialSettings->GetTextureIndex("Diffuse");
m_basicTextureIndexes.baseColor = materialSettings->GetTextureIndex("BaseColor");
m_phongTextureIndexes.emissive = materialSettings->GetTextureIndex("Emissive");
m_phongTextureIndexes.height = materialSettings->GetTextureIndex("Height");
@ -55,7 +55,7 @@ namespace Nz
if (m_uniformBlockIndex != MaterialSettings::InvalidIndex)
{
m_basicUniformOffsets.alphaThreshold = materialSettings->GetUniformBlockVariableOffset(m_uniformBlockIndex, "AlphaThreshold");
m_basicUniformOffsets.diffuseColor = materialSettings->GetUniformBlockVariableOffset(m_uniformBlockIndex, "DiffuseColor");
m_basicUniformOffsets.baseColor = materialSettings->GetUniformBlockVariableOffset(m_uniformBlockIndex, "BaseColor");
m_phongUniformOffsets.ambientColor = materialSettings->GetUniformBlockVariableOffset(m_uniformBlockIndex, "AmbientColor");
m_phongUniformOffsets.shininess = materialSettings->GetUniformBlockVariableOffset(m_uniformBlockIndex, "Shininess");
@ -64,7 +64,7 @@ namespace Nz
else
{
m_basicUniformOffsets.alphaThreshold = MaterialSettings::InvalidIndex;
m_basicUniformOffsets.diffuseColor = MaterialSettings::InvalidIndex;
m_basicUniformOffsets.baseColor = MaterialSettings::InvalidIndex;
m_phongUniformOffsets.ambientColor = MaterialSettings::InvalidIndex;
m_phongUniformOffsets.shininess = MaterialSettings::InvalidIndex;
@ -121,16 +121,16 @@ namespace Nz
AccessByOffset<float&>(bufferData.data(), m_phongUniformOffsets.shininess) = shininess;
}
void PhongLightingMaterial::SetSpecularColor(const Color& diffuse)
void PhongLightingMaterial::SetSpecularColor(const Color& specular)
{
NazaraAssert(HasSpecularColor(), "Material has no specular color uniform");
std::vector<UInt8>& bufferData = GetMaterial().GetUniformBufferData(m_uniformBlockIndex);
float* colorPtr = AccessByOffset<float*>(bufferData.data(), m_phongUniformOffsets.specularColor);
colorPtr[0] = diffuse.r;
colorPtr[1] = diffuse.g;
colorPtr[2] = diffuse.b;
colorPtr[3] = diffuse.a;
colorPtr[0] = specular.r;
colorPtr[1] = specular.g;
colorPtr[2] = specular.b;
colorPtr[3] = specular.a;
}
const std::shared_ptr<MaterialSettings>& PhongLightingMaterial::GetSettings()

View File

@ -36,7 +36,7 @@ namespace Nz
{
m_basicOptionIndexes.alphaTest = materialSettings->GetOptionIndex("AlphaTest");
m_basicOptionIndexes.hasAlphaMap = materialSettings->GetOptionIndex("HasAlphaMap");
m_basicOptionIndexes.hasDiffuseMap = materialSettings->GetOptionIndex("HasDiffuseMap");
m_basicOptionIndexes.hasBaseColorMap = materialSettings->GetOptionIndex("HasBaseColorMap");
m_pbrOptionIndexes.hasEmissiveMap = materialSettings->GetOptionIndex("HasEmissiveMap");
m_pbrOptionIndexes.hasHeightMap = materialSettings->GetOptionIndex("HasHeightMap");
@ -46,7 +46,7 @@ namespace Nz
m_pbrOptionIndexes.hasSpecularMap = materialSettings->GetOptionIndex("HasSpecularMap");
m_basicTextureIndexes.alpha = materialSettings->GetTextureIndex("Alpha");
m_basicTextureIndexes.diffuse = materialSettings->GetTextureIndex("Diffuse");
m_basicTextureIndexes.baseColor = materialSettings->GetTextureIndex("BaseColor");
m_pbrTextureIndexes.emissive = materialSettings->GetTextureIndex("Emissive");
m_pbrTextureIndexes.height = materialSettings->GetTextureIndex("Height");
@ -57,7 +57,7 @@ namespace Nz
if (m_uniformBlockIndex != MaterialSettings::InvalidIndex)
{
m_basicUniformOffsets.alphaThreshold = materialSettings->GetUniformBlockVariableOffset(m_uniformBlockIndex, "AlphaThreshold");
m_basicUniformOffsets.diffuseColor = materialSettings->GetUniformBlockVariableOffset(m_uniformBlockIndex, "DiffuseColor");
m_basicUniformOffsets.baseColor = materialSettings->GetUniformBlockVariableOffset(m_uniformBlockIndex, "BaseColor");
m_pbrUniformOffsets.ambientColor = materialSettings->GetUniformBlockVariableOffset(m_uniformBlockIndex, "AmbientColor");
m_pbrUniformOffsets.shininess = materialSettings->GetUniformBlockVariableOffset(m_uniformBlockIndex, "Shininess");
@ -66,7 +66,7 @@ namespace Nz
else
{
m_basicUniformOffsets.alphaThreshold = MaterialSettings::InvalidIndex;
m_basicUniformOffsets.diffuseColor = MaterialSettings::InvalidIndex;
m_basicUniformOffsets.baseColor = MaterialSettings::InvalidIndex;
m_pbrUniformOffsets.ambientColor = MaterialSettings::InvalidIndex;
m_pbrUniformOffsets.shininess = MaterialSettings::InvalidIndex;
@ -123,7 +123,7 @@ namespace Nz
AccessByOffset<float&>(bufferData.data(), m_pbrUniformOffsets.shininess) = shininess;
}
void PhysicallyBasedMaterial::SetSpecularColor(const Color& diffuse)
void PhysicallyBasedMaterial::SetSpecularColor(const Color& specular)
{
NazaraAssert(HasSpecularColor(), "Material has no specular color uniform");

View File

@ -4,7 +4,7 @@ module BasicMaterial;
import InstanceData from Engine.InstanceData;
import ViewerData from Engine.ViewerData;
option HasDiffuseTexture: bool = false;
option HasBaseColorTexture: bool = false;
option HasAlphaTexture: bool = false;
option AlphaTest: bool = false;
@ -27,13 +27,13 @@ const HasUV = (UvLocation >= 0);
struct MaterialSettings
{
AlphaThreshold: f32,
DiffuseColor: vec4[f32]
BaseColor: vec4[f32]
}
external
{
[binding(0)] settings: uniform[MaterialSettings],
[binding(1)] MaterialDiffuseMap: sampler2D[f32],
[binding(1)] MaterialBaseColorMap: sampler2D[f32],
[binding(2)] MaterialAlphaMap: sampler2D[f32],
[binding(3)] TextureOverlay: sampler2D[f32],
[binding(4)] instanceData: uniform[InstanceData],
@ -55,28 +55,28 @@ struct FragOut
[entry(frag)]
fn main(input: FragIn) -> FragOut
{
let diffuseColor = settings.DiffuseColor;
let color = settings.BaseColor;
const if (HasUV)
diffuseColor *= TextureOverlay.Sample(input.uv);
color *= TextureOverlay.Sample(input.uv);
const if (HasColor)
diffuseColor *= input.color;
color *= input.color;
const if (HasDiffuseTexture)
diffuseColor *= MaterialDiffuseMap.Sample(input.uv);
const if (HasBaseColorTexture)
color *= MaterialBaseColorMap.Sample(input.uv);
const if (HasAlphaTexture)
diffuseColor.w *= MaterialAlphaMap.Sample(input.uv).x;
color.w *= MaterialAlphaMap.Sample(input.uv).x;
const if (AlphaTest)
{
if (diffuseColor.w < settings.AlphaThreshold)
if (color.w < settings.AlphaThreshold)
discard;
}
let output: FragOut;
output.RenderTarget0 = diffuseColor;
output.RenderTarget0 = color;
return output;
}

View File

@ -4,23 +4,23 @@ module DepthMaterial;
import InstanceData from Engine.InstanceData;
import ViewerData from Engine.ViewerData;
option HasDiffuseTexture: bool = false;
option HasBaseColorTexture: bool = false;
option HasAlphaTexture: bool = false;
option AlphaTest: bool = false;
const HasUV = AlphaTest && (HasDiffuseTexture || HasAlphaTexture);
const HasUV = AlphaTest && (HasBaseColorTexture || HasAlphaTexture);
[layout(std140)]
struct BasicSettings
{
AlphaThreshold: f32,
DiffuseColor: vec4[f32]
BaseColor: vec4[f32]
}
external
{
[binding(0)] settings: uniform[BasicSettings],
[binding(1)] MaterialDiffuseMap: sampler2D[f32],
[binding(1)] MaterialBaseColorMap: sampler2D[f32],
[binding(2)] MaterialAlphaMap: sampler2D[f32],
[binding(3)] TextureOverlay: sampler2D[f32],
[binding(4)] instanceData: uniform[InstanceData],
@ -36,13 +36,13 @@ struct FragIn
[entry(frag), cond(AlphaTest)]
fn main(input: FragIn)
{
let alpha = settings.DiffuseColor.a;
let alpha = settings.BaseColor.a;
const if (HasUV)
alpha *= TextureOverlay.Sample(input.uv).a;
const if (HasDiffuseTexture)
alpha *= MaterialDiffuseMap.Sample(input.uv).a;
const if (HasBaseColorTexture)
alpha *= MaterialBaseColorMap.Sample(input.uv).a;
const if (HasAlphaTexture)
alpha *= MaterialAlphaMap.Sample(input.uv).x;

View File

@ -6,7 +6,7 @@ import LightData from Engine.LightData;
import ViewerData from Engine.ViewerData;
// Basic material options
option HasDiffuseTexture: bool = false;
option HasBaseColorTexture: bool = false;
option HasAlphaTexture: bool = false;
option AlphaTest: bool = false;
@ -41,7 +41,7 @@ struct MaterialSettings
{
// BasicSettings
AlphaThreshold: f32,
DiffuseColor: vec4[f32],
BaseColor: vec4[f32],
// PhongSettings
AmbientColor: vec3[f32],
@ -57,7 +57,7 @@ const SpotLight = 2;
external
{
[binding(0)] settings: uniform[MaterialSettings],
[binding(1)] MaterialDiffuseMap: sampler2D[f32],
[binding(1)] MaterialBaseColorMap: sampler2D[f32],
[binding(2)] MaterialAlphaMap: sampler2D[f32],
[binding(3)] TextureOverlay: sampler2D[f32],
[binding(4)] instanceData: uniform[InstanceData],
@ -88,23 +88,23 @@ struct FragOut
[entry(frag)]
fn main(input: VertToFrag) -> FragOut
{
let diffuseColor = settings.DiffuseColor;
let color = settings.BaseColor;
const if (HasUV)
diffuseColor *= TextureOverlay.Sample(input.uv);
color *= TextureOverlay.Sample(input.uv);
const if (HasColor)
diffuseColor *= input.color;
color *= input.color;
const if (HasDiffuseTexture)
diffuseColor *= MaterialDiffuseMap.Sample(input.uv);
const if (HasBaseColorTexture)
color *= MaterialBaseColorMap.Sample(input.uv);
const if (HasAlphaTexture)
diffuseColor.w *= MaterialAlphaMap.Sample(input.uv).x;
color.w *= MaterialAlphaMap.Sample(input.uv).x;
const if (AlphaTest)
{
if (diffuseColor.w < settings.AlphaThreshold)
if (color.w < settings.AlphaThreshold)
discard;
}
@ -216,13 +216,13 @@ fn main(input: VertToFrag) -> FragOut
let lightColor = lightAmbient + lightDiffuse + lightSpecular;
let output: FragOut;
output.RenderTarget0 = vec4[f32](lightColor, 1.0) * diffuseColor;
output.RenderTarget0 = vec4[f32](lightColor, 1.0) * color;
return output;
}
else
{
let output: FragOut;
output.RenderTarget0 = diffuseColor;
output.RenderTarget0 = color;
return output;
}
}

View File

@ -6,7 +6,7 @@ import LightData from Engine.LightData;
import ViewerData from Engine.ViewerData;
// Basic material options
option HasDiffuseTexture: bool = false;
option HasBaseColorTexture: bool = false;
option HasAlphaTexture: bool = false;
option AlphaTest: bool = false;
@ -43,7 +43,7 @@ struct MaterialSettings
{
// BasicSettings
AlphaThreshold: f32,
DiffuseColor: vec4[f32],
BaseColor: vec4[f32],
// PhongSettings
AmbientColor: vec3[f32],
@ -59,7 +59,7 @@ const SpotLight = 2;
external
{
[binding(0)] settings: uniform[MaterialSettings],
[binding(1)] MaterialDiffuseMap: sampler2D[f32],
[binding(1)] MaterialBaseColorMap: sampler2D[f32],
[binding(2)] MaterialAlphaMap: sampler2D[f32],
[binding(3)] TextureOverlay: sampler2D[f32],
[binding(4)] instanceData: uniform[InstanceData],
@ -95,23 +95,23 @@ struct FragOut
[entry(frag)]
fn main(input: VertToFrag) -> FragOut
{
let diffuseColor = settings.DiffuseColor;
let color = settings.BaseColor;
const if (HasUV)
diffuseColor *= TextureOverlay.Sample(input.uv);
color *= TextureOverlay.Sample(input.uv);
const if (HasColor)
diffuseColor *= input.color;
color *= input.color;
const if (HasDiffuseTexture)
diffuseColor *= MaterialDiffuseMap.Sample(input.uv);
const if (HasBaseColorTexture)
color *= MaterialBaseColorMap.Sample(input.uv);
const if (HasAlphaTexture)
diffuseColor.w *= MaterialAlphaMap.Sample(input.uv).x;
color.w *= MaterialAlphaMap.Sample(input.uv).x;
const if (AlphaTest)
{
if (diffuseColor.w < settings.AlphaThreshold)
if (color.w < settings.AlphaThreshold)
discard;
}
@ -134,7 +134,7 @@ fn main(input: VertToFrag) -> FragOut
else
normal = normalize(input.normal);
let albedo = diffuseColor.xyz;
let albedo = color.xyz;
let metallic: f32;
let roughness: f32;
@ -211,7 +211,7 @@ fn main(input: VertToFrag) -> FragOut
let ambient = (0.03).rrr * albedo;
let color = ambient + lightRadiance * diffuseColor.rgb;
let color = ambient + lightRadiance * color.rgb;
color = color / (color + vec3[f32](1.0, 1.0, 1.0));
color = pow(color, (1.0 / 2.2).xxx);
@ -222,7 +222,7 @@ fn main(input: VertToFrag) -> FragOut
else
{
let output: FragOut;
output.RenderTarget0 = diffuseColor;
output.RenderTarget0 = color;
return output;
}
}

View File

@ -63,10 +63,10 @@ namespace Nz
if (const auto& material = m_material->FindPass("ForwardPass"))
{
BasicMaterial mat(*material);
if (mat.HasDiffuseMap())
if (mat.HasBaseColorMap())
{
// Material should always have textures but we're better safe than sorry
if (const auto& texture = mat.GetDiffuseMap())
if (const auto& texture = mat.GetBaseColorMap())
return texture->GetSize();
}
}

View File

@ -67,10 +67,10 @@ namespace Nz
if (const auto& material = m_material->FindPass("ForwardPass"))
{
BasicMaterial mat(*material);
if (mat.HasDiffuseMap())
if (mat.HasBaseColorMap())
{
// Material should always have textures but we're better safe than sorry
if (const auto& texture = mat.GetDiffuseMap())
if (const auto& texture = mat.GetBaseColorMap())
return texture->GetSize();
}
}

View File

@ -101,7 +101,7 @@ namespace Nz
stream.Read(skin, 68*sizeof(char));
ParameterList matData;
matData.SetParameter(MaterialData::DiffuseTexturePath, (baseDir / skin).generic_u8string());
matData.SetParameter(MaterialData::BaseColorTexturePath, (baseDir / skin).generic_u8string());
mesh->SetMaterialData(i, std::move(matData));
}

View File

@ -78,14 +78,14 @@ namespace Nz
float alphaValue = mtlMat->alpha;
Color ambientColor(mtlMat->ambient);
Color diffuseColor(mtlMat->diffuse);
Color baseColor(mtlMat->diffuse);
Color specularColor(mtlMat->specular);
ambientColor.a = alphaValue;
diffuseColor.a = alphaValue;
baseColor.a = alphaValue;
specularColor.a = alphaValue;
data.SetParameter(MaterialData::AmbientColor, ambientColor);
data.SetParameter(MaterialData::DiffuseColor, diffuseColor);
data.SetParameter(MaterialData::BaseColor, baseColor);
data.SetParameter(MaterialData::Shininess, mtlMat->shininess);
data.SetParameter(MaterialData::SpecularColor, specularColor);
@ -104,7 +104,7 @@ namespace Nz
if (!fullPath.is_absolute())
fullPath = baseDir / fullPath;
data.SetParameter(MaterialData::DiffuseTexturePath, fullPath.generic_u8string());
data.SetParameter(MaterialData::BaseColorTexturePath, fullPath.generic_u8string());
}
if (!mtlMat->emissiveMap.empty())

View File

@ -123,7 +123,7 @@ namespace Nz
if (matData.GetColorParameter(MaterialData::AmbientColor, &colorVal))
material->ambient = colorVal;
if (matData.GetColorParameter(MaterialData::DiffuseColor, &colorVal))
if (matData.GetColorParameter(MaterialData::BaseColor, &colorVal))
material->diffuse = colorVal;
if (matData.GetColorParameter(MaterialData::SpecularColor, &colorVal))
@ -133,7 +133,7 @@ namespace Nz
material->shininess = float(dValue);
matData.GetStringParameter(MaterialData::AlphaTexturePath, &material->alphaMap);
matData.GetStringParameter(MaterialData::DiffuseTexturePath, &material->diffuseMap);
matData.GetStringParameter(MaterialData::BaseColorTexturePath, &material->diffuseMap);
matData.GetStringParameter(MaterialData::SpecularTexturePath, &material->specularMap);
}
}

View File

@ -66,7 +66,7 @@ namespace Nz
material->AddPass("ForwardPass", buttonMaterialPass);
BasicMaterial buttonBasicMat(*buttonMaterialPass);
buttonBasicMat.SetDiffuseMap(texture);
buttonBasicMat.SetBaseColorMap(texture);
return material;
};