hydra_AtomEditorComponentsLevel_DisplayMapperAdded.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. """
  2. Copyright (c) Contributors to the Open 3D Engine Project.
  3. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. SPDX-License-Identifier: Apache-2.0 OR MIT
  5. """
  6. class Tests:
  7. creation_undo = (
  8. "UNDO level component addition success",
  9. "P0: UNDO level component addition failed")
  10. creation_redo = (
  11. "REDO Level component addition success",
  12. "P0: REDO Level component addition failed")
  13. display_mapper_component = (
  14. "Level has a Display Mapper component",
  15. "P0: Level failed to find Display Mapper component")
  16. ldr_color_grading_lut = (
  17. "LDR color Grading LUT asset set",
  18. "P0: LDR color Grading LUT asset could not be set")
  19. enable_ldr_color_grading_lut = (
  20. "Enable LDR color grading LUT set",
  21. "P0: Enable LDR color grading LUT could not be set")
  22. enter_game_mode = (
  23. "Entered game mode",
  24. "P0: Failed to enter game mode")
  25. exit_game_mode = (
  26. "Exited game mode",
  27. "P0: Couldn't exit game mode")
  28. override_defaults = (
  29. "Override Defaults property set",
  30. "P1: Override Defaults property failed to be set correctly")
  31. alter_surround = (
  32. "Alter Surround property set",
  33. "P1: Alter Surround property failed to be set correctly")
  34. alter_desaturation = (
  35. "Alter Desaturation property set",
  36. "P1: Alter Desaturation property failed to be set correctly")
  37. alter_cat = (
  38. "Alter CAT D60 to D65 property set",
  39. "P1: Alter CAT D60 to D65 property failed to be set correctly")
  40. black_level_min = (
  41. "Cinema Limit (black) property set to minimum value",
  42. "P1: Cinema Limit (black) property failed to take minimum value")
  43. black_level_max = (
  44. "Cinema Limit (black) property set to maximum value",
  45. "P1: Cinema Limit (black) property failed to take maximum value")
  46. white_level_min = (
  47. "Cinema Limit (white) property set to minimum value",
  48. "P1: Cinema Limit (white) property failed to take minimum value")
  49. white_level_max = (
  50. "Cinema Limit (white) property set to maximum value",
  51. "P1: Cinema Limit (white) property failed to take maximum value")
  52. luminance_level_min = (
  53. "Min Point (luminance) property set",
  54. "P1: Min Point (luminance) property failed to set expected value")
  55. luminance_level_mid = (
  56. "Mid Point (luminance) property set",
  57. "P1: Mid Point (luminance) property failed to set expected value")
  58. luminance_level_max = (
  59. "Max Point (luminance) property set",
  60. "P1: Max Point (luminance) property failed to set expected value")
  61. surround_gamma = (
  62. "Surround Gamma property set",
  63. "P1: Surround Gamma property failed to set expected value")
  64. gamma = (
  65. "Gamma property set",
  66. "P1: Gamma property failed to set expected value")
  67. display_mapper_type = (
  68. "Display Mapper Operation Type is correctly set",
  69. "P1: Display Mapper Operation type is not as expected")
  70. # IsClose tolerance defaults to , 1e-9, but float values in some tests need a looser tolerance
  71. TOLERANCE = 1e-6
  72. def AtomEditorComponentsLevel_DisplayMapper_AddedToEntity():
  73. """
  74. Summary:
  75. Tests the Display Mapper level component can be added to the level entity and has the expected functionality.
  76. Test setup:
  77. - Wait for Editor idle loop.
  78. - Open the "Base" level.
  79. Expected Behavior:
  80. The component can be added, used in game mode, and has accurate required components.
  81. Creation and deletion undo/redo should also work.
  82. Test Steps:
  83. 1) Add Display Mapper level component to the level entity.
  84. 2) UNDO the level component addition.
  85. 3) REDO the level component addition.
  86. 4) Set LDR color Grading LUT asset.
  87. 5) Set the Display Mapper Operation Type enumerated in DISPLAY_MAPPER_OPERATION_TYPE for each type
  88. 6) Set Enable LDR color grading LUT property True
  89. 7) Toggle Override Defaults
  90. 8) Toggle Alter Surround
  91. 9) Toggle Alter Desaturation
  92. 10) Toggle 'Alter CAT D60 to D65'
  93. 11) Set 'Cinema Limit (black)' max value which is dynamic based on Cinema Limit (white) then min value
  94. 12) Set 'Cinema Limit (white)' max value then min, and finally back to default
  95. 13) Set 'Min Point (luminance)' to high and low value
  96. 14) Set 'Mid Point (luminance)' to high and low value then set default
  97. 15) Set 'Max Point (luminance)' to high and low value then set default
  98. 16) Set 'Surround Gamma' to high and low value
  99. 17) Set 'Gamma' to high and low value
  100. 18) Enter/Exit game mode.
  101. 19) Select and load each preset
  102. 20) Look for errors and asserts.
  103. :return: None
  104. """
  105. import os
  106. import azlmbr.bus as bus
  107. import azlmbr.legacy.general as general
  108. import azlmbr.render as render
  109. from azlmbr.math import Math_IsClose
  110. from editor_python_test_tools.asset_utils import Asset
  111. from editor_python_test_tools.editor_entity_utils import EditorLevelEntity
  112. from editor_python_test_tools.wait_utils import PrefabWaiter
  113. from editor_python_test_tools.utils import Report, Tracer, TestHelper
  114. from Atom.atom_utils.atom_constants import AtomComponentProperties, DISPLAY_MAPPER_PRESET, DISPLAY_MAPPER_OPERATION_TYPE
  115. with Tracer() as error_tracer:
  116. # Test setup begins.
  117. # Setup: Wait for Editor idle loop before executing Python hydra scripts then open "Base" level.
  118. TestHelper.init_idle()
  119. TestHelper.open_level("Graphics", "base_empty")
  120. # Test steps begin.
  121. # 1. Add Display Mapper level component to the level entity.
  122. display_mapper_component = EditorLevelEntity.add_component(AtomComponentProperties.display_mapper())
  123. PrefabWaiter.wait_for_propagation()
  124. Report.critical_result(
  125. Tests.display_mapper_component,
  126. EditorLevelEntity.has_component(AtomComponentProperties.display_mapper()))
  127. # 2. UNDO the level component addition.
  128. # -> UNDO component addition.
  129. general.undo()
  130. PrefabWaiter.wait_for_propagation()
  131. Report.result(Tests.creation_undo, not EditorLevelEntity.has_component(AtomComponentProperties.display_mapper()))
  132. # 3. REDO the level component addition.
  133. # -> REDO component addition.
  134. general.redo()
  135. PrefabWaiter.wait_for_propagation()
  136. Report.result(Tests.creation_redo, EditorLevelEntity.has_component(AtomComponentProperties.display_mapper()))
  137. # 4. Set LDR color Grading LUT asset.
  138. display_mapper_asset_path = os.path.join("lookuptables", "lut_sepia.azasset")
  139. display_mapper_asset = Asset.find_asset_by_path(display_mapper_asset_path, False)
  140. display_mapper_component.set_component_property_value(
  141. AtomComponentProperties.display_mapper('LDR color Grading LUT'), display_mapper_asset.id)
  142. Report.result(
  143. Tests.ldr_color_grading_lut,
  144. display_mapper_component.get_component_property_value(
  145. AtomComponentProperties.display_mapper('LDR color Grading LUT')) == display_mapper_asset.id)
  146. for operation_type in DISPLAY_MAPPER_OPERATION_TYPE.keys():
  147. # 5. Set the Display Mapper Operation Type enumerated in DISPLAY_MAPPER_OPERATION_TYPE for each type
  148. display_mapper_component.set_component_property_value(
  149. AtomComponentProperties.display_mapper('Type'), DISPLAY_MAPPER_OPERATION_TYPE[operation_type])
  150. general.idle_wait_frames(3)
  151. set_type = render.DisplayMapperComponentRequestBus(bus.Broadcast, "GetDisplayMapperOperationType")
  152. Report.info(f"DiplayMapperOperationType: {set_type}")
  153. Report.result(Tests.display_mapper_type, set_type == DISPLAY_MAPPER_OPERATION_TYPE[operation_type])
  154. # 6. Set Enable LDR color grading LUT property True
  155. display_mapper_component.set_component_property_value(
  156. AtomComponentProperties.display_mapper('Enable LDR color grading LUT'), True)
  157. Report.result(
  158. Tests.enable_ldr_color_grading_lut,
  159. display_mapper_component.get_component_property_value(
  160. AtomComponentProperties.display_mapper('Enable LDR color grading LUT')) is True)
  161. # 7. Toggle Override Defaults
  162. # Set Override Defaults to False
  163. display_mapper_component.set_component_property_value(
  164. AtomComponentProperties.display_mapper('Override Defaults'), False)
  165. Report.result(
  166. Tests.override_defaults,
  167. display_mapper_component.get_component_property_value(
  168. AtomComponentProperties.display_mapper('Override Defaults')) is False)
  169. # Set Override Defaults to True
  170. display_mapper_component.set_component_property_value(
  171. AtomComponentProperties.display_mapper('Override Defaults'), True)
  172. Report.result(
  173. Tests.override_defaults,
  174. display_mapper_component.get_component_property_value(
  175. AtomComponentProperties.display_mapper('Override Defaults')) is True)
  176. # 8. Toggle Alter Surround
  177. # Set Alter Surround to True
  178. display_mapper_component.set_component_property_value(
  179. AtomComponentProperties.display_mapper('Alter Surround'), True)
  180. Report.result(
  181. Tests.alter_surround,
  182. display_mapper_component.get_component_property_value(
  183. AtomComponentProperties.display_mapper('Alter Surround')) is True)
  184. # Set Alter Surround to False
  185. display_mapper_component.set_component_property_value(
  186. AtomComponentProperties.display_mapper('Alter Surround'), False)
  187. Report.result(
  188. Tests.alter_surround,
  189. display_mapper_component.get_component_property_value(
  190. AtomComponentProperties.display_mapper('Alter Surround')) is False)
  191. # 9. Toggle Alter Desaturation
  192. # Set Alter Desaturation to True
  193. display_mapper_component.set_component_property_value(
  194. AtomComponentProperties.display_mapper('Alter Desaturation'), True)
  195. Report.result(
  196. Tests.alter_desaturation,
  197. display_mapper_component.get_component_property_value(
  198. AtomComponentProperties.display_mapper('Alter Desaturation')) is True)
  199. # Set Alter Desaturation to False
  200. display_mapper_component.set_component_property_value(
  201. AtomComponentProperties.display_mapper('Alter Desaturation'), False)
  202. Report.result(
  203. Tests.alter_desaturation,
  204. display_mapper_component.get_component_property_value(
  205. AtomComponentProperties.display_mapper('Alter Desaturation')) is False)
  206. # 10. Toggle 'Alter CAT D60 to D65'
  207. # Set 'Alter CAT D60 to D65' to True
  208. display_mapper_component.set_component_property_value(
  209. AtomComponentProperties.display_mapper('Alter CAT D60 to D65'), True)
  210. Report.result(
  211. Tests.alter_cat,
  212. display_mapper_component.get_component_property_value(
  213. AtomComponentProperties.display_mapper('Alter CAT D60 to D65')) is True)
  214. # Set 'Alter CAT D60 to D65' to False
  215. display_mapper_component.set_component_property_value(
  216. AtomComponentProperties.display_mapper('Alter CAT D60 to D65'), False)
  217. Report.result(
  218. Tests.alter_cat,
  219. display_mapper_component.get_component_property_value(
  220. AtomComponentProperties.display_mapper('Alter CAT D60 to D65')) is False)
  221. general.idle_wait_frames(1)
  222. # 11. Set 'Cinema Limit (black)' max value which is dynamic based on Cinema Limit (white) then min value
  223. # set max value
  224. display_mapper_component.set_component_property_value(
  225. AtomComponentProperties.display_mapper('Cinema Limit (black)'), value=48.0)
  226. Report.result(Tests.black_level_max, Math_IsClose(display_mapper_component.get_component_property_value(
  227. AtomComponentProperties.display_mapper('Cinema Limit (black)')), 48.0, TOLERANCE))
  228. # set min value
  229. display_mapper_component.set_component_property_value(
  230. AtomComponentProperties.display_mapper('Cinema Limit (black)'), value=0.02)
  231. Report.result(Tests.black_level_min, Math_IsClose(display_mapper_component.get_component_property_value(
  232. AtomComponentProperties.display_mapper('Cinema Limit (black)')), 0.02, TOLERANCE))
  233. # 12. Set 'Cinema Limit (white)' maximum value then min, and finally back to default
  234. # set max value
  235. display_mapper_component.set_component_property_value(
  236. AtomComponentProperties.display_mapper('Cinema Limit (white)'), value=4000.0)
  237. Report.result(Tests.white_level_max, Math_IsClose(display_mapper_component.get_component_property_value(
  238. AtomComponentProperties.display_mapper('Cinema Limit (white)')), 4000.0, TOLERANCE))
  239. # Set min value which is dynamic based on Cinema Limit (black)
  240. display_mapper_component.set_component_property_value(
  241. AtomComponentProperties.display_mapper('Cinema Limit (white)'), value=0.02)
  242. Report.result(Tests.white_level_min, Math_IsClose(display_mapper_component.get_component_property_value(
  243. AtomComponentProperties.display_mapper('Cinema Limit (white)')), 0.02, TOLERANCE))
  244. # Reset this to the default 48 so following cycles don't impact Cinema Limit (Black)
  245. display_mapper_component.set_component_property_value(
  246. AtomComponentProperties.display_mapper('Cinema Limit (white)'), value=48.0)
  247. # 13. Set 'Min Point (luminance)' to high and low value
  248. # set high value
  249. display_mapper_component.set_component_property_value(
  250. AtomComponentProperties.display_mapper('Min Point (luminance)'), value=4.8)
  251. Report.info(display_mapper_component.get_component_property_value(
  252. AtomComponentProperties.display_mapper('Min Point (luminance)')))
  253. Report.result(Tests.luminance_level_min, Math_IsClose(display_mapper_component.get_component_property_value(
  254. AtomComponentProperties.display_mapper('Min Point (luminance)')), 4.8, TOLERANCE))
  255. # set low value
  256. display_mapper_component.set_component_property_value(
  257. AtomComponentProperties.display_mapper('Min Point (luminance)'), value=0.002)
  258. Report.result(Tests.luminance_level_min, Math_IsClose(display_mapper_component.get_component_property_value(
  259. AtomComponentProperties.display_mapper('Min Point (luminance)')), 0.002, TOLERANCE))
  260. # 14. Set 'Mid Point (luminance)' to high and low value then set default
  261. # set high value
  262. display_mapper_component.set_component_property_value(
  263. AtomComponentProperties.display_mapper('Mid Point (luminance)'), value=1005.0)
  264. Report.result(Tests.luminance_level_mid, Math_IsClose(display_mapper_component.get_component_property_value(
  265. AtomComponentProperties.display_mapper('Mid Point (luminance)')), 1005.0, TOLERANCE))
  266. # set low value
  267. display_mapper_component.set_component_property_value(
  268. AtomComponentProperties.display_mapper('Mid Point (luminance)'), value=0.002)
  269. Report.result(Tests.luminance_level_mid, Math_IsClose(display_mapper_component.get_component_property_value(
  270. AtomComponentProperties.display_mapper('Mid Point (luminance)')), 0.002, TOLERANCE))
  271. # restore the default since as this impacts the range of 'Min Point (luminance)'
  272. display_mapper_component.set_component_property_value(
  273. AtomComponentProperties.display_mapper('Mid Point (luminance)'), value=4.8)
  274. # 15. Set 'Max Point (luminance)' to high and low value then set default
  275. # set a high value
  276. display_mapper_component.set_component_property_value(
  277. AtomComponentProperties.display_mapper('Max Point (luminance)'), value=4000.0)
  278. Report.result(Tests.luminance_level_max, Math_IsClose(display_mapper_component.get_component_property_value(
  279. AtomComponentProperties.display_mapper('Max Point (luminance)')), 4000.0, TOLERANCE))
  280. # set a low value
  281. display_mapper_component.set_component_property_value(
  282. AtomComponentProperties.display_mapper('Max Point (luminance)'), value=0.002)
  283. Report.result(Tests.luminance_level_max, Math_IsClose(display_mapper_component.get_component_property_value(
  284. AtomComponentProperties.display_mapper('Max Point (luminance)')), 0.002, TOLERANCE))
  285. # restore the default since this impacts the range of 'Mid Point (luminance)'
  286. display_mapper_component.set_component_property_value(
  287. AtomComponentProperties.display_mapper('Max Point (luminance)'), value=1005.7191162)
  288. # 16. Set 'Surround Gamma' to high and low value
  289. # set a high value
  290. display_mapper_component.set_component_property_value(
  291. AtomComponentProperties.display_mapper('Surround Gamma'), value=1.2)
  292. Report.result(Tests.surround_gamma, Math_IsClose(display_mapper_component.get_component_property_value(
  293. AtomComponentProperties.display_mapper('Surround Gamma')), 1.2, TOLERANCE))
  294. # set a low value
  295. display_mapper_component.set_component_property_value(
  296. AtomComponentProperties.display_mapper('Surround Gamma'), value=0.6)
  297. Report.result(Tests.surround_gamma, Math_IsClose(display_mapper_component.get_component_property_value(
  298. AtomComponentProperties.display_mapper('Surround Gamma')), 0.6, TOLERANCE))
  299. # 17. Set 'Gamma' to high and low value
  300. # set a high value
  301. display_mapper_component.set_component_property_value(
  302. AtomComponentProperties.display_mapper('Gamma'), value=4.0)
  303. Report.result(Tests.gamma, Math_IsClose(display_mapper_component.get_component_property_value(
  304. AtomComponentProperties.display_mapper('Gamma')), 4.0, TOLERANCE))
  305. # set a low value
  306. display_mapper_component.set_component_property_value(
  307. AtomComponentProperties.display_mapper('Gamma'), value=0.2)
  308. Report.result(Tests.gamma, Math_IsClose(display_mapper_component.get_component_property_value(
  309. AtomComponentProperties.display_mapper('Gamma')), 0.2, TOLERANCE))
  310. # 18. Enter/Exit game mode.
  311. TestHelper.enter_game_mode(Tests.enter_game_mode)
  312. general.idle_wait_frames(1)
  313. TestHelper.exit_game_mode(Tests.exit_game_mode)
  314. display_mapper_component.set_component_property_value(
  315. AtomComponentProperties.display_mapper('Enable LDR color grading LUT'), False)
  316. display_mapper_component.set_component_property_value(
  317. AtomComponentProperties.display_mapper('Enable LDR color grading LUT'), True)
  318. cinema_limit_white_presets = [48.0, 184.3200073, 368.6400146, 737.2800293]
  319. for preset in DISPLAY_MAPPER_PRESET.keys():
  320. # 19. Select and load each preset
  321. display_mapper_component.set_component_property_value(
  322. AtomComponentProperties.display_mapper('Preset Selection'), DISPLAY_MAPPER_PRESET[preset])
  323. general.idle_wait_frames(1)
  324. render.DisplayMapperComponentRequestBus(
  325. bus.Broadcast,
  326. "LoadPreset",
  327. display_mapper_component.get_component_property_value(
  328. AtomComponentProperties.display_mapper('Preset Selection')))
  329. general.idle_wait_frames(1)
  330. # check some value to confirm preset loaded
  331. test_preset = (f"Preset {preset} loaded expected value",
  332. f"P1: Preset {preset} failed to load values as expected")
  333. Report.result(test_preset, Math_IsClose(
  334. display_mapper_component.get_component_property_value(
  335. AtomComponentProperties.display_mapper('Cinema Limit (white)')),
  336. cinema_limit_white_presets[DISPLAY_MAPPER_PRESET[preset]], TOLERANCE))
  337. # 20. Look for errors and asserts.
  338. TestHelper.wait_for_condition(lambda: error_tracer.has_errors or error_tracer.has_asserts, 1.0)
  339. for error_info in error_tracer.errors:
  340. Report.info(f"Error: {error_info.filename} {error_info.function} | {error_info.message}")
  341. for assert_info in error_tracer.asserts:
  342. Report.info(f"Assert: {assert_info.filename} {assert_info.function} | {assert_info.message}")
  343. if __name__ == "__main__":
  344. from editor_python_test_tools.utils import Report
  345. Report.start_test(AtomEditorComponentsLevel_DisplayMapper_AddedToEntity)