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>monroegm-disable-blank-issue-2
parent
b1cc469914
commit
2c59f1b8a4
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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/std/string/string.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
class ReflectContext;
|
||||
class Name;
|
||||
|
||||
namespace RPI
|
||||
{
|
||||
//! This acts like a namespace description for various types of identifiers that appear in .materialtype files.
|
||||
//! When reusable property groups are nested inside other property groups, they usually need alternate naming
|
||||
//! to connect to the appropriate shader inputs. For example, a baseColor property group inside a "layer1" group
|
||||
//! needs to connect to "m_layer1_baseColor_texture" and the same property definition is repeated inside a "layer2"
|
||||
//! group where it connects to "m_layer2_baseColor_texture". This data structure provides the name context, like
|
||||
//! "m_layer1_" or "m_layer2_".
|
||||
class MaterialNameContext
|
||||
{
|
||||
public:
|
||||
AZ_TYPE_INFO(MaterialNameContext, "{AAC9BB28-F463-455D-8467-F877E50E1FA7}")
|
||||
|
||||
static void Reflect(ReflectContext* context);
|
||||
|
||||
MaterialNameContext() = default;
|
||||
|
||||
//! Extends the name context to a deeper property group.
|
||||
void ExtendPropertyIdContext(AZStd::string_view nameContext, bool insertDelimiter=true);
|
||||
void ExtendSrgInputContext(AZStd::string_view nameContext);
|
||||
void ExtendShaderOptionContext(AZStd::string_view nameContext);
|
||||
|
||||
//! Applies the name context to a given leaf name.
|
||||
bool ContextualizeProperty(Name& propertyName) const;
|
||||
bool ContextualizeSrgInput(Name& srgInputName) const;
|
||||
bool ContextualizeShaderOption(Name& shaderOptionName) const;
|
||||
|
||||
//! Returns true if there is some non-default name context.
|
||||
bool HasContextForProperties() const { return !m_propertyIdContext.empty(); }
|
||||
bool HasContextForSrgInputs() const { return !m_srgInputNameContext.empty(); }
|
||||
bool HasContextForShaderOptions() const { return !m_shaderOptionNameContext.empty(); }
|
||||
|
||||
//! Returns true if the name context is empty.
|
||||
bool IsDefault() const;
|
||||
|
||||
private:
|
||||
AZStd::string m_propertyIdContext;
|
||||
AZStd::string m_srgInputNameContext;
|
||||
AZStd::string m_shaderOptionNameContext;
|
||||
};
|
||||
|
||||
} // namespace RPI
|
||||
} // namespace AZ
|
||||
@ -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
|
||||
Loading…
Reference in New Issue