/* * 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 "./UseTextureFunctor.h" #include #include #include namespace AZ { namespace Render { void UseTextureFunctor::Reflect(ReflectContext* context) { if (auto* serializeContext = azrtti_cast(context)) { serializeContext->Class() ->Version(5) ->Field("texturePropertyIndex", &UseTextureFunctor::m_texturePropertyIndex) ->Field("useTexturePropertyIndex", &UseTextureFunctor::m_useTexturePropertyIndex) ->Field("dependentPropertyIndexes", &UseTextureFunctor::m_dependentPropertyIndexes) ->Field("shaderTags", &UseTextureFunctor::m_shaderTags) ->Field("useTextureOptionIndices", &UseTextureFunctor::m_useTextureOptionIndices) ; } } void UseTextureFunctor::Process(RuntimeContext& context) { using namespace RPI; auto texture = context.GetMaterialPropertyValue>(m_texturePropertyIndex); bool useTextureFlag = context.GetMaterialPropertyValue(m_useTexturePropertyIndex); ShaderOptionValue useTexture{useTextureFlag && nullptr != texture}; for (const auto& shaderTag : m_shaderTags) { context.SetShaderOptionValue(shaderTag, m_useTextureOptionIndices[shaderTag], useTexture); } } void UseTextureFunctor::Process(EditorContext& context) { const bool useTextureFlag = context.GetMaterialPropertyValue(m_useTexturePropertyIndex); Data::Instance image = context.GetMaterialPropertyValue>(m_texturePropertyIndex); context.SetMaterialPropertyVisibility( m_useTexturePropertyIndex, nullptr != image ? RPI::MaterialPropertyVisibility::Enabled : RPI::MaterialPropertyVisibility::Hidden ); RPI::MaterialPropertyVisibility dependentVisibility = RPI::MaterialPropertyVisibility::Enabled; if (nullptr == image) { dependentVisibility = RPI::MaterialPropertyVisibility::Hidden; } else if (!useTextureFlag) { dependentVisibility = RPI::MaterialPropertyVisibility::Disabled; } // These properties are enabled only when the texture is actually going to be sampled by the shader. for (RPI::MaterialPropertyIndex index : m_dependentPropertyIndexes) { context.SetMaterialPropertyVisibility(index, dependentVisibility); } } } // namespace Render } // namespace AZ