Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,79 @@
/*
* 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 <SkyBox/EditorHDRiSkyboxComponent.h>
#include <AzCore/RTTI/BehaviorContext.h>
namespace AZ
{
namespace Render
{
void EditorHDRiSkyboxComponent::Reflect(AZ::ReflectContext* context)
{
BaseClass::Reflect(context);
if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<EditorHDRiSkyboxComponent, BaseClass>()
->Version(2, ConvertToEditorRenderComponentAdapter<2>);
if (AZ::EditContext* editContext = serializeContext->GetEditContext())
{
editContext->Class<EditorHDRiSkyboxComponent>(
"HDRi Skybox", "SkyBox component render the background of your scene with cubemap")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::Category, "Atom")
->Attribute(AZ::Edit::Attributes::Icon, "Editor/Icons/Components/Component_Placeholder.svg")
->Attribute(AZ::Edit::Attributes::ViewportIcon, "editor/icons/components/viewport/component_placeholder.png")
->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("Game", 0x232b318c))
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
->Attribute(AZ::Edit::Attributes::HelpPageURL, "")
;
editContext->Class<HDRiSkyboxComponentController>(
"HDRiSkyboxComponentController", "")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
->DataElement(AZ::Edit::UIHandlers::Default, &HDRiSkyboxComponentController::m_configuration, "Configuration", "")
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
;
editContext->Class<HDRiSkyboxComponentConfig>(
"HDRiSkyboxComponentConfig", "")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
->DataElement(AZ::Edit::UIHandlers::Default, &HDRiSkyboxComponentConfig::m_cubemapAsset, "Cubemap Texture", "The texture used for cubemap rendering")
->DataElement(AZ::Edit::UIHandlers::Slider, &HDRiSkyboxComponentConfig::m_exposure, "Exposure", "Exposure in stops")
->Attribute(AZ::Edit::Attributes::SoftMin, -5.0f)
->Attribute(AZ::Edit::Attributes::SoftMax, 5.0f)
->Attribute(AZ::Edit::Attributes::Min, -20.0f)
->Attribute(AZ::Edit::Attributes::Max, 20.0f)
;
}
}
if (auto behaviorContext = azrtti_cast<BehaviorContext*>(context))
{
behaviorContext->Class<EditorHDRiSkyboxComponent>()->RequestBus("HDRiSkyboxRequestBus");
behaviorContext->ConstantProperty("EditorHDRiSkyboxComponentTypeId", BehaviorConstant(Uuid(EditorHDRiSkyboxComponentTypeId)))
->Attribute(AZ::Script::Attributes::Module, "render")
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation);
}
}
EditorHDRiSkyboxComponent::EditorHDRiSkyboxComponent(const HDRiSkyboxComponentConfig& config)
: BaseClass(config)
{
}
}
}
@@ -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 <Atom/Feature/Utils/EditorRenderComponentAdapter.h>
#include <Atom/Feature/SkyBox/SkyboxConstants.h>
#include <SkyBox/HDRiSkyboxComponent.h>
namespace AZ
{
namespace Render
{
class EditorHDRiSkyboxComponent final
: public EditorRenderComponentAdapter<HDRiSkyboxComponentController, HDRiSkyboxComponent, HDRiSkyboxComponentConfig>
{
public:
using BaseClass = EditorRenderComponentAdapter<HDRiSkyboxComponentController, HDRiSkyboxComponent, HDRiSkyboxComponentConfig>;
AZ_EDITOR_COMPONENT(AZ::Render::EditorHDRiSkyboxComponent, EditorHDRiSkyboxComponentTypeId, BaseClass);
static void Reflect(AZ::ReflectContext* context);
EditorHDRiSkyboxComponent() = default;
EditorHDRiSkyboxComponent(const HDRiSkyboxComponentConfig& config);
};
} // namespace Render
} // namespace AZ
@@ -0,0 +1,107 @@
/*
* 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 <SkyBox/EditorPhysicalSkyComponent.h>
#include <AzCore/RTTI/BehaviorContext.h>
namespace AZ
{
namespace Render
{
void EditorPhysicalSkyComponent::Reflect(AZ::ReflectContext* context)
{
BaseClass::Reflect(context);
if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<EditorPhysicalSkyComponent, BaseClass>()
->Version(1, ConvertToEditorRenderComponentAdapter<1>);
if (AZ::EditContext* editContext = serializeContext->GetEditContext())
{
editContext->Class<EditorPhysicalSkyComponent>(
"Physical Sky", "Physical Sky render the background of your scene with physical simulation")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::Category, "Atom")
->Attribute(AZ::Edit::Attributes::Icon, "Editor/Icons/Components/Component_Placeholder.svg")
->Attribute(AZ::Edit::Attributes::ViewportIcon, "editor/icons/components/viewport/component_placeholder.png")
->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("Game", 0x232b318c))
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
->Attribute(AZ::Edit::Attributes::HelpPageURL, "")
;
editContext->Class<PhysicalSkyComponentController>(
"PhysicalSkyComponentController", "")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
->DataElement(AZ::Edit::UIHandlers::Default, &PhysicalSkyComponentController::m_configuration, "Configuration", "")
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
;
editContext->Class<PhysicalSkyComponentConfig>(
"PhysicalSkyComponentConfig", "")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->DataElement(Edit::UIHandlers::ComboBox, &PhysicalSkyComponentConfig::m_intensityMode, "Intensity Mode", "Specifying the light unit")
->EnumAttribute(PhotometricUnit::Ev100Luminance, "Ev100")
->EnumAttribute(PhotometricUnit::Nit, "Nit")
->DataElement(AZ::Edit::UIHandlers::Slider, &PhysicalSkyComponentConfig::m_skyIntensity, "Sky Intensity", "Brightness of the sky")
->Attribute(AZ::Edit::Attributes::Min, &PhysicalSkyComponentConfig::GetSkyIntensityMin)
->Attribute(AZ::Edit::Attributes::Max, &PhysicalSkyComponentConfig::GetSkyIntensityMax)
->Attribute(Edit::Attributes::Suffix, &PhysicalSkyComponentConfig::GetIntensitySuffix)
->DataElement(AZ::Edit::UIHandlers::Slider, &PhysicalSkyComponentConfig::m_sunIntensity, "Sun Intensity", "Brightness of the sun")
->Attribute(AZ::Edit::Attributes::Min, &PhysicalSkyComponentConfig::GetSunIntensityMin)
->Attribute(AZ::Edit::Attributes::Max, &PhysicalSkyComponentConfig::GetSunIntensityMax)
->Attribute(Edit::Attributes::Suffix, &PhysicalSkyComponentConfig::GetIntensitySuffix)
->DataElement(AZ::Edit::UIHandlers::Slider, &PhysicalSkyComponentConfig::m_sunRadiusFactor, "Sun Radius Factor", "A factor for Physical sun radius in millions of km. 1 unit is 695,508 km")
->Attribute(AZ::Edit::Attributes::Min, 0.1f)
->Attribute(AZ::Edit::Attributes::Max, 2.f)
->DataElement(AZ::Edit::UIHandlers::Slider, &PhysicalSkyComponentConfig::m_turbidity, "Turbidity", "A measure of the aerosol content in the air. Default is 1.")
->Attribute(AZ::Edit::Attributes::Min, 1)
->Attribute(AZ::Edit::Attributes::Max, 10)
->Attribute(AZ::Edit::Attributes::Step, 1)
;
}
}
if (auto behaviorContext = azrtti_cast<BehaviorContext*>(context))
{
behaviorContext->Class<EditorPhysicalSkyComponent>()->RequestBus("PhysicalSkyRequestBus");
behaviorContext->ConstantProperty("EditorPhysicalSkyComponentTypeId", BehaviorConstant(Uuid(EditorPhysicalSkyComponentTypeId)))
->Attribute(AZ::Script::Attributes::Module, "render")
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation);
}
}
EditorPhysicalSkyComponent::EditorPhysicalSkyComponent(const PhysicalSkyComponentConfig& config)
: BaseClass(config)
{
}
u32 EditorPhysicalSkyComponent::OnConfigurationChanged()
{
// If the intensity mode changes in the editor, convert the photometric value and update the intensity
if (m_controller.m_configuration.m_intensityMode != m_controller.m_skyPhotometricValue.GetType())
{
m_controller.m_skyPhotometricValue.ConvertToPhotometricUnit(m_controller.m_configuration.m_intensityMode);
m_controller.m_configuration.m_skyIntensity = m_controller.m_skyPhotometricValue.GetIntensity();
m_controller.m_sunPhotometricValue.ConvertToPhotometricUnit(m_controller.m_configuration.m_intensityMode);
m_controller.m_configuration.m_sunIntensity = m_controller.m_sunPhotometricValue.GetIntensity();
}
BaseClass::OnConfigurationChanged();
return Edit::PropertyRefreshLevels::AttributesAndValues;
}
}
}
@@ -0,0 +1,41 @@
/*
* 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 <Atom/Feature/Utils/EditorRenderComponentAdapter.h>
#include <Atom/Feature/SkyBox/SkyboxConstants.h>
#include <SkyBox/PhysicalSkyComponent.h>
namespace AZ
{
namespace Render
{
class EditorPhysicalSkyComponent final
: public EditorRenderComponentAdapter<PhysicalSkyComponentController, PhysicalSkyComponent, PhysicalSkyComponentConfig>
{
public:
using BaseClass = EditorRenderComponentAdapter<PhysicalSkyComponentController, PhysicalSkyComponent, PhysicalSkyComponentConfig>;
AZ_EDITOR_COMPONENT(AZ::Render::EditorPhysicalSkyComponent, EditorPhysicalSkyComponentTypeId, BaseClass);
static void Reflect(AZ::ReflectContext* context);
EditorPhysicalSkyComponent() = default;
EditorPhysicalSkyComponent(const PhysicalSkyComponentConfig& config);
//! EditorRenderComponentAdapter overrides...
AZ::u32 OnConfigurationChanged() override;
};
} // namespace Render
} // namespace AZ
@@ -0,0 +1,45 @@
/*
* 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 <SkyBox/HDRiSkyboxComponent.h>
#include <AzCore/RTTI/BehaviorContext.h>
namespace AZ
{
namespace Render
{
HDRiSkyboxComponent::HDRiSkyboxComponent(const HDRiSkyboxComponentConfig& config)
: BaseClass(config)
{
}
void HDRiSkyboxComponent::Reflect(AZ::ReflectContext* context)
{
BaseClass::Reflect(context);
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<HDRiSkyboxComponent, BaseClass>();
}
if (auto behaviorContext = azrtti_cast<BehaviorContext*>(context))
{
behaviorContext->Class<HDRiSkyboxComponent>()->RequestBus("HDRiSkyboxRequestBus");
behaviorContext->ConstantProperty("HDRiSkyboxComponentTypeId", BehaviorConstant(Uuid(HDRiSkyboxComponentTypeId)))
->Attribute(AZ::Script::Attributes::Module, "render")
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common);
}
}
} // namespace Render
} // namespace AZ
@@ -0,0 +1,37 @@
/*
* 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 <AzFramework/Components/ComponentAdapter.h>
#include <Atom/Feature/SkyBox/SkyboxConstants.h>
#include <AtomLyIntegration/CommonFeatures/SkyBox/HDRiSkyboxComponentConfig.h>
#include <SkyBox/HDRiSkyboxComponentController.h>
namespace AZ
{
namespace Render
{
class HDRiSkyboxComponent final
: public AzFramework::Components::ComponentAdapter<HDRiSkyboxComponentController, HDRiSkyboxComponentConfig>
{
public:
using BaseClass = AzFramework::Components::ComponentAdapter<HDRiSkyboxComponentController, HDRiSkyboxComponentConfig>;
AZ_COMPONENT(AZ::Render::HDRiSkyboxComponent, HDRiSkyboxComponentTypeId , BaseClass);
HDRiSkyboxComponent() = default;
HDRiSkyboxComponent(const HDRiSkyboxComponentConfig& config);
static void Reflect(AZ::ReflectContext* context);
};
} // namespace Render
} // namespace AZ
@@ -0,0 +1,33 @@
/*
* 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 <AtomLyIntegration/CommonFeatures/SkyBox/HDRiSkyboxComponentConfig.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Math/Matrix4x4.h>
namespace AZ
{
namespace Render
{
void HDRiSkyboxComponentConfig::Reflect(ReflectContext* context)
{
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<HDRiSkyboxComponentConfig, ComponentConfig>()
->Version(7)
->Field("CubemapAsset", &HDRiSkyboxComponentConfig::m_cubemapAsset)
->Field("Exposure", &HDRiSkyboxComponentConfig::m_exposure)
;
}
}
}
}
@@ -0,0 +1,249 @@
/*
* 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 <Atom/Feature/SkyBox/SkyboxConstants.h>
#include <SkyBox/HDRiSkyboxComponentController.h>
#include <AzCore/RTTI/BehaviorContext.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <Atom/RPI.Public/Scene.h>
namespace AZ
{
namespace Render
{
void HDRiSkyboxComponentController::Reflect(ReflectContext* context)
{
HDRiSkyboxComponentConfig::Reflect(context);
if (auto* serializeContext = azrtti_cast<SerializeContext*>(context))
{
serializeContext->Class<HDRiSkyboxComponentController>()
->Version(1)
->Field("Configuration", &HDRiSkyboxComponentController::m_configuration);
}
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
{
behaviorContext->EBus<HDRiSkyboxRequestBus>("HDRiSkyboxRequestBus")
->Event("SetExposure", &HDRiSkyboxRequestBus::Events::SetExposure)
->Event("GetExposure", &HDRiSkyboxRequestBus::Events::GetExposure)
->VirtualProperty("Exposure", "GetExposure", "SetExposure")
;
}
}
void HDRiSkyboxComponentController::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
{
provided.push_back(AZ_CRC("SkyBoxService", 0x8169a709));
}
void HDRiSkyboxComponentController::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
{
incompatible.push_back(AZ_CRC("SkyBoxService", 0x8169a709));
}
void HDRiSkyboxComponentController::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
{
required.push_back(AZ_CRC("TransformService"));
}
HDRiSkyboxComponentController::HDRiSkyboxComponentController(const HDRiSkyboxComponentConfig& config)
: m_configuration(config)
{
}
void HDRiSkyboxComponentController::Activate(EntityId entityId)
{
m_featureProcessorInterface = RPI::Scene::GetFeatureProcessorForEntity<SkyBoxFeatureProcessorInterface>(entityId);
// only activate if there is no other skybox activate
if (!m_featureProcessorInterface->IsEnable())
{
m_featureProcessorInterface->SetSkyboxMode(SkyBoxMode::Cubemap);
m_featureProcessorInterface->Enable(true);
m_entityId = entityId;
SetCubemapAsset(m_configuration.m_cubemapAsset);
SetExposure(m_configuration.m_exposure);
m_transformInterface = TransformBus::FindFirstHandler(m_entityId);
AZ_Assert(m_transformInterface, "Unable to attach to a TransformBus handler. Entity transform will not affect to skybox.");
const AZ::Transform& transform = m_transformInterface ? m_transformInterface->GetWorldTM() : Transform::Identity();
m_featureProcessorInterface->SetCubemapRotationMatrix(GetInverseTransform(transform));
HDRiSkyboxRequestBus::Handler::BusConnect(m_entityId);
TransformNotificationBus::Handler::BusConnect(m_entityId);
m_isActive = true;
}
else
{
m_featureProcessorInterface = nullptr;
AZ_Warning("HDRiSkyboxComponentController", false, "There is already another HDRi Skybox or Physical Sky component in the scene!");
}
}
void HDRiSkyboxComponentController::Deactivate()
{
// Run deactivate if this skybox is activate
if (m_isActive)
{
HDRiSkyboxRequestBus::Handler::BusDisconnect(m_entityId);
TransformNotificationBus::Handler::BusDisconnect(m_entityId);
Data::AssetBus::MultiHandler::BusDisconnect();
m_configuration.m_cubemapAsset.Release();
m_featureProcessorInterface->Enable(false);
m_featureProcessorInterface = nullptr;
m_transformInterface = nullptr;
m_isActive = false;
}
}
void HDRiSkyboxComponentController::SetConfiguration(const HDRiSkyboxComponentConfig& config)
{
m_configuration = config;
}
const HDRiSkyboxComponentConfig& HDRiSkyboxComponentController::GetConfiguration() const
{
return m_configuration;
}
void HDRiSkyboxComponentController::OnAssetReady(Data::Asset<Data::AssetData> asset)
{
UpdateWithAsset(asset);
}
void HDRiSkyboxComponentController::OnAssetReloaded(Data::Asset<Data::AssetData> asset)
{
UpdateWithAsset(asset);
}
void HDRiSkyboxComponentController::OnAssetError(Data::Asset<Data::AssetData> asset)
{
UpdateWithAsset(asset);
}
void HDRiSkyboxComponentController::OnTransformChanged([[maybe_unused]] const AZ::Transform& local, const AZ::Transform& world)
{
m_featureProcessorInterface->SetCubemapRotationMatrix(GetInverseTransform(world));
}
Data::Asset<RPI::StreamingImageAsset> HDRiSkyboxComponentController::GetCubemapAsset() const
{
return m_configuration.m_cubemapAsset;
}
void HDRiSkyboxComponentController::SetCubemapAsset(const Data::Asset<RPI::StreamingImageAsset>& cubemapAsset)
{
Data::AssetBus::MultiHandler::BusDisconnect(m_configuration.m_cubemapAsset.GetId());
m_configuration.m_cubemapAsset = cubemapAsset;
LoadImage(m_configuration.m_cubemapAsset);
}
void HDRiSkyboxComponentController::SetExposure(float exposure)
{
m_configuration.m_exposure = exposure;
m_featureProcessorInterface->SetCubemapExposure(exposure);
}
float HDRiSkyboxComponentController::GetExposure() const
{
return m_configuration.m_exposure;
}
void HDRiSkyboxComponentController::LoadImage(Data::Asset<RPI::StreamingImageAsset>& imageAsset)
{
Data::AssetBus::MultiHandler::BusDisconnect(imageAsset.GetId());
if (imageAsset.GetId().IsValid())
{
// If the asset is already loaded it'll call OnAssetReady() immediately on BusConnect().
Data::AssetBus::MultiHandler::BusConnect(imageAsset.GetId());
imageAsset.QueueLoad();
}
else
{
// Call update for invalid assets so current assets can be cleared if necessary.
UpdateWithAsset(imageAsset);
}
}
void HDRiSkyboxComponentController::UpdateWithAsset(Data::Asset<Data::AssetData> updatedAsset)
{
if (m_configuration.m_cubemapAsset.GetId() == updatedAsset.GetId())
{
m_configuration.m_cubemapAsset = updatedAsset;
if (IsAssetValid(m_configuration.m_cubemapAsset))
{
m_featureProcessorInterface->SetCubemap(RPI::StreamingImage::FindOrCreate(m_configuration.m_cubemapAsset));
}
else
{
// If this asset didn't load or isn't a cubemap, release it.
m_configuration.m_cubemapAsset.Release();
m_featureProcessorInterface->SetCubemap(nullptr);
}
}
}
bool HDRiSkyboxComponentController::IsAssetValid(Data::Asset<RPI::StreamingImageAsset>& asset)
{
if (asset.GetId().IsValid() && asset->IsReady())
{
auto& descriptor = asset->GetImageDescriptor();
bool isCubemap = descriptor.m_isCubemap || descriptor.m_arraySize == 6;
if (isCubemap)
{
return true;
}
}
return false;
}
AZ::Matrix4x4 HDRiSkyboxComponentController::GetInverseTransform(const AZ::Transform& world)
{
float matrix[16];
// remove scale
Transform worldNoScale = world;
worldNoScale.ExtractScale();
AZ::Matrix3x4 transformMatrix = AZ::Matrix3x4::CreateFromTransform(worldNoScale);
transformMatrix.StoreToRowMajorFloat12(matrix);
// remove translation
matrix[3] = 0;
matrix[7] = 0;
matrix[11] = 0;
matrix[12] = 0;
matrix[13] = 0;
matrix[14] = 0;
matrix[15] = 1;
return AZ::Matrix4x4::CreateFromRowMajorFloat16(matrix).GetInverseFast();
}
} // namespace Render
} // namespace AZ
@@ -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.
*
*/
#pragma once
#include <AzCore/Component/Component.h>
#include <AzCore/Component/TransformBus.h>
#include <Atom/Feature/SkyBox/SkyBoxFeatureProcessorInterface.h>
#include <AtomLyIntegration/CommonFeatures/SkyBox/HDRiSkyboxComponentConfig.h>
#include <AtomLyIntegration/CommonFeatures/SkyBox/HDRiSkyboxBus.h>
namespace AZ
{
namespace Render
{
class HDRiSkyboxComponentController final
: public TransformNotificationBus::Handler
, public HDRiSkyboxRequestBus::Handler
, Data::AssetBus::MultiHandler
{
public:
friend class EditorHDRiSkyboxComponent;
AZ_TYPE_INFO(AZ::Render::HDRiSkyboxComponentController, "{D01C123D-4EA1-4A9B-A7D9-47EF26A55CD0}");
static void Reflect(AZ::ReflectContext* context);
static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
HDRiSkyboxComponentController() = default;
HDRiSkyboxComponentController(const HDRiSkyboxComponentConfig& config);
void Activate(EntityId entityId);
void Deactivate();
void SetConfiguration(const HDRiSkyboxComponentConfig& config);
const HDRiSkyboxComponentConfig& GetConfiguration() const;
private:
AZ_DISABLE_COPY(HDRiSkyboxComponentController);
//! Data::AssetBus interface
void OnAssetReady(Data::Asset<Data::AssetData> asset) override;
void OnAssetReloaded(Data::Asset<Data::AssetData> asset) override;
void OnAssetError(Data::Asset<Data::AssetData> asset) override;
// TransformNotificationBus::Handler overrides ...
void OnTransformChanged(const AZ::Transform& local, const AZ::Transform& world) override;
// HDRiSkyboxRequestBus::Handler overrides ...
Data::Asset<RPI::StreamingImageAsset> GetCubemapAsset() const override;
void SetCubemapAsset(const Data::Asset<RPI::StreamingImageAsset>& cubemapAsset) override;
void SetExposure(float exposure) override;
float GetExposure() const override;
//! Queues a load of an image Asset
void LoadImage(Data::Asset<RPI::StreamingImageAsset>& imageAsset);
//! Handles all Data::AssetBus calls in a unified way
void UpdateWithAsset(Data::Asset<Data::AssetData> updatedAsset);
//! Validates individual asset updates, returns true for valid ready assets.
bool IsAssetValid(Data::Asset<RPI::StreamingImageAsset>& asset);
//! Get the inverse matrix from entity transfom, without scale and translate
AZ::Matrix4x4 GetInverseTransform(const AZ::Transform& world);
TransformInterface* m_transformInterface = nullptr;
SkyBoxFeatureProcessorInterface* m_featureProcessorInterface = nullptr;
HDRiSkyboxComponentConfig m_configuration;
EntityId m_entityId;
bool m_isActive = false;
};
}
}
@@ -0,0 +1,45 @@
/*
* 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 <SkyBox/PhysicalSkyComponent.h>
#include <AzCore/RTTI/BehaviorContext.h>
namespace AZ
{
namespace Render
{
PhysicalSkyComponent::PhysicalSkyComponent(const PhysicalSkyComponentConfig& config)
: BaseClass(config)
{
}
void PhysicalSkyComponent::Reflect(AZ::ReflectContext* context)
{
BaseClass::Reflect(context);
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<PhysicalSkyComponent, BaseClass>();
}
if (auto behaviorContext = azrtti_cast<BehaviorContext*>(context))
{
behaviorContext->Class<PhysicalSkyComponent>()->RequestBus("PhysicalSkyRequestBus");
behaviorContext->ConstantProperty("PhysicalSkyComponentTypeId", BehaviorConstant(Uuid(PhysicalSkyComponentTypeId)))
->Attribute(AZ::Script::Attributes::Module, "render")
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common);
}
}
} // namespace Render
} // namespace AZ
@@ -0,0 +1,37 @@
/*
* 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 <AzFramework/Components/ComponentAdapter.h>
#include <Atom/Feature/SkyBox/SkyboxConstants.h>
#include <AtomLyIntegration/CommonFeatures/SkyBox/PhysicalSkyComponentConfig.h>
#include <SkyBox/PhysicalSkyComponentController.h>
namespace AZ
{
namespace Render
{
class PhysicalSkyComponent final
: public AzFramework::Components::ComponentAdapter<PhysicalSkyComponentController, PhysicalSkyComponentConfig>
{
public:
using BaseClass = AzFramework::Components::ComponentAdapter<PhysicalSkyComponentController, PhysicalSkyComponentConfig>;
AZ_COMPONENT(AZ::Render::PhysicalSkyComponent, PhysicalSkyComponentTypeId , BaseClass);
PhysicalSkyComponent() = default;
PhysicalSkyComponent(const PhysicalSkyComponentConfig& config);
static void Reflect(AZ::ReflectContext* context);
};
} // namespace Render
} // namespace AZ
@@ -0,0 +1,89 @@
/*
* 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 <AtomLyIntegration/CommonFeatures/SkyBox/PhysicalSkyComponentConfig.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Serialization/EditContext.h>
namespace AZ
{
namespace Render
{
void PhysicalSkyComponentConfig::Reflect(ReflectContext* context)
{
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<PhysicalSkyComponentConfig, ComponentConfig>()
->Version(3)
->Field("IntensityMode", &PhysicalSkyComponentConfig::m_intensityMode)
->Field("SkyIntensity", &PhysicalSkyComponentConfig::m_skyIntensity)
->Field("SunIntensity", &PhysicalSkyComponentConfig::m_sunIntensity)
->Field("Turbidity", &PhysicalSkyComponentConfig::m_turbidity)
->Field("SunRadiusFactor", &PhysicalSkyComponentConfig::m_sunRadiusFactor)
;
}
}
const char* PhysicalSkyComponentConfig::GetIntensitySuffix() const
{
return PhotometricValue::GetTypeSuffix(m_intensityMode);
}
float PhysicalSkyComponentConfig::GetSunIntensityMin() const
{
switch (m_intensityMode)
{
case PhotometricUnit::Nit:
return 0.1f;
case PhotometricUnit::Ev100Luminance:
return -4.0f;
}
return 0.0f;
}
float PhysicalSkyComponentConfig::GetSunIntensityMax() const
{
switch (m_intensityMode)
{
case PhotometricUnit::Nit:
return 100'000.0f;
case PhotometricUnit::Ev100Luminance:
return 16.0f;
}
return 0.0f;
}
float PhysicalSkyComponentConfig::GetSkyIntensityMin() const
{
switch (m_intensityMode)
{
case PhotometricUnit::Nit:
return 0.1f;
case PhotometricUnit::Ev100Luminance:
return -4.0f;
}
return 0.0f;
}
float PhysicalSkyComponentConfig::GetSkyIntensityMax() const
{
switch (m_intensityMode)
{
case PhotometricUnit::Nit:
return 5000.0f;
case PhotometricUnit::Ev100Luminance:
return 11.0;
}
return 0.0f;
}
}
}
@@ -0,0 +1,232 @@
/*
* 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 <SkyBox/PhysicalSkyComponentController.h>
#include <AzCore/RTTI/BehaviorContext.h>
#include <Atom/RPI.Public/Scene.h>
namespace AZ
{
namespace Render
{
void PhysicalSkyComponentController::Reflect(ReflectContext* context)
{
PhysicalSkyComponentConfig::Reflect(context);
if (auto* serializeContext = azrtti_cast<SerializeContext*>(context))
{
serializeContext->Class<PhysicalSkyComponentController>()
->Version(0)
->Field("Configuration", &PhysicalSkyComponentController::m_configuration);
}
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
{
behaviorContext->EBus<PhysicalSkyRequestBus>("PhysicalSkyRequestBus")
->Event("SetTurbidity", &PhysicalSkyRequestBus::Events::SetTurbidity)
->Event("GetTurbidity", &PhysicalSkyRequestBus::Events::GetTurbidity)
->Event("SetSunRadiusFactor", &PhysicalSkyRequestBus::Events::SetSunRadiusFactor)
->Event("GetSunRadiusFactor", &PhysicalSkyRequestBus::Events::GetSunRadiusFactor)
->Event("SetSkyIntensity", static_cast<void(PhysicalSkyRequestBus::Events::*)(float)>(&PhysicalSkyRequestBus::Events::SetSkyIntensity))
->Event("GetSkyIntensity", static_cast<float(PhysicalSkyRequestBus::Events::*)()>(&PhysicalSkyRequestBus::Events::GetSkyIntensity))
->Event("SetSunIntensity", static_cast<void(PhysicalSkyRequestBus::Events::*)(float)>(&PhysicalSkyRequestBus::Events::SetSunIntensity))
->Event("GetSunIntensity", static_cast<float(PhysicalSkyRequestBus::Events::*)()>(&PhysicalSkyRequestBus::Events::GetSunIntensity))
->VirtualProperty("Turbidity", "GetTurbidity", "SetTurbidity")
->VirtualProperty("SunRadiusFactor", "GetSunRadiusFactor", "SetSunRadiusFactor")
->VirtualProperty("SkyIntensity", "GetSkyIntensity", "SetSkyIntensity")
->VirtualProperty("SunIntensity", "GetSunIntensity", "SetSunIntensity")
;
}
}
void PhysicalSkyComponentController::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
{
provided.push_back(AZ_CRC("SkyBoxService", 0x8169a709));
}
void PhysicalSkyComponentController::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
{
incompatible.push_back(AZ_CRC("SkyBoxService", 0x8169a709));
}
void PhysicalSkyComponentController::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
{
required.push_back(AZ_CRC("TransformService"));
}
PhysicalSkyComponentController::PhysicalSkyComponentController(const PhysicalSkyComponentConfig& config)
: m_configuration(config)
{
}
void PhysicalSkyComponentController::Activate(EntityId entityId)
{
m_featureProcessorInterface = RPI::Scene::GetFeatureProcessorForEntity<SkyBoxFeatureProcessorInterface>(entityId);
// only activate if there is no other skybox activate
if (!m_featureProcessorInterface->IsEnable())
{
m_featureProcessorInterface->SetSkyboxMode(SkyBoxMode::PhysicalSky);
m_featureProcessorInterface->Enable(true);
m_entityId = entityId;
m_skyPhotometricValue = PhotometricValue(m_configuration.m_skyIntensity, Color::CreateOne(), m_configuration.m_intensityMode);
m_sunPhotometricValue = PhotometricValue(m_configuration.m_sunIntensity, Color::CreateOne(), m_configuration.m_intensityMode);
SetTurbidity(m_configuration.m_turbidity);
SetSunRadiusFactor(m_configuration.m_sunRadiusFactor);
SetSkyIntensity(m_configuration.m_skyIntensity, m_configuration.m_intensityMode);
SetSunIntensity(m_configuration.m_sunIntensity, m_configuration.m_intensityMode);
m_transformInterface = TransformBus::FindFirstHandler(m_entityId);
AZ_Assert(m_transformInterface, "Unable to attach to a TransformBus handler. Entity transform will not affect to skybox.");
const AZ::Transform& transform = m_transformInterface ? m_transformInterface->GetWorldTM() : Transform::Identity();
m_featureProcessorInterface->SetSunPosition(GetSunTransform(transform));
PhysicalSkyRequestBus::Handler::BusConnect(m_entityId);
TransformNotificationBus::Handler::BusConnect(m_entityId);
m_isActive = true;
}
else
{
m_featureProcessorInterface = nullptr;
AZ_Warning("PhysicalSkyComponentController", false, "There is already another HDRi Skybox or Physical Sky component in the scene!");
}
}
void PhysicalSkyComponentController::Deactivate()
{
// Run deactivate if this skybox is activate
if (m_isActive)
{
PhysicalSkyRequestBus::Handler::BusDisconnect(m_entityId);
TransformNotificationBus::Handler::BusDisconnect(m_entityId);
m_featureProcessorInterface->Enable(false);
m_featureProcessorInterface = nullptr;
m_transformInterface = nullptr;
m_isActive = false;
}
}
void PhysicalSkyComponentController::SetConfiguration(const PhysicalSkyComponentConfig& config)
{
m_configuration = config;
}
const PhysicalSkyComponentConfig& PhysicalSkyComponentController::GetConfiguration() const
{
return m_configuration;
}
void PhysicalSkyComponentController::OnTransformChanged([[maybe_unused]] const AZ::Transform& local, const AZ::Transform& world)
{
m_featureProcessorInterface->SetSunPosition(GetSunTransform(world));
}
void PhysicalSkyComponentController::SetTurbidity(int turbidity)
{
m_configuration.m_turbidity = turbidity;
m_featureProcessorInterface->SetTurbidity(turbidity);
}
int PhysicalSkyComponentController::GetTurbidity()
{
return m_configuration.m_turbidity;
}
void PhysicalSkyComponentController::SetSunRadiusFactor(float factor)
{
m_configuration.m_sunRadiusFactor = factor;
m_featureProcessorInterface->SetSunRadiusFactor(factor);
}
float PhysicalSkyComponentController::GetSunRadiusFactor()
{
return m_configuration.m_sunRadiusFactor;
}
void PhysicalSkyComponentController::SetSkyIntensity(float intensity, PhotometricUnit unit)
{
m_skyPhotometricValue.ConvertToPhotometricUnit(unit);
m_skyPhotometricValue.SetIntensity(intensity);
m_configuration.m_skyIntensity = intensity;
m_featureProcessorInterface->SetSkyIntensity(intensity, unit);
}
void PhysicalSkyComponentController::SetSkyIntensity(float intensity)
{
m_skyPhotometricValue.SetIntensity(intensity);
m_configuration.m_skyIntensity = intensity;
m_featureProcessorInterface->SetSkyIntensity(intensity, m_skyPhotometricValue.GetType());
}
float PhysicalSkyComponentController::GetSkyIntensity(PhotometricUnit unit)
{
m_skyPhotometricValue.ConvertToPhotometricUnit(unit);
m_configuration.m_skyIntensity = m_skyPhotometricValue.GetIntensity();
return m_configuration.m_skyIntensity;
}
float PhysicalSkyComponentController::GetSkyIntensity()
{
return m_configuration.m_skyIntensity;
}
void PhysicalSkyComponentController::SetSunIntensity(float intensity, PhotometricUnit unit)
{
m_sunPhotometricValue.ConvertToPhotometricUnit(unit);
m_sunPhotometricValue.SetIntensity(intensity);
m_configuration.m_sunIntensity = intensity;
m_featureProcessorInterface->SetSunIntensity(intensity, unit);
}
void PhysicalSkyComponentController::SetSunIntensity(float intensity)
{
m_sunPhotometricValue.SetIntensity(intensity);
m_configuration.m_sunIntensity = intensity;
m_featureProcessorInterface->SetSunIntensity(intensity, m_sunPhotometricValue.GetType());
}
float PhysicalSkyComponentController::GetSunIntensity(PhotometricUnit unit)
{
m_sunPhotometricValue.ConvertToPhotometricUnit(unit);
m_configuration.m_sunIntensity = m_sunPhotometricValue.GetIntensity();
return m_configuration.m_sunIntensity;
}
float PhysicalSkyComponentController::GetSunIntensity()
{
return m_configuration.m_sunIntensity;
}
SunPosition PhysicalSkyComponentController::GetSunTransform(const AZ::Transform& world)
{
Transform worldNoScale = world;
worldNoScale.ExtractScale();
AZ::Vector3 sunPositionAtom = worldNoScale.TransformVector(AZ::Vector3(0, -1, 0)); // transform Sun from default position
// Convert sun position to Y-up coordinate
AZ::Vector3 sunPosition;
sunPosition.SetX(-sunPositionAtom.GetY());
sunPosition.SetY(sunPositionAtom.GetZ());
sunPosition.SetZ(sunPositionAtom.GetX());
return SunPosition(atan2(sunPosition.GetZ(), sunPosition.GetX()), asin(sunPosition.GetY()));
}
}
}
@@ -0,0 +1,80 @@
/*
* 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 <AzCore/Component/Component.h>
#include <AzCore/Component/TransformBus.h>
#include <AtomLyIntegration/CommonFeatures/SkyBox/PhysicalSkyComponentConfig.h>
#include <AtomLyIntegration/CommonFeatures/SkyBox/PhysicalSkyBus.h>
#include <Atom/Feature/SkyBox/SkyBoxFeatureProcessorInterface.h>
namespace AZ
{
namespace Render
{
class PhysicalSkyComponentController final
: public TransformNotificationBus::Handler
, public PhysicalSkyRequestBus::Handler
{
public:
friend class EditorPhysicalSkyComponent;
AZ_TYPE_INFO(AZ::Render::PhysicalSkyComponentController, "{C3EEB94D-AEB9-4727-9493-791F86924804}");
static void Reflect(AZ::ReflectContext* context);
static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
PhysicalSkyComponentController() = default;
PhysicalSkyComponentController(const PhysicalSkyComponentConfig& config);
void Activate(EntityId entityId);
void Deactivate();
void SetConfiguration(const PhysicalSkyComponentConfig& config);
const PhysicalSkyComponentConfig& GetConfiguration() const;
private:
AZ_DISABLE_COPY(PhysicalSkyComponentController);
// TransformNotificationBus::Handler overrides ...
void OnTransformChanged(const AZ::Transform& local, const AZ::Transform& world) override;
// PhysicalSkyRequestBus::Handler overrides ...
void SetTurbidity(int turbidity) override;
int GetTurbidity() override;
void SetSunRadiusFactor(float factor) override;
float GetSunRadiusFactor() override;
void SetSkyIntensity(float intensity, PhotometricUnit unit) override;
void SetSkyIntensity(float intensity) override;
float GetSkyIntensity(PhotometricUnit unit) override;
float GetSkyIntensity() override;
void SetSunIntensity(float intensity, PhotometricUnit unit) override;
void SetSunIntensity(float intensity) override;
float GetSunIntensity(PhotometricUnit unit) override;
float GetSunIntensity() override;
//! Get Sun azimuth and altitude from entity transfom, without scale
SunPosition GetSunTransform(const AZ::Transform& world);
TransformInterface* m_transformInterface = nullptr;
SkyBoxFeatureProcessorInterface* m_featureProcessorInterface = nullptr;
PhysicalSkyComponentConfig m_configuration;
EntityId m_entityId;
bool m_isActive = false;
// For light unit update on UI
PhotometricValue m_skyPhotometricValue;
PhotometricValue m_sunPhotometricValue;
};
}
}