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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user