From c127a044d41df0c302464989f50db99d51050196 Mon Sep 17 00:00:00 2001 From: hershey5045 <43485729+hershey5045@users.noreply.github.com> Date: Fri, 18 Jun 2021 13:39:11 -0700 Subject: [PATCH] Enable fog in physical sky component to blend with deferred fog (#1320) --- .../SkyBox/SceneSrg.azsli | 5 ++ .../Common/Assets/Shaders/SkyBox/SkyBox.azsl | 12 +++ .../SkyBox/SkyBoxFeatureProcessorInterface.h | 11 ++- .../Atom/Feature/SkyBox/SkyBoxFogBus.h | 46 ++++++++++ .../Code/Source/CommonSystemComponent.cpp | 3 +- .../Source/SkyBox/SkyBoxFeatureProcessor.cpp | 44 +++++++++- .../Source/SkyBox/SkyBoxFeatureProcessor.h | 13 ++- .../Code/Source/SkyBox/SkyBoxFogSettings.cpp | 83 +++++++++++++++++++ .../Code/Source/SkyBox/SkyBoxFogSettings.h | 38 +++++++++ .../Code/atom_feature_common_files.cmake | 3 + .../SkyBox/PhysicalSkyComponentConfig.h | 5 ++ .../SkyBox/EditorPhysicalSkyComponent.cpp | 6 +- .../SkyBox/HDRiSkyboxComponentController.cpp | 2 +- .../Source/SkyBox/PhysicalSkyComponent.cpp | 4 +- .../SkyBox/PhysicalSkyComponentConfig.cpp | 1 + .../SkyBox/PhysicalSkyComponentController.cpp | 58 +++++++++++-- .../SkyBox/PhysicalSkyComponentController.h | 14 +++- 17 files changed, 335 insertions(+), 13 deletions(-) create mode 100644 Gems/Atom/Feature/Common/Code/Include/Atom/Feature/SkyBox/SkyBoxFogBus.h create mode 100644 Gems/Atom/Feature/Common/Code/Source/SkyBox/SkyBoxFogSettings.cpp create mode 100644 Gems/Atom/Feature/Common/Code/Source/SkyBox/SkyBoxFogSettings.h diff --git a/Gems/Atom/Feature/Common/Assets/ShaderResourceGroups/SkyBox/SceneSrg.azsli b/Gems/Atom/Feature/Common/Assets/ShaderResourceGroups/SkyBox/SceneSrg.azsli index 9a2c996d04..0a54fdfab0 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderResourceGroups/SkyBox/SceneSrg.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderResourceGroups/SkyBox/SceneSrg.azsli @@ -40,6 +40,11 @@ partial ShaderResourceGroup SceneSrg ConstantBuffer m_physicalSkyData; bool m_physicalSky; + float m_fogTopHeight; + float m_fogBottomHeight; + float4 m_fogColor; + bool m_fogEnable; + TextureCube m_skyboxCubemap; float4x4 m_cubemapRotationMatrix; float m_cubemapExposure; diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/SkyBox/SkyBox.azsl b/Gems/Atom/Feature/Common/Assets/Shaders/SkyBox/SkyBox.azsl index 1bebb2ec47..3c09fc077c 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/SkyBox/SkyBox.azsl +++ b/Gems/Atom/Feature/Common/Assets/Shaders/SkyBox/SkyBox.azsl @@ -152,6 +152,18 @@ PSOutput MainPS(VSOutput input) float3 srgbColor = Z * HosekWilkie(cosGamma, gamma, cosTheta) * SceneSrg::m_physicalSkyData.m_physicalSkyAndSunIntensity.x; color = TransformColor(srgbColor, ColorSpaceId::LinearSRGB, ColorSpaceId::ACEScg); } + } + + if (SceneSrg::m_fogEnable) + { + if (input.m_cubemapCoord.z >= 0.0 && input.m_cubemapCoord.z <= SceneSrg::m_fogTopHeight) + { + color = lerp(SceneSrg::m_fogColor.rgb, color, input.m_cubemapCoord.z > 0.0 ? input.m_cubemapCoord.z/SceneSrg::m_fogTopHeight : 0.0); + } + else if (input.m_cubemapCoord.z < 0.0 && input.m_cubemapCoord.z >= -SceneSrg::m_fogBottomHeight) + { + color = SceneSrg::m_fogColor.rgb; + } } } else diff --git a/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/SkyBox/SkyBoxFeatureProcessorInterface.h b/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/SkyBox/SkyBoxFeatureProcessorInterface.h index 9679850023..2b632a3f6a 100644 --- a/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/SkyBox/SkyBoxFeatureProcessorInterface.h +++ b/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/SkyBox/SkyBoxFeatureProcessorInterface.h @@ -16,6 +16,7 @@ #include #include #include +#include namespace AZ { @@ -49,8 +50,9 @@ namespace AZ AZ_RTTI(AZ::Render::SkyBoxFeatureProcessorInterface, "{71061869-1190-4451-A337-E9CFF16441B4}"); virtual void Enable(bool enable) = 0; - virtual bool IsEnable() = 0; + virtual bool IsEnabled() = 0; virtual void SetSkyboxMode(SkyBoxMode mode) = 0; + virtual void SetFogSettings(const SkyBoxFogSettings& fogSettings) = 0; // HDRiSkyBox virtual void SetCubemap(Data::Instance cubemap) = 0; @@ -64,6 +66,13 @@ namespace AZ virtual void SetSkyIntensity(float intensity, PhotometricUnit type) = 0; virtual void SetSunIntensity(float intensity, PhotometricUnit type) = 0; virtual void SetSunRadiusFactor(float factor) = 0; + + // Fog Settings + virtual void SetFogEnabled(bool enable) = 0; + virtual bool IsFogEnabled() = 0; + virtual void SetFogColor(const AZ::Color &color) = 0; + virtual void SetFogTopHeight(float topHeight) = 0; + virtual void SetFogBottomHeight(float bottomHeight) = 0; }; } } diff --git a/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/SkyBox/SkyBoxFogBus.h b/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/SkyBox/SkyBoxFogBus.h new file mode 100644 index 0000000000..b89ef2e33b --- /dev/null +++ b/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/SkyBox/SkyBoxFogBus.h @@ -0,0 +1,46 @@ +/* + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or + * its licensors. + * + * For complete copyright and license terms please see the LICENSE at the root of this + * distribution (the "License"). All use of this software is governed by the License, + * or, if provided, by the license below or the license accompanying this file. Do not + * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ + +#pragma once + +#include +#include + +namespace AZ +{ + namespace Render + { + // EBus to get and set fog settings rendered with the sky + class SkyBoxFogRequests + : public ComponentBus + { + public: + AZ_RTTI(AZ::Render::SkyBoxFogRequests, "{4D477566-54B1-49EC-B8FE-4264EA228482}"); + + static const EBusHandlerPolicy HandlerPolicy = EBusHandlerPolicy::Single; + virtual ~SkyBoxFogRequests() {} + + virtual void SetEnabled(bool enable) = 0; + virtual bool IsEnabled() const = 0; + virtual void SetColor(const AZ::Color& color) = 0; + virtual const AZ::Color& GetColor() const = 0; + // Set and Get the height upwards from the horizon + virtual void SetTopHeight(float topHeight) = 0; + virtual float GetTopHeight() const = 0; + // Set and Get the height downwards from the horizon + virtual void SetBottomHeight(float bottomHeight) = 0; + virtual float GetBottomHeight() const = 0; + }; + + typedef AZ::EBus SkyBoxFogRequestBus; + } +} diff --git a/Gems/Atom/Feature/Common/Code/Source/CommonSystemComponent.cpp b/Gems/Atom/Feature/Common/Code/Source/CommonSystemComponent.cpp index 1866da63e5..05d79cd6c3 100644 --- a/Gems/Atom/Feature/Common/Code/Source/CommonSystemComponent.cpp +++ b/Gems/Atom/Feature/Common/Code/Source/CommonSystemComponent.cpp @@ -70,7 +70,7 @@ #include #include #include - +#include #include #include @@ -117,6 +117,7 @@ namespace AZ TransformServiceFeatureProcessor::Reflect(context); ProjectedShadowFeatureProcessor::Reflect(context); SkyBoxFeatureProcessor::Reflect(context); + SkyBoxFogSettings::Reflect(context); UseTextureFunctor::Reflect(context); DrawListFunctor::Reflect(context); SubsurfaceTransmissionParameterFunctor::Reflect(context); diff --git a/Gems/Atom/Feature/Common/Code/Source/SkyBox/SkyBoxFeatureProcessor.cpp b/Gems/Atom/Feature/Common/Code/Source/SkyBox/SkyBoxFeatureProcessor.cpp index 4a3586a799..8fd45f3083 100644 --- a/Gems/Atom/Feature/Common/Code/Source/SkyBox/SkyBoxFeatureProcessor.cpp +++ b/Gems/Atom/Feature/Common/Code/Source/SkyBox/SkyBoxFeatureProcessor.cpp @@ -89,6 +89,10 @@ namespace AZ m_cubemapIndex.Reset(); m_cubemapRotationMatrixIndex.Reset(); m_cubemapExposureIndex.Reset(); + m_fogEnableIndex.Reset(); + m_fogColorIndex.Reset(); + m_fogTopHeightIndex.Reset(); + m_fogBottomHeightIndex.Reset(); if (m_buffer) { @@ -160,6 +164,14 @@ namespace AZ m_mapBuffer = false; } + m_sceneSrg->SetConstant(m_fogEnableIndex, m_fogSettings.m_enable); + if (m_fogSettings.m_enable) + { + m_sceneSrg->SetConstant(m_fogTopHeightIndex, m_fogSettings.m_topHeight); + m_sceneSrg->SetConstant(m_fogBottomHeightIndex, m_fogSettings.m_bottomHeight); + m_sceneSrg->SetConstant(m_fogColorIndex, m_fogSettings.m_color); + } + m_sceneSrg->SetConstant(m_physicalSkyIndex, true); break; } @@ -213,7 +225,7 @@ namespace AZ m_enable = enable; } - bool SkyBoxFeatureProcessor::IsEnable() + bool SkyBoxFeatureProcessor::IsEnabled() { return m_enable; } @@ -238,6 +250,36 @@ namespace AZ m_skyboxMode = mode; } + void SkyBoxFeatureProcessor::SetFogSettings(const SkyBoxFogSettings& fogSettings) + { + m_fogSettings = fogSettings; + } + + void SkyBoxFeatureProcessor::SetFogEnabled(bool enable) + { + m_fogSettings.m_enable = enable; + } + + bool SkyBoxFeatureProcessor::IsFogEnabled() + { + return m_fogSettings.m_enable; + } + + void SkyBoxFeatureProcessor::SetFogColor(const AZ::Color& color) + { + m_fogSettings.m_color = color; + } + + void SkyBoxFeatureProcessor::SetFogTopHeight(float topHeight) + { + m_fogSettings.m_topHeight = topHeight; + } + + void SkyBoxFeatureProcessor::SetFogBottomHeight(float bottomHeight) + { + m_fogSettings.m_bottomHeight = bottomHeight; + } + void SkyBoxFeatureProcessor::SetSunPosition(SunPosition sunPosition) { m_skyNeedUpdate = true; diff --git a/Gems/Atom/Feature/Common/Code/Source/SkyBox/SkyBoxFeatureProcessor.h b/Gems/Atom/Feature/Common/Code/Source/SkyBox/SkyBoxFeatureProcessor.h index ab019cfd9b..8c8157a614 100644 --- a/Gems/Atom/Feature/Common/Code/Source/SkyBox/SkyBoxFeatureProcessor.h +++ b/Gems/Atom/Feature/Common/Code/Source/SkyBox/SkyBoxFeatureProcessor.h @@ -67,8 +67,14 @@ namespace AZ // SkyBoxFeatureProcessorInterface overrides ... void Enable(bool enable) override; - bool IsEnable() override; + bool IsEnabled() override; void SetSkyboxMode(SkyBoxMode mode) override; + void SetFogSettings(const SkyBoxFogSettings& fogSettings) override; + void SetFogEnabled(bool enable) override; + bool IsFogEnabled() override; + void SetFogColor(const AZ::Color& color) override; + void SetFogTopHeight(float topHeight) override; + void SetFogBottomHeight(float bottomHeight) override; void SetCubemapRotationMatrix(AZ::Matrix4x4 matrix) override; void SetCubemap(Data::Instance cubemap) override; @@ -145,6 +151,10 @@ namespace AZ RHI::ShaderInputNameIndex m_cubemapIndex = "m_skyboxCubemap"; RHI::ShaderInputNameIndex m_cubemapRotationMatrixIndex = "m_cubemapRotationMatrix"; RHI::ShaderInputNameIndex m_cubemapExposureIndex = "m_cubemapExposure"; + RHI::ShaderInputNameIndex m_fogEnableIndex = "m_fogEnable"; + RHI::ShaderInputNameIndex m_fogColorIndex = "m_fogColor"; + RHI::ShaderInputNameIndex m_fogTopHeightIndex = "m_fogTopHeight"; + RHI::ShaderInputNameIndex m_fogBottomHeightIndex = "m_fogBottomHeight"; bool m_skyNeedUpdate = true; bool m_sunNeedUpdate = true; @@ -152,6 +162,7 @@ namespace AZ bool m_enable = false; SkyBoxMode m_skyboxMode = SkyBoxMode::None; + SkyBoxFogSettings m_fogSettings; Data::Instance m_sceneSrg = nullptr; Data::Instance m_cubemapTexture = nullptr; diff --git a/Gems/Atom/Feature/Common/Code/Source/SkyBox/SkyBoxFogSettings.cpp b/Gems/Atom/Feature/Common/Code/Source/SkyBox/SkyBoxFogSettings.cpp new file mode 100644 index 0000000000..a908be8b66 --- /dev/null +++ b/Gems/Atom/Feature/Common/Code/Source/SkyBox/SkyBoxFogSettings.cpp @@ -0,0 +1,83 @@ +/* + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or + * its licensors. + * + * For complete copyright and license terms please see the LICENSE at the root of this + * distribution (the "License"). All use of this software is governed by the License, + * or, if provided, by the license below or the license accompanying this file. Do not + * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ + +#include +#include +#include +#include +#include + +namespace AZ +{ + namespace Render + { + void SkyBoxFogSettings::Reflect(ReflectContext* context) + { + if (auto serializeContext = azrtti_cast(context)) + { + serializeContext->Class() + ->Version(1) + ->Field("Enable", &SkyBoxFogSettings::m_enable) + ->Field("Color", &SkyBoxFogSettings::m_color) + ->Field("TopHeight", &SkyBoxFogSettings::m_topHeight) + ->Field("BottomHeight", &SkyBoxFogSettings::m_bottomHeight) + ; + + if (auto editContext = serializeContext->GetEditContext()) + { + editContext->Class("SkyBoxFogSettings", "") + ->ClassElement(AZ::Edit::ClassElements::EditorData, "") + ->DataElement(AZ::Edit::UIHandlers::Default, &SkyBoxFogSettings::m_enable, "Enable Fog", "Toggle fog on or off") + ->DataElement(AZ::Edit::UIHandlers::Default, &SkyBoxFogSettings::m_color, "Fog Color", "Color of the fog") + ->Attribute(AZ::Edit::Attributes::ReadOnly, &SkyBoxFogSettings::IsFogDisabled) + ->DataElement(AZ::Edit::UIHandlers::Slider, &SkyBoxFogSettings::m_topHeight, "Fog Top Height", "Height of the fog upwards from the horizon") + ->Attribute(AZ::Edit::Attributes::ReadOnly, &SkyBoxFogSettings::IsFogDisabled) + ->Attribute(AZ::Edit::Attributes::Min, 0.0) + ->Attribute(AZ::Edit::Attributes::Max, 0.5) + ->Attribute(AZ::Edit::Attributes::Step, 0.01) + ->DataElement(AZ::Edit::UIHandlers::Slider, &SkyBoxFogSettings::m_bottomHeight, "Fog Bottom Height", "Height of the fog downwards from the horizon") + ->Attribute(AZ::Edit::Attributes::ReadOnly, &SkyBoxFogSettings::IsFogDisabled) + ->Attribute(AZ::Edit::Attributes::Min, 0.0) + ->Attribute(AZ::Edit::Attributes::Max, 0.3) + ->Attribute(AZ::Edit::Attributes::Step, 0.01) + ; + } + } + + if (auto behaviorContext = azrtti_cast(context)) + { + behaviorContext->EBus("SkyBoxFogRequestBus") + ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common) + ->Attribute(AZ::Script::Attributes::Category, "render") + ->Attribute(AZ::Script::Attributes::Module, "render") + ->Event("SetEnabled", &SkyBoxFogRequestBus::Events::SetEnabled) + ->Event("IsEnabled", &SkyBoxFogRequestBus::Events::IsEnabled) + ->Event("SetColor", &SkyBoxFogRequestBus::Events::SetColor) + ->Event("GetColor", &SkyBoxFogRequestBus::Events::GetColor) + ->Event("SetTopHeight", &SkyBoxFogRequestBus::Events::SetTopHeight) + ->Event("GetTopHeight", &SkyBoxFogRequestBus::Events::GetTopHeight) + ->Event("SetBottomHeight", &SkyBoxFogRequestBus::Events::SetBottomHeight) + ->Event("GetBottomHeight", &SkyBoxFogRequestBus::Events::GetBottomHeight) + ->VirtualProperty("Enable", "IsEnabled", "SetEnabled") + ->VirtualProperty("Color", "GetColor", "SetColor") + ->VirtualProperty("TopHeight", "GetTopHeight", "SetTopHeight") + ->VirtualProperty("BottomHeight", "GetTopHeight", "SetBottomHeight") + ; + } + } + + bool SkyBoxFogSettings::IsFogDisabled() const + { + return !m_enable; + } + } +} diff --git a/Gems/Atom/Feature/Common/Code/Source/SkyBox/SkyBoxFogSettings.h b/Gems/Atom/Feature/Common/Code/Source/SkyBox/SkyBoxFogSettings.h new file mode 100644 index 0000000000..9c3d04aa7b --- /dev/null +++ b/Gems/Atom/Feature/Common/Code/Source/SkyBox/SkyBoxFogSettings.h @@ -0,0 +1,38 @@ +/* + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or + * its licensors. + * + * For complete copyright and license terms please see the LICENSE at the root of this + * distribution (the "License"). All use of this software is governed by the License, + * or, if provided, by the license below or the license accompanying this file. Do not + * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ + +#pragma once + +#include +#include + +namespace AZ +{ + namespace Render + { + struct SkyBoxFogSettings final + { + AZ_RTTI(AZ::Render::SkyBoxFogSettings, "{DB13027C-BA92-4E46-B428-BB77C2A80C51}"); + + static void Reflect(ReflectContext* context); + + SkyBoxFogSettings() = default; + + bool IsFogDisabled() const; + + AZ::Color m_color = AZ::Color::CreateOne(); + bool m_enable = false; + float m_topHeight = 0.01; + float m_bottomHeight = 0.0; + }; + } +} diff --git a/Gems/Atom/Feature/Common/Code/atom_feature_common_files.cmake b/Gems/Atom/Feature/Common/Code/atom_feature_common_files.cmake index a656558abf..b97df65ad2 100644 --- a/Gems/Atom/Feature/Common/Code/atom_feature_common_files.cmake +++ b/Gems/Atom/Feature/Common/Code/atom_feature_common_files.cmake @@ -32,6 +32,7 @@ set(FILES Include/Atom/Feature/PostProcessing/SMAAFeatureProcessorInterface.h Include/Atom/Feature/PostProcess/PostFxLayerCategoriesConstants.h Include/Atom/Feature/ReflectionProbe/ReflectionProbeFeatureProcessor.h + Include/Atom/Feature/SkyBox/SkyBoxFogBus.h Include/Atom/Feature/SkyBox/SkyboxConstants.h Include/Atom/Feature/SkyBox/SkyBoxLUT.h Include/Atom/Feature/SphericalHarmonics/SphericalHarmonicsUtility.h @@ -297,6 +298,8 @@ set(FILES Source/SkinnedMesh/SkinnedMeshVertexStreamProperties.h Source/SkyBox/SkyBoxFeatureProcessor.cpp Source/SkyBox/SkyBoxFeatureProcessor.h + Source/SkyBox/SkyBoxFogSettings.h + Source/SkyBox/SkyBoxFogSettings.cpp Source/TransformService/TransformServiceFeatureProcessor.cpp Source/Utils/GpuBufferHandler.cpp Source/LuxCore/LuxCoreTexturePass.cpp diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Include/AtomLyIntegration/CommonFeatures/SkyBox/PhysicalSkyComponentConfig.h b/Gems/AtomLyIntegration/CommonFeatures/Code/Include/AtomLyIntegration/CommonFeatures/SkyBox/PhysicalSkyComponentConfig.h index bf16207a80..c7f82dde2c 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Include/AtomLyIntegration/CommonFeatures/SkyBox/PhysicalSkyComponentConfig.h +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Include/AtomLyIntegration/CommonFeatures/SkyBox/PhysicalSkyComponentConfig.h @@ -15,6 +15,7 @@ #include #include #include +#include namespace AZ { @@ -35,6 +36,8 @@ namespace AZ int m_turbidity = 1; float m_sunRadiusFactor = 1.0f; + SkyBoxFogSettings m_skyBoxFogSettings; + //! Returns characters for a suffix for the light type including a space. " lm" for lumens for example. const char* GetIntensitySuffix() const; @@ -45,6 +48,8 @@ namespace AZ //! Returns the maximum intensity value allowed depending on the m_intensityMode float GetSkyIntensityMax() const; float GetSunIntensityMax() const; + + bool IsFogDisabled() const { return !m_skyBoxFogSettings.m_enable; } }; } } diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/SkyBox/EditorPhysicalSkyComponent.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/SkyBox/EditorPhysicalSkyComponent.cpp index 8f9b98c15c..265053a9e1 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/SkyBox/EditorPhysicalSkyComponent.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/SkyBox/EditorPhysicalSkyComponent.cpp @@ -68,13 +68,17 @@ namespace AZ ->Attribute(AZ::Edit::Attributes::Min, 1) ->Attribute(AZ::Edit::Attributes::Max, 10) ->Attribute(AZ::Edit::Attributes::Step, 1) + ->DataElement(AZ::Edit::UIHandlers::Default, &PhysicalSkyComponentConfig::m_skyBoxFogSettings, "Fog", "Fog settings for rendering on top of physical sky") + ->Attribute(AZ::Edit::Attributes::AutoExpand, true) ; } } if (auto behaviorContext = azrtti_cast(context)) { - behaviorContext->Class()->RequestBus("PhysicalSkyRequestBus"); + behaviorContext->Class() + ->RequestBus("PhysicalSkyRequestBus") + ->RequestBus("SkyBoxFogRequestBus"); behaviorContext->ConstantProperty("EditorPhysicalSkyComponentTypeId", BehaviorConstant(Uuid(EditorPhysicalSkyComponentTypeId))) ->Attribute(AZ::Script::Attributes::Module, "render") diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/SkyBox/HDRiSkyboxComponentController.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/SkyBox/HDRiSkyboxComponentController.cpp index 72cc765238..7ab8267986 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/SkyBox/HDRiSkyboxComponentController.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/SkyBox/HDRiSkyboxComponentController.cpp @@ -69,7 +69,7 @@ namespace AZ m_featureProcessorInterface = RPI::Scene::GetFeatureProcessorForEntity(entityId); // only activate if there is no other skybox activate - if (!m_featureProcessorInterface->IsEnable()) + if (!m_featureProcessorInterface->IsEnabled()) { m_featureProcessorInterface->SetSkyboxMode(SkyBoxMode::Cubemap); m_featureProcessorInterface->Enable(true); diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/SkyBox/PhysicalSkyComponent.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/SkyBox/PhysicalSkyComponent.cpp index 024abc13cf..558cf09f65 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/SkyBox/PhysicalSkyComponent.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/SkyBox/PhysicalSkyComponent.cpp @@ -34,7 +34,9 @@ namespace AZ if (auto behaviorContext = azrtti_cast(context)) { - behaviorContext->Class()->RequestBus("PhysicalSkyRequestBus"); + behaviorContext->Class() + ->RequestBus("PhysicalSkyRequestBus") + ->RequestBus("SkyBoxFogRequestBus"); behaviorContext->ConstantProperty("PhysicalSkyComponentTypeId", BehaviorConstant(Uuid(PhysicalSkyComponentTypeId))) ->Attribute(AZ::Script::Attributes::Module, "render") diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/SkyBox/PhysicalSkyComponentConfig.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/SkyBox/PhysicalSkyComponentConfig.cpp index e0c07fe0ec..b2fe88756f 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/SkyBox/PhysicalSkyComponentConfig.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/SkyBox/PhysicalSkyComponentConfig.cpp @@ -29,6 +29,7 @@ namespace AZ ->Field("SunIntensity", &PhysicalSkyComponentConfig::m_sunIntensity) ->Field("Turbidity", &PhysicalSkyComponentConfig::m_turbidity) ->Field("SunRadiusFactor", &PhysicalSkyComponentConfig::m_sunRadiusFactor) + ->Field("FogSettings", &PhysicalSkyComponentConfig::m_skyBoxFogSettings) ; } } diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/SkyBox/PhysicalSkyComponentController.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/SkyBox/PhysicalSkyComponentController.cpp index 192c1ad509..189a338967 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/SkyBox/PhysicalSkyComponentController.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/SkyBox/PhysicalSkyComponentController.cpp @@ -12,8 +12,6 @@ #include #include - - #include namespace AZ @@ -34,6 +32,9 @@ namespace AZ if (AZ::BehaviorContext* behaviorContext = azrtti_cast(context)) { behaviorContext->EBus("PhysicalSkyRequestBus") + ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common) + ->Attribute(AZ::Script::Attributes::Category, "render") + ->Attribute(AZ::Script::Attributes::Module, "render") ->Event("SetTurbidity", &PhysicalSkyRequestBus::Events::SetTurbidity) ->Event("GetTurbidity", &PhysicalSkyRequestBus::Events::GetTurbidity) ->Event("SetSunRadiusFactor", &PhysicalSkyRequestBus::Events::SetSunRadiusFactor) @@ -76,7 +77,7 @@ namespace AZ m_featureProcessorInterface = RPI::Scene::GetFeatureProcessorForEntity(entityId); // only activate if there is no other skybox activate - if (!m_featureProcessorInterface->IsEnable()) + if (!m_featureProcessorInterface->IsEnabled()) { m_featureProcessorInterface->SetSkyboxMode(SkyBoxMode::PhysicalSky); m_featureProcessorInterface->Enable(true); @@ -95,8 +96,10 @@ namespace AZ const AZ::Transform& transform = m_transformInterface ? m_transformInterface->GetWorldTM() : Transform::Identity(); m_featureProcessorInterface->SetSunPosition(GetSunTransform(transform)); + m_featureProcessorInterface->SetFogSettings(m_configuration.m_skyBoxFogSettings); PhysicalSkyRequestBus::Handler::BusConnect(m_entityId); + SkyBoxFogRequestBus::Handler::BusConnect(m_entityId); TransformNotificationBus::Handler::BusConnect(m_entityId); m_isActive = true; @@ -113,8 +116,9 @@ namespace AZ // Run deactivate if this skybox is activate if (m_isActive) { - PhysicalSkyRequestBus::Handler::BusDisconnect(m_entityId); - TransformNotificationBus::Handler::BusDisconnect(m_entityId); + PhysicalSkyRequestBus::Handler::BusDisconnect(); + SkyBoxFogRequestBus::Handler::BusDisconnect(); + TransformNotificationBus::Handler::BusDisconnect(); m_featureProcessorInterface->Enable(false); m_featureProcessorInterface = nullptr; @@ -229,5 +233,49 @@ namespace AZ return SunPosition(atan2(sunPosition.GetZ(), sunPosition.GetX()), asin(sunPosition.GetY())); } + + void PhysicalSkyComponentController::SetEnabled(bool enable) + { + m_configuration.m_skyBoxFogSettings.m_enable = enable; + m_featureProcessorInterface->SetFogEnabled(enable); + } + + bool PhysicalSkyComponentController::IsEnabled() const + { + return m_configuration.m_skyBoxFogSettings.m_enable; + } + + void PhysicalSkyComponentController::SetColor(const AZ::Color& color) + { + m_configuration.m_skyBoxFogSettings.m_color = color; + m_featureProcessorInterface->SetFogColor(color); + } + + const AZ::Color& PhysicalSkyComponentController::GetColor() const + { + return m_configuration.m_skyBoxFogSettings.m_color; + } + + void PhysicalSkyComponentController::SetTopHeight(float topHeight) + { + m_configuration.m_skyBoxFogSettings.m_topHeight = topHeight; + m_featureProcessorInterface->SetFogTopHeight(topHeight); + } + + float PhysicalSkyComponentController::GetTopHeight() const + { + return m_configuration.m_skyBoxFogSettings.m_topHeight; + } + + void PhysicalSkyComponentController::SetBottomHeight(float bottomHeight) + { + m_configuration.m_skyBoxFogSettings.m_bottomHeight = bottomHeight; + m_featureProcessorInterface->SetFogBottomHeight(bottomHeight); + } + + float PhysicalSkyComponentController::GetBottomHeight() const + { + return m_configuration.m_skyBoxFogSettings.m_bottomHeight; + } } } diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/SkyBox/PhysicalSkyComponentController.h b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/SkyBox/PhysicalSkyComponentController.h index ddd17183ea..0a5f3aac41 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/SkyBox/PhysicalSkyComponentController.h +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/SkyBox/PhysicalSkyComponentController.h @@ -16,6 +16,7 @@ #include #include #include +#include #include namespace AZ @@ -25,6 +26,7 @@ namespace AZ class PhysicalSkyComponentController final : public TransformNotificationBus::Handler , public PhysicalSkyRequestBus::Handler + , public SkyBoxFogRequestBus::Handler { public: friend class EditorPhysicalSkyComponent; @@ -63,7 +65,17 @@ namespace AZ float GetSunIntensity(PhotometricUnit unit) override; float GetSunIntensity() override; - //! Get Sun azimuth and altitude from entity transfom, without scale + // SkyBoxFogRequestBus::Handler overrides ... + void SetEnabled(bool enable) override; + bool IsEnabled() const override; + void SetColor(const AZ::Color& color) override; + const AZ::Color& GetColor() const override; + void SetTopHeight(float topHeight) override; + float GetTopHeight() const override; + void SetBottomHeight(float bottomHeight) override; + float GetBottomHeight() const override; + + //! Get Sun azimuth and altitude from entity transform, without scale SunPosition GetSunTransform(const AZ::Transform& world); TransformInterface* m_transformInterface = nullptr;