Merged MaterialAssetCreatorCommon class into MaterialTypeAssetCreator because it is no longer needed for MaterialAssetCreator.
Signed-off-by: santorac <55155825+santorac@users.noreply.github.com>
This commit is contained in:
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/Name/Name.h>
|
||||
#include <Atom/RPI.Reflect/Image/ImageAsset.h>
|
||||
#include <Atom/RPI.Reflect/Material/MaterialPropertiesLayout.h>
|
||||
#include <Atom/RHI.Reflect/ShaderSemantic.h>
|
||||
#include <Atom/RPI.Reflect/Material/MaterialPropertyValue.h>
|
||||
|
||||
// These classes are not directly referenced in this header only because the SetPropertyValue()
|
||||
// function is templatized. But the API is still specific to these data types so we include them here.
|
||||
#include <AzCore/Math/Vector2.h>
|
||||
#include <AzCore/Math/Vector3.h>
|
||||
#include <AzCore/Math/Vector4.h>
|
||||
#include <AzCore/Math/Color.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
namespace RPI
|
||||
{
|
||||
class StreamingImageAsset;
|
||||
class AttachmentImageAsset;
|
||||
|
||||
//! Provides common functionality to both MaterialTypeAssetCreator and MaterialAssetCreator.
|
||||
class MaterialAssetCreatorCommon
|
||||
{
|
||||
public:
|
||||
void SetPropertyValue(const Name& name, const Data::Asset<ImageAsset>& imageAsset);
|
||||
void SetPropertyValue(const Name& name, const Data::Asset<StreamingImageAsset>& imageAsset);
|
||||
void SetPropertyValue(const Name& name, const Data::Asset<AttachmentImageAsset>& imageAsset);
|
||||
|
||||
//! Sets a property value using data in AZStd::variant-based MaterialPropertyValue. The contained data must match
|
||||
//! the data type of the property. For type Image, the value must be a Data::Asset<ImageAsset>.
|
||||
void SetPropertyValue(const Name& name, const MaterialPropertyValue& value);
|
||||
|
||||
protected:
|
||||
MaterialAssetCreatorCommon() = default;
|
||||
|
||||
void OnBegin(
|
||||
const MaterialPropertiesLayout* propertyLayout,
|
||||
AZStd::vector<MaterialPropertyValue>* propertyValues,
|
||||
const AZStd::function<void(const char*)>& warningFunc,
|
||||
const AZStd::function<void(const char*)>& errorFunc);
|
||||
void OnEnd();
|
||||
|
||||
private:
|
||||
bool PropertyCheck(TypeId typeId, const Name& name);
|
||||
|
||||
const MaterialPropertiesLayout* m_propertyLayout = nullptr;
|
||||
//! Points to the m_propertyValues list in a MaterialAsset or MaterialTypeAsset
|
||||
AZStd::vector<MaterialPropertyValue>* m_propertyValues = nullptr;
|
||||
|
||||
AZStd::function<void(const char*)> m_reportWarning = nullptr;
|
||||
AZStd::function<void(const char*)> m_reportError = nullptr;
|
||||
};
|
||||
|
||||
} // namespace RPI
|
||||
} // namespace AZ
|
||||
@@ -54,7 +54,6 @@ namespace AZ
|
||||
{
|
||||
friend class MaterialTypeAssetCreator;
|
||||
friend class MaterialTypeAssetHandler;
|
||||
friend class MaterialAssetCreatorCommon;
|
||||
|
||||
public:
|
||||
AZ_RTTI(MaterialTypeAsset, "{CD7803AB-9C4C-4A33-9A14-7412F1665464}", AZ::Data::AssetData);
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <Atom/RPI.Reflect/AssetCreator.h>
|
||||
#include <Atom/RPI.Reflect/Material/MaterialAssetCreatorCommon.h>
|
||||
#include <Atom/RPI.Reflect/Material/MaterialTypeAsset.h>
|
||||
#include <AtomCore/std/containers/array_view.h>
|
||||
|
||||
@@ -27,7 +26,6 @@ namespace AZ
|
||||
//! which provides the MaterialTypeAsset and default property values.
|
||||
class MaterialTypeAssetCreator
|
||||
: public AssetCreator<MaterialTypeAsset>
|
||||
, public MaterialAssetCreatorCommon
|
||||
{
|
||||
public:
|
||||
//! Begin creating a MaterialTypeAsset
|
||||
@@ -71,6 +69,14 @@ namespace AZ
|
||||
|
||||
//! Finishes creating a material property.
|
||||
void EndMaterialProperty();
|
||||
|
||||
void SetPropertyValue(const Name& name, const Data::Asset<ImageAsset>& imageAsset);
|
||||
void SetPropertyValue(const Name& name, const Data::Asset<StreamingImageAsset>& imageAsset);
|
||||
void SetPropertyValue(const Name& name, const Data::Asset<AttachmentImageAsset>& imageAsset);
|
||||
|
||||
//! Sets a property value using data in AZStd::variant-based MaterialPropertyValue. The contained data must match
|
||||
//! the data type of the property. For type Image, the value must be a Data::Asset<ImageAsset>.
|
||||
void SetPropertyValue(const Name& name, const MaterialPropertyValue& value);
|
||||
|
||||
//! Adds a MaterialFunctor.
|
||||
//! Material functors provide custom logic and calculations to configure shaders, render states, and more.See MaterialFunctor.h for details.
|
||||
@@ -101,7 +107,9 @@ namespace AZ
|
||||
private:
|
||||
|
||||
void AddMaterialProperty(MaterialPropertyDescriptor&& materialProperty);
|
||||
|
||||
|
||||
bool PropertyCheck(TypeId typeId, const Name& name);
|
||||
|
||||
//! The material type holds references to shader assets that contain SRGs that are supposed to be the same across all passes in the material.
|
||||
//! This function searches for an SRG given a @bindingSlot. If a valid one is found it makes sure it is the same across all shaders
|
||||
//! and records in srgShaderIndexToUpdate the index of the ShaderAsset in the ShaderCollection where it was found.
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace AZ
|
||||
{
|
||||
AssetBuilderSDK::AssetBuilderDesc materialBuilderDescriptor;
|
||||
materialBuilderDescriptor.m_name = JobKey;
|
||||
materialBuilderDescriptor.m_version = 112; // material dependency improvements
|
||||
materialBuilderDescriptor.m_version = 113; // material dependency improvements
|
||||
materialBuilderDescriptor.m_patterns.push_back(AssetBuilderSDK::AssetBuilderPattern("*.material", AssetBuilderSDK::AssetBuilderPattern::PatternType::Wildcard));
|
||||
materialBuilderDescriptor.m_patterns.push_back(AssetBuilderSDK::AssetBuilderPattern("*.materialtype", AssetBuilderSDK::AssetBuilderPattern::PatternType::Wildcard));
|
||||
materialBuilderDescriptor.m_busId = azrtti_typeid<MaterialBuilder>();
|
||||
@@ -95,7 +95,7 @@ namespace AZ
|
||||
|
||||
const bool currentFileIsMaterial = AzFramework::StringFunc::Path::IsExtension(currentFilePath.c_str(), MaterialSourceData::Extension);
|
||||
const bool referencedFileIsMaterialType = AzFramework::StringFunc::Path::IsExtension(referencedParentPath.c_str(), MaterialTypeSourceData::Extension);
|
||||
const bool ShouldFinalizeMaterialAssets = MaterialUtils::BuildersShouldFinalizeMaterialAssets();
|
||||
const bool shouldFinalizeMaterialAssets = MaterialUtils::BuildersShouldFinalizeMaterialAssets();
|
||||
|
||||
AZStd::vector<AZStd::string> possibleDependencies = RPI::AssetUtils::GetPossibleDepenencyPaths(currentFilePath, referencedParentPath);
|
||||
for (auto& file : possibleDependencies)
|
||||
@@ -118,7 +118,7 @@ namespace AZ
|
||||
// If we aren't finalizing material assets, then a normal job dependency isn't needed because the MaterialTypeAsset data won't be used.
|
||||
// However, we do still need at least an OrderOnce dependency to ensure the Asset Processor knows about the material type asset so the builder can get it's AssetId.
|
||||
// This can significantly reduce AP processing time when a material type or its shaders are edited.
|
||||
if (currentFileIsMaterial && referencedFileIsMaterialType && !ShouldFinalizeMaterialAssets)
|
||||
if (currentFileIsMaterial && referencedFileIsMaterialType && !shouldFinalizeMaterialAssets)
|
||||
{
|
||||
jobDependency.m_type = AssetBuilderSDK::JobDependencyType::OrderOnce;
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ namespace AZ
|
||||
if (auto* serialize = azrtti_cast<SerializeContext*>(context))
|
||||
{
|
||||
serialize->Class<MaterialAssetBuilderComponent, SceneAPI::SceneCore::ExportingComponent>()
|
||||
->Version(18); // material dependency improvements
|
||||
->Version(19); // material dependency improvements
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include <Atom/RPI.Reflect/Material/MaterialAssetCreatorCommon.h>
|
||||
#include <Atom/RPI.Reflect/Material/MaterialAssetCreatorCommon.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
namespace RPI
|
||||
{
|
||||
void MaterialAssetCreatorCommon::OnBegin(
|
||||
const MaterialPropertiesLayout* propertyLayout,
|
||||
AZStd::vector<MaterialPropertyValue>* propertyValues,
|
||||
const AZStd::function<void(const char*)>& warningFunc,
|
||||
const AZStd::function<void(const char*)>& errorFunc)
|
||||
{
|
||||
m_propertyLayout = propertyLayout;
|
||||
m_propertyValues = propertyValues;
|
||||
m_reportWarning = warningFunc;
|
||||
m_reportError = errorFunc;
|
||||
}
|
||||
|
||||
void MaterialAssetCreatorCommon::OnEnd()
|
||||
{
|
||||
m_propertyLayout = nullptr;
|
||||
m_propertyValues = nullptr;
|
||||
m_reportWarning = nullptr;
|
||||
m_reportError = nullptr;
|
||||
}
|
||||
|
||||
bool MaterialAssetCreatorCommon::PropertyCheck(TypeId typeId, const Name& name)
|
||||
{
|
||||
if (!m_reportWarning || !m_reportError)
|
||||
{
|
||||
AZ_Assert(false, "Call Begin() on the AssetCreator before using it.");
|
||||
return false;
|
||||
}
|
||||
|
||||
MaterialPropertyIndex propertyIndex = m_propertyLayout->FindPropertyIndex(name);
|
||||
if (!propertyIndex.IsValid())
|
||||
{
|
||||
m_reportWarning(
|
||||
AZStd::string::format("Material property '%s' not found",
|
||||
name.GetCStr()
|
||||
).data());
|
||||
return false;
|
||||
}
|
||||
|
||||
const MaterialPropertyDescriptor* materialPropertyDescriptor = m_propertyLayout->GetPropertyDescriptor(propertyIndex);
|
||||
if (!materialPropertyDescriptor)
|
||||
{
|
||||
m_reportError("A material property index was found but the property descriptor was null");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ValidateMaterialPropertyDataType(typeId, name, materialPropertyDescriptor, m_reportError))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void MaterialAssetCreatorCommon::SetPropertyValue(const Name& name, const Data::Asset<ImageAsset>& imageAsset)
|
||||
{
|
||||
return SetPropertyValue(name, MaterialPropertyValue(imageAsset));
|
||||
}
|
||||
|
||||
void MaterialAssetCreatorCommon::SetPropertyValue(const Name& name, const MaterialPropertyValue& value)
|
||||
{
|
||||
if (PropertyCheck(value.GetTypeId(), name))
|
||||
{
|
||||
MaterialPropertyIndex propertyIndex = m_propertyLayout->FindPropertyIndex(name);
|
||||
(*m_propertyValues)[propertyIndex.GetIndex()] = value;
|
||||
}
|
||||
}
|
||||
|
||||
void MaterialAssetCreatorCommon::SetPropertyValue(const Name& name, const Data::Asset<StreamingImageAsset>& imageAsset)
|
||||
{
|
||||
SetPropertyValue(name, Data::Asset<ImageAsset>(imageAsset));
|
||||
}
|
||||
|
||||
void MaterialAssetCreatorCommon::SetPropertyValue(const Name& name, const Data::Asset<AttachmentImageAsset>& imageAsset)
|
||||
{
|
||||
SetPropertyValue(name, Data::Asset<ImageAsset>(imageAsset));
|
||||
}
|
||||
} // namespace RPI
|
||||
} // namespace AZ
|
||||
@@ -22,17 +22,6 @@ namespace AZ
|
||||
{
|
||||
m_materialPropertiesLayout = aznew MaterialPropertiesLayout;
|
||||
m_asset->m_materialPropertiesLayout = m_materialPropertiesLayout;
|
||||
|
||||
auto warningFunc = [this](const char* message)
|
||||
{
|
||||
ReportWarning("%s", message);
|
||||
};
|
||||
auto errorFunc = [this](const char* message)
|
||||
{
|
||||
ReportError("%s", message);
|
||||
};
|
||||
// Set empty for UV names as material type asset doesn't have overrides.
|
||||
MaterialAssetCreatorCommon::OnBegin(m_materialPropertiesLayout, &(m_asset->m_propertyValues), warningFunc, errorFunc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,8 +37,6 @@ namespace AZ
|
||||
m_materialShaderResourceGroupLayout = nullptr;
|
||||
m_materialPropertiesLayout = nullptr;
|
||||
|
||||
MaterialAssetCreatorCommon::OnEnd();
|
||||
|
||||
return EndCommon(result);
|
||||
}
|
||||
|
||||
@@ -499,6 +486,54 @@ namespace AZ
|
||||
|
||||
m_wipMaterialProperty = MaterialPropertyDescriptor{};
|
||||
}
|
||||
|
||||
bool MaterialTypeAssetCreator::PropertyCheck(TypeId typeId, const Name& name)
|
||||
{
|
||||
MaterialPropertyIndex propertyIndex = m_materialPropertiesLayout->FindPropertyIndex(name);
|
||||
if (!propertyIndex.IsValid())
|
||||
{
|
||||
ReportWarning("Material property '%s' not found", name.GetCStr());
|
||||
return false;
|
||||
}
|
||||
|
||||
const MaterialPropertyDescriptor* materialPropertyDescriptor = m_materialPropertiesLayout->GetPropertyDescriptor(propertyIndex);
|
||||
if (!materialPropertyDescriptor)
|
||||
{
|
||||
ReportError("A material property index was found but the property descriptor was null");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ValidateMaterialPropertyDataType(typeId, name, materialPropertyDescriptor, [this](const char* message){ReportError("%s", message);}))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void MaterialTypeAssetCreator::SetPropertyValue(const Name& name, const Data::Asset<ImageAsset>& imageAsset)
|
||||
{
|
||||
return SetPropertyValue(name, MaterialPropertyValue(imageAsset));
|
||||
}
|
||||
|
||||
void MaterialTypeAssetCreator::SetPropertyValue(const Name& name, const MaterialPropertyValue& value)
|
||||
{
|
||||
if (PropertyCheck(value.GetTypeId(), name))
|
||||
{
|
||||
MaterialPropertyIndex propertyIndex = m_materialPropertiesLayout->FindPropertyIndex(name);
|
||||
m_asset->m_propertyValues[propertyIndex.GetIndex()] = value;
|
||||
}
|
||||
}
|
||||
|
||||
void MaterialTypeAssetCreator::SetPropertyValue(const Name& name, const Data::Asset<StreamingImageAsset>& imageAsset)
|
||||
{
|
||||
SetPropertyValue(name, Data::Asset<ImageAsset>(imageAsset));
|
||||
}
|
||||
|
||||
void MaterialTypeAssetCreator::SetPropertyValue(const Name& name, const Data::Asset<AttachmentImageAsset>& imageAsset)
|
||||
{
|
||||
SetPropertyValue(name, Data::Asset<ImageAsset>(imageAsset));
|
||||
}
|
||||
|
||||
void MaterialTypeAssetCreator::AddMaterialFunctor(const Ptr<MaterialFunctor>& functor)
|
||||
{
|
||||
|
||||
@@ -51,7 +51,6 @@ set(FILES
|
||||
Include/Atom/RPI.Reflect/Image/StreamingImagePoolAssetCreator.h
|
||||
Include/Atom/RPI.Reflect/Material/LuaMaterialFunctor.h
|
||||
Include/Atom/RPI.Reflect/Material/MaterialAsset.h
|
||||
Include/Atom/RPI.Reflect/Material/MaterialAssetCreatorCommon.h
|
||||
Include/Atom/RPI.Reflect/Material/MaterialAssetCreator.h
|
||||
Include/Atom/RPI.Reflect/Material/MaterialDynamicMetadata.h
|
||||
Include/Atom/RPI.Reflect/Material/MaterialPropertyDescriptor.h
|
||||
@@ -133,7 +132,6 @@ set(FILES
|
||||
Source/RPI.Reflect/Image/StreamingImagePoolAssetCreator.cpp
|
||||
Source/RPI.Reflect/Material/MaterialPropertyValue.cpp
|
||||
Source/RPI.Reflect/Material/MaterialAsset.cpp
|
||||
Source/RPI.Reflect/Material/MaterialAssetCreatorCommon.cpp
|
||||
Source/RPI.Reflect/Material/MaterialAssetCreator.cpp
|
||||
Source/RPI.Reflect/Material/LuaMaterialFunctor.cpp
|
||||
Source/RPI.Reflect/Material/MaterialDynamicMetadata.cpp
|
||||
|
||||
Reference in New Issue
Block a user