2
0

CullingAndLodExampleComponent.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  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.fbx.azmodel";
  143. const char planeModelFilename[] = "Objects/plane.fbx.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->SetShadowEnabled(handle, m_dirShadowEnabled);
  189. dirLightFP->SetCascadeCount(handle, s_cascadesCountDefault);
  190. dirLightFP->SetShadowmapSize(handle, s_shadowmapSizes[s_shadowmapSizeIndexDefault]);
  191. dirLightFP->SetDebugFlags(handle,
  192. m_isDebugColoringEnabled ?
  193. AZ::Render::DirectionalLightFeatureProcessorInterface::DebugDrawFlags::DebugDrawAll :
  194. AZ::Render::DirectionalLightFeatureProcessorInterface::DebugDrawFlags::DebugDrawNone);
  195. dirLightFP->SetViewFrustumCorrectionEnabled(handle, m_isCascadeCorrectionEnabled);
  196. dirLightFP->SetShadowFilterMethod(handle, s_shadowFilterMethods[m_shadowFilterMethodIndex]);
  197. dirLightFP->SetFilteringSampleCount(handle, static_cast<uint16_t>(m_filteringSampleCount));
  198. dirLightFP->SetGroundHeight(handle, 0.f);
  199. m_directionalLightHandle = handle;
  200. }
  201. // disk lights
  202. {
  203. m_diskLights.clear();
  204. m_diskLights.reserve(DiskLightCountMax);
  205. const float disklightSpacing = 10.0f;
  206. const int diskLightsPerRow = 10;
  207. const Color colors[5] = {Colors::Red, Colors::Green, Colors::Blue, Colors::Orange, Colors::Pink};
  208. for (int index = 0; index < DiskLightCountMax; ++index)
  209. {
  210. float xPos = (index % diskLightsPerRow) * disklightSpacing;
  211. float yPos = (index / diskLightsPerRow) * disklightSpacing;
  212. m_diskLights.emplace_back(
  213. colors[index % 5],
  214. Vector3(xPos, yPos, 10.0f),
  215. Vector3(1.0f, 1.0f, -1.0f).GetNormalized(),
  216. Render::ShadowmapSize::Size256);
  217. }
  218. UpdateDiskLightCount(20);
  219. }
  220. }
  221. void CullingAndLodExampleComponent::UpdateDiskLightCount(uint16_t count)
  222. {
  223. using namespace AZ;
  224. for (int index = count; index < m_diskLightCount; ++index)
  225. {
  226. DiskLightHandle& handle = m_diskLights[index].m_handle;
  227. m_diskLightFeatureProcessor->ReleaseLight(handle);
  228. }
  229. const int previousDiskLightCount = m_diskLightCount;
  230. for (int index = previousDiskLightCount; index < count; ++index)
  231. {
  232. Render::DiskLightFeatureProcessorInterface* const diskLightFP = m_diskLightFeatureProcessor;
  233. const DiskLightHandle handle = diskLightFP->AcquireLight();
  234. const DiskLight &diskLight = m_diskLights[index];
  235. diskLightFP->SetPosition(handle, diskLight.m_position);
  236. diskLightFP->SetDirection(handle, diskLight.m_direction);
  237. diskLightFP->SetRgbIntensity(handle, Render::PhotometricColor<Render::PhotometricUnit::Candela>(diskLight.m_color * m_diskLightIntensity));
  238. const float radius = sqrtf(m_diskLightIntensity / CutoffIntensity);
  239. diskLightFP->SetAttenuationRadius(handle, radius);
  240. diskLightFP->SetShadowsEnabled(handle, m_diskLightShadowEnabled);
  241. if (m_diskLightShadowEnabled)
  242. {
  243. diskLightFP->SetShadowmapMaxResolution(handle, m_diskLights[index].m_shadowmapSize);
  244. }
  245. diskLightFP->SetConeAngles(handle, DegToRad(45.f), DegToRad(55.f));
  246. m_diskLights[index].m_handle = handle;
  247. }
  248. m_diskLightCount = count;
  249. }
  250. void CullingAndLodExampleComponent::DrawSidebar()
  251. {
  252. using namespace AZ;
  253. using namespace AZ::Render;
  254. if (!m_imguiSidebar.Begin())
  255. {
  256. return;
  257. }
  258. ImGui::Spacing();
  259. if (ImGui::Button("Spawn 20x20 Grid of objects"))
  260. {
  261. SpawnModelsIn2DGrid(20, 20);
  262. }
  263. if (ImGui::Button("Spawn 50x50 Grid of objects"))
  264. {
  265. SpawnModelsIn2DGrid(50, 50);
  266. }
  267. if (ImGui::Button("Spawn 100x100 Grid of objects"))
  268. {
  269. SpawnModelsIn2DGrid(100, 100);
  270. }
  271. ImGui::Separator();
  272. ImGui::Text("Directional Light");
  273. ImGui::Indent();
  274. {
  275. //SliderAngle() displays angles in degrees, but returns an angle in radians
  276. ImGui::SliderAngle("Pitch", &m_directionalLightPitch, -90.0f, 0.f);
  277. ImGui::SliderAngle("Yaw", &m_directionalLightYaw, 0.f, 360.f);
  278. const auto lightTrans = Transform::CreateRotationZ(m_directionalLightYaw) * Transform::CreateRotationX(m_directionalLightPitch);
  279. m_directionalLightFeatureProcessor->SetDirection(m_directionalLightHandle, lightTrans.GetBasis(1));
  280. if (ImGui::SliderFloat("Intensity##directional", &m_directionalLightIntensity, 0.f, 20.f, "%.1f", ImGuiSliderFlags_Logarithmic))
  281. {
  282. m_directionalLightFeatureProcessor->SetRgbIntensity(
  283. m_directionalLightHandle,
  284. Render::PhotometricColor<Render::PhotometricUnit::Lux>(DirectionalLightColor * m_directionalLightIntensity));
  285. }
  286. ImGui::Separator();
  287. ImGui::Text("Shadowmap Size");
  288. if (ImGui::Combo( "Size", &m_directionalLightShadowmapSizeIndex, s_directionalLightShadowmapSizeLabels, aznumeric_cast<int>(AZStd::size(s_directionalLightShadowmapSizeLabels))))
  289. {
  290. m_directionalLightFeatureProcessor->SetShadowmapSize(m_directionalLightHandle, s_shadowmapSizes[m_directionalLightShadowmapSizeIndex]);
  291. }
  292. ImGui::Text("Number of cascades");
  293. bool cascadesChanged = false;
  294. cascadesChanged = cascadesChanged ||
  295. ImGui::RadioButton("1", &m_cascadeCount, 1);
  296. ImGui::SameLine();
  297. cascadesChanged = cascadesChanged ||
  298. ImGui::RadioButton("2", &m_cascadeCount, 2);
  299. ImGui::SameLine();
  300. cascadesChanged = cascadesChanged ||
  301. ImGui::RadioButton("3", &m_cascadeCount, 3);
  302. ImGui::SameLine();
  303. cascadesChanged = cascadesChanged ||
  304. ImGui::RadioButton("4", &m_cascadeCount, 4);
  305. if (cascadesChanged)
  306. {
  307. m_directionalLightFeatureProcessor->SetCascadeCount(m_directionalLightHandle, static_cast<uint16_t>(m_cascadeCount));
  308. }
  309. ImGui::Spacing();
  310. ImGui::Text("Cascade partition scheme");
  311. ImGui::Text(" (uniform <--> logarithm)");
  312. if (ImGui::SliderFloat("Ratio", &m_ratioLogarithmUniform, 0.f, 1.f, "%0.3f"))
  313. {
  314. m_directionalLightFeatureProcessor->SetShadowmapFrustumSplitSchemeRatio(m_directionalLightHandle, m_ratioLogarithmUniform);
  315. }
  316. ImGui::Spacing();
  317. if (ImGui::Checkbox("Cascade Position Correction", &m_isCascadeCorrectionEnabled))
  318. {
  319. m_directionalLightFeatureProcessor->SetViewFrustumCorrectionEnabled(m_directionalLightHandle, m_isCascadeCorrectionEnabled);
  320. }
  321. if (ImGui::Checkbox("Debug Coloring", &m_isDebugColoringEnabled))
  322. {
  323. m_directionalLightFeatureProcessor->SetDebugFlags(m_directionalLightHandle,
  324. m_isDebugColoringEnabled ?
  325. AZ::Render::DirectionalLightFeatureProcessorInterface::DebugDrawFlags::DebugDrawAll :
  326. AZ::Render::DirectionalLightFeatureProcessorInterface::DebugDrawFlags::DebugDrawNone);
  327. }
  328. ImGui::Spacing();
  329. ImGui::Text("Filtering");
  330. if (ImGui::Combo("Filter Method", &m_shadowFilterMethodIndex, s_shadowFilterMethodLabels, aznumeric_cast<int>(AZStd::size(s_shadowFilterMethodLabels))))
  331. {
  332. m_directionalLightFeatureProcessor->SetShadowFilterMethod(m_directionalLightHandle, s_shadowFilterMethods[m_shadowFilterMethodIndex]);
  333. }
  334. ImGui::Spacing();
  335. ImGui::Text("Filtering (PCF specific)");
  336. if (ImGui::SliderInt("Filtering #", &m_filteringSampleCount, 4, 64))
  337. {
  338. m_directionalLightFeatureProcessor->SetFilteringSampleCount(m_directionalLightHandle, static_cast<uint16_t>(m_filteringSampleCount));
  339. }
  340. }
  341. ImGui::Unindent();
  342. ImGui::Separator();
  343. ImGui::Text("Disk Lights");
  344. ImGui::Indent();
  345. {
  346. int diskLightCount = m_diskLightCount;
  347. if (ImGui::SliderInt("Number", &diskLightCount, 0, DiskLightCountMax))
  348. {
  349. UpdateDiskLightCount(static_cast<uint16_t>(diskLightCount));
  350. }
  351. if (ImGui::SliderFloat("Intensity##disk", &m_diskLightIntensity, 0.f, 100000.f, "%.1f", ImGuiSliderFlags_Logarithmic))
  352. {
  353. for (const DiskLight& light : m_diskLights)
  354. {
  355. if (light.m_handle.IsValid())
  356. {
  357. m_diskLightFeatureProcessor->SetRgbIntensity(light.m_handle, Render::PhotometricColor<Render::PhotometricUnit::Candela>(light.m_color * m_diskLightIntensity));
  358. const float radius = sqrtf(m_diskLightIntensity / CutoffIntensity);
  359. m_diskLightFeatureProcessor->SetAttenuationRadius(light.m_handle, radius);
  360. }
  361. }
  362. }
  363. bool diskLightShadowmapChanged = ImGui::Checkbox("Enable Shadow", &m_diskLightShadowEnabled);
  364. ImGui::Text("Shadowmap Size");
  365. int newSize = static_cast<int>(m_diskLightShadowmapSize);
  366. // To avoid GPU memory consumption, we avoid bigger shadowmap sizes here.
  367. diskLightShadowmapChanged = diskLightShadowmapChanged ||
  368. ImGui::RadioButton("256", &newSize, static_cast<int>(Render::ShadowmapSize::Size256)) ||
  369. ImGui::RadioButton("512", &newSize, static_cast<int>(Render::ShadowmapSize::Size512)) ||
  370. ImGui::RadioButton("Random", &newSize, static_cast<int>(Render::ShadowmapSize::None));
  371. if (diskLightShadowmapChanged)
  372. {
  373. m_diskLightShadowmapSize = static_cast<Render::ShadowmapSize>(newSize);
  374. UpdateDiskLightShadowmapSize();
  375. }
  376. }
  377. ImGui::Unindent();
  378. // 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)
  379. if (ScriptableImGui::Button("Begin Verification"))
  380. {
  381. Debug::CameraControllerRequestBus::Event(GetCameraEntityId(), &Debug::CameraControllerRequestBus::Events::Disable);
  382. Transform tm = Transform::CreateTranslation(Vector3(3.0f, -16.0f, 6.0f));
  383. TransformBus::Event(GetCameraEntityId(), &TransformBus::Events::SetWorldTM, tm);
  384. }
  385. if (ScriptableImGui::Button("End Verification"))
  386. {
  387. Debug::CameraControllerRequestBus::Event(GetCameraEntityId(), &Debug::CameraControllerRequestBus::Events::Enable, azrtti_typeid<Debug::NoClipControllerComponent>());
  388. }
  389. m_imguiSidebar.End();
  390. }
  391. void CullingAndLodExampleComponent::UpdateDiskLightShadowmapSize()
  392. {
  393. using namespace AZ::Render;
  394. DiskLightFeatureProcessorInterface* const featureProcessor = m_diskLightFeatureProcessor;
  395. if (!m_diskLightShadowEnabled)
  396. {
  397. // disabled shadows
  398. for (const DiskLight& light : m_diskLights)
  399. {
  400. if (light.m_handle.IsValid())
  401. {
  402. featureProcessor->SetShadowsEnabled(light.m_handle, false);
  403. }
  404. }
  405. }
  406. else if (m_diskLightShadowmapSize != ShadowmapSize::None)
  407. {
  408. // uniform size
  409. for (const DiskLight& light : m_diskLights)
  410. {
  411. if (light.m_handle.IsValid())
  412. {
  413. featureProcessor->SetShadowsEnabled(light.m_handle, true);
  414. featureProcessor->SetShadowmapMaxResolution(light.m_handle, m_diskLightShadowmapSize);
  415. }
  416. }
  417. }
  418. else
  419. {
  420. // random sizes
  421. for (const DiskLight& light : m_diskLights)
  422. {
  423. if (light.m_handle.IsValid())
  424. {
  425. featureProcessor->SetShadowsEnabled(light.m_handle, true);
  426. featureProcessor->SetShadowmapMaxResolution(light.m_handle, light.m_shadowmapSize);
  427. }
  428. }
  429. }
  430. }
  431. } // namespace AtomSampleViewer