GradientSignalTestFixtures.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  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. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <Tests/GradientSignalTestFixtures.h>
  9. #include <Tests/GradientSignalTestHelpers.h>
  10. #include <Atom/RPI.Public/Image/ImageSystem.h>
  11. #include <Atom/RPI.Public/RPISystem.h>
  12. #include <Common/RHI/Factory.h>
  13. #include <Common/RHI/Stubs.h>
  14. #include <Atom/RPI.Reflect/Image/ImageMipChainAsset.h>
  15. #include <Atom/RPI.Reflect/Image/StreamingImageAssetHandler.h>
  16. #include <AzFramework/Components/TransformComponent.h>
  17. #include <GradientSignal/Components/GradientSurfaceDataComponent.h>
  18. #include <GradientSignal/Components/GradientTransformComponent.h>
  19. #include <LmbrCentral/Shape/BoxShapeComponentBus.h>
  20. #include <LmbrCentral/Shape/SphereShapeComponentBus.h>
  21. #include <SurfaceData/Components/SurfaceDataShapeComponent.h>
  22. #include <SurfaceData/Components/SurfaceDataSystemComponent.h>
  23. // Base gradient components
  24. #include <GradientSignal/Components/ConstantGradientComponent.h>
  25. #include <GradientSignal/Components/ImageGradientComponent.h>
  26. #include <GradientSignal/Components/PerlinGradientComponent.h>
  27. #include <GradientSignal/Components/RandomGradientComponent.h>
  28. #include <GradientSignal/Components/ShapeAreaFalloffGradientComponent.h>
  29. // Gradient modifier components
  30. #include <GradientSignal/Components/DitherGradientComponent.h>
  31. #include <GradientSignal/Components/InvertGradientComponent.h>
  32. #include <GradientSignal/Components/LevelsGradientComponent.h>
  33. #include <GradientSignal/Components/MixedGradientComponent.h>
  34. #include <GradientSignal/Components/PosterizeGradientComponent.h>
  35. #include <GradientSignal/Components/ReferenceGradientComponent.h>
  36. #include <GradientSignal/Components/SmoothStepGradientComponent.h>
  37. #include <GradientSignal/Components/ThresholdGradientComponent.h>
  38. // Gradient surface data components
  39. #include <GradientSignal/Components/SurfaceAltitudeGradientComponent.h>
  40. #include <GradientSignal/Components/SurfaceMaskGradientComponent.h>
  41. #include <GradientSignal/Components/SurfaceSlopeGradientComponent.h>
  42. namespace UnitTest
  43. {
  44. void GradientSignalTestEnvironment::AddGemsAndComponents()
  45. {
  46. AddDynamicModulePaths({ "LmbrCentral", "SurfaceData" });
  47. AddComponentDescriptors({
  48. AzFramework::TransformComponent::CreateDescriptor(),
  49. GradientSignal::ConstantGradientComponent::CreateDescriptor(),
  50. GradientSignal::DitherGradientComponent::CreateDescriptor(),
  51. GradientSignal::GradientSurfaceDataComponent::CreateDescriptor(),
  52. GradientSignal::GradientTransformComponent::CreateDescriptor(),
  53. GradientSignal::ImageGradientComponent::CreateDescriptor(),
  54. GradientSignal::InvertGradientComponent::CreateDescriptor(),
  55. GradientSignal::LevelsGradientComponent::CreateDescriptor(),
  56. GradientSignal::MixedGradientComponent::CreateDescriptor(),
  57. GradientSignal::PerlinGradientComponent::CreateDescriptor(),
  58. GradientSignal::PosterizeGradientComponent::CreateDescriptor(),
  59. GradientSignal::RandomGradientComponent::CreateDescriptor(),
  60. GradientSignal::ReferenceGradientComponent::CreateDescriptor(),
  61. GradientSignal::ShapeAreaFalloffGradientComponent::CreateDescriptor(),
  62. GradientSignal::SmoothStepGradientComponent::CreateDescriptor(),
  63. GradientSignal::SurfaceAltitudeGradientComponent::CreateDescriptor(),
  64. GradientSignal::SurfaceMaskGradientComponent::CreateDescriptor(),
  65. GradientSignal::SurfaceSlopeGradientComponent::CreateDescriptor(),
  66. GradientSignal::ThresholdGradientComponent::CreateDescriptor(),
  67. MockShapeComponent::CreateDescriptor(),
  68. MockSurfaceProviderComponent::CreateDescriptor(),
  69. MockGradientSignal::CreateDescriptor()
  70. });
  71. }
  72. void GradientSignalTestEnvironment::PostCreateApplication()
  73. {
  74. // Ebus usage will allocate a global context on first usage. If that first usage occurs in a DLL, then the context will be
  75. // invalid on subsequent unit test runs if using gtest_repeat. However, if we force the ebus to create their global context in
  76. // the main test DLL (this one), the context will remain active throughout repeated runs. By creating them in
  77. // PostCreateApplication(), they will be created before the DLLs get loaded and any system components from those DLLs run, so we
  78. // can guarantee this will be the first usage.
  79. // These ebuses need their contexts created here before any of the dependent DLLs get loaded:
  80. AZ::AssetTypeInfoBus::GetOrCreateContext();
  81. SurfaceData::SurfaceDataSystemRequestBus::GetOrCreateContext();
  82. SurfaceData::SurfaceDataProviderRequestBus::GetOrCreateContext();
  83. SurfaceData::SurfaceDataModifierRequestBus::GetOrCreateContext();
  84. LmbrCentral::ShapeComponentRequestsBus::GetOrCreateContext();
  85. }
  86. GradientSignalBaseFixture::GradientSignalBaseFixture()
  87. {
  88. // Even though this is an empty function, it needs to appear here so that the destruction code for the unique pointers
  89. // is created here instead of inline wherever the GradientSignalTest class is used. This lets us keep the #includes for
  90. // these Atom classes private to this file instead of exposing them outward through the header and requiring everything
  91. // using this class to include the Atom libs as well.
  92. }
  93. GradientSignalBaseFixture::~GradientSignalBaseFixture()
  94. {
  95. // This also needs to appear here, even though it's an empty function.
  96. }
  97. void GradientSignalBaseFixture::SetupCoreSystems()
  98. {
  99. // Create a stub RHI for use by Atom
  100. m_rhiFactory.reset(aznew UnitTest::StubRHI::Factory());
  101. // Create the Atom RPISystem
  102. AZ::RPI::RPISystemDescriptor rpiSystemDescriptor;
  103. m_rpiSystem = AZStd::make_unique<AZ::RPI::RPISystem>();
  104. m_rpiSystem->Initialize(rpiSystemDescriptor);
  105. AZ::RPI::ImageSystemDescriptor imageSystemDescriptor;
  106. m_imageSystem = AZStd::make_unique<AZ::RPI::ImageSystem>();
  107. m_imageSystem->Init(imageSystemDescriptor);
  108. }
  109. void GradientSignalBaseFixture::TearDownCoreSystems()
  110. {
  111. m_imageSystem->Shutdown();
  112. m_rpiSystem->Shutdown();
  113. m_imageSystem = nullptr;
  114. m_rpiSystem = nullptr;
  115. m_rhiFactory = nullptr;
  116. AzFramework::LegacyAssetEventBus::ClearQueuedEvents();
  117. }
  118. AZStd::unique_ptr<AZ::Entity> GradientSignalBaseFixture::CreateTestEntity(float shapeHalfBounds)
  119. {
  120. // Create the base entity
  121. AZStd::unique_ptr<AZ::Entity> testEntity = CreateEntity();
  122. LmbrCentral::BoxShapeConfig boxConfig(AZ::Vector3(shapeHalfBounds * 2.0f));
  123. auto boxComponent = testEntity->CreateComponent(LmbrCentral::AxisAlignedBoxShapeComponentTypeId);
  124. boxComponent->SetConfiguration(boxConfig);
  125. // Create a transform that locates our gradient in the center of our desired Shape.
  126. auto transform = testEntity->CreateComponent<AzFramework::TransformComponent>();
  127. transform->SetWorldTM(AZ::Transform::CreateTranslation(AZ::Vector3(shapeHalfBounds)));
  128. return testEntity;
  129. }
  130. AZStd::unique_ptr<AZ::Entity> GradientSignalBaseFixture::CreateTestSphereEntity(float shapeRadius)
  131. {
  132. // Create the base entity
  133. AZStd::unique_ptr<AZ::Entity> testEntity = CreateEntity();
  134. LmbrCentral::SphereShapeConfig sphereConfig(shapeRadius);
  135. auto sphereComponent = testEntity->CreateComponent(LmbrCentral::SphereShapeComponentTypeId);
  136. sphereComponent->SetConfiguration(sphereConfig);
  137. // Create a transform that locates our gradient in the center of our desired Shape.
  138. auto transform = testEntity->CreateComponent<AzFramework::TransformComponent>();
  139. transform->SetWorldTM(AZ::Transform::CreateTranslation(AZ::Vector3(shapeRadius)));
  140. return testEntity;
  141. }
  142. AZStd::unique_ptr<AZ::Entity> GradientSignalBaseFixture::BuildTestConstantGradient(float shapeHalfBounds, float value)
  143. {
  144. // Create a Constant Gradient Component with arbitrary parameters.
  145. auto entity = CreateTestEntity(shapeHalfBounds);
  146. GradientSignal::ConstantGradientConfig config;
  147. config.m_value = value;
  148. entity->CreateComponent<GradientSignal::ConstantGradientComponent>(config);
  149. ActivateEntity(entity.get());
  150. return entity;
  151. }
  152. AZStd::unique_ptr<AZ::Entity> GradientSignalBaseFixture::BuildTestImageGradient(float shapeHalfBounds)
  153. {
  154. // Create an Image Gradient Component with arbitrary sizes and parameters.
  155. auto entity = CreateTestEntity(shapeHalfBounds);
  156. GradientSignal::ImageGradientConfig config;
  157. const uint32_t imageSize = 4096;
  158. const int32_t imageSeed = 12345;
  159. config.m_imageAsset = UnitTest::CreateImageAsset(imageSize, imageSize, imageSeed);
  160. config.m_tiling = AZ::Vector2::CreateOne();
  161. entity->CreateComponent<GradientSignal::ImageGradientComponent>(config);
  162. // Create a Gradient Transform Component with arbitrary parameters.
  163. GradientSignal::GradientTransformConfig gradientTransformConfig;
  164. gradientTransformConfig.m_wrappingType = GradientSignal::WrappingType::None;
  165. entity->CreateComponent<GradientSignal::GradientTransformComponent>(gradientTransformConfig);
  166. ActivateEntity(entity.get());
  167. return entity;
  168. }
  169. AZStd::unique_ptr<AZ::Entity> GradientSignalBaseFixture::BuildTestPerlinGradient(float shapeHalfBounds)
  170. {
  171. // Create a Perlin Gradient Component with arbitrary parameters.
  172. auto entity = CreateTestEntity(shapeHalfBounds);
  173. GradientSignal::PerlinGradientConfig config;
  174. config.m_amplitude = 1.0f;
  175. config.m_frequency = 1.1f;
  176. config.m_octave = 4;
  177. config.m_randomSeed = 12345;
  178. entity->CreateComponent<GradientSignal::PerlinGradientComponent>(config);
  179. // Create a Gradient Transform Component with arbitrary parameters.
  180. GradientSignal::GradientTransformConfig gradientTransformConfig;
  181. gradientTransformConfig.m_wrappingType = GradientSignal::WrappingType::None;
  182. entity->CreateComponent<GradientSignal::GradientTransformComponent>(gradientTransformConfig);
  183. ActivateEntity(entity.get());
  184. return entity;
  185. }
  186. AZStd::unique_ptr<AZ::Entity> GradientSignalBaseFixture::BuildTestRandomGradient(float shapeHalfBounds)
  187. {
  188. // Create a Random Gradient Component with arbitrary parameters.
  189. auto entity = CreateTestEntity(shapeHalfBounds);
  190. GradientSignal::RandomGradientConfig config;
  191. config.m_randomSeed = 12345;
  192. entity->CreateComponent<GradientSignal::RandomGradientComponent>(config);
  193. // Create a Gradient Transform Component with arbitrary parameters.
  194. GradientSignal::GradientTransformConfig gradientTransformConfig;
  195. gradientTransformConfig.m_wrappingType = GradientSignal::WrappingType::None;
  196. entity->CreateComponent<GradientSignal::GradientTransformComponent>(gradientTransformConfig);
  197. ActivateEntity(entity.get());
  198. return entity;
  199. }
  200. AZStd::unique_ptr<AZ::Entity> GradientSignalBaseFixture::BuildTestShapeAreaFalloffGradient(float shapeHalfBounds)
  201. {
  202. // Create a Shape Area Falloff Gradient Component with arbitrary parameters.
  203. auto entity = CreateTestEntity(shapeHalfBounds);
  204. GradientSignal::ShapeAreaFalloffGradientConfig config;
  205. config.m_shapeEntityId = entity->GetId();
  206. config.m_falloffWidth = 16.0f;
  207. config.m_falloffType = GradientSignal::FalloffType::InnerOuter;
  208. entity->CreateComponent<GradientSignal::ShapeAreaFalloffGradientComponent>(config);
  209. ActivateEntity(entity.get());
  210. return entity;
  211. }
  212. AZStd::unique_ptr<AZ::Entity> GradientSignalBaseFixture::BuildTestDitherGradient(
  213. float shapeHalfBounds, const AZ::EntityId& inputGradientId)
  214. {
  215. // Create a Dither Gradient Component with arbitrary parameters.
  216. auto entity = CreateTestEntity(shapeHalfBounds);
  217. GradientSignal::DitherGradientConfig config;
  218. config.m_gradientSampler.m_gradientId = inputGradientId;
  219. config.m_useSystemPointsPerUnit = false;
  220. // Use a number other than 1.0f for pointsPerUnit to ensure the dither math is getting exercised properly.
  221. config.m_pointsPerUnit = 0.25f;
  222. config.m_patternOffset = AZ::Vector3::CreateZero();
  223. config.m_patternType = GradientSignal::DitherGradientConfig::BayerPatternType::PATTERN_SIZE_4x4;
  224. entity->CreateComponent<GradientSignal::DitherGradientComponent>(config);
  225. ActivateEntity(entity.get());
  226. return entity;
  227. }
  228. AZStd::unique_ptr<AZ::Entity> GradientSignalBaseFixture::BuildTestInvertGradient(
  229. float shapeHalfBounds, const AZ::EntityId& inputGradientId)
  230. {
  231. // Create an Invert Gradient Component.
  232. auto entity = CreateTestEntity(shapeHalfBounds);
  233. GradientSignal::InvertGradientConfig config;
  234. config.m_gradientSampler.m_gradientId = inputGradientId;
  235. entity->CreateComponent<GradientSignal::InvertGradientComponent>(config);
  236. ActivateEntity(entity.get());
  237. return entity;
  238. }
  239. AZStd::unique_ptr<AZ::Entity> GradientSignalBaseFixture::BuildTestLevelsGradient(
  240. float shapeHalfBounds, const AZ::EntityId& inputGradientId)
  241. {
  242. // Create a Levels Gradient Component with arbitrary parameters.
  243. auto entity = CreateTestEntity(shapeHalfBounds);
  244. GradientSignal::LevelsGradientConfig config;
  245. config.m_gradientSampler.m_gradientId = inputGradientId;
  246. config.m_inputMin = 0.1f;
  247. config.m_inputMid = 0.3f;
  248. config.m_inputMax = 0.9f;
  249. config.m_outputMin = 0.0f;
  250. config.m_outputMax = 1.0f;
  251. entity->CreateComponent<GradientSignal::LevelsGradientComponent>(config);
  252. ActivateEntity(entity.get());
  253. return entity;
  254. }
  255. AZStd::unique_ptr<AZ::Entity> GradientSignalBaseFixture::BuildTestMixedGradient(
  256. float shapeHalfBounds, const AZ::EntityId& baseGradientId, const AZ::EntityId& mixedGradientId)
  257. {
  258. // Create a Mixed Gradient Component that mixes two input gradients together in arbitrary ways.
  259. auto entity = CreateTestEntity(shapeHalfBounds);
  260. GradientSignal::MixedGradientConfig config;
  261. GradientSignal::MixedGradientLayer layer;
  262. layer.m_enabled = true;
  263. layer.m_operation = GradientSignal::MixedGradientLayer::MixingOperation::Initialize;
  264. layer.m_gradientSampler.m_gradientId = baseGradientId;
  265. layer.m_gradientSampler.m_opacity = 1.0f;
  266. config.m_layers.push_back(layer);
  267. layer.m_operation = GradientSignal::MixedGradientLayer::MixingOperation::Overlay;
  268. layer.m_gradientSampler.m_gradientId = mixedGradientId;
  269. layer.m_gradientSampler.m_opacity = 0.75f;
  270. config.m_layers.push_back(layer);
  271. entity->CreateComponent<GradientSignal::MixedGradientComponent>(config);
  272. ActivateEntity(entity.get());
  273. return entity;
  274. }
  275. AZStd::unique_ptr<AZ::Entity> GradientSignalBaseFixture::BuildTestPosterizeGradient(
  276. float shapeHalfBounds, const AZ::EntityId& inputGradientId)
  277. {
  278. // Create a Posterize Gradient Component with arbitrary parameters.
  279. auto entity = CreateTestEntity(shapeHalfBounds);
  280. GradientSignal::PosterizeGradientConfig config;
  281. config.m_gradientSampler.m_gradientId = inputGradientId;
  282. config.m_mode = GradientSignal::PosterizeGradientConfig::ModeType::Ps;
  283. config.m_bands = 5;
  284. entity->CreateComponent<GradientSignal::PosterizeGradientComponent>(config);
  285. ActivateEntity(entity.get());
  286. return entity;
  287. }
  288. AZStd::unique_ptr<AZ::Entity> GradientSignalBaseFixture::BuildTestReferenceGradient(
  289. float shapeHalfBounds, const AZ::EntityId& inputGradientId)
  290. {
  291. // Create a Reference Gradient Component.
  292. auto entity = CreateTestEntity(shapeHalfBounds);
  293. GradientSignal::ReferenceGradientConfig config;
  294. config.m_gradientSampler.m_gradientId = inputGradientId;
  295. config.m_gradientSampler.m_ownerEntityId = entity->GetId();
  296. entity->CreateComponent<GradientSignal::ReferenceGradientComponent>(config);
  297. ActivateEntity(entity.get());
  298. return entity;
  299. }
  300. AZStd::unique_ptr<AZ::Entity> GradientSignalBaseFixture::BuildTestSmoothStepGradient(
  301. float shapeHalfBounds, const AZ::EntityId& inputGradientId)
  302. {
  303. // Create a Smooth Step Gradient Component with arbitrary parameters.
  304. auto entity = CreateTestEntity(shapeHalfBounds);
  305. GradientSignal::SmoothStepGradientConfig config;
  306. config.m_gradientSampler.m_gradientId = inputGradientId;
  307. config.m_smoothStep.m_falloffMidpoint = 0.75f;
  308. config.m_smoothStep.m_falloffRange = 0.125f;
  309. config.m_smoothStep.m_falloffStrength = 0.25f;
  310. entity->CreateComponent<GradientSignal::SmoothStepGradientComponent>(config);
  311. ActivateEntity(entity.get());
  312. return entity;
  313. }
  314. AZStd::unique_ptr<AZ::Entity> GradientSignalBaseFixture::BuildTestThresholdGradient(
  315. float shapeHalfBounds, const AZ::EntityId& inputGradientId)
  316. {
  317. // Create a Threshold Gradient Component with arbitrary parameters.
  318. auto entity = CreateTestEntity(shapeHalfBounds);
  319. GradientSignal::ThresholdGradientConfig config;
  320. config.m_gradientSampler.m_gradientId = inputGradientId;
  321. config.m_threshold = 0.75f;
  322. entity->CreateComponent<GradientSignal::ThresholdGradientComponent>(config);
  323. ActivateEntity(entity.get());
  324. return entity;
  325. }
  326. AZStd::unique_ptr<AZ::Entity> GradientSignalBaseFixture::BuildTestSurfaceAltitudeGradient(float shapeHalfBounds)
  327. {
  328. // Create a Surface Altitude Gradient Component with arbitrary parameters.
  329. auto entity = CreateTestSphereEntity(shapeHalfBounds);
  330. GradientSignal::SurfaceAltitudeGradientConfig config;
  331. config.m_altitudeMin = -5.0f;
  332. config.m_altitudeMax = 15.0f + (shapeHalfBounds * 2.0f);
  333. entity->CreateComponent<GradientSignal::SurfaceAltitudeGradientComponent>(config);
  334. // Create a SurfaceDataShape component to provide surface points from this component.
  335. SurfaceData::SurfaceDataShapeConfig shapeConfig;
  336. shapeConfig.m_providerTags.emplace_back("test_mask");
  337. auto surfaceShapeComponent = entity->CreateComponent(azrtti_typeid<SurfaceData::SurfaceDataShapeComponent>());
  338. surfaceShapeComponent->SetConfiguration(shapeConfig);
  339. ActivateEntity(entity.get());
  340. return entity;
  341. }
  342. AZStd::unique_ptr<AZ::Entity> GradientSignalBaseFixture::BuildTestSurfaceMaskGradient(float shapeHalfBounds)
  343. {
  344. // Create a Surface Mask Gradient Component with arbitrary parameters.
  345. auto entity = CreateTestSphereEntity(shapeHalfBounds);
  346. GradientSignal::SurfaceMaskGradientConfig config;
  347. config.m_surfaceTagList.push_back(AZ_CRC_CE("test_mask"));
  348. entity->CreateComponent<GradientSignal::SurfaceMaskGradientComponent>(config);
  349. // Create a SurfaceDataShape component to provide surface points from this component.
  350. SurfaceData::SurfaceDataShapeConfig shapeConfig;
  351. shapeConfig.m_providerTags.emplace_back("test_mask");
  352. auto surfaceShapeComponent = entity->CreateComponent(azrtti_typeid<SurfaceData::SurfaceDataShapeComponent>());
  353. surfaceShapeComponent->SetConfiguration(shapeConfig);
  354. ActivateEntity(entity.get());
  355. return entity;
  356. }
  357. AZStd::unique_ptr<AZ::Entity> GradientSignalBaseFixture::BuildTestSurfaceSlopeGradient(float shapeHalfBounds)
  358. {
  359. // Create a Surface Slope Gradient Component with arbitrary parameters.
  360. auto entity = CreateTestSphereEntity(shapeHalfBounds);
  361. GradientSignal::SurfaceSlopeGradientConfig config;
  362. config.m_slopeMin = 5.0f;
  363. config.m_slopeMax = 50.0f;
  364. config.m_rampType = GradientSignal::SurfaceSlopeGradientConfig::RampType::SMOOTH_STEP;
  365. config.m_smoothStep.m_falloffMidpoint = 0.75f;
  366. config.m_smoothStep.m_falloffRange = 0.125f;
  367. config.m_smoothStep.m_falloffStrength = 0.25f;
  368. entity->CreateComponent<GradientSignal::SurfaceSlopeGradientComponent>(config);
  369. // Create a SurfaceDataShape component to provide surface points from this component.
  370. SurfaceData::SurfaceDataShapeConfig shapeConfig;
  371. shapeConfig.m_providerTags.emplace_back("test_mask");
  372. auto surfaceShapeComponent = entity->CreateComponent(azrtti_typeid<SurfaceData::SurfaceDataShapeComponent>());
  373. surfaceShapeComponent->SetConfiguration(shapeConfig);
  374. ActivateEntity(entity.get());
  375. return entity;
  376. }
  377. void GradientSignalTest::SetUp()
  378. {
  379. SetupCoreSystems();
  380. }
  381. void GradientSignalTest::TearDown()
  382. {
  383. TearDownCoreSystems();
  384. }
  385. void GradientSignalTest::TestFixedDataSampler(const AZStd::vector<float>& expectedOutput, int size, AZ::EntityId gradientEntityId)
  386. {
  387. GradientSignal::GradientSampler gradientSampler;
  388. gradientSampler.m_gradientId = gradientEntityId;
  389. TestFixedDataSampler(expectedOutput, size, gradientSampler);
  390. }
  391. void GradientSignalTest::TestFixedDataSampler(
  392. const AZStd::vector<float>& expectedOutput, int size, GradientSignal::GradientSampler& gradientSampler)
  393. {
  394. for (int y = 0; y < size; ++y)
  395. {
  396. for (int x = 0; x < size; ++x)
  397. {
  398. GradientSignal::GradientSampleParams params;
  399. params.m_position = AZ::Vector3(static_cast<float>(x), static_cast<float>(y), 0.0f);
  400. const int index = y * size + x;
  401. float actualValue = gradientSampler.GetValue(params);
  402. float expectedValue = expectedOutput[index];
  403. EXPECT_NEAR(actualValue, expectedValue, 0.01f);
  404. }
  405. }
  406. }
  407. }