Atom/mriegger/decalnormalmaps (#4302)

* Adding normal maps to decals initial commit

Signed-off-by: mrieggeramzn <mriegger@amazon.com>

* Adding checks for normal maps not present

Signed-off-by: mrieggeramzn <mriegger@amazon.com>

* Readding the proper switch statement

Signed-off-by: mrieggeramzn <mriegger@amazon.com>

* Addressing PR feedback, adding brackets

Signed-off-by: mrieggeramzn <mriegger@amazon.com>

* Adding comments

Signed-off-by: mrieggeramzn <mriegger@amazon.com>

* fixing compile issue

Signed-off-by: mrieggeramzn <mriegger@amazon.com>
This commit is contained in:
mrieggeramzn
2021-09-30 15:34:12 -07:00
committed by GitHub
parent 8a1af282c4
commit 60a0d2ba01
7 changed files with 181 additions and 83 deletions
@@ -322,13 +322,30 @@ namespace AZ
void DecalTextureArrayFeatureProcessor::CacheShaderIndices()
{
for (int i = 0; i < NumTextureArrays; ++i)
{
const RHI::ShaderResourceGroupLayout* viewSrgLayout = RPI::RPISystemInterface::Get()->GetViewSrgLayout().get();
const AZStd::string baseName = "m_decalTextureArray" + AZStd::to_string(i);
// The azsl shader should define several texture arrays such as:
// Texture2DArray<float4> m_decalTextureArrayDiffuse0;
// Texture2DArray<float4> m_decalTextureArrayDiffuse1;
// Texture2DArray<float4> m_decalTextureArrayDiffuse2;
// and
// Texture2DArray<float2> m_decalTextureArrayNormalMaps0;
// Texture2DArray<float2> m_decalTextureArrayNormalMaps1;
// Texture2DArray<float2> m_decalTextureArrayNormalMaps2;
static const AZStd::array<AZStd::string, DecalMapType_Num> ShaderNames = { "m_decalTextureArrayDiffuse",
"m_decalTextureArrayNormalMaps" };
m_decalTextureArrayIndices[i] = viewSrgLayout->FindShaderInputImageIndex(Name(baseName.c_str()));
AZ_Warning("DecalTextureArrayFeatureProcessor", m_decalTextureArrayIndices[i].IsValid(), "Unable to find %s in decal shader.", baseName.c_str());
for (int mapType = 0; mapType < DecalMapType_Num; ++mapType)
{
for (int texArrayIdx = 0; texArrayIdx < NumTextureArrays; ++texArrayIdx)
{
const RHI::ShaderResourceGroupLayout* viewSrgLayout = RPI::RPISystemInterface::Get()->GetViewSrgLayout().get();
const AZStd::string baseName = ShaderNames[mapType] + AZStd::to_string(texArrayIdx);
m_decalTextureArrayIndices[texArrayIdx][mapType] = viewSrgLayout->FindShaderInputImageIndex(Name(baseName.c_str()));
AZ_Warning(
"DecalTextureArrayFeatureProcessor", m_decalTextureArrayIndices[texArrayIdx][mapType].IsValid(),
"Unable to find %s in decal shader.",
baseName.c_str());
}
}
}
@@ -411,8 +428,11 @@ namespace AZ
int iter = m_textureArrayList.begin();
while (iter != -1)
{
const auto& packedTexture = m_textureArrayList[iter].second.GetPackedTexture();
view->GetShaderResourceGroup()->SetImage(m_decalTextureArrayIndices[iter], packedTexture);
for (int mapType = 0 ; mapType < DecalMapType_Num ; ++mapType)
{
const auto& packedTexture = m_textureArrayList[iter].second.GetPackedTexture(aznumeric_cast<DecalMapType>(mapType));
view->GetShaderResourceGroup()->SetImage(m_decalTextureArrayIndices[iter][mapType], packedTexture);
}
iter = m_textureArrayList.next(iter);
}
}