Merge pull request #2752 from greenrazer/ExposeLodControls
Expose lod controls
This commit is contained in:
@@ -62,9 +62,9 @@ namespace AZ
|
||||
void BuildDrawPacketList(size_t modelLodIndex);
|
||||
void SetRayTracingData();
|
||||
void SetSortKey(RHI::DrawItemSortKey sortKey);
|
||||
RHI::DrawItemSortKey GetSortKey();
|
||||
void SetLodOverride(RPI::Cullable::LodOverride lodOverride);
|
||||
RPI::Cullable::LodOverride GetLodOverride();
|
||||
RHI::DrawItemSortKey GetSortKey() const;
|
||||
void SetMeshLodConfiguration(RPI::Cullable::LodConfiguration meshLodConfig);
|
||||
RPI::Cullable::LodConfiguration GetMeshLodConfiguration() const;
|
||||
void UpdateDrawPackets(bool forceUpdate = false);
|
||||
void BuildCullable();
|
||||
void UpdateCullBounds(const TransformServiceFeatureProcessor* transformService);
|
||||
@@ -153,10 +153,10 @@ namespace AZ
|
||||
AZ::Aabb GetLocalAabb(const MeshHandle& meshHandle) const override;
|
||||
|
||||
void SetSortKey(const MeshHandle& meshHandle, RHI::DrawItemSortKey sortKey) override;
|
||||
RHI::DrawItemSortKey GetSortKey(const MeshHandle& meshHandle) override;
|
||||
RHI::DrawItemSortKey GetSortKey(const MeshHandle& meshHandle) const override;
|
||||
|
||||
void SetLodOverride(const MeshHandle& meshHandle, RPI::Cullable::LodOverride lodOverride) override;
|
||||
RPI::Cullable::LodOverride GetLodOverride(const MeshHandle& meshHandle) override;
|
||||
void SetMeshLodConfiguration(const MeshHandle& meshHandle, const RPI::Cullable::LodConfiguration& meshLodConfig) override;
|
||||
RPI::Cullable::LodConfiguration GetMeshLodConfiguration(const MeshHandle& meshHandle) const override;
|
||||
|
||||
void SetExcludeFromReflectionCubeMaps(const MeshHandle& meshHandle, bool excludeFromReflectionCubeMaps) override;
|
||||
void SetRayTracingEnabled(const MeshHandle& meshHandle, bool rayTracingEnabled) override;
|
||||
|
||||
+5
-5
@@ -93,11 +93,11 @@ namespace AZ
|
||||
//! Sets the sort key for a given mesh handle.
|
||||
virtual void SetSortKey(const MeshHandle& meshHandle, RHI::DrawItemSortKey sortKey) = 0;
|
||||
//! Gets the sort key for a given mesh handle.
|
||||
virtual RHI::DrawItemSortKey GetSortKey(const MeshHandle& meshHandle) = 0;
|
||||
//! Sets an LOD override for a given mesh handle. This LOD will always be rendered instead being automatically determined.
|
||||
virtual void SetLodOverride(const MeshHandle& meshHandle, RPI::Cullable::LodOverride lodOverride) = 0;
|
||||
//! Gets the LOD override for a given mesh handle.
|
||||
virtual RPI::Cullable::LodOverride GetLodOverride(const MeshHandle& meshHandle) = 0;
|
||||
virtual RHI::DrawItemSortKey GetSortKey(const MeshHandle& meshHandle) const = 0;
|
||||
//! Sets LOD mesh configurations to be used in the Mesh Feature Processor
|
||||
virtual void SetMeshLodConfiguration(const MeshHandle& meshHandle, const RPI::Cullable::LodConfiguration& meshLodConfig) = 0;
|
||||
//! Gets the LOD mesh configurations being used in the Mesh Feature Processor
|
||||
virtual RPI::Cullable::LodConfiguration GetMeshLodConfiguration(const MeshHandle& meshHandle) const = 0;
|
||||
//! Sets the option to exclude this mesh from baked reflection probe cubemaps
|
||||
virtual void SetExcludeFromReflectionCubeMaps(const MeshHandle& meshHandle, bool excludeFromReflectionCubeMaps) = 0;
|
||||
//! Sets the option to exclude this mesh from raytracing
|
||||
|
||||
@@ -32,9 +32,9 @@ namespace UnitTest
|
||||
MOCK_METHOD2(SetLocalAabb, void(const MeshHandle&, const AZ::Aabb&));
|
||||
MOCK_CONST_METHOD1(GetLocalAabb, AZ::Aabb(const MeshHandle&));
|
||||
MOCK_METHOD2(SetSortKey, void (const MeshHandle&, AZ::RHI::DrawItemSortKey));
|
||||
MOCK_METHOD1(GetSortKey, AZ::RHI::DrawItemSortKey(const MeshHandle&));
|
||||
MOCK_METHOD2(SetLodOverride, void(const MeshHandle&, AZ::RPI::Cullable::LodOverride));
|
||||
MOCK_METHOD1(GetLodOverride, AZ::RPI::Cullable::LodOverride(const MeshHandle&));
|
||||
MOCK_CONST_METHOD1(GetSortKey, AZ::RHI::DrawItemSortKey(const MeshHandle&));
|
||||
MOCK_METHOD2(SetMeshLodConfiguration, void(const MeshHandle&, const AZ::RPI::Cullable::LodConfiguration&));
|
||||
MOCK_CONST_METHOD1(GetMeshLodConfiguration, AZ::RPI::Cullable::LodConfiguration(const MeshHandle&));
|
||||
MOCK_METHOD2(AcquireMesh, MeshHandle (const AZ::Render::MeshHandleDescriptor&, const AZ::Render::MaterialAssignmentMap&));
|
||||
MOCK_METHOD2(AcquireMesh, MeshHandle (const AZ::Render::MeshHandleDescriptor&, const AZ::Data::Instance<AZ::RPI::Material>&));
|
||||
MOCK_METHOD2(SetRayTracingEnabled, void (const MeshHandle&, bool));
|
||||
|
||||
@@ -346,7 +346,7 @@ namespace AZ
|
||||
}
|
||||
}
|
||||
|
||||
RHI::DrawItemSortKey MeshFeatureProcessor::GetSortKey(const MeshHandle& meshHandle)
|
||||
RHI::DrawItemSortKey MeshFeatureProcessor::GetSortKey(const MeshHandle& meshHandle) const
|
||||
{
|
||||
if (meshHandle.IsValid())
|
||||
{
|
||||
@@ -359,24 +359,24 @@ namespace AZ
|
||||
}
|
||||
}
|
||||
|
||||
void MeshFeatureProcessor::SetLodOverride(const MeshHandle& meshHandle, RPI::Cullable::LodOverride lodOverride)
|
||||
void MeshFeatureProcessor::SetMeshLodConfiguration(const MeshHandle& meshHandle, const RPI::Cullable::LodConfiguration& meshLodConfig)
|
||||
{
|
||||
if (meshHandle.IsValid())
|
||||
{
|
||||
meshHandle->SetLodOverride(lodOverride);
|
||||
meshHandle->SetMeshLodConfiguration(meshLodConfig);
|
||||
}
|
||||
}
|
||||
|
||||
RPI::Cullable::LodOverride MeshFeatureProcessor::GetLodOverride(const MeshHandle& meshHandle)
|
||||
RPI::Cullable::LodConfiguration MeshFeatureProcessor::GetMeshLodConfiguration(const MeshHandle& meshHandle) const
|
||||
{
|
||||
if (meshHandle.IsValid())
|
||||
{
|
||||
return meshHandle->GetLodOverride();
|
||||
return meshHandle->GetMeshLodConfiguration();
|
||||
}
|
||||
else
|
||||
{
|
||||
AZ_Assert(false, "Invalid mesh handle");
|
||||
return 0;
|
||||
return {RPI::Cullable::LodType::Default, 0, 0.0f, 0.0f };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -968,19 +968,19 @@ namespace AZ
|
||||
}
|
||||
}
|
||||
|
||||
RHI::DrawItemSortKey MeshDataInstance::GetSortKey()
|
||||
RHI::DrawItemSortKey MeshDataInstance::GetSortKey() const
|
||||
{
|
||||
return m_sortKey;
|
||||
}
|
||||
|
||||
void MeshDataInstance::SetLodOverride(RPI::Cullable::LodOverride lodOverride)
|
||||
void MeshDataInstance::SetMeshLodConfiguration(RPI::Cullable::LodConfiguration meshLodConfig)
|
||||
{
|
||||
m_cullable.m_lodData.m_lodOverride = lodOverride;
|
||||
m_cullable.m_lodData.m_lodConfiguration = meshLodConfig;
|
||||
}
|
||||
|
||||
RPI::Cullable::LodOverride MeshDataInstance::GetLodOverride()
|
||||
RPI::Cullable::LodConfiguration MeshDataInstance::GetMeshLodConfiguration() const
|
||||
{
|
||||
return m_cullable.m_lodData.m_lodOverride;
|
||||
return m_cullable.m_lodData.m_lodConfiguration;
|
||||
}
|
||||
|
||||
void MeshDataInstance::UpdateDrawPackets(bool forceUpdate /*= false*/)
|
||||
@@ -1022,9 +1022,6 @@ namespace AZ
|
||||
{
|
||||
//initialize the lod
|
||||
RPI::Cullable::LodData::Lod& lod = lodData.m_lods[lodIndex];
|
||||
//[GFX TODO][ATOM-5562] - Level of detail: override lod distances and add global lod multiplier(s)
|
||||
static const float MinimumScreenCoverage = 1.0f/1080.0f; //mesh should cover at least a screen pixel at 1080p to be drawn
|
||||
static const float ReductionFactor = 0.5f;
|
||||
if (lodIndex == 0)
|
||||
{
|
||||
//first lod
|
||||
@@ -1033,17 +1030,18 @@ namespace AZ
|
||||
else
|
||||
{
|
||||
//every other lod: use the previous lod's min
|
||||
lod.m_screenCoverageMax = AZStd::GetMax(lodData.m_lods[lodIndex-1].m_screenCoverageMin, MinimumScreenCoverage);
|
||||
lod.m_screenCoverageMax = AZStd::GetMax(lodData.m_lods[lodIndex - 1].m_screenCoverageMin, lodData.m_lodConfiguration.m_minimumScreenCoverage);
|
||||
}
|
||||
|
||||
if (lodIndex < lodAssets.size() - 1)
|
||||
{
|
||||
//first and middle lods: compute a stepdown value for the min
|
||||
lod.m_screenCoverageMin = AZStd::GetMax(ReductionFactor * lod.m_screenCoverageMax, MinimumScreenCoverage);
|
||||
lod.m_screenCoverageMin = AZStd::GetMax(lodData.m_lodConfiguration.m_qualityDecayRate * lod.m_screenCoverageMax, lodData.m_lodConfiguration.m_minimumScreenCoverage);
|
||||
}
|
||||
else
|
||||
{
|
||||
//last lod: use MinimumScreenCoverage for the min
|
||||
lod.m_screenCoverageMin = MinimumScreenCoverage;
|
||||
lod.m_screenCoverageMin = lodData.m_lodConfiguration.m_minimumScreenCoverage;
|
||||
}
|
||||
|
||||
lod.m_drawPackets.clear();
|
||||
|
||||
@@ -70,8 +70,23 @@ namespace AZ
|
||||
};
|
||||
CullData m_cullData;
|
||||
|
||||
enum LodType : uint8_t
|
||||
{
|
||||
Default = 0,
|
||||
ScreenCoverage,
|
||||
SpecificLod,
|
||||
};
|
||||
using LodOverride = uint8_t;
|
||||
static constexpr uint8_t NoLodOverride = AZStd::numeric_limits<LodOverride>::max();
|
||||
|
||||
struct LodConfiguration
|
||||
{
|
||||
LodType m_lodType = LodType::Default;
|
||||
LodOverride m_lodOverride = 0;
|
||||
// the minimum possibe area a sphere enclosing a mesh projected onto the screen should have before it is culled.
|
||||
float m_minimumScreenCoverage = 1.0f / 1080.0f; // For default, mesh should cover at least a screen pixel at 1080p to be drawn;
|
||||
// The screen area decay between 0 and 1, i.e. closer to 1 -> lose quality immediately, closer to 0 -> never lose quality
|
||||
float m_qualityDecayRate = 0.5f;
|
||||
};
|
||||
|
||||
struct LodData
|
||||
{
|
||||
@@ -88,7 +103,7 @@ namespace AZ
|
||||
//! Suggest setting to: 0.5f*localAabb.GetExtents().GetMaxElement()
|
||||
float m_lodSelectionRadius = 1.0f;
|
||||
|
||||
LodOverride m_lodOverride = NoLodOverride;
|
||||
LodConfiguration m_lodConfiguration;
|
||||
};
|
||||
LodData m_lodData;
|
||||
|
||||
|
||||
@@ -672,20 +672,25 @@ namespace AZ
|
||||
}
|
||||
};
|
||||
|
||||
if (lodData.m_lodOverride == Cullable::NoLodOverride)
|
||||
switch (lodData.m_lodConfiguration.m_lodType)
|
||||
{
|
||||
for (const Cullable::LodData::Lod& lod : lodData.m_lods)
|
||||
{
|
||||
//Note that this supports overlapping lod ranges (to suport cross-fading lods, for example)
|
||||
if (approxScreenPercentage >= lod.m_screenCoverageMin && approxScreenPercentage <= lod.m_screenCoverageMax)
|
||||
case Cullable::LodType::SpecificLod:
|
||||
if (lodData.m_lodConfiguration.m_lodOverride < lodData.m_lods.size())
|
||||
{
|
||||
addLodToDrawPacket(lod);
|
||||
addLodToDrawPacket(lodData.m_lods.at(lodData.m_lodConfiguration.m_lodOverride));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(lodData.m_lodOverride < lodData.m_lods.size())
|
||||
{
|
||||
addLodToDrawPacket(lodData.m_lods.at(lodData.m_lodOverride));
|
||||
break;
|
||||
case Cullable::LodType::ScreenCoverage:
|
||||
default:
|
||||
for (const Cullable::LodData::Lod& lod : lodData.m_lods)
|
||||
{
|
||||
// Note that this supports overlapping lod ranges (to suport cross-fading lods, for example)
|
||||
if (approxScreenPercentage >= lod.m_screenCoverageMin && approxScreenPercentage <= lod.m_screenCoverageMax)
|
||||
{
|
||||
addLodToDrawPacket(lod);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return numVisibleDrawPackets;
|
||||
|
||||
+9
@@ -36,9 +36,18 @@ namespace AZ
|
||||
virtual void SetSortKey(RHI::DrawItemSortKey sortKey) = 0;
|
||||
virtual RHI::DrawItemSortKey GetSortKey() const = 0;
|
||||
|
||||
virtual void SetLodType(RPI::Cullable::LodType lodType) = 0;
|
||||
virtual RPI::Cullable::LodType GetLodType() const = 0;
|
||||
|
||||
virtual void SetLodOverride(RPI::Cullable::LodOverride lodOverride) = 0;
|
||||
virtual RPI::Cullable::LodOverride GetLodOverride() const = 0;
|
||||
|
||||
virtual void SetMinimumScreenCoverage(float minimumScreenCoverage) = 0;
|
||||
virtual float GetMinimumScreenCoverage() const = 0;
|
||||
|
||||
virtual void SetQualityDecayRate(float qualityDecayRate) = 0;
|
||||
virtual float GetQualityDecayRate() const = 0;
|
||||
|
||||
virtual void SetVisibility(bool visible) = 0;
|
||||
virtual bool GetVisibility() const = 0;
|
||||
|
||||
|
||||
@@ -71,16 +71,36 @@ namespace AZ
|
||||
"MeshComponentConfig", "")
|
||||
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
|
||||
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &MeshComponentConfig::m_modelAsset, "Mesh Asset", "Mesh asset reference")
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &MeshComponentConfig::m_sortKey, "Sort Key", "Transparent meshes are drawn by sort key then depth. Used this to force certain transparent meshes to draw before or after others.")
|
||||
->DataElement(AZ::Edit::UIHandlers::ComboBox, &MeshComponentConfig::m_lodOverride, "Lod Override", "Allows the rendered LOD to be overridden instead of being calculated automatically.")
|
||||
->Attribute(AZ::Edit::Attributes::EnumValues, &MeshComponentConfig::GetLodOverrideValues)
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, &MeshComponentConfig::IsAssetSet)
|
||||
->DataElement(AZ::Edit::UIHandlers::CheckBox, &MeshComponentConfig::m_excludeFromReflectionCubeMaps, "Exclude from reflection cubemaps", "Mesh will not be visible in baked reflection probe cubemaps")
|
||||
->Attribute(AZ::Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::ValuesOnly)
|
||||
->DataElement(AZ::Edit::UIHandlers::CheckBox, &MeshComponentConfig::m_useForwardPassIblSpecular, "Use Forward Pass IBL Specular",
|
||||
"Renders IBL specular reflections in the forward pass, using only the most influential probe (based on the position of the entity) and the global IBL cubemap. Can reduce rendering costs, but only recommended for static objects that are affected by at most one reflection probe.")
|
||||
->Attribute(AZ::Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::ValuesOnly)
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &MeshComponentConfig::m_modelAsset, "Mesh Asset", "Mesh asset reference")
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &MeshComponentConfig::m_sortKey, "Sort Key", "Transparent meshes are drawn by sort key then depth. Used this to force certain transparent meshes to draw before or after others.")
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, &MeshComponentConfig::IsAssetSet)
|
||||
->DataElement(AZ::Edit::UIHandlers::CheckBox, &MeshComponentConfig::m_excludeFromReflectionCubeMaps, "Exclude from reflection cubemaps", "Mesh will not be visible in baked reflection probe cubemaps")
|
||||
->Attribute(AZ::Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::ValuesOnly)
|
||||
->DataElement(AZ::Edit::UIHandlers::CheckBox, &MeshComponentConfig::m_useForwardPassIblSpecular, "Use Forward Pass IBL Specular",
|
||||
"Renders IBL specular reflections in the forward pass, using only the most influential probe (based on the position of the entity) and the global IBL cubemap. Can reduce rendering costs, but only recommended for static objects that are affected by at most one reflection probe.")
|
||||
->Attribute(AZ::Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::ValuesOnly)
|
||||
->DataElement(AZ::Edit::UIHandlers::ComboBox, &MeshComponentConfig::m_lodType, "Lod Type", "Lod Method.")
|
||||
->EnumAttribute(RPI::Cullable::LodType::Default, "Default")
|
||||
->EnumAttribute(RPI::Cullable::LodType::ScreenCoverage, "Screen Coverage")
|
||||
->EnumAttribute(RPI::Cullable::LodType::SpecificLod, "Specific Lod")
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, &MeshComponentConfig::IsAssetSet)
|
||||
->Attribute(AZ::Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::EntireTree)
|
||||
->ClassElement(AZ::Edit::ClassElements::Group, "Lod Configuration")
|
||||
->Attribute(AZ::Edit::Attributes::AutoExpand, false)
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, &MeshComponentConfig::ShowLodConfig)
|
||||
->DataElement(AZ::Edit::UIHandlers::ComboBox, &MeshComponentConfig::m_lodOverride, "Lod Override", "Allows the rendered LOD to be overridden instead of being calculated automatically.")
|
||||
->Attribute(AZ::Edit::Attributes::EnumValues, &MeshComponentConfig::GetLodOverrideValues)
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, &MeshComponentConfig::LodTypeIsSpecificLOD)
|
||||
->DataElement(AZ::Edit::UIHandlers::Slider, &MeshComponentConfig::m_minimumScreenCoverage, "Minimum Screen Coverage", "Minimum proportion of screen area an entitiy takes up, after that the entitiy is culled.")
|
||||
->Attribute(AZ::Edit::Attributes::Min, 0.f)
|
||||
->Attribute(AZ::Edit::Attributes::Max, 1.f)
|
||||
->Attribute(AZ::Edit::Attributes::Suffix, " percent")
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, &MeshComponentConfig::LodTypeIsScreenCoverage)
|
||||
->DataElement(AZ::Edit::UIHandlers::Slider, &MeshComponentConfig::m_qualityDecayRate, "Quality Decay Rate",
|
||||
"Rate at which mesh quality decays (0 -> always stay highest quality, 1 -> quality falls off to lowest quality immediately).")
|
||||
->Attribute(AZ::Edit::Attributes::Min, 0.f)
|
||||
->Attribute(AZ::Edit::Attributes::Max, 1.f)
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, &MeshComponentConfig::LodTypeIsScreenCoverage)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
+112
-10
@@ -31,18 +31,40 @@ namespace AZ
|
||||
{
|
||||
namespace Render
|
||||
{
|
||||
|
||||
namespace MeshComponentControllerVersionUtility
|
||||
{
|
||||
bool VersionConverter(AZ::SerializeContext& context, AZ::SerializeContext::DataElementNode& classElement)
|
||||
{
|
||||
if (classElement.GetVersion() < 2)
|
||||
{
|
||||
RPI::Cullable::LodOverride lodOverride = aznumeric_cast<RPI::Cullable::LodOverride>(classElement.FindElement(AZ_CRC("LodOverride")));
|
||||
static constexpr uint8_t old_NoLodOverride = AZStd::numeric_limits <RPI::Cullable::LodOverride>::max();
|
||||
if (lodOverride == old_NoLodOverride)
|
||||
{
|
||||
classElement.AddElementWithData(context, "LodType", RPI::Cullable::LodType::SpecificLod);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace MeshComponentControllerVersionUtility
|
||||
|
||||
void MeshComponentConfig::Reflect(ReflectContext* context)
|
||||
{
|
||||
if (auto* serializeContext = azrtti_cast<SerializeContext*>(context))
|
||||
{
|
||||
serializeContext->Class<MeshComponentConfig>()
|
||||
->Version(1)
|
||||
->Version(2, &MeshComponentControllerVersionUtility::VersionConverter)
|
||||
->Field("ModelAsset", &MeshComponentConfig::m_modelAsset)
|
||||
->Field("SortKey", &MeshComponentConfig::m_sortKey)
|
||||
->Field("LodOverride", &MeshComponentConfig::m_lodOverride)
|
||||
->Field("ExcludeFromReflectionCubeMaps", &MeshComponentConfig::m_excludeFromReflectionCubeMaps)
|
||||
->Field("UseForwardPassIBLSpecular", &MeshComponentConfig::m_useForwardPassIblSpecular);
|
||||
->Field("UseForwardPassIBLSpecular", &MeshComponentConfig::m_useForwardPassIblSpecular)
|
||||
->Field("LodType", &MeshComponentConfig::m_lodType)
|
||||
->Field("LodOverride", &MeshComponentConfig::m_lodOverride)
|
||||
->Field("MinimumScreenCoverage", &MeshComponentConfig::m_minimumScreenCoverage)
|
||||
->Field("QualityDecayRate", &MeshComponentConfig::m_qualityDecayRate);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool MeshComponentConfig::IsAssetSet()
|
||||
@@ -50,6 +72,21 @@ namespace AZ
|
||||
return m_modelAsset.GetId().IsValid();
|
||||
}
|
||||
|
||||
bool MeshComponentConfig::LodTypeIsScreenCoverage()
|
||||
{
|
||||
return m_lodType == RPI::Cullable::LodType::ScreenCoverage;
|
||||
}
|
||||
|
||||
bool MeshComponentConfig::LodTypeIsSpecificLOD()
|
||||
{
|
||||
return m_lodType == RPI::Cullable::LodType::SpecificLod;
|
||||
}
|
||||
|
||||
bool MeshComponentConfig::ShowLodConfig()
|
||||
{
|
||||
return LodTypeIsScreenCoverage() && LodTypeIsSpecificLOD();
|
||||
}
|
||||
|
||||
AZStd::vector<AZStd::pair<RPI::Cullable::LodOverride, AZStd::string>> MeshComponentConfig::GetLodOverrideValues()
|
||||
{
|
||||
AZStd::vector<AZStd::pair<RPI::Cullable::LodOverride, AZStd::string>> values;
|
||||
@@ -72,9 +109,9 @@ namespace AZ
|
||||
}
|
||||
|
||||
values.reserve(lodCount + 1);
|
||||
values.push_back({ RPI::Cullable::NoLodOverride, "Not Set" });
|
||||
values.push_back({ aznumeric_cast<RPI::Cullable::LodOverride>(0), "Default (Highest)" });
|
||||
|
||||
for (uint32_t i = 0; i < lodCount; ++i)
|
||||
for (uint32_t i = 1; i < lodCount; ++i)
|
||||
{
|
||||
AZStd::string enumDescription = AZStd::string::format("Lod %i", i);
|
||||
values.push_back({ aznumeric_cast<RPI::Cullable::LodOverride>(i), enumDescription.c_str() });
|
||||
@@ -102,7 +139,12 @@ namespace AZ
|
||||
|
||||
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
|
||||
{
|
||||
behaviorContext->ConstantProperty("NoLodOverride", BehaviorConstant(RPI::Cullable::NoLodOverride))
|
||||
behaviorContext->ConstantProperty("DefaultLodOverride", BehaviorConstant(0))
|
||||
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
|
||||
->Attribute(AZ::Script::Attributes::Category, "render")
|
||||
->Attribute(AZ::Script::Attributes::Module, "render");
|
||||
|
||||
behaviorContext->ConstantProperty("DefaultLodType", BehaviorConstant(RPI::Cullable::LodType::Default))
|
||||
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
|
||||
->Attribute(AZ::Script::Attributes::Category, "render")
|
||||
->Attribute(AZ::Script::Attributes::Module, "render");
|
||||
@@ -114,12 +156,21 @@ namespace AZ
|
||||
->Event("SetModelAssetPath", &MeshComponentRequestBus::Events::SetModelAssetPath)
|
||||
->Event("SetSortKey", &MeshComponentRequestBus::Events::SetSortKey)
|
||||
->Event("GetSortKey", &MeshComponentRequestBus::Events::GetSortKey)
|
||||
->Event("SetLodType", &MeshComponentRequestBus::Events::SetLodType)
|
||||
->Event("GetLodType", &MeshComponentRequestBus::Events::GetLodType)
|
||||
->Event("SetLodOverride", &MeshComponentRequestBus::Events::SetLodOverride)
|
||||
->Event("GetLodOverride", &MeshComponentRequestBus::Events::GetLodOverride)
|
||||
->Event("SetMinimumScreenCoverage", &MeshComponentRequestBus::Events::SetMinimumScreenCoverage)
|
||||
->Event("GetMinimumScreenCoverage", &MeshComponentRequestBus::Events::GetMinimumScreenCoverage)
|
||||
->Event("SetQualityDecayRate", &MeshComponentRequestBus::Events::SetQualityDecayRate)
|
||||
->Event("GetQualityDecayRate", &MeshComponentRequestBus::Events::GetQualityDecayRate)
|
||||
->VirtualProperty("ModelAssetId", "GetModelAssetId", "SetModelAssetId")
|
||||
->VirtualProperty("ModelAssetPath", "GetModelAssetPath", "SetModelAssetPath")
|
||||
->VirtualProperty("SortKey", "GetSortKey", "SetSortKey")
|
||||
->VirtualProperty("LodType", "GetLodType", "SetLodType")
|
||||
->VirtualProperty("LodOverride", "GetLodOverride", "SetLodOverride")
|
||||
->VirtualProperty("MinimumScreenCoverage", "GetMinimumScreenCoverage", "SetMinimumScreenCoverage")
|
||||
->VirtualProperty("QualityDecayRate", "GetQualityDecayRate", "SetQualityDecayRate")
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -343,7 +394,7 @@ namespace AZ
|
||||
|
||||
m_meshFeatureProcessor->SetTransform(m_meshHandle, transform, m_cachedNonUniformScale);
|
||||
m_meshFeatureProcessor->SetSortKey(m_meshHandle, m_configuration.m_sortKey);
|
||||
m_meshFeatureProcessor->SetLodOverride(m_meshHandle, m_configuration.m_lodOverride);
|
||||
m_meshFeatureProcessor->SetMeshLodConfiguration(m_meshHandle, GetMeshLodConfiguration());
|
||||
m_meshFeatureProcessor->SetExcludeFromReflectionCubeMaps(m_meshHandle, m_configuration.m_excludeFromReflectionCubeMaps);
|
||||
m_meshFeatureProcessor->SetVisible(m_meshHandle, m_isVisible);
|
||||
|
||||
@@ -434,15 +485,66 @@ namespace AZ
|
||||
return m_meshFeatureProcessor->GetSortKey(m_meshHandle);
|
||||
}
|
||||
|
||||
RPI::Cullable::LodConfiguration MeshComponentController::GetMeshLodConfiguration() const
|
||||
{
|
||||
return {
|
||||
m_configuration.m_lodType,
|
||||
m_configuration.m_lodOverride,
|
||||
m_configuration.m_minimumScreenCoverage,
|
||||
m_configuration.m_qualityDecayRate
|
||||
};
|
||||
}
|
||||
// -----------------------
|
||||
void MeshComponentController::SetLodType(RPI::Cullable::LodType lodType)
|
||||
{
|
||||
RPI::Cullable::LodConfiguration lodConfig = GetMeshLodConfiguration();
|
||||
lodConfig.m_lodType = lodType;
|
||||
m_meshFeatureProcessor->SetMeshLodConfiguration(m_meshHandle, lodConfig);
|
||||
}
|
||||
|
||||
RPI::Cullable::LodType MeshComponentController::GetLodType() const
|
||||
{
|
||||
RPI::Cullable::LodConfiguration lodConfig = m_meshFeatureProcessor->GetMeshLodConfiguration(m_meshHandle);
|
||||
return lodConfig.m_lodType;
|
||||
}
|
||||
|
||||
void MeshComponentController::SetLodOverride(RPI::Cullable::LodOverride lodOverride)
|
||||
{
|
||||
m_configuration.m_lodOverride = lodOverride; // Save for serialization
|
||||
m_meshFeatureProcessor->SetLodOverride(m_meshHandle, lodOverride);
|
||||
RPI::Cullable::LodConfiguration lodConfig = GetMeshLodConfiguration();
|
||||
lodConfig.m_lodOverride = lodOverride;
|
||||
m_meshFeatureProcessor->SetMeshLodConfiguration(m_meshHandle, lodConfig);
|
||||
}
|
||||
|
||||
RPI::Cullable::LodOverride MeshComponentController::GetLodOverride() const
|
||||
{
|
||||
return static_cast<RPI::Cullable::LodOverride>(m_meshFeatureProcessor->GetSortKey(m_meshHandle));
|
||||
RPI::Cullable::LodConfiguration lodConfig = m_meshFeatureProcessor->GetMeshLodConfiguration(m_meshHandle);
|
||||
return lodConfig.m_lodOverride;
|
||||
}
|
||||
|
||||
void MeshComponentController::SetMinimumScreenCoverage(float minimumScreenCoverage)
|
||||
{
|
||||
RPI::Cullable::LodConfiguration lodConfig = GetMeshLodConfiguration();
|
||||
lodConfig.m_minimumScreenCoverage = minimumScreenCoverage;
|
||||
m_meshFeatureProcessor->SetMeshLodConfiguration(m_meshHandle, lodConfig);
|
||||
}
|
||||
|
||||
float MeshComponentController::GetMinimumScreenCoverage() const
|
||||
{
|
||||
RPI::Cullable::LodConfiguration lodConfig = m_meshFeatureProcessor->GetMeshLodConfiguration(m_meshHandle);
|
||||
return lodConfig.m_minimumScreenCoverage;
|
||||
}
|
||||
|
||||
void MeshComponentController::SetQualityDecayRate(float qualityDecayRate)
|
||||
{
|
||||
RPI::Cullable::LodConfiguration lodConfig = GetMeshLodConfiguration();
|
||||
lodConfig.m_qualityDecayRate = qualityDecayRate;
|
||||
m_meshFeatureProcessor->SetMeshLodConfiguration(m_meshHandle, lodConfig);
|
||||
}
|
||||
|
||||
float MeshComponentController::GetQualityDecayRate() const
|
||||
{
|
||||
RPI::Cullable::LodConfiguration lodConfig = m_meshFeatureProcessor->GetMeshLodConfiguration(m_meshHandle);
|
||||
return lodConfig.m_qualityDecayRate;
|
||||
}
|
||||
|
||||
void MeshComponentController::SetVisibility(bool visible)
|
||||
|
||||
@@ -30,6 +30,9 @@ namespace AZ
|
||||
{
|
||||
namespace Render
|
||||
{
|
||||
|
||||
|
||||
|
||||
//! A configuration structure for the MeshComponentController
|
||||
class MeshComponentConfig final
|
||||
: public AZ::ComponentConfig
|
||||
@@ -41,13 +44,20 @@ namespace AZ
|
||||
|
||||
// Editor helper functions
|
||||
bool IsAssetSet();
|
||||
bool LodTypeIsScreenCoverage();
|
||||
bool LodTypeIsSpecificLOD();
|
||||
bool ShowLodConfig();
|
||||
AZStd::vector<AZStd::pair<RPI::Cullable::LodOverride, AZStd::string>> GetLodOverrideValues();
|
||||
|
||||
Data::Asset<RPI::ModelAsset> m_modelAsset = { AZ::Data::AssetLoadBehavior::QueueLoad };
|
||||
RHI::DrawItemSortKey m_sortKey = 0;
|
||||
RPI::Cullable::LodOverride m_lodOverride = RPI::Cullable::NoLodOverride;
|
||||
bool m_excludeFromReflectionCubeMaps = false;
|
||||
bool m_useForwardPassIblSpecular = false;
|
||||
|
||||
RPI::Cullable::LodType m_lodType = RPI::Cullable::LodType::Default;
|
||||
RPI::Cullable::LodOverride m_lodOverride = aznumeric_cast<RPI::Cullable::LodOverride>(0);
|
||||
float m_minimumScreenCoverage = 1.0f / 1080.0f;
|
||||
float m_qualityDecayRate = 0.5f;
|
||||
};
|
||||
|
||||
class MeshComponentController final
|
||||
@@ -94,8 +104,17 @@ namespace AZ
|
||||
void SetSortKey(RHI::DrawItemSortKey sortKey) override;
|
||||
RHI::DrawItemSortKey GetSortKey() const override;
|
||||
|
||||
void SetLodOverride(RPI::Cullable::LodOverride lodOverride) override;
|
||||
RPI::Cullable::LodOverride GetLodOverride() const override;
|
||||
void SetLodType(RPI::Cullable::LodType lodType) override;
|
||||
RPI::Cullable::LodType GetLodType() const override;
|
||||
|
||||
virtual void SetLodOverride(RPI::Cullable::LodOverride lodOverride);
|
||||
virtual RPI::Cullable::LodOverride GetLodOverride() const;
|
||||
|
||||
virtual void SetMinimumScreenCoverage(float minimumScreenCoverage);
|
||||
virtual float GetMinimumScreenCoverage() const;
|
||||
|
||||
virtual void SetQualityDecayRate(float qualityDecayRate);
|
||||
virtual float GetQualityDecayRate() const;
|
||||
|
||||
void SetVisibility(bool visible) override;
|
||||
bool GetVisibility() const override;
|
||||
@@ -132,6 +151,8 @@ namespace AZ
|
||||
void UnregisterModel();
|
||||
void RefreshModelRegistration();
|
||||
|
||||
RPI::Cullable::LodConfiguration GetMeshLodConfiguration() const;
|
||||
|
||||
void HandleNonUniformScaleChange(const AZ::Vector3& nonUniformScale);
|
||||
|
||||
Render::MeshFeatureProcessorInterface* m_meshFeatureProcessor = nullptr;
|
||||
|
||||
@@ -426,15 +426,53 @@ namespace AZ
|
||||
{
|
||||
return m_meshFeatureProcessor->GetSortKey(*m_meshHandle);
|
||||
}
|
||||
|
||||
void AtomActorInstance::SetLodType(RPI::Cullable::LodType lodType)
|
||||
{
|
||||
RPI::Cullable::LodConfiguration config = m_meshFeatureProcessor->GetMeshLodConfiguration(*m_meshHandle);
|
||||
config.m_lodType = lodType;
|
||||
m_meshFeatureProcessor->SetMeshLodConfiguration(*m_meshHandle, config);
|
||||
}
|
||||
|
||||
RPI::Cullable::LodType AtomActorInstance::GetLodType() const
|
||||
{
|
||||
return m_meshFeatureProcessor->GetMeshLodConfiguration(*m_meshHandle).m_lodType;
|
||||
}
|
||||
|
||||
void AtomActorInstance::SetLodOverride(RPI::Cullable::LodOverride lodOverride)
|
||||
{
|
||||
m_meshFeatureProcessor->SetLodOverride(*m_meshHandle, lodOverride);
|
||||
RPI::Cullable::LodConfiguration config = m_meshFeatureProcessor->GetMeshLodConfiguration(*m_meshHandle);
|
||||
config.m_lodOverride = lodOverride;
|
||||
m_meshFeatureProcessor->SetMeshLodConfiguration(*m_meshHandle, config);
|
||||
}
|
||||
|
||||
RPI::Cullable::LodOverride AtomActorInstance::GetLodOverride() const
|
||||
{
|
||||
return m_meshFeatureProcessor->GetLodOverride(*m_meshHandle);
|
||||
return m_meshFeatureProcessor->GetMeshLodConfiguration(*m_meshHandle).m_lodOverride;
|
||||
}
|
||||
|
||||
void AtomActorInstance::SetMinimumScreenCoverage(float minimumScreenCoverage)
|
||||
{
|
||||
RPI::Cullable::LodConfiguration config = m_meshFeatureProcessor->GetMeshLodConfiguration(*m_meshHandle);
|
||||
config.m_minimumScreenCoverage = minimumScreenCoverage;
|
||||
m_meshFeatureProcessor->SetMeshLodConfiguration(*m_meshHandle, config);
|
||||
}
|
||||
|
||||
float AtomActorInstance::GetMinimumScreenCoverage() const
|
||||
{
|
||||
return m_meshFeatureProcessor->GetMeshLodConfiguration(*m_meshHandle).m_minimumScreenCoverage;
|
||||
}
|
||||
|
||||
void AtomActorInstance::SetQualityDecayRate(float qualityDecayRate)
|
||||
{
|
||||
RPI::Cullable::LodConfiguration config = m_meshFeatureProcessor->GetMeshLodConfiguration(*m_meshHandle);
|
||||
config.m_qualityDecayRate = qualityDecayRate;
|
||||
m_meshFeatureProcessor->SetMeshLodConfiguration(*m_meshHandle, config);
|
||||
}
|
||||
|
||||
float AtomActorInstance::GetQualityDecayRate() const
|
||||
{
|
||||
return m_meshFeatureProcessor->GetMeshLodConfiguration(*m_meshHandle).m_qualityDecayRate;
|
||||
}
|
||||
|
||||
void AtomActorInstance::SetVisibility(bool visible)
|
||||
|
||||
@@ -141,8 +141,14 @@ namespace AZ
|
||||
AZ::Data::Instance<RPI::Model> GetModel() const override;
|
||||
void SetSortKey(RHI::DrawItemSortKey sortKey) override;
|
||||
RHI::DrawItemSortKey GetSortKey() const override;
|
||||
void SetLodType(RPI::Cullable::LodType lodType) override;
|
||||
RPI::Cullable::LodType GetLodType() const override;
|
||||
void SetLodOverride(RPI::Cullable::LodOverride lodOverride) override;
|
||||
RPI::Cullable::LodOverride GetLodOverride() const override;
|
||||
void SetMinimumScreenCoverage(float minimumScreenCoverage) override;
|
||||
float GetMinimumScreenCoverage() const override;
|
||||
void SetQualityDecayRate(float qualityDecayRate) override;
|
||||
float GetQualityDecayRate() const override;
|
||||
void SetVisibility(bool visible) override;
|
||||
bool GetVisibility() const override;
|
||||
// GetWorldBounds/GetLocalBounds already overridden by BoundsRequestBus::Handler
|
||||
|
||||
@@ -554,6 +554,16 @@ namespace UnitTest
|
||||
return m_drawItemSortKeyOutput;
|
||||
}
|
||||
|
||||
AZ::RPI::Cullable::LodType m_lodTypeOutput;
|
||||
void SetLodType(AZ::RPI::Cullable::LodType lodType) override
|
||||
{
|
||||
m_lodTypeOutput = lodType;
|
||||
}
|
||||
AZ::RPI::Cullable::LodType GetLodType() const override
|
||||
{
|
||||
return m_lodTypeOutput;
|
||||
}
|
||||
|
||||
AZ::RPI::Cullable::LodOverride m_lodOverrideOutput;
|
||||
void SetLodOverride(AZ::RPI::Cullable::LodOverride lodOverride) override
|
||||
{
|
||||
@@ -563,6 +573,26 @@ namespace UnitTest
|
||||
{
|
||||
return m_lodOverrideOutput;
|
||||
}
|
||||
|
||||
float m_minimumScreenCoverageOutput;
|
||||
void SetMinimumScreenCoverage(float minimumScreenCoverage) override
|
||||
{
|
||||
m_minimumScreenCoverageOutput = minimumScreenCoverage;
|
||||
}
|
||||
float GetMinimumScreenCoverage() const override
|
||||
{
|
||||
return m_minimumScreenCoverageOutput;
|
||||
}
|
||||
|
||||
float m_qualityDecayRateOutput;
|
||||
void SetQualityDecayRate(float qualityDecayRate) override
|
||||
{
|
||||
m_qualityDecayRateOutput = qualityDecayRate;
|
||||
}
|
||||
float GetQualityDecayRate() const override
|
||||
{
|
||||
return m_qualityDecayRateOutput;
|
||||
}
|
||||
};
|
||||
|
||||
struct MockTransformBus
|
||||
|
||||
Reference in New Issue
Block a user