CullingAndLodExampleComponent.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  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 <CullingAndLodExampleComponent.h>
  9. #include <SampleComponentConfig.h>
  10. #include <Automation/ScriptableImGui.h>
  11. #include <Atom/Component/DebugCamera/CameraControllerBus.h>
  12. #include <Atom/Component/DebugCamera/NoClipControllerComponent.h>
  13. #include <Atom/Component/DebugCamera/NoClipControllerBus.h>
  14. #include <imgui/imgui.h>
  15. #include <Atom/RPI.Public/RPISystemInterface.h>
  16. #include <Atom/RPI.Public/Scene.h>
  17. #include <Atom/RPI.Reflect/Asset/AssetUtils.h>
  18. #include <AzCore/Asset/AssetManagerBus.h>
  19. #include <AzCore/Component/TransformBus.h>
  20. #include <AzCore/Console/IConsole.h>
  21. #include <AzCore/Math/Transform.h>
  22. #include <AzCore/RTTI/BehaviorContext.h>
  23. #include <AzFramework/Components/CameraBus.h>
  24. #include <AzFramework/Components/TransformComponent.h>
  25. namespace AtomSampleViewer
  26. {
  27. const AZ::Color CullingAndLodExampleComponent::DirectionalLightColor = AZ::Color::CreateOne();
  28. const AZ::Render::ShadowmapSize CullingAndLodExampleComponent::s_shadowmapSizes[] =
  29. {
  30. AZ::Render::ShadowmapSize::Size256,
  31. AZ::Render::ShadowmapSize::Size512,
  32. AZ::Render::ShadowmapSize::Size1024,
  33. AZ::Render::ShadowmapSize::Size2048
  34. };
  35. const char* CullingAndLodExampleComponent::s_directionalLightShadowmapSizeLabels[] =
  36. {
  37. "256",
  38. "512",
  39. "1024",
  40. "2048"
  41. };
  42. const AZ::Render::ShadowFilterMethod CullingAndLodExampleComponent::s_shadowFilterMethods[] =
  43. {
  44. AZ::Render::ShadowFilterMethod::None,
  45. AZ::Render::ShadowFilterMethod::Pcf,
  46. AZ::Render::ShadowFilterMethod::Esm,
  47. AZ::Render::ShadowFilterMethod::EsmPcf
  48. };
  49. const char* CullingAndLodExampleComponent::s_shadowFilterMethodLabels[] =
  50. {
  51. "None",
  52. "PCF",
  53. "ESM",
  54. "ESM+PCF"
  55. };
  56. void CullingAndLodExampleComponent::Reflect(AZ::ReflectContext* context)
  57. {
  58. if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  59. {
  60. serializeContext->Class<CullingAndLodExampleComponent, AZ::Component>()
  61. ->Version(0)
  62. ;
  63. }
  64. }
  65. void CullingAndLodExampleComponent::Activate()
  66. {
  67. using namespace AZ;
  68. Debug::CameraControllerRequestBus::Event(GetCameraEntityId(), &Debug::CameraControllerRequestBus::Events::Enable, azrtti_typeid<Debug::NoClipControllerComponent>());
  69. SaveCameraConfiguration();
  70. ResetNoClipController();
  71. SetupScene();
  72. m_imguiSidebar.Activate();
  73. TickBus::Handler::BusConnect();
  74. }
  75. void CullingAndLodExampleComponent::Deactivate()
  76. {
  77. using namespace AZ;
  78. TickBus::Handler::BusDisconnect();
  79. m_imguiSidebar.Deactivate();
  80. // disable camera control
  81. RestoreCameraConfiguration();
  82. Debug::CameraControllerRequestBus::Event(GetCameraEntityId(), &Debug::CameraControllerRequestBus::Events::Disable);
  83. ClearMeshes();
  84. m_directionalLightFeatureProcessor->ReleaseLight(m_directionalLightHandle);
  85. UpdateDiskLightCount(0);
  86. }
  87. void CullingAndLodExampleComponent::OnTick(float deltaTime, AZ::ScriptTimePoint timePoint)
  88. {
  89. AZ_UNUSED(deltaTime);
  90. AZ_UNUSED(timePoint);
  91. using namespace AZ;
  92. DrawSidebar();
  93. // Pass camera data to the DirectionalLightFeatureProcessor
  94. if (m_directionalLightHandle.IsValid())
  95. {
  96. Camera::Configuration config;
  97. Camera::CameraRequestBus::EventResult(config, GetCameraEntityId(), &Camera::CameraRequestBus::Events::GetCameraConfiguration);
  98. m_directionalLightFeatureProcessor->SetCameraConfiguration(m_directionalLightHandle, config);
  99. Transform transform = Transform::CreateIdentity();
  100. TransformBus::EventResult(transform, GetCameraEntityId(), &TransformBus::Events::GetWorldTM);
  101. m_directionalLightFeatureProcessor->SetCameraTransform( m_directionalLightHandle, transform);
  102. }
  103. }
  104. void CullingAndLodExampleComponent::ResetNoClipController()
  105. {
  106. using namespace AZ;
  107. using namespace AZ::Debug;
  108. Camera::CameraRequestBus::Event(GetCameraEntityId(), &Camera::CameraRequestBus::Events::SetFarClipDistance, 2000.0f);
  109. NoClipControllerRequestBus::Event(GetCameraEntityId(), &NoClipControllerRequestBus::Events::SetPosition, Vector3(0.0f, -1.2f, 3.4f));
  110. NoClipControllerRequestBus::Event(GetCameraEntityId(), &NoClipControllerRequestBus::Events::SetHeading, 0.0f);
  111. NoClipControllerRequestBus::Event(GetCameraEntityId(), &NoClipControllerRequestBus::Events::SetPitch, 0.0f);
  112. }
  113. void CullingAndLodExampleComponent::SaveCameraConfiguration()
  114. {
  115. Camera::CameraRequestBus::EventResult(m_originalFarClipDistance, GetCameraEntityId(), &Camera::CameraRequestBus::Events::GetFarClipDistance);
  116. }
  117. void CullingAndLodExampleComponent::RestoreCameraConfiguration()
  118. {
  119. Camera::CameraRequestBus::Event(GetCameraEntityId(), &Camera::CameraRequestBus::Events::SetFarClipDistance, m_originalFarClipDistance);
  120. }
  121. void CullingAndLodExampleComponent::SetupScene()
  122. {
  123. using namespace AZ;
  124. SpawnModelsIn2DGrid(5, 5);
  125. SetupLights();
  126. }
  127. void CullingAndLodExampleComponent::ClearMeshes()
  128. {
  129. using namespace AZ;
  130. Render::MeshFeatureProcessorInterface* meshFP = GetMeshFeatureProcessor();
  131. for (auto& meshHandle : m_meshHandles)
  132. {
  133. meshFP->ReleaseMesh(meshHandle);
  134. }
  135. m_meshHandles.clear();
  136. }
  137. void CullingAndLodExampleComponent::SpawnModelsIn2DGrid(uint32_t numAlongXAxis, uint32_t numAlongYAxis)
  138. {
  139. using namespace AZ;
  140. Render::MeshFeatureProcessorInterface* meshFP = GetMeshFeatureProcessor();
  141. ClearMeshes();
  142. const char objectModelFilename[] = "Objects/sphere_5lods.azmodel";
  143. const char planeModelFilename[] = "Objects/plane.azmodel";
  144. Data::Asset<RPI::ModelAsset> objectModelAsset = RPI::AssetUtils::LoadAssetByProductPath<RPI::ModelAsset>(
  145. objectModelFilename, RPI::AssetUtils::TraceLevel::Assert);
  146. Data::Asset<RPI::ModelAsset> planeModelAsset = RPI::AssetUtils::LoadAssetByProductPath<RPI::ModelAsset>(
  147. planeModelFilename, RPI::AssetUtils::TraceLevel::Assert);
  148. Data::Asset<RPI::MaterialAsset> materialAsset = RPI::AssetUtils::LoadAssetByProductPath<RPI::MaterialAsset>(
  149. DefaultPbrMaterialPath, RPI::AssetUtils::TraceLevel::Assert);
  150. Data::Instance<RPI::Material> material = RPI::Material::FindOrCreate(materialAsset);
  151. float spacing = 2.0f*objectModelAsset->GetAabb().GetExtents().GetMaxElement();
  152. for (uint32_t x = 0; x < numAlongXAxis; ++x)
  153. {
  154. for (uint32_t y = 0; y < numAlongYAxis; ++y)
  155. {
  156. auto meshHandle = meshFP->AcquireMesh(Render::MeshHandleDescriptor{ objectModelAsset }, material);
  157. Transform modelToWorld = Transform::CreateTranslation(Vector3(x * spacing, y * spacing, 2.0f));
  158. meshFP->SetTransform(meshHandle, modelToWorld);
  159. m_meshHandles.push_back(AZStd::move(meshHandle));
  160. }
  161. }
  162. auto planeMeshHandle = meshFP->AcquireMesh(Render::MeshHandleDescriptor{ planeModelAsset }, material);
  163. Vector3 planeNonUniformScale(numAlongXAxis * spacing, numAlongYAxis * spacing, 1.0f);
  164. Transform planeModelToWorld = Transform::CreateTranslation(Vector3(0.5f * numAlongXAxis * spacing, 0.5f * numAlongYAxis * spacing, 0.0f));
  165. meshFP->SetTransform(planeMeshHandle, planeModelToWorld, planeNonUniformScale);
  166. m_meshHandles.push_back(AZStd::move(planeMeshHandle));
  167. }
  168. void CullingAndLodExampleComponent::SetupLights()
  169. {
  170. using namespace AZ;
  171. m_directionalLightShadowmapSizeIndex = s_shadowmapSizeIndexDefault;
  172. m_diskLightShadowmapSize = Render::ShadowmapSize::None; // random
  173. m_cascadeCount = s_cascadesCountDefault;
  174. m_ratioLogarithmUniform = s_ratioLogarithmUniformDefault;
  175. m_diskLightCount = 0;
  176. RPI::Scene* scene = RPI::Scene::GetSceneForEntityContextId(GetEntityContextId());
  177. m_directionalLightFeatureProcessor = scene->GetFeatureProcessor<Render::DirectionalLightFeatureProcessorInterface>();
  178. m_diskLightFeatureProcessor = scene->GetFeatureProcessor<Render::DiskLightFeatureProcessorInterface>();
  179. // directional light
  180. {
  181. Render::DirectionalLightFeatureProcessorInterface* dirLightFP = m_directionalLightFeatureProcessor;
  182. const DirectionalLightHandle handle = dirLightFP->AcquireLight();
  183. const auto lightTransform = Transform::CreateLookAt(
  184. Vector3(100, 100, 100),
  185. Vector3::CreateZero());
  186. dirLightFP->SetDirection(handle, lightTransform.GetBasis(1));
  187. dirLightFP->SetRgbIntensity(handle, Render::PhotometricColor<Render::PhotometricUnit::Lux>(m_directionalLightIntensity * DirectionalLightColor));
  188. dirLightFP->SetCascadeCount(handle, s_cascadesCountDefault);
  189. dirLightFP->SetShadowmapSize(handle, s_shadowmapSizes[s_shadowmapSizeIndexDefault]);
  190. dirLightFP->SetDebugFlags(handle,
  191. m_isDebugColoringEnabled ?
  192. AZ::Render::DirectionalLightFeatureProcessorInterface::DebugDrawFlags::DebugDrawAll :
  193. AZ::Render::DirectionalLightFeatureProcessorInterface::DebugDrawFlags::DebugDrawNone);
  194. dirLightFP->SetViewFrustumCorrectionEnabled(handle, m_isCascadeCorrectionEnabled);
  195. dirLightFP->SetShadowFilterMethod(handle, s_shadowFilterMethods[m_shadowFilterMethodIndex]);
  196. dirLightFP->SetFilteringSampleCount(handle, static_cast<uint16_t>(m_filteringSampleCount));
  197. dirLightFP->SetGroundHeight(handle, 0.f);
  198. m_directionalLightHandle = handle;
  199. }
  200. // disk lights
  201. {
  202. m_diskLights.clear();
  203. m_diskLights.reserve(DiskLightCountMax);
  204. const float disklightSpacing = 10.0f;
  205. const int diskLightsPerRow = 10;
  206. const Color colors[5] = {Colors::Red, Colors::Green, Colors::Blue, Colors::Orange, Colors::Pink};
  207. for (int index = 0; index < DiskLightCountMax; ++index)
  208. {
  209. float xPos = (index % diskLightsPerRow) * disklightSpacing;
  210. float yPos = (index / diskLightsPerRow) * disklightSpacing;
  211. m_diskLights.emplace_back(
  212. colors[index % 5],
  213. Vector3(xPos, yPos, 10.0f),
  214. Vector3(1.0f, 1.0f, -1.0f).GetNormalized(),
  215. Render::ShadowmapSize::Size256);
  216. }
  217. UpdateDiskLightCount(20);
  218. }
  219. }
  220. void CullingAndLodExampleComponent::UpdateDiskLightCount(uint16_t count)
  221. {
  222. using namespace AZ;
  223. for (int index = count; index < m_diskLightCount; ++index)
  224. {
  225. DiskLightHandle& handle = m_diskLights[index].m_handle;
  226. m_diskLightFeatureProcessor->ReleaseLight(handle);
  227. }
  228. const int previousDiskLightCount = m_diskLightCount;
  229. for (int index = previousDiskLightCount; index < count; ++index)
  230. {
  231. Render::DiskLightFeatureProcessorInterface* const diskLightFP = m_diskLightFeatureProcessor;
  232. const DiskLightHandle handle = diskLightFP->AcquireLight();
  233. const DiskLight &diskLight = m_diskLights[index];
  234. diskLightFP->SetPosition(handle, diskLight.m_position);
  235. diskLightFP->SetDirection(handle, diskLight.m_direction);
  236. diskLightFP->SetRgbIntensity(handle, Render::PhotometricColor<Render::PhotometricUnit::Candela>(diskLight.m_color * m_diskLightIntensity));
  237. const float radius = sqrtf(m_diskLightIntensity / CutoffIntensity);
  238. diskLightFP->SetAttenuationRadius(handle, radius);
  239. diskLightFP->SetShadowsEnabled(handle, m_diskLightShadowEnabled);
  240. if (m_diskLightShadowEnabled)
  241. {
  242. diskLightFP->SetShadowmapMaxResolution(handle, m_diskLights[index].m_shadowmapSize);
  243. }
  244. diskLightFP->SetConeAngles(handle, DegToRad(45.f), DegToRad(55.f));
  245. m_diskLights[index].m_handle = handle;
  246. }
  247. m_diskLightCount = count;
  248. }
  249. void CullingAndLodExampleComponent::DrawSidebar()
  250. {
  251. using namespace AZ;
  252. using namespace AZ::Render;
  253. if (!m_imguiSidebar.Begin())
  254. {
  255. return;
  256. }
  257. ImGui::Spacing();
  258. if (ImGui::Button("Spawn 20x20 Grid of objects"))
  259. {
  260. SpawnModelsIn2DGrid(20, 20);
  261. }
  262. if (ImGui::Button("Spawn 50x50 Grid of objects"))
  263. {
  264. SpawnModelsIn2DGrid(50, 50);
  265. }
  266. if (ImGui::Button("Spawn 100x100 Grid of objects"))
  267. {
  268. SpawnModelsIn2DGrid(100, 100);
  269. }
  270. ImGui::Separator();
  271. ImGui::Text("Directional Light");
  272. ImGui::Indent();
  273. {
  274. //SliderAngle() displays angles in degrees, but returns an angle in radians
  275. ImGui::SliderAngle("Pitch", &m_directionalLightPitch, -90.0f, 0.f);
  276. ImGui::SliderAngle("Yaw", &m_directionalLightYaw, 0.f, 360.f);
  277. const auto lightTrans = Transform::CreateRotationZ(m_directionalLightYaw) * Transform::CreateRotationX(m_directionalLightPitch);
  278. m_directionalLightFeatureProcessor->SetDirection(m_directionalLightHandle, lightTrans.GetBasis(1));
  279. if (ImGui::SliderFloat("Intensity##directional", &m_directionalLightIntensity, 0.f, 20.f, "%.1f", ImGuiSliderFlags_Logarithmic))
  280. {
  281. m_directionalLightFeatureProcessor->SetRgbIntensity(
  282. m_directionalLightHandle,
  283. Render::PhotometricColor<Render::PhotometricUnit::Lux>(DirectionalLightColor * m_directionalLightIntensity));
  284. }
  285. ImGui::Separator();
  286. ImGui::Text("Shadowmap Size");
  287. if (ImGui::Combo( "Size", &m_directionalLightShadowmapSizeIndex, s_directionalLightShadowmapSizeLabels, AZ_ARRAY_SIZE(s_directionalLightShadowmapSizeLabels)))
  288. {
  289. m_directionalLightFeatureProcessor->SetShadowmapSize(m_directionalLightHandle, s_shadowmapSizes[m_directionalLightShadowmapSizeIndex]);
  290. }
  291. ImGui::Text("Number of cascades");
  292. bool cascadesChanged = false;
  293. cascadesChanged = cascadesChanged ||
  294. ImGui::RadioButton("1", &m_cascadeCount, 1);
  295. ImGui::SameLine();
  296. cascadesChanged = cascadesChanged ||
  297. ImGui::RadioButton("2", &m_cascadeCount, 2);
  298. ImGui::SameLine();
  299. cascadesChanged = cascadesChanged ||
  300. ImGui::RadioButton("3", &m_cascadeCount, 3);
  301. ImGui::SameLine();
  302. cascadesChanged = cascadesChanged ||
  303. ImGui::RadioButton("4", &m_cascadeCount, 4);
  304. if (cascadesChanged)
  305. {
  306. m_directionalLightFeatureProcessor->SetCascadeCount(m_directionalLightHandle, static_cast<uint16_t>(m_cascadeCount));
  307. }
  308. ImGui::Spacing();
  309. ImGui::Text("Cascade partition scheme");
  310. ImGui::Text(" (uniform <--> logarithm)");
  311. if (ImGui::SliderFloat("Ratio", &m_ratioLogarithmUniform, 0.f, 1.f, "%0.3f"))
  312. {
  313. m_directionalLightFeatureProcessor->SetShadowmapFrustumSplitSchemeRatio(m_directionalLightHandle, m_ratioLogarithmUniform);
  314. }
  315. ImGui::Spacing();
  316. if (ImGui::Checkbox("Cascade Position Correction", &m_isCascadeCorrectionEnabled))
  317. {
  318. m_directionalLightFeatureProcessor->SetViewFrustumCorrectionEnabled(m_directionalLightHandle, m_isCascadeCorrectionEnabled);
  319. }
  320. if (ImGui::Checkbox("Debug Coloring", &m_isDebugColoringEnabled))
  321. {
  322. m_directionalLightFeatureProcessor->SetDebugFlags(m_directionalLightHandle,
  323. m_isDebugColoringEnabled ?
  324. AZ::Render::DirectionalLightFeatureProcessorInterface::DebugDrawFlags::DebugDrawAll :
  325. AZ::Render::DirectionalLightFeatureProcessorInterface::DebugDrawFlags::DebugDrawNone);
  326. }
  327. ImGui::Spacing();
  328. ImGui::Text("Filtering");
  329. if (ImGui::Combo("Filter Method", &m_shadowFilterMethodIndex, s_shadowFilterMethodLabels, AZ_ARRAY_SIZE(s_shadowFilterMethodLabels)))
  330. {
  331. m_directionalLightFeatureProcessor->SetShadowFilterMethod(m_directionalLightHandle, s_shadowFilterMethods[m_shadowFilterMethodIndex]);
  332. }
  333. ImGui::Spacing();
  334. ImGui::Text("Filtering (PCF specific)");
  335. if (ImGui::SliderInt("Filtering #", &m_filteringSampleCount, 4, 64))
  336. {
  337. m_directionalLightFeatureProcessor->SetFilteringSampleCount(m_directionalLightHandle, static_cast<uint16_t>(m_filteringSampleCount));
  338. }
  339. }
  340. ImGui::Unindent();
  341. ImGui::Separator();
  342. ImGui::Text("Disk Lights");
  343. ImGui::Indent();
  344. {
  345. int diskLightCount = m_diskLightCount;
  346. if (ImGui::SliderInt("Number", &diskLightCount, 0, DiskLightCountMax))
  347. {
  348. UpdateDiskLightCount(static_cast<uint16_t>(diskLightCount));
  349. }
  350. if (ImGui::SliderFloat("Intensity##disk", &m_diskLightIntensity, 0.f, 100000.f, "%.1f", ImGuiSliderFlags_Logarithmic))
  351. {
  352. for (const DiskLight& light : m_diskLights)
  353. {
  354. if (light.m_handle.IsValid())
  355. {
  356. m_diskLightFeatureProcessor->SetRgbIntensity(light.m_handle, Render::PhotometricColor<Render::PhotometricUnit::Candela>(light.m_color * m_diskLightIntensity));
  357. const float radius = sqrtf(m_diskLightIntensity / CutoffIntensity);
  358. m_diskLightFeatureProcessor->SetAttenuationRadius(light.m_handle, radius);
  359. }
  360. }
  361. }
  362. bool diskLightShadowmapChanged = ImGui::Checkbox("Enable Shadow", &m_diskLightShadowEnabled);
  363. ImGui::Text("Shadowmap Size");
  364. int newSize = static_cast<int>(m_diskLightShadowmapSize);
  365. // To avoid GPU memory consumption, we avoid bigger shadowmap sizes here.
  366. diskLightShadowmapChanged = diskLightShadowmapChanged ||
  367. ImGui::RadioButton("256", &newSize, static_cast<int>(Render::ShadowmapSize::Size256)) ||
  368. ImGui::RadioButton("512", &newSize, static_cast<int>(Render::ShadowmapSize::Size512)) ||
  369. ImGui::RadioButton("Random", &newSize, static_cast<int>(Render::ShadowmapSize::None));
  370. if (diskLightShadowmapChanged)
  371. {
  372. m_diskLightShadowmapSize = static_cast<Render::ShadowmapSize>(newSize);
  373. UpdateDiskLightShadowmapSize();
  374. }
  375. }
  376. ImGui::Unindent();
  377. // For automated screenshot verification testing: force the camera transform and turn on the debug window so the cull stats show up in the screenshot(s)
  378. if (ScriptableImGui::Button("Begin Verification"))
  379. {
  380. Debug::CameraControllerRequestBus::Event(GetCameraEntityId(), &Debug::CameraControllerRequestBus::Events::Disable);
  381. Transform tm = Transform::CreateTranslation(Vector3(3.0f, -16.0f, 6.0f));
  382. TransformBus::Event(GetCameraEntityId(), &TransformBus::Events::SetWorldTM, tm);
  383. }
  384. if (ScriptableImGui::Button("End Verification"))
  385. {
  386. Debug::CameraControllerRequestBus::Event(GetCameraEntityId(), &Debug::CameraControllerRequestBus::Events::Enable, azrtti_typeid<Debug::NoClipControllerComponent>());
  387. }
  388. m_imguiSidebar.End();
  389. }
  390. void CullingAndLodExampleComponent::UpdateDiskLightShadowmapSize()
  391. {
  392. using namespace AZ::Render;
  393. DiskLightFeatureProcessorInterface* const featureProcessor = m_diskLightFeatureProcessor;
  394. if (!m_diskLightShadowEnabled)
  395. {
  396. // disabled shadows
  397. for (const DiskLight& light : m_diskLights)
  398. {
  399. if (light.m_handle.IsValid())
  400. {
  401. featureProcessor->SetShadowsEnabled(light.m_handle, false);
  402. }
  403. }
  404. }
  405. else if (m_diskLightShadowmapSize != ShadowmapSize::None)
  406. {
  407. // uniform size
  408. for (const DiskLight& light : m_diskLights)
  409. {
  410. if (light.m_handle.IsValid())
  411. {
  412. featureProcessor->SetShadowsEnabled(light.m_handle, true);
  413. featureProcessor->SetShadowmapMaxResolution(light.m_handle, m_diskLightShadowmapSize);
  414. }
  415. }
  416. }
  417. else
  418. {
  419. // random sizes
  420. for (const DiskLight& light : m_diskLights)
  421. {
  422. if (light.m_handle.IsValid())
  423. {
  424. featureProcessor->SetShadowsEnabled(light.m_handle, true);
  425. featureProcessor->SetShadowmapMaxResolution(light.m_handle, light.m_shadowmapSize);
  426. }
  427. }
  428. }
  429. }
  430. } // namespace AtomSampleViewer