GradientSignalServicesTests.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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 <AzTest/AzTest.h>
  10. #include <AzFramework/Components/TransformComponent.h>
  11. #include <GradientSignal/Components/ConstantGradientComponent.h>
  12. #include <GradientSignal/Components/DitherGradientComponent.h>
  13. #include <GradientSignal/Components/InvertGradientComponent.h>
  14. #include <GradientSignal/Ebuses/ShapeAreaFalloffGradientRequestBus.h>
  15. namespace UnitTest
  16. {
  17. struct GradientSignalServicesTestsFixture
  18. : public GradientSignalTest
  19. {
  20. };
  21. TEST_F(GradientSignalServicesTestsFixture, ConstantGradientComponent_KnownValue)
  22. {
  23. // Given a constant value as input, verify that sampling a set of points all produces that same constant value.
  24. constexpr float dataSize = 8.0f;
  25. constexpr float expectedOutput = 0.123f;
  26. GradientSignal::ConstantGradientConfig config;
  27. config.m_value = expectedOutput;
  28. auto entity = CreateEntity();
  29. entity->CreateComponent<GradientSignal::ConstantGradientComponent>(config);
  30. ActivateEntity(entity.get());
  31. GradientSignal::GradientSampler gradientSampler;
  32. gradientSampler.m_gradientId = entity->GetId();
  33. for (float x = 0.0f; x < dataSize; x++)
  34. {
  35. for (float y = 0.0f; y < dataSize; y++)
  36. {
  37. GradientSignal::GradientSampleParams params;
  38. params.m_position = AZ::Vector3(x, y, 0.0f);
  39. EXPECT_EQ(expectedOutput, gradientSampler.GetValue(params));
  40. }
  41. }
  42. }
  43. TEST_F(GradientSignalServicesTestsFixture, DitherGradientComponent_4x4At50Pct)
  44. {
  45. // With a 4x4 gradient filled with 8/16 (0.5), verify that the resulting dithered output
  46. // is an expected checkerboard pattern with 8 of 16 pixels filled.
  47. constexpr int dataSize = 4;
  48. AZStd::vector<float> inputData(dataSize * dataSize, 8.0f / 16.0f);
  49. AZStd::vector<float> expectedOutput =
  50. {
  51. 1.0f, 0.0f, 1.0f, 0.0f,
  52. 0.0f, 1.0f, 0.0f, 1.0f,
  53. 1.0f, 0.0f, 1.0f, 0.0f,
  54. 0.0f, 1.0f, 0.0f, 1.0f,
  55. };
  56. auto entityMock = CreateEntity();
  57. const AZ::EntityId id = entityMock->GetId();
  58. UnitTest::MockGradientArrayRequestsBus mockGradientRequestsBus(id, inputData, dataSize);
  59. GradientSignal::DitherGradientConfig config;
  60. config.m_useSystemPointsPerUnit = false;
  61. config.m_pointsPerUnit = 1.0f;
  62. config.m_patternOffset = AZ::Vector3::CreateZero();
  63. config.m_patternType = GradientSignal::DitherGradientConfig::BayerPatternType::PATTERN_SIZE_4x4;
  64. config.m_gradientSampler.m_gradientId = entityMock->GetId();
  65. auto entity = CreateEntity();
  66. entity->CreateComponent<GradientSignal::DitherGradientComponent>(config);
  67. ActivateEntity(entity.get());
  68. TestFixedDataSampler(expectedOutput, dataSize, entity->GetId());
  69. }
  70. TEST_F(GradientSignalServicesTestsFixture, DitherGradientComponent_4x4At50Pct_CrossingZero)
  71. {
  72. // With a 4x4 gradient filled with 8/16 (0.5), verify that the resulting dithered output
  73. // is an expected checkerboard pattern with 8 of 16 pixels filled. The pattern offset is
  74. // shifted -2 in the X direction so that the lookups go from [-2, 2) to verify that the
  75. // pattern remains consistent across negative and positive coordinates.
  76. constexpr int dataSize = 4;
  77. AZStd::vector<float> inputData(dataSize * dataSize, 8.0f / 16.0f);
  78. AZStd::vector<float> expectedOutput = {
  79. 1.0f, 0.0f, 1.0f, 0.0f,
  80. 0.0f, 1.0f, 0.0f, 1.0f,
  81. 1.0f, 0.0f, 1.0f, 0.0f,
  82. 0.0f, 1.0f, 0.0f, 1.0f,
  83. };
  84. auto entityMock = CreateEntity();
  85. const AZ::EntityId id = entityMock->GetId();
  86. UnitTest::MockGradientArrayRequestsBus mockGradientRequestsBus(id, inputData, dataSize);
  87. GradientSignal::DitherGradientConfig config;
  88. config.m_useSystemPointsPerUnit = false;
  89. config.m_pointsPerUnit = 1.0f;
  90. config.m_patternOffset = AZ::Vector3(-2.0f, 0.0f, 0.0f);
  91. config.m_patternType = GradientSignal::DitherGradientConfig::BayerPatternType::PATTERN_SIZE_4x4;
  92. config.m_gradientSampler.m_gradientId = entityMock->GetId();
  93. auto entity = CreateEntity();
  94. entity->CreateComponent<GradientSignal::DitherGradientComponent>(config);
  95. ActivateEntity(entity.get());
  96. TestFixedDataSampler(expectedOutput, dataSize, entity->GetId());
  97. }
  98. TEST_F(GradientSignalServicesTestsFixture, DitherGradientComponent_4x4At50Pct_MorePointsPerUnit)
  99. {
  100. // With a 4x4 gradient filled with 8/16 (0.5), and 1/2 point per unit, if we query a 4x4 region,
  101. // we should get a checkerboard in 2x2 blocks of the same value because it takes 2 units before the value changes.
  102. constexpr int dataSize = 4;
  103. AZStd::vector<float> inputData(dataSize * dataSize, 8.0f / 16.0f);
  104. AZStd::vector<float> expectedOutput = {
  105. 1.0f, 1.0f, 0.0f, 0.0f,
  106. 1.0f, 1.0f, 0.0f, 0.0f,
  107. 0.0f, 0.0f, 1.0f, 1.0f,
  108. 0.0f, 0.0f, 1.0f, 1.0f,
  109. };
  110. auto entityMock = CreateEntity();
  111. const AZ::EntityId id = entityMock->GetId();
  112. UnitTest::MockGradientArrayRequestsBus mockGradientRequestsBus(id, inputData, dataSize);
  113. GradientSignal::DitherGradientConfig config;
  114. config.m_useSystemPointsPerUnit = false;
  115. config.m_pointsPerUnit = 0.5f;
  116. config.m_patternOffset = AZ::Vector3::CreateZero();
  117. config.m_patternType = GradientSignal::DitherGradientConfig::BayerPatternType::PATTERN_SIZE_4x4;
  118. config.m_gradientSampler.m_gradientId = entityMock->GetId();
  119. auto entity = CreateEntity();
  120. entity->CreateComponent<GradientSignal::DitherGradientComponent>(config);
  121. ActivateEntity(entity.get());
  122. TestFixedDataSampler(expectedOutput, dataSize, entity->GetId());
  123. }
  124. TEST_F(GradientSignalServicesTestsFixture, DitherGradientComponent_4x4At50Pct_MorePointsAndCrossingZero)
  125. {
  126. // With a 4x4 gradient filled with 8/16 (0.5), and 2 points per unit, verify that querying
  127. // from -1 to 1 produces a constant checkerboard pattern of results as it crosses the 0 boundary.
  128. // Our expected results are a consistent checkerboard pattern, but with 2x2 blocks of the same value because we're
  129. // querying at 2x the point density (i.e. querying 4 points per unit) to ensure that fractional position lookups work too.
  130. float expectedValues[] = {
  131. 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f,
  132. 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f,
  133. 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f,
  134. 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f,
  135. 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f,
  136. 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f,
  137. 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f,
  138. 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f,
  139. };
  140. // Create a 50% constant gradient.
  141. GradientSignal::ConstantGradientConfig constantConfig;
  142. constantConfig.m_value = 8.0f / 16.0f;
  143. auto constantGradientEntity = CreateEntity();
  144. constantGradientEntity->CreateComponent<GradientSignal::ConstantGradientComponent>(constantConfig);
  145. ActivateEntity(constantGradientEntity.get());
  146. GradientSignal::DitherGradientConfig config;
  147. config.m_useSystemPointsPerUnit = false;
  148. config.m_pointsPerUnit = 2.0f;
  149. config.m_patternOffset = AZ::Vector3::CreateZero();
  150. config.m_patternType = GradientSignal::DitherGradientConfig::BayerPatternType::PATTERN_SIZE_4x4;
  151. config.m_gradientSampler.m_gradientId = constantGradientEntity->GetId();
  152. auto entity = CreateEntity();
  153. entity->CreateComponent<GradientSignal::DitherGradientComponent>(config);
  154. ActivateEntity(entity.get());
  155. // Run through [-1, 1) at 1/4 intervals and make sure we get our expected checkerboard. This is testing both that
  156. // we have a consistent pattern across the 0 boundary and that fractional position lookups work correctly
  157. GradientSignal::GradientSampler gradientSampler;
  158. gradientSampler.m_gradientId = entity->GetId();
  159. int expectedValueIndex = 0;
  160. for (float y = -1.0f; y < 1.0f; y += 0.25f)
  161. {
  162. for (float x = -1.0f; x < 1.0f; x += 0.25f)
  163. {
  164. GradientSignal::GradientSampleParams params;
  165. params.m_position = AZ::Vector3(x, y, 0.0f);
  166. float actualValue = gradientSampler.GetValue(params);
  167. float expectedValue = expectedValues[expectedValueIndex++];
  168. EXPECT_NEAR(actualValue, expectedValue, 0.01f);
  169. }
  170. }
  171. }
  172. TEST_F(GradientSignalServicesTestsFixture, DitherGradientComponent_4x4At31Pct)
  173. {
  174. // With a 4x4 gradient filled with 5/16 (0.3125), verify that the resulting dithered output
  175. // has the correct 5 of 16 pixels set
  176. constexpr int dataSize = 4;
  177. AZStd::vector<float> inputData(dataSize * dataSize, 5.0f / 16.0f);
  178. AZStd::vector<float> expectedOutput =
  179. {
  180. 1.0f, 0.0f, 1.0f, 0.0f,
  181. 0.0f, 1.0f, 0.0f, 0.0f,
  182. 1.0f, 0.0f, 1.0f, 0.0f,
  183. 0.0f, 0.0f, 0.0f, 0.0f,
  184. };
  185. auto entityMock = CreateEntity();
  186. const AZ::EntityId id = entityMock->GetId();
  187. UnitTest::MockGradientArrayRequestsBus mockGradientRequestsBus(id, inputData, dataSize);
  188. GradientSignal::DitherGradientConfig config;
  189. config.m_useSystemPointsPerUnit = false;
  190. config.m_pointsPerUnit = 1.0f;
  191. config.m_patternOffset = AZ::Vector3::CreateZero();
  192. config.m_patternType = GradientSignal::DitherGradientConfig::BayerPatternType::PATTERN_SIZE_4x4;
  193. config.m_gradientSampler.m_gradientId = entityMock->GetId();
  194. auto entity = CreateEntity();
  195. entity->CreateComponent<GradientSignal::DitherGradientComponent>(config);
  196. ActivateEntity(entity.get());
  197. TestFixedDataSampler(expectedOutput, dataSize, entity->GetId());
  198. }
  199. TEST_F(GradientSignalServicesTestsFixture, DitherGradientComponent_8x8At50Pct)
  200. {
  201. // With an 8x8 gradient filled with 32/64 (0.5), verify that the resulting dithered output
  202. // is an expected checkerboard pattern with 32 of 64 pixels filled.
  203. constexpr int dataSize = 8;
  204. AZStd::vector<float> inputData(dataSize * dataSize, 32.0f / 64.0f);
  205. AZStd::vector<float> expectedOutput =
  206. {
  207. 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
  208. 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f,
  209. 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
  210. 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f,
  211. 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
  212. 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f,
  213. 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
  214. 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f,
  215. };
  216. auto entityMock = CreateEntity();
  217. const AZ::EntityId id = entityMock->GetId();
  218. UnitTest::MockGradientArrayRequestsBus mockGradientRequestsBus(id, inputData, dataSize);
  219. GradientSignal::DitherGradientConfig config;
  220. config.m_useSystemPointsPerUnit = false;
  221. config.m_pointsPerUnit = 1.0f;
  222. config.m_patternOffset = AZ::Vector3::CreateZero();
  223. config.m_patternType = GradientSignal::DitherGradientConfig::BayerPatternType::PATTERN_SIZE_8x8;
  224. config.m_gradientSampler.m_gradientId = entityMock->GetId();
  225. auto entity = CreateEntity();
  226. entity->CreateComponent<GradientSignal::DitherGradientComponent>(config);
  227. ActivateEntity(entity.get());
  228. TestFixedDataSampler(expectedOutput, dataSize, entity->GetId());
  229. }
  230. TEST_F(GradientSignalServicesTestsFixture, DitherGradientComponent_8x8At55Pct)
  231. {
  232. // With an 8x8 gradient filled with 35/64 (0.546875), verify that the resulting dithered output
  233. // has the correct 35 of 64 pixels set
  234. constexpr int dataSize = 8;
  235. AZStd::vector<float> inputData(dataSize * dataSize, 35.0f / 64.0f);
  236. AZStd::vector<float> expectedOutput =
  237. {
  238. 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f,
  239. 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f,
  240. 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
  241. 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f,
  242. 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f,
  243. 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f,
  244. 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
  245. 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f,
  246. };
  247. auto entityMock = CreateEntity();
  248. const AZ::EntityId id = entityMock->GetId();
  249. UnitTest::MockGradientArrayRequestsBus mockGradientRequestsBus(id, inputData, dataSize);
  250. GradientSignal::DitherGradientConfig config;
  251. config.m_useSystemPointsPerUnit = false;
  252. config.m_pointsPerUnit = 1.0f;
  253. config.m_patternOffset = AZ::Vector3::CreateZero();
  254. config.m_patternType = GradientSignal::DitherGradientConfig::BayerPatternType::PATTERN_SIZE_8x8;
  255. config.m_gradientSampler.m_gradientId = entityMock->GetId();
  256. auto entity = CreateEntity();
  257. entity->CreateComponent<GradientSignal::DitherGradientComponent>(config);
  258. ActivateEntity(entity.get());
  259. TestFixedDataSampler(expectedOutput, dataSize, entity->GetId());
  260. }
  261. TEST_F(GradientSignalServicesTestsFixture, InvertGradientComponent_InvertKnownPoints)
  262. {
  263. // Try inverting 0, 1, 0.5, and 0.2 (endpoints, middle, and arbitrary value) and verify
  264. // that we get back the expected inverted results.
  265. constexpr int dataSize = 2;
  266. AZStd::vector<float> inputData =
  267. {
  268. 0.0f, 1.0f,
  269. 0.5f, 0.2f
  270. };
  271. AZStd::vector<float> expectedOutput =
  272. {
  273. 1.0f, 0.0f,
  274. 0.5f, 0.8f
  275. };
  276. auto entityMock = CreateEntity();
  277. const AZ::EntityId id = entityMock->GetId();
  278. UnitTest::MockGradientArrayRequestsBus mockGradientRequestsBus(id, inputData, dataSize);
  279. // Create the entity with an arbitrarily-sized box.
  280. const float HalfBounds = 64.0f;
  281. auto entity = BuildTestInvertGradient(HalfBounds, entityMock->GetId());
  282. TestFixedDataSampler(expectedOutput, dataSize, entity->GetId());
  283. }
  284. TEST_F(GradientSignalServicesTestsFixture, ShapeAreaFalloffGradientComponent_ValidateKnownPoints)
  285. {
  286. // Create a shape area falloff gradient centered at (10,10,10) with a box of size 20 and falloff of 10.
  287. // This will give us the following:
  288. // |_______________|------------------|_______________|
  289. // (-10) falloff (0) box (20) falloff (30)
  290. const float HalfBounds = 10.0f;
  291. auto entity = BuildTestShapeAreaFalloffGradient(HalfBounds);
  292. const float FalloffWidth = 10.0f;
  293. GradientSignal::ShapeAreaFalloffGradientRequestBus::Event(
  294. entity->GetId(), &GradientSignal::ShapeAreaFalloffGradientRequestBus::Events::SetFalloffWidth, FalloffWidth);
  295. GradientSignal::ShapeAreaFalloffGradientRequestBus::Event(
  296. entity->GetId(), &GradientSignal::ShapeAreaFalloffGradientRequestBus::Events::Set3dFalloff, false);
  297. GradientSignal::GradientSampler gradientSampler;
  298. gradientSampler.m_gradientId = entity->GetId();
  299. const AZStd::vector<AZStd::pair<AZ::Vector3, float>> positionsAndOutputs =
  300. {
  301. // Verify that points that occur within the box get a gradient value of 1.
  302. { { 0.0f, 0.0f, 0.0f }, 1.0f },
  303. { { 10.0f, 0.0f, 0.0f }, 1.0f },
  304. { { 20.0f, 0.0f, 0.0f }, 1.0f },
  305. { { 0.0f, 10.0f, 0.0f }, 1.0f },
  306. { { 0.0f, 20.0f, 0.0f }, 1.0f },
  307. // Verify that points far away from the box get a gradient value of 0. (i.e. outside of -10 to 30)
  308. { { -11.0f, 0.0f, 0.0f }, 0.0f },
  309. { { 31.0f, 0.0f, 0.0f }, 0.0f },
  310. { { 0.0f, -11.0f, 0.0f }, 0.0f },
  311. { { 0.0f, 31.0f, 0.0f }, 0.0f },
  312. // Verify that points halfway into the falloff get a value of 0.5.
  313. // The box goes from 0 to 20, and the falloff is 10, so -5 and 25 should be halfway into the falloff in each direction.
  314. { { -5.0f, 0.0f, 0.0f }, 0.5f },
  315. { { 25.0f, 0.0f, 0.0f }, 0.5f },
  316. { { 0.0f, -5.0f, 0.0f }, 0.5f },
  317. { { 0.0f, 25.0f, 0.0f }, 0.5f },
  318. // Verify that the Z height of the query has no bearing on the falloff value.
  319. { { -5.0f, 0.0f, 1000.0f }, 0.5f },
  320. { { 25.0f, 0.0f, 1000.0f }, 0.5f },
  321. { { 0.0f, -5.0f, 1000.0f }, 0.5f },
  322. { { 0.0f, 25.0f, 1000.0f }, 0.5f },
  323. };
  324. for (auto& [queryPosition, expectedOutput] : positionsAndOutputs)
  325. {
  326. GradientSignal::GradientSampleParams params;
  327. params.m_position = queryPosition;
  328. float actualValue = gradientSampler.GetValue(params);
  329. EXPECT_NEAR(actualValue, expectedOutput, 0.01f);
  330. }
  331. }
  332. TEST_F(GradientSignalServicesTestsFixture, ShapeAreaFalloffGradientComponent_Validate3dFalloff)
  333. {
  334. // Create a shape area falloff gradient centered at (10,10,10) with a box of size 20 and falloff of 10.
  335. // This will give us the following:
  336. // |_______________|------------------|_______________|
  337. // (-10) falloff (0) box (20) falloff (30)
  338. const float HalfBounds = 10.0f;
  339. auto entity = BuildTestShapeAreaFalloffGradient(HalfBounds);
  340. const float FalloffWidth = 10.0f;
  341. GradientSignal::ShapeAreaFalloffGradientRequestBus::Event(
  342. entity->GetId(), &GradientSignal::ShapeAreaFalloffGradientRequestBus::Events::SetFalloffWidth, FalloffWidth);
  343. // Enable 3d falloff
  344. GradientSignal::ShapeAreaFalloffGradientRequestBus::Event(
  345. entity->GetId(), &GradientSignal::ShapeAreaFalloffGradientRequestBus::Events::Set3dFalloff, true);
  346. GradientSignal::GradientSampler gradientSampler;
  347. gradientSampler.m_gradientId = entity->GetId();
  348. const AZStd::vector<AZStd::pair<AZ::Vector3, float>> positionsAndOutputs = {
  349. // Verify that points halfway into the falloff in the X direction get a value of 0.5.
  350. // The box goes from 0 to 20, and the falloff is 10, so -5 and 25 should be halfway into the falloff in each direction.
  351. { { -5.0f, 0.0f, 0.0f }, 0.5f },
  352. { { -5.0f, 0.0f, 10.0f }, 0.5f },
  353. { { -5.0f, 0.0f, 20.0f }, 0.5f },
  354. { { 25.0f, 0.0f, 0.0f }, 0.5f },
  355. { { 25.0f, 0.0f, 10.0f }, 0.5f },
  356. { { 25.0f, 0.0f, 20.0f }, 0.5f },
  357. // Verify that points halfway into the falloff in the Y direction get a value of 0.5.
  358. { { 0.0f, -5.0f, 0.0f }, 0.5f },
  359. { { 0.0f, -5.0f, 10.0f }, 0.5f },
  360. { { 0.0f, -5.0f, 20.0f }, 0.5f },
  361. { { 0.0f, 25.0f, 0.0f }, 0.5f },
  362. { { 0.0f, 25.0f, 10.0f }, 0.5f },
  363. { { 0.0f, 25.0f, 20.0f }, 0.5f },
  364. // Verify that points halfway into the falloff in the Z direction get a value of 0.5.
  365. { { 0.0f, 0.0f, -5.0f }, 0.5f },
  366. { { 10.0f, 10.0f, -5.0f }, 0.5f },
  367. { { 20.0f, 20.0f, -5.0f }, 0.5f },
  368. { { 0.0f, 0.0f, 25.0f }, 0.5f },
  369. { { 10.0f, 10.0f, 25.0f }, 0.5f },
  370. { { 20.0f, 20.0f, 25.0f }, 0.5f },
  371. // Verify that faraway Z points have 0 falloff, even though the XY points are within the box.
  372. { { 10.0f, 10.0f, -1000.0f }, 0.0f },
  373. { { 10.0f, 10.0f, 1000.0f }, 0.0f },
  374. };
  375. for (auto& [queryPosition, expectedOutput] : positionsAndOutputs)
  376. {
  377. GradientSignal::GradientSampleParams params;
  378. params.m_position = queryPosition;
  379. float actualValue = gradientSampler.GetValue(params);
  380. EXPECT_NEAR(actualValue, expectedOutput, 0.01f);
  381. }
  382. }
  383. }