Enable fog in physical sky component to blend with deferred fog (#1320)

This commit is contained in:
hershey5045
2021-06-18 13:39:11 -07:00
committed by GitHub
parent 1ad6264d0d
commit c127a044d4
17 changed files with 335 additions and 13 deletions
@@ -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<BehaviorContext*>(context))
{
behaviorContext->Class<EditorPhysicalSkyComponent>()->RequestBus("PhysicalSkyRequestBus");
behaviorContext->Class<EditorPhysicalSkyComponent>()
->RequestBus("PhysicalSkyRequestBus")
->RequestBus("SkyBoxFogRequestBus");
behaviorContext->ConstantProperty("EditorPhysicalSkyComponentTypeId", BehaviorConstant(Uuid(EditorPhysicalSkyComponentTypeId)))
->Attribute(AZ::Script::Attributes::Module, "render")
@@ -69,7 +69,7 @@ namespace AZ
m_featureProcessorInterface = RPI::Scene::GetFeatureProcessorForEntity<SkyBoxFeatureProcessorInterface>(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);
@@ -34,7 +34,9 @@ namespace AZ
if (auto behaviorContext = azrtti_cast<BehaviorContext*>(context))
{
behaviorContext->Class<PhysicalSkyComponent>()->RequestBus("PhysicalSkyRequestBus");
behaviorContext->Class<PhysicalSkyComponent>()
->RequestBus("PhysicalSkyRequestBus")
->RequestBus("SkyBoxFogRequestBus");
behaviorContext->ConstantProperty("PhysicalSkyComponentTypeId", BehaviorConstant(Uuid(PhysicalSkyComponentTypeId)))
->Attribute(AZ::Script::Attributes::Module, "render")
@@ -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)
;
}
}
@@ -12,8 +12,6 @@
#include <SkyBox/PhysicalSkyComponentController.h>
#include <AzCore/RTTI/BehaviorContext.h>
#include <Atom/RPI.Public/Scene.h>
namespace AZ
@@ -34,6 +32,9 @@ namespace AZ
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
{
behaviorContext->EBus<PhysicalSkyRequestBus>("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<SkyBoxFeatureProcessorInterface>(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;
}
}
}
@@ -16,6 +16,7 @@
#include <AzCore/Component/TransformBus.h>
#include <AtomLyIntegration/CommonFeatures/SkyBox/PhysicalSkyComponentConfig.h>
#include <AtomLyIntegration/CommonFeatures/SkyBox/PhysicalSkyBus.h>
#include <Atom/Feature/SkyBox/SkyBoxFogBus.h>
#include <Atom/Feature/SkyBox/SkyBoxFeatureProcessorInterface.h>
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;