Initial commit for editor LUT generation.

Signed-off-by: rbarrand <rbarrand@amazon.com>
This commit is contained in:
Robin
2021-10-06 16:15:15 -07:00
committed by rbarrand
parent 4a133f1251
commit 2313f912bc
18 changed files with 4903 additions and 8 deletions
@@ -7,6 +7,7 @@
*/
#include <PostProcess/ColorGrading/EditorHDRColorGradingComponent.h>
#include <AzToolsFramework/API/EditorPythonRunnerRequestsBus.h>
namespace AZ
{
@@ -31,6 +32,12 @@ namespace AZ
->Attribute(Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("Game"))
->Attribute(Edit::Attributes::AutoExpand, true)
->Attribute(Edit::Attributes::HelpPageURL, "https://") // [TODO ATOM-2672][PostFX] need to create page for PostProcessing.
->ClassElement(AZ::Edit::ClassElements::Group, "LUT Generation")
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
->UIElement(AZ::Edit::UIHandlers::Button, "Generate LUT", "Generates a LUT from the scene's enabled color grading blend.")
->Attribute(AZ::Edit::Attributes::NameLabelOverride, "")
->Attribute(AZ::Edit::Attributes::ButtonText, "Generate LUT")
->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorHDRColorGradingComponent::GenerateLut)
;
editContext->Class<HDRColorGradingComponentController>(
@@ -136,6 +143,69 @@ namespace AZ
{
}
void EditorHDRColorGradingComponent::OnTick([[maybe_unused]] float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time)
{
if (m_controller.m_configuration.m_generateLut && m_frameCounter)
{
--m_frameCounter;
return;
}
else if (m_controller.m_configuration.m_generateLut && m_lutGenerationInProgress)
{
const char* LutAttachment = "LutOutput";
const AZStd::vector<AZStd::string> LutGenerationPassHierarchy{ "LutGenerationPass" };
// capture frame
AZ::Render::FrameCaptureNotificationBus::Handler::BusConnect();
bool startedCapture = false;
AZ::Render::FrameCaptureRequestBus::BroadcastResult(
startedCapture,
&AZ::Render::FrameCaptureRequestBus::Events::CapturePassAttachment,
LutGenerationPassHierarchy,
AZStd::string(LutAttachment), TempTiffFilePath,
AZ::RPI::PassAttachmentReadbackOption::Output);
m_lutGenerationInProgress = !startedCapture;
}
}
void EditorHDRColorGradingComponent::OnCaptureFinished([[maybe_unused]] AZ::Render::FrameCaptureResult result, [[maybe_unused]]const AZStd::string& info)
{
char resolvedInputFilePath[AZ_MAX_PATH_LEN] = { 0 };
AZ::IO::FileIOBase::GetDirectInstance()->ResolvePath(TempTiffFilePath, resolvedInputFilePath, AZ_MAX_PATH_LEN);
char resolvedOutputFilePath[AZ_MAX_PATH_LEN] = { 0 };
AZ::IO::FileIOBase::GetDirectInstance()->ResolvePath(GeneratedLutFilePath, resolvedOutputFilePath, AZ_MAX_PATH_LEN);
AZStd::vector<AZStd::string_view> pythonArgs
{
"--i", resolvedInputFilePath,
"--o", resolvedOutputFilePath
};
AzToolsFramework::EditorPythonRunnerRequestBus::Broadcast(
&AzToolsFramework::EditorPythonRunnerRequestBus::Events::ExecuteByFilenameWithArgs,
"@devroot@/Gems/Atom/Feature/Common/Editor/Scripts/ColorGrading/tiff_to_3dl_azasset.py", pythonArgs);
m_controller.m_configuration.m_generateLut = false;
m_controller.OnConfigChanged();
AZ::TickBus::Handler::BusDisconnect();
AZ::Render::FrameCaptureNotificationBus::Handler::BusDisconnect();
}
void EditorHDRColorGradingComponent::GenerateLut()
{
// turn on lut generation pass
m_lutGenerationInProgress = true;
m_controller.m_configuration.m_generateLut = true;
m_controller.OnConfigChanged();
m_frameCounter = FramesToWait;
AZ::TickBus::Handler::BusConnect();
}
u32 EditorHDRColorGradingComponent::OnConfigurationChanged()
{
m_controller.OnConfigChanged();
@@ -8,16 +8,23 @@
#pragma once
#include <AzCore/Component/TickBus.h>
#include <AzToolsFramework/ToolsComponents/EditorComponentAdapter.h>
#include <Atom/Feature/Utils/FrameCaptureBus.h>
#include <PostProcess/ColorGrading/HDRColorGradingComponent.h>
namespace AZ
{
namespace Render
{
static const char* const TempTiffFilePath{ "@projectcache@/LutGeneration/SavedLut.tiff" };
static const char* const GeneratedLutFilePath{ "@projectcache@/LutGeneration/SavedLut" };
class EditorHDRColorGradingComponent final
: public AzToolsFramework::Components::
EditorComponentAdapter<HDRColorGradingComponentController, HDRColorGradingComponent, HDRColorGradingComponentConfig>
, private TickBus::Handler
, private FrameCaptureNotificationBus::Handler
{
public:
using BaseClass = AzToolsFramework::Components::EditorComponentAdapter<HDRColorGradingComponentController, HDRColorGradingComponent, HDRColorGradingComponentConfig>;
@@ -25,11 +32,27 @@ namespace AZ
static void Reflect(AZ::ReflectContext* context);
static const int FramesToWait = 5;
//static const char* LutAttachment;
//static const AZStd::vector<AZStd::string> LutGenerationPassHierarchy;
EditorHDRColorGradingComponent() = default;
EditorHDRColorGradingComponent(const HDRColorGradingComponentConfig& config);
//! EditorRenderComponentAdapter overrides...
AZ::u32 OnConfigurationChanged() override;
private:
// AZ::TickBus overrides ...
void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
// FrameCaptureNotificationBus overrides ...
void OnCaptureFinished(AZ::Render::FrameCaptureResult result, const AZStd::string& info) override;
void GenerateLut();
AZStd::atomic_bool m_lutGenerationInProgress = false;
int m_frameCounter;
};
} // namespace Render
} // namespace AZ