From a8b6c1e77b1288f8433ba95c53de97f04b645198 Mon Sep 17 00:00:00 2001 From: rbarrand Date: Fri, 15 Oct 2021 12:56:19 -0700 Subject: [PATCH] Add cmake file for editor scripts. Add constexpr keyword to constants. Use AZ_CRC_CE for LookModificationComponent. Signed-off-by: rbarrand --- Gems/Atom/Feature/Common/Code/CMakeLists.txt | 1 + .../Source/ColorGrading/LutGenerationPass.h | 4 -- .../ColorGrading}/activate_lut_asset.py | 3 +- .../ColorGrading/azasset_converter_utils.py | 63 +++++++++++++++++++ .../ColorGrading/exr_to_3dl_azasset.py | 43 +------------ .../ColorGrading/tiff_to_3dl_azasset.py | 45 +------------ ...m_feature_common_editor_script_files.cmake | 16 +++++ .../EditorHDRColorGradingComponent.h | 8 +-- .../HDRColorGradingComponentController.cpp | 2 +- .../LookModificationComponentController.cpp | 4 +- 10 files changed, 91 insertions(+), 98 deletions(-) rename Gems/Atom/Feature/Common/{Assets/Scripts => Editor/Scripts/ColorGrading}/activate_lut_asset.py (96%) create mode 100644 Gems/Atom/Feature/Common/Editor/Scripts/ColorGrading/azasset_converter_utils.py create mode 100644 Gems/Atom/Feature/Common/Editor/atom_feature_common_editor_script_files.cmake diff --git a/Gems/Atom/Feature/Common/Code/CMakeLists.txt b/Gems/Atom/Feature/Common/Code/CMakeLists.txt index 470c40503c..b558be3714 100644 --- a/Gems/Atom/Feature/Common/Code/CMakeLists.txt +++ b/Gems/Atom/Feature/Common/Code/CMakeLists.txt @@ -76,6 +76,7 @@ ly_add_target( FILES_CMAKE atom_feature_common_shared_files.cmake ../Assets/atom_feature_common_asset_files.cmake + ../Editor/atom_feature_common_editor_script_files.cmake PLATFORM_INCLUDE_FILES ${pal_source_dir}/runtime_dependencies_clients.cmake INCLUDE_DIRECTORIES diff --git a/Gems/Atom/Feature/Common/Code/Source/ColorGrading/LutGenerationPass.h b/Gems/Atom/Feature/Common/Code/Source/ColorGrading/LutGenerationPass.h index 9f1707339e..4a9b358d2f 100644 --- a/Gems/Atom/Feature/Common/Code/Source/ColorGrading/LutGenerationPass.h +++ b/Gems/Atom/Feature/Common/Code/Source/ColorGrading/LutGenerationPass.h @@ -25,8 +25,6 @@ namespace AZ : public AZ::Render::HDRColorGradingPass { public: - static const int NumLuts = 3; - AZ_RTTI(LutGenerationPass, "{C21DABA8-B538-4C80-BA18-5B97CC9259E5}", AZ::RPI::FullscreenTrianglePass); AZ_CLASS_ALLOCATOR(LutGenerationPass, SystemAllocator, 0); @@ -46,8 +44,6 @@ namespace AZ // Set viewport scissor based on output LUT resolution void SetViewportScissorFromImageSize(const RHI::Size& imageSize); - DisplayMapperAssetLut m_colorGradingLuts[NumLuts]; - RHI::ShaderInputNameIndex m_lutResolutionIndex = "m_lutResolution"; RHI::ShaderInputNameIndex m_lutShaperTypeIndex = "m_shaperType"; RHI::ShaderInputNameIndex m_lutShaperBiasIndex = "m_shaperBias"; diff --git a/Gems/Atom/Feature/Common/Assets/Scripts/activate_lut_asset.py b/Gems/Atom/Feature/Common/Editor/Scripts/ColorGrading/activate_lut_asset.py similarity index 96% rename from Gems/Atom/Feature/Common/Assets/Scripts/activate_lut_asset.py rename to Gems/Atom/Feature/Common/Editor/Scripts/ColorGrading/activate_lut_asset.py index 39f2e67752..016ad024aa 100644 --- a/Gems/Atom/Feature/Common/Assets/Scripts/activate_lut_asset.py +++ b/Gems/Atom/Feature/Common/Editor/Scripts/ColorGrading/activate_lut_asset.py @@ -22,7 +22,6 @@ LOOK_MODIFICATION_COMPONENT_ID = azlmbr.editor.EditorComponentAPIBus(azlmbr.bus. def disable_hdr_color_grading_component(entity_id): - typeIdsList = azlmbr.editor.EditorComponentAPIBus(azlmbr.bus.Broadcast, 'FindComponentTypeIdsByEntityType', ["HDR Color Grading"], 0) componentOutcome = azlmbr.editor.EditorComponentAPIBus(azlmbr.bus.Broadcast, 'GetComponentOfType', entity_id, COLOR_GRADING_COMPONENT_ID[0]) if(componentOutcome.IsSuccess()): azlmbr.editor.EditorComponentAPIBus(azlmbr.bus.Broadcast, 'DisableComponents', [componentOutcome.GetValue()]) @@ -35,6 +34,8 @@ def get_look_modification_component(entity_id): componentOutcome = azlmbr.editor.EditorComponentAPIBus(azlmbr.bus.Broadcast, 'GetComponentOfType', entity_id, LOOK_MODIFICATION_COMPONENT_ID[0]) if componentOutcome.IsSuccess(): return componentOutcome.GetValue() + else: + return None def activate_look_modification_lut(look_modification_component, asset_relative_path): print(asset_relative_path) diff --git a/Gems/Atom/Feature/Common/Editor/Scripts/ColorGrading/azasset_converter_utils.py b/Gems/Atom/Feature/Common/Editor/Scripts/ColorGrading/azasset_converter_utils.py new file mode 100644 index 0000000000..1a2bf41711 --- /dev/null +++ b/Gems/Atom/Feature/Common/Editor/Scripts/ColorGrading/azasset_converter_utils.py @@ -0,0 +1,63 @@ +# coding:utf-8 +#!/usr/bin/python +# +# Copyright (c) Contributors to the Open 3D Engine Project. +# For complete copyright and license terms please see the LICENSE at the root of this distribution. +# +# SPDX-License-Identifier: Apache-2.0 OR MIT +# +# +import numpy as np +import logging as _logging +from ColorGrading import get_uv_coord + +# ------------------------------------------------------------------------ +_MODULENAME = 'ColorGrading.azasset_converter_utils' + +_LOGGER = _logging.getLogger(_MODULENAME) +_LOGGER.debug('Initializing: {0}.'.format({_MODULENAME})) +# ------------------------------------------------------------------------ + +""" Utility functions for generating LUT azassets """ +def generate_lut_values(image_spec, image_buffer): + lut_size = image_spec.height + + lut_intervals = [] + lut_values = [] + + # First line contains the vertex intervals + dv = 1023.0 / float(lut_size-1) + for i in range(lut_size): + lut_intervals.append(np.uint16(dv * i)) + # Texels are in R G B per line with indices increasing first with blue, then green, and then red. + for r in range(lut_size): + for g in range(lut_size): + for b in range(lut_size): + uv = get_uv_coord(lut_size, r, g, b) + px = np.array(image_buffer.getpixel(uv[0], uv[1]), dtype='f') + px = np.clip(px, 0.0, 1.0) + px = np.uint16(px * 4095) + lut_values.append(px) + + return lut_intervals, lut_values + +# To Do: add some input file validation +# If the input file doesn't exist, you'll get a LUT with res of 0 x 0 and result in a math error +#Resolution is 0 x 0 +#writing C:\Depot\o3de-engine\Gems\AtomLyIntegration\CommonFeatures\Tools\ColorGrading\TestData\Nuke\HDR\Nuke_Post_grade_LUT.3dl... +#Traceback (most recent call last): + #File "..\..\Editor\Scripts\ColorGrading\exr_to_3dl_azasset.py", line 103, in + #dv = 1023.0 / float(lutSize) +# ZeroDivisionError: float division by zero + +def write_3DL(file_path, lut_size, lut_intervals, lut_values): + lut_file_path = f'{file_path}.3dl' + _LOGGER.info(f"Writing {lut_file_path}...") + lut_file = open(lut_file_path, 'w') + for i in range(lut_size): + lut_file.write(f"{lut_intervals[i]} ") + lut_file.write("\n") + for px in lut_values: + lut_file.write(f"{px[0]} {px[1]} {px[2]}\n") + lut_file.close() + diff --git a/Gems/Atom/Feature/Common/Editor/Scripts/ColorGrading/exr_to_3dl_azasset.py b/Gems/Atom/Feature/Common/Editor/Scripts/ColorGrading/exr_to_3dl_azasset.py index a3aae9cb94..3186b7498f 100644 --- a/Gems/Atom/Feature/Common/Editor/Scripts/ColorGrading/exr_to_3dl_azasset.py +++ b/Gems/Atom/Feature/Common/Editor/Scripts/ColorGrading/exr_to_3dl_azasset.py @@ -46,48 +46,7 @@ from ColorGrading.from_3dl_to_azasset import write_azasset from ColorGrading import get_uv_coord -def generate_lut_values(image_spec, image_buffer): - lut_size = image_spec.height - - lut_intervals = [] - lut_values = [] - - # First line contains the vertex intervals - dv = 1023.0 / float(lut_size-1) - for i in range(lut_size): - lut_intervals.append(np.uint16(dv * i)) - # Texels are in R G B per line with indices increasing first with blue, then green, and then red. - for r in range(lut_size): - for g in range(lut_size): - for b in range(lut_size): - uv = get_uv_coord(lut_size, r, g, b) - px = np.array(image_buffer.getpixel(uv[0], uv[1]), dtype='f') - px = np.clip(px, 0.0, 1.0) - px = np.uint16(px * 4095) - lut_values.append(px) - - return lut_intervals, lut_values - -# To Do: add some input file validation -# If the input file doesn't exist, you'll get a LUT with res of 0 x 0 and result in a math error -#Resolution is 0 x 0 -#writing C:\Depot\o3de-engine\Gems\AtomLyIntegration\CommonFeatures\Tools\ColorGrading\TestData\Nuke\HDR\Nuke_Post_grade_LUT.3dl... -#Traceback (most recent call last): - #File "..\..\Editor\Scripts\ColorGrading\exr_to_3dl_azasset.py", line 103, in - #dv = 1023.0 / float(lutSize) -# ZeroDivisionError: float division by zero - -def write_3DL(file_path, lut_size, lut_intervals, lut_values): - lut_file_path = f'{file_path}.3dl' - _LOGGER.info(f"Writing {lut_file_path}...") - lut_file = open(lut_file_path, 'w') - for i in range(lut_size): - lut_file.write(f"{lut_intervals[i]} ") - lut_file.write("\n") - for px in lut_values: - lut_file.write(f"{px[0]} {px[1]} {px[2]}\n") - lut_file.close() - +from ColorGrading.azasset_converter_utils import generate_lut_values, write_3DL ########################################################################### # Main Code Block, runs this script as main (testing) diff --git a/Gems/Atom/Feature/Common/Editor/Scripts/ColorGrading/tiff_to_3dl_azasset.py b/Gems/Atom/Feature/Common/Editor/Scripts/ColorGrading/tiff_to_3dl_azasset.py index 02bfb97edd..479aa40976 100644 --- a/Gems/Atom/Feature/Common/Editor/Scripts/ColorGrading/tiff_to_3dl_azasset.py +++ b/Gems/Atom/Feature/Common/Editor/Scripts/ColorGrading/tiff_to_3dl_azasset.py @@ -44,50 +44,7 @@ if ColorGrading.initialize.start(): # ------------------------------------------------------------------------ from ColorGrading.from_3dl_to_azasset import write_azasset -from ColorGrading import get_uv_coord - -def generate_lut_values(image_spec, image_buffer): - lut_size = image_spec.height - - lut_intervals = [] - lut_values = [] - - # First line contains the vertex intervals - dv = 1023.0 / float(lut_size-1) - for i in range(lut_size): - lut_intervals.append(np.uint16(dv * i)) - # Texels are in R G B per line with indices increasing first with blue, then green, and then red. - for r in range(lut_size): - for g in range(lut_size): - for b in range(lut_size): - uv = get_uv_coord(lut_size, r, g, b) - px = np.array(image_buffer.getpixel(uv[0], uv[1]), dtype='f') - px = np.clip(px, 0.0, 1.0) - px = np.uint16(px * 4095) - lut_values.append(px) - - return lut_intervals, lut_values - -# To Do: add some input file validation -# If the input file doesn't exist, you'll get a LUT with res of 0 x 0 and result in a math error -#Resolution is 0 x 0 -#writing C:\Depot\o3de-engine\Gems\AtomLyIntegration\CommonFeatures\Tools\ColorGrading\TestData\Nuke\HDR\Nuke_Post_grade_LUT.3dl... -#Traceback (most recent call last): - #File "..\..\Editor\Scripts\ColorGrading\exr_to_3dl_azasset.py", line 103, in - #dv = 1023.0 / float(lutSize) -# ZeroDivisionError: float division by zero - -def write_3DL(file_path, lut_size, lut_intervals, lut_values): - lut_file_path = f'{file_path}.3dl' - _LOGGER.info(f"Writing {lut_file_path}...") - lut_file = open(lut_file_path, 'w') - for i in range(lut_size): - lut_file.write(f"{lut_intervals[i]} ") - lut_file.write("\n") - for px in lut_values: - lut_file.write(f"{px[0]} {px[1]} {px[2]}\n") - lut_file.close() - +from ColorGrading.azasset_converter_utils import generate_lut_values, write_3DL ########################################################################### # Main Code Block, runs this script as main (testing) diff --git a/Gems/Atom/Feature/Common/Editor/atom_feature_common_editor_script_files.cmake b/Gems/Atom/Feature/Common/Editor/atom_feature_common_editor_script_files.cmake new file mode 100644 index 0000000000..c9fa76e7dc --- /dev/null +++ b/Gems/Atom/Feature/Common/Editor/atom_feature_common_editor_script_files.cmake @@ -0,0 +1,16 @@ +# +# Copyright (c) Contributors to the Open 3D Engine Project. +# For complete copyright and license terms please see the LICENSE at the root of this distribution. +# +# SPDX-License-Identifier: Apache-2.0 OR MIT +# +# + +set(FILES + Scripts/ColorGrading/__init__.py + Scripts/ColorGrading/initialize.py + Scripts/ColorGrading/azasset_converter_utils.py + Scripts/ColorGrading/from_3dl_to_azasset.py + Scripts/ColorGrading/tiff_to_3dl_azasset.py + Scripts/ColorGrading/activate_lut_asset.py +) diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/PostProcess/ColorGrading/EditorHDRColorGradingComponent.h b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/PostProcess/ColorGrading/EditorHDRColorGradingComponent.h index ebd2f70b96..df3842d57a 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/PostProcess/ColorGrading/EditorHDRColorGradingComponent.h +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/PostProcess/ColorGrading/EditorHDRColorGradingComponent.h @@ -17,10 +17,10 @@ namespace AZ { namespace Render { - static const char* const TempTiffFilePath{ "@usercache@/LutGeneration/SavedLut_%s.tiff" }; - static const char* const GeneratedLutRelativePath = { "LutGeneration/SavedLut_%s" }; - static const char* const TiffToAzassetPythonScriptPath{ "@engroot@/Gems/Atom/Feature/Common/Editor/Scripts/ColorGrading/tiff_to_3dl_azasset.py" }; - static const char* const ActivateLutAssetPythonScriptPath{ "@engroot@/Gems/Atom/Feature/Common/Assets/Scripts/activate_lut_asset.py" }; + static constexpr const char* const TempTiffFilePath{ "@usercache@/LutGeneration/SavedLut_%s.tiff" }; + static constexpr const char* const GeneratedLutRelativePath = { "LutGeneration/SavedLut_%s" }; + static constexpr const char* const TiffToAzassetPythonScriptPath{ "@engroot@/Gems/Atom/Feature/Common/Editor/Scripts/ColorGrading/tiff_to_3dl_azasset.py" }; + static constexpr const char* const ActivateLutAssetPythonScriptPath{ "@engroot@/Gems/Atom/Feature/Common/Editor/Scripts/ColorGrading/activate_lut_asset.py" }; class EditorHDRColorGradingComponent final : public AzToolsFramework::Components:: diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/PostProcess/ColorGrading/HDRColorGradingComponentController.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/PostProcess/ColorGrading/HDRColorGradingComponentController.cpp index a18943161b..fb5e792430 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/PostProcess/ColorGrading/HDRColorGradingComponentController.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/PostProcess/ColorGrading/HDRColorGradingComponentController.cpp @@ -52,7 +52,7 @@ namespace AZ void HDRColorGradingComponentController::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible) { incompatible.push_back(AZ_CRC_CE("HDRColorGradingService")); - incompatible.push_back(AZ_CRC("LookModificationService", 0x207b7539)); + incompatible.push_back(AZ_CRC_CE("LookModificationService")); } void HDRColorGradingComponentController::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required) diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/PostProcess/LookModification/LookModificationComponentController.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/PostProcess/LookModification/LookModificationComponentController.cpp index 4f321ed8b1..aa8c305e72 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/PostProcess/LookModification/LookModificationComponentController.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/PostProcess/LookModification/LookModificationComponentController.cpp @@ -49,12 +49,12 @@ namespace AZ void LookModificationComponentController::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided) { - provided.push_back(AZ_CRC("LookModificationService", 0x207b7539)); + provided.push_back(AZ_CRC_CE("LookModificationService")); } void LookModificationComponentController::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible) { - incompatible.push_back(AZ_CRC("LookModificationService", 0x207b7539)); + incompatible.push_back(AZ_CRC("LookModificationService")); } void LookModificationComponentController::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)