Rename Diffuse to BaseColor
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace Nz
|
||||
material->AddPass("ForwardPass", buttonMaterialPass);
|
||||
|
||||
BasicMaterial buttonBasicMat(*buttonMaterialPass);
|
||||
buttonBasicMat.SetDiffuseMap(texture);
|
||||
buttonBasicMat.SetBaseColorMap(texture);
|
||||
|
||||
return material;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user