Added support for deeply nested material property groups.
The main addition here is the MaterialNameContext class which represents the concept of a namespace for properties, shader options, and SRG fields. This concept was already somewhat supported in LuaMaterialFunctor through bespoke "prefix" fields, but I have generalized it be available for all material functors. Note that I have not yet updated the other material functor types to ensure they take advantage of this feature, that will be in another commit. Signed-off-by: santorac <55155825+santorac@users.noreply.github.com>
This commit is contained in:
@@ -29,9 +29,7 @@ namespace AZ
|
||||
serializeContext->Class<LuaMaterialFunctor, RPI::MaterialFunctor>()
|
||||
->Version(1)
|
||||
->Field("scriptAsset", &LuaMaterialFunctor::m_scriptAsset)
|
||||
->Field("propertyNamePrefix", &LuaMaterialFunctor::m_propertyNamePrefix)
|
||||
->Field("srgNamePrefix", &LuaMaterialFunctor::m_srgNamePrefix)
|
||||
->Field("optionsNamePrefix", &LuaMaterialFunctor::m_optionsNamePrefix)
|
||||
->Field("materialNameContext", &LuaMaterialFunctor::m_materialNameContext)
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -127,7 +125,7 @@ namespace AZ
|
||||
|
||||
if (m_scriptStatus == ScriptStatus::Ready)
|
||||
{
|
||||
LuaMaterialFunctorRuntimeContext luaContext{&context, &GetMaterialPropertyDependencies(), m_propertyNamePrefix, m_srgNamePrefix, m_optionsNamePrefix};
|
||||
LuaMaterialFunctorRuntimeContext luaContext{&context, &GetMaterialPropertyDependencies(), m_materialNameContext};
|
||||
AZ::ScriptDataContext call;
|
||||
if (m_scriptContext->Call("Process", call))
|
||||
{
|
||||
@@ -145,7 +143,7 @@ namespace AZ
|
||||
|
||||
if (m_scriptStatus == ScriptStatus::Ready)
|
||||
{
|
||||
LuaMaterialFunctorEditorContext luaContext{&context, &GetMaterialPropertyDependencies(), m_propertyNamePrefix, m_srgNamePrefix, m_optionsNamePrefix};
|
||||
LuaMaterialFunctorEditorContext luaContext{&context, &GetMaterialPropertyDependencies(), m_materialNameContext};
|
||||
AZ::ScriptDataContext call;
|
||||
if (m_scriptContext->Call("ProcessEditor", call))
|
||||
{
|
||||
@@ -157,27 +155,19 @@ namespace AZ
|
||||
|
||||
LuaMaterialFunctorCommonContext::LuaMaterialFunctorCommonContext(MaterialFunctor::RuntimeContext* runtimeContextImpl,
|
||||
const MaterialPropertyFlags* materialPropertyDependencies,
|
||||
const AZStd::string& propertyNamePrefix,
|
||||
const AZStd::string& srgNamePrefix,
|
||||
const AZStd::string& optionsNamePrefix)
|
||||
const MaterialNameContext& materialNameContext)
|
||||
: m_runtimeContextImpl(runtimeContextImpl)
|
||||
, m_materialPropertyDependencies(materialPropertyDependencies)
|
||||
, m_propertyNamePrefix(propertyNamePrefix)
|
||||
, m_srgNamePrefix(srgNamePrefix)
|
||||
, m_optionsNamePrefix(optionsNamePrefix)
|
||||
, m_materialNameContext(materialNameContext)
|
||||
{
|
||||
}
|
||||
|
||||
LuaMaterialFunctorCommonContext::LuaMaterialFunctorCommonContext(MaterialFunctor::EditorContext* editorContextImpl,
|
||||
const MaterialPropertyFlags* materialPropertyDependencies,
|
||||
const AZStd::string& propertyNamePrefix,
|
||||
const AZStd::string& srgNamePrefix,
|
||||
const AZStd::string& optionsNamePrefix)
|
||||
const MaterialNameContext& materialNameContext)
|
||||
: m_editorContextImpl(editorContextImpl)
|
||||
, m_materialPropertyDependencies(materialPropertyDependencies)
|
||||
, m_propertyNamePrefix(propertyNamePrefix)
|
||||
, m_srgNamePrefix(srgNamePrefix)
|
||||
, m_optionsNamePrefix(optionsNamePrefix)
|
||||
, m_materialNameContext(materialNameContext)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -256,7 +246,8 @@ namespace AZ
|
||||
{
|
||||
MaterialPropertyIndex propertyIndex;
|
||||
|
||||
Name propertyFullName{m_propertyNamePrefix + name};
|
||||
Name propertyFullName{name};
|
||||
m_materialNameContext.ContextualizeProperty(propertyFullName);
|
||||
|
||||
propertyIndex = GetMaterialPropertiesLayout()->FindPropertyIndex(propertyFullName);
|
||||
|
||||
@@ -361,10 +352,8 @@ namespace AZ
|
||||
|
||||
LuaMaterialFunctorRuntimeContext::LuaMaterialFunctorRuntimeContext(MaterialFunctor::RuntimeContext* runtimeContextImpl,
|
||||
const MaterialPropertyFlags* materialPropertyDependencies,
|
||||
const AZStd::string& propertyNamePrefix,
|
||||
const AZStd::string& srgNamePrefix,
|
||||
const AZStd::string& optionsNamePrefix)
|
||||
: LuaMaterialFunctorCommonContext(runtimeContextImpl, materialPropertyDependencies, propertyNamePrefix, srgNamePrefix, optionsNamePrefix)
|
||||
const MaterialNameContext& materialNameContext)
|
||||
: LuaMaterialFunctorCommonContext(runtimeContextImpl, materialPropertyDependencies, materialNameContext)
|
||||
, m_runtimeContextImpl(runtimeContextImpl)
|
||||
{
|
||||
}
|
||||
@@ -379,7 +368,8 @@ namespace AZ
|
||||
{
|
||||
bool didSetOne = false;
|
||||
|
||||
Name fullOptionName{m_optionsNamePrefix + name};
|
||||
Name fullOptionName{name};
|
||||
m_materialNameContext.ContextualizeShaderOption(fullOptionName);
|
||||
|
||||
for (AZStd::size_t i = 0; i < m_runtimeContextImpl->m_shaderCollection->size(); ++i)
|
||||
{
|
||||
@@ -429,7 +419,8 @@ namespace AZ
|
||||
|
||||
RHI::ShaderInputConstantIndex LuaMaterialFunctorRuntimeContext::GetShaderInputConstantIndex(const char* name, const char* functionName) const
|
||||
{
|
||||
Name fullInputName{m_srgNamePrefix + name};
|
||||
Name fullInputName{name};
|
||||
m_materialNameContext.ContextualizeSrgInput(fullInputName);
|
||||
|
||||
RHI::ShaderInputConstantIndex index = m_runtimeContextImpl->m_shaderResourceGroup->FindShaderInputConstantIndex(fullInputName);
|
||||
|
||||
@@ -524,10 +515,8 @@ namespace AZ
|
||||
|
||||
LuaMaterialFunctorEditorContext::LuaMaterialFunctorEditorContext(MaterialFunctor::EditorContext* editorContextImpl,
|
||||
const MaterialPropertyFlags* materialPropertyDependencies,
|
||||
const AZStd::string& propertyNamePrefix,
|
||||
const AZStd::string& srgNamePrefix,
|
||||
const AZStd::string& optionsNamePrefix)
|
||||
: LuaMaterialFunctorCommonContext(editorContextImpl, materialPropertyDependencies, propertyNamePrefix, srgNamePrefix, optionsNamePrefix)
|
||||
const MaterialNameContext& materialNameContext)
|
||||
: LuaMaterialFunctorCommonContext(editorContextImpl, materialPropertyDependencies, materialNameContext)
|
||||
, m_editorContextImpl(editorContextImpl)
|
||||
{
|
||||
}
|
||||
@@ -598,7 +587,9 @@ namespace AZ
|
||||
{
|
||||
if (m_editorContextImpl)
|
||||
{
|
||||
return m_editorContextImpl->SetMaterialPropertyGroupVisibility(Name{m_propertyNamePrefix + name}, visibility);
|
||||
Name fullName{name};
|
||||
m_materialNameContext.ContextualizeProperty(fullName);
|
||||
return m_editorContextImpl->SetMaterialPropertyGroupVisibility(fullName, visibility);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -607,7 +598,9 @@ namespace AZ
|
||||
{
|
||||
if (m_editorContextImpl)
|
||||
{
|
||||
return m_editorContextImpl->SetMaterialPropertyVisibility(Name{m_propertyNamePrefix + name}, visibility);
|
||||
Name fullName{name};
|
||||
m_materialNameContext.ContextualizeProperty(fullName);
|
||||
return m_editorContextImpl->SetMaterialPropertyVisibility(fullName, visibility);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -616,7 +609,9 @@ namespace AZ
|
||||
{
|
||||
if (m_editorContextImpl)
|
||||
{
|
||||
return m_editorContextImpl->SetMaterialPropertyDescription(Name{m_propertyNamePrefix + name}, description);
|
||||
Name fullName{name};
|
||||
m_materialNameContext.ContextualizeProperty(fullName);
|
||||
return m_editorContextImpl->SetMaterialPropertyDescription(fullName, description);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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/MaterialNameContext.h>
|
||||
#include <AzCore/RTTI/ReflectContext.h>
|
||||
#include <AzCore/Serialization/SerializeContext.h>
|
||||
#include <AzCore/Name/Name.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
namespace RPI
|
||||
{
|
||||
void MaterialNameContext::Reflect(ReflectContext* context)
|
||||
{
|
||||
if (auto* serializeContext = azrtti_cast<SerializeContext*>(context))
|
||||
{
|
||||
serializeContext->Class<MaterialNameContext>()
|
||||
->Version(1)
|
||||
->Field("propertyIdContext", &MaterialNameContext::m_propertyIdContext)
|
||||
->Field("srgInputNameContext", &MaterialNameContext::m_srgInputNameContext)
|
||||
->Field("shaderOptionNameContext", &MaterialNameContext::m_shaderOptionNameContext)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
bool MaterialNameContext::IsDefault() const
|
||||
{
|
||||
return m_propertyIdContext.empty() && m_srgInputNameContext.empty() && m_shaderOptionNameContext.empty();
|
||||
}
|
||||
|
||||
void MaterialNameContext::ExtendPropertyIdContext(AZStd::string_view nameContext, bool insertDelimiter)
|
||||
{
|
||||
m_propertyIdContext += nameContext;
|
||||
if (insertDelimiter && !nameContext.empty() && !nameContext.ends_with("."))
|
||||
{
|
||||
m_propertyIdContext += ".";
|
||||
}
|
||||
}
|
||||
|
||||
void MaterialNameContext::ExtendSrgInputContext(AZStd::string_view nameContext)
|
||||
{
|
||||
m_srgInputNameContext += nameContext;
|
||||
}
|
||||
|
||||
void MaterialNameContext::ExtendShaderOptionContext(AZStd::string_view nameContext)
|
||||
{
|
||||
m_shaderOptionNameContext += nameContext;
|
||||
}
|
||||
|
||||
bool MaterialNameContext::ContextualizeProperty(Name& propertyName) const
|
||||
{
|
||||
if (m_propertyIdContext.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
propertyName = m_propertyIdContext + propertyName.GetCStr();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MaterialNameContext::ContextualizeSrgInput(Name& srgInputName) const
|
||||
{
|
||||
if (m_srgInputNameContext.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
srgInputName = m_srgInputNameContext + srgInputName.GetCStr();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MaterialNameContext::ContextualizeShaderOption(Name& shaderOptionName) const
|
||||
{
|
||||
if (m_shaderOptionNameContext.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
shaderOptionName = m_shaderOptionNameContext + shaderOptionName.GetCStr();
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace RPI
|
||||
} // namespace AZ
|
||||
Reference in New Issue
Block a user