Improvements. You can now call SetDecalMaterial() with any permutation and it works as expected

Signed-off-by: mrieggeramzn <mriegger@amazon.com>
This commit is contained in:
mrieggeramzn
2021-10-01 13:03:52 -07:00
parent e1c49e436d
commit b3d7de1e78
5 changed files with 38 additions and 14 deletions
@@ -70,6 +70,8 @@ void ApplyDecal(uint currDecalIndex, inout Surface surface)
float4 baseMap = 0;
float2 normalMap = 0;
// Each texture array handles a size permutation.
// e.g. it could be that tex array 0 handles 256x256 and tex array 1 handles 512x64, etc.
switch(textureArrayIndex)
{
case 0:
@@ -301,23 +301,44 @@ namespace AZ
return;
}
if (material.IsValid())
if (GetMaterialUsedByDecal(handle) == material)
return;
const auto decalIndex = handle.GetIndex();
const bool isValidMaterialBeingUsedCurrently = m_decalData.GetData(decalIndex).m_textureArrayIndex != DecalData::UnusedIndex;
if (isValidMaterialBeingUsedCurrently)
{
AZ_Assert(m_decalData.GetData(handle.GetIndex()).m_textureArrayIndex == DecalData::UnusedIndex, "Setting Material on a decal more than once is not currently supported.");
RemoveMaterialFromDecal(decalIndex);
}
const auto iter = m_materialToTextureArrayLookupTable.find(material);
if (iter != m_materialToTextureArrayLookupTable.end())
{
// This material is already loaded and registered with this feature processor
iter->second.m_useCount++;
SetDecalTextureLocation(handle, iter->second.m_location);
return;
}
if (!material.IsValid())
return;
// Material not loaded so queue it up for loading.
QueueMaterialLoadForDecal(material, handle);
const auto iter = m_materialToTextureArrayLookupTable.find(material);
if (iter != m_materialToTextureArrayLookupTable.end())
{
// This material is already loaded and registered with this feature processor
iter->second.m_useCount++;
SetDecalTextureLocation(handle, iter->second.m_location);
return;
}
// Material not loaded so queue it up for loading.
QueueMaterialLoadForDecal(material, handle);
}
void DecalTextureArrayFeatureProcessor::RemoveMaterialFromDecal(const uint16_t decalIndex)
{
DecalLocation decalLocation;
decalLocation.textureArrayIndex = m_decalData.GetData(decalIndex).m_textureArrayIndex;
decalLocation.textureIndex = m_decalData.GetData(decalIndex).m_textureIndex;
RemoveDecalFromTextureArrays(decalLocation);
m_decalData.GetData(decalIndex).m_textureArrayIndex = DecalData::UnusedIndex;
m_decalData.GetData(decalIndex).m_textureIndex = DecalData::UnusedIndex;
m_deviceBufferNeedsUpdate = true;
}
void DecalTextureArrayFeatureProcessor::CacheShaderIndices()
@@ -114,6 +114,7 @@ namespace AZ
AZStd::optional<DecalLocation> AddMaterialToTextureArrays(const AZ::RPI::MaterialAsset* materialAsset);
int FindTextureArrayWithSize(const RHI::Size& size) const;
void RemoveMaterialFromDecal(const uint16_t decalIndex);
void SetDecalTextureLocation(const DecalHandle& handle, const DecalLocation location);
void QueueMaterialLoadForDecal(const AZ::Data::AssetId material, const DecalHandle handle);
bool RemoveDecalFromTextureArrays(const DecalLocation decalLocation);
@@ -230,7 +230,7 @@ namespace AZ
{
DecalNotificationBus::Event(m_entityId, &DecalNotifications::OnMaterialChanged, m_configuration.m_materialAsset);
if (m_featureProcessor && m_configuration.m_materialAsset.GetId().IsValid())
if (m_featureProcessor)
{
m_featureProcessor->SetDecalMaterial(m_handle, m_configuration.m_materialAsset.GetId());
}
@@ -192,7 +192,7 @@ namespace AZ
u32 EditorDecalComponent::OnConfigurationChanged()
{
BaseClass::OnConfigurationChanged();
m_controller.ConfigurationChanged();
return Edit::PropertyRefreshLevels::AttributesAndValues;
}