Add cmake file for editor scripts. Add constexpr keyword to constants. Use AZ_CRC_CE for LookModificationComponent.

Signed-off-by: rbarrand <rbarrand@amazon.com>
This commit is contained in:
rbarrand
2021-10-15 12:56:19 -07:00
parent 67c14c21cc
commit a8b6c1e77b
10 changed files with 91 additions and 98 deletions
@@ -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
@@ -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";
@@ -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)
@@ -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 <module>
#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()
@@ -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 <module>
#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)
@@ -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 <module>
#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)
@@ -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
)
@@ -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::
@@ -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)
@@ -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)