Skip to content

Commit

Permalink
Add function "Allow pipeline changes" to CameraComponent (#18524)
Browse files Browse the repository at this point in the history
* Add function "Allow pipeline changes" to CameraComponent

This is usefull for rendering to texture using features like:
- Sky atmosphere
- Global illumination
Since a lot of feaures processors don't beheave with multiple cameras
this function is activated after changing registry setting:
`/O3DE/Atom/ExperimentalFeaturesEnabled` to `true`
It is to prevent exposure of this function to the majority of users.

This function allows to change the camera pipeline in runtime


---------

Signed-off-by: Michał Pełka <[email protected]>
  • Loading branch information
michalpelka authored Dec 5, 2024
1 parent 59f92fd commit 6933b66
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 15 additions & 2 deletions Gems/Camera/Code/Source/CameraComponentController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <AzCore/Math/Vector2.h>

#include <AzFramework/Viewport/ViewportScreen.h>

#include <AzCore/Settings/SettingsRegistry.h>

namespace Camera
{
Expand All @@ -42,6 +42,7 @@ namespace Camera
->Field("MakeActiveViewOnActivation", &CameraComponentConfig::m_makeActiveViewOnActivation)
->Field("RenderToTexture", &CameraComponentConfig::m_renderTextureAsset)
->Field("PipelineTemplate", &CameraComponentConfig::m_pipelineTemplate)
->Field("AllowPipelineChange", &CameraComponentConfig::m_allowPipelineChanges)
;

if (auto editContext = serializeContext->GetEditContext())
Expand Down Expand Up @@ -82,10 +83,22 @@ namespace Camera
->ClassElement(AZ::Edit::ClassElements::Group, "Render To Texture")
->DataElement(AZ::Edit::UIHandlers::Default, &CameraComponentConfig::m_renderTextureAsset, "Target texture", "The render target texture which the camera renders to.")
->DataElement(AZ::Edit::UIHandlers::Default, &CameraComponentConfig::m_pipelineTemplate, "Pipeline template", "The root pass template for the camera's render pipeline")
->DataElement(AZ::Edit::UIHandlers::Default, &CameraComponentConfig::m_allowPipelineChanges, "Allow pipeline changes", "If true, the camera's render pipeline can be changed at runtime.")
->Attribute(AZ::Edit::Attributes::Visibility, &CameraComponentConfig::GetAllowPipelineChangesVisibility)
;
}
}
}
AZ::u32 CameraComponentConfig::GetAllowPipelineChangesVisibility() const
{
bool experimentalFeaturesEnabled = false;
const auto* registry = AZ::SettingsRegistry::Get();
if (registry)
{
registry->Get(experimentalFeaturesEnabled, "/O3DE/Atom/ExperimentalFeaturesEnabled");
}
return experimentalFeaturesEnabled ? AZ::Edit::PropertyVisibility::Show : AZ::Edit::PropertyVisibility::Hide;
}

float CameraComponentConfig::GetFarClipDistance() const
{
Expand Down Expand Up @@ -326,7 +339,7 @@ namespace Camera
pipelineDesc.m_name = pipelineName;
pipelineDesc.m_rootPassTemplate = m_config.m_pipelineTemplate;
pipelineDesc.m_renderSettings.m_multisampleState = AZ::RPI::RPISystemInterface::Get()->GetApplicationMultisampleState();
pipelineDesc.m_allowModification = false;
pipelineDesc.m_allowModification = m_config.m_allowPipelineChanges;
m_renderToTexturePipeline = AZ::RPI::RenderPipeline::CreateRenderPipelineForImage(pipelineDesc, m_config.m_renderTextureAsset);

if (!m_renderToTexturePipeline)
Expand Down
4 changes: 4 additions & 0 deletions Gems/Camera/Code/Source/CameraComponentController.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ namespace Camera
bool m_specifyFrustumDimensions = false;
bool m_makeActiveViewOnActivation = true;
bool m_orthographic = false;
bool m_allowPipelineChanges = false;
float m_orthographicHalfWidth = 5.f;

AZ::u64 m_editorEntityId = AZ::EntityId::InvalidEntityId;
Expand All @@ -66,6 +67,9 @@ namespace Camera
AZ::Data::Asset<AZ::RPI::AttachmentImageAsset> m_renderTextureAsset;
// The pass template name used for render pipeline's root template
AZStd::string m_pipelineTemplate = "CameraPipeline";
private:
//! Check if experimental features are enabled
AZ::u32 GetAllowPipelineChangesVisibility() const;
};

class CameraComponentController
Expand Down

0 comments on commit 6933b66

Please sign in to comment.