|
@@ -6,7 +6,7 @@
|
|
|
*
|
|
|
*/
|
|
|
|
|
|
-#include <HighInstanceExampleComponent.h>
|
|
|
+#include <Performance/HighInstanceExampleComponent.h>
|
|
|
#include <SampleComponentManager.h>
|
|
|
#include <SampleComponentConfig.h>
|
|
|
|
|
@@ -15,6 +15,8 @@
|
|
|
#include <Atom/RPI.Reflect/Model/ModelAsset.h>
|
|
|
#include <Atom/RPI.Reflect/Material/MaterialAsset.h>
|
|
|
#include <Atom/RPI.Reflect/Asset/AssetUtils.h>
|
|
|
+#include <Atom/RPI.Public/AuxGeom/AuxGeomFeatureProcessorInterface.h>
|
|
|
+#include <Atom/RPI.Public/AuxGeom/AuxGeomDraw.h>
|
|
|
|
|
|
#include <Automation/ScriptRunnerBus.h>
|
|
|
|
|
@@ -23,8 +25,6 @@
|
|
|
|
|
|
#include <RHI/BasicRHIComponent.h>
|
|
|
|
|
|
-#include <HighInstanceTestComponent_Traits_Platform.h>
|
|
|
-
|
|
|
AZ_DECLARE_BUDGET(AtomSampleViewer);
|
|
|
|
|
|
namespace AtomSampleViewer
|
|
@@ -47,8 +47,6 @@ namespace AtomSampleViewer
|
|
|
, m_modelBrowser("@user@/HighInstanceTestComponent/model_browser.xml")
|
|
|
, m_imguiSidebar("@user@/HighInstanceTestComponent/sidebar.xml")
|
|
|
{
|
|
|
- m_sampleName = "HighInstanceTest";
|
|
|
-
|
|
|
m_materialBrowser.SetFilter([](const AZ::Data::AssetInfo& assetInfo)
|
|
|
{
|
|
|
return assetInfo.m_assetType == azrtti_typeid<AZ::RPI::MaterialAsset>();
|
|
@@ -59,45 +57,10 @@ namespace AtomSampleViewer
|
|
|
return assetInfo.m_assetType == azrtti_typeid<AZ::RPI::ModelAsset>();
|
|
|
});
|
|
|
|
|
|
+ // Only use a diffuse white material so light colors are easily visible.
|
|
|
const AZStd::vector<AZStd::string> materialAllowlist =
|
|
|
{
|
|
|
- "materials/presets/pbr/metal_aluminum.azmaterial",
|
|
|
- "materials/presets/pbr/metal_aluminum_matte.azmaterial",
|
|
|
- "materials/presets/pbr/metal_aluminum_polished.azmaterial",
|
|
|
- "materials/presets/pbr/metal_brass.azmaterial",
|
|
|
- "materials/presets/pbr/metal_brass_matte.azmaterial",
|
|
|
- "materials/presets/pbr/metal_brass_polished.azmaterial",
|
|
|
- "materials/presets/pbr/metal_chrome.azmaterial",
|
|
|
- "materials/presets/pbr/metal_chrome_matte.azmaterial",
|
|
|
- "materials/presets/pbr/metal_chrome_polished.azmaterial",
|
|
|
- "materials/presets/pbr/metal_cobalt.azmaterial",
|
|
|
- "materials/presets/pbr/metal_cobalt_matte.azmaterial",
|
|
|
- "materials/presets/pbr/metal_cobalt_polished.azmaterial",
|
|
|
- "materials/presets/pbr/metal_copper.azmaterial",
|
|
|
- "materials/presets/pbr/metal_copper_matte.azmaterial",
|
|
|
- "materials/presets/pbr/metal_copper_polished.azmaterial",
|
|
|
- "materials/presets/pbr/metal_gold.azmaterial",
|
|
|
- "materials/presets/pbr/metal_gold_matte.azmaterial",
|
|
|
- "materials/presets/pbr/metal_gold_polished.azmaterial",
|
|
|
- "materials/presets/pbr/metal_iron.azmaterial",
|
|
|
- "materials/presets/pbr/metal_iron_matte.azmaterial",
|
|
|
- "materials/presets/pbr/metal_iron_polished.azmaterial",
|
|
|
- "materials/presets/pbr/metal_mercury.azmaterial",
|
|
|
- "materials/presets/pbr/metal_nickel.azmaterial",
|
|
|
- "materials/presets/pbr/metal_nickel_matte.azmaterial",
|
|
|
- "materials/presets/pbr/metal_nickel_polished.azmaterial",
|
|
|
- "materials/presets/pbr/metal_palladium.azmaterial",
|
|
|
- "materials/presets/pbr/metal_palladium_matte.azmaterial",
|
|
|
- "materials/presets/pbr/metal_palladium_polished.azmaterial",
|
|
|
- "materials/presets/pbr/metal_platinum.azmaterial",
|
|
|
- "materials/presets/pbr/metal_platinum_matte.azmaterial",
|
|
|
- "materials/presets/pbr/metal_platinum_polished.azmaterial",
|
|
|
- "materials/presets/pbr/metal_silver.azmaterial",
|
|
|
- "materials/presets/pbr/metal_silver_matte.azmaterial",
|
|
|
- "materials/presets/pbr/metal_silver_polished.azmaterial",
|
|
|
- "materials/presets/pbr/metal_titanium.azmaterial",
|
|
|
- "materials/presets/pbr/metal_titanium_matte.azmaterial",
|
|
|
- "materials/presets/pbr/metal_titanium_polished.azmaterial",
|
|
|
+ "materials/presets/macbeth/19_white_9-5_0-05d.azmaterial",
|
|
|
};
|
|
|
m_materialBrowser.SetDefaultPinnedAssets(materialAllowlist);
|
|
|
|
|
@@ -124,6 +87,11 @@ namespace AtomSampleViewer
|
|
|
|
|
|
void HighInstanceTestComponent::Activate()
|
|
|
{
|
|
|
+ BuildDiskLightParameters();
|
|
|
+
|
|
|
+ m_directionalLightFeatureProcessor = m_scene->GetFeatureProcessor<Render::DirectionalLightFeatureProcessorInterface>();
|
|
|
+ m_diskLightFeatureProcessor = m_scene->GetFeatureProcessor<Render::DiskLightFeatureProcessorInterface>();
|
|
|
+
|
|
|
AZ::TickBus::Handler::BusConnect();
|
|
|
|
|
|
m_imguiSidebar.Activate();
|
|
@@ -136,9 +104,15 @@ namespace AtomSampleViewer
|
|
|
m_modelBrowser.ResetPinnedAssetsToDefault();
|
|
|
|
|
|
SetLatticeDimensions(
|
|
|
- ATOMSAMPLEVIEWER_TRAIT_HIGH_INSTANCE_COUNT_TEST_COMPONENT_LATTICE_SIZE_X,
|
|
|
- ATOMSAMPLEVIEWER_TRAIT_HIGH_INSTANCE_COUNT_TEST_COMPONENT_LATTICE_SIZE_Y,
|
|
|
- ATOMSAMPLEVIEWER_TRAIT_HIGH_INSTANCE_COUNT_TEST_COMPONENT_LATTICE_SIZE_Z);
|
|
|
+ m_testParameters.m_latticeSize[0],
|
|
|
+ m_testParameters.m_latticeSize[1],
|
|
|
+ m_testParameters.m_latticeSize[2]);
|
|
|
+ SetLatticeSpacing(
|
|
|
+ m_testParameters.m_latticeSpacing[0],
|
|
|
+ m_testParameters.m_latticeSpacing[1],
|
|
|
+ m_testParameters.m_latticeSpacing[2]);
|
|
|
+ SetLatticeEntityScale(m_testParameters.m_entityScale);
|
|
|
+
|
|
|
Base::Activate();
|
|
|
|
|
|
AzFramework::NativeWindowHandle windowHandle = nullptr;
|
|
@@ -158,10 +132,13 @@ namespace AtomSampleViewer
|
|
|
|
|
|
SaveCameraConfiguration();
|
|
|
ResetNoClipController();
|
|
|
+
|
|
|
+ SetIBLExposure(m_testParameters.m_iblExposure);
|
|
|
}
|
|
|
|
|
|
void HighInstanceTestComponent::Deactivate()
|
|
|
{
|
|
|
+ DestroyLights();
|
|
|
RestoreCameraConfiguration();
|
|
|
AzFramework::NativeWindowHandle windowHandle = nullptr;
|
|
|
AzFramework::WindowSystemRequestBus::BroadcastResult(
|
|
@@ -184,6 +161,7 @@ namespace AtomSampleViewer
|
|
|
void HighInstanceTestComponent::PrepareCreateLatticeInstances(uint32_t instanceCount)
|
|
|
{
|
|
|
m_modelInstanceData.reserve(instanceCount);
|
|
|
+ DestroyLights();
|
|
|
}
|
|
|
|
|
|
void HighInstanceTestComponent::CreateLatticeInstance(const AZ::Transform& transform)
|
|
@@ -232,6 +210,16 @@ namespace AtomSampleViewer
|
|
|
// pause script and tick until assets are ready
|
|
|
ScriptRunnerRequestBus::Broadcast(&ScriptRunnerRequests::PauseScriptWithTimeout, 120.0f);
|
|
|
AZ::TickBus::Handler::BusDisconnect();
|
|
|
+
|
|
|
+ if (m_testParameters.m_numShadowCastingSpotLights > 0 && m_diskLightsEnabled)
|
|
|
+ {
|
|
|
+ CreateSpotLights();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (m_testParameters.m_activateDirectionalLight && m_directionalLightEnabled)
|
|
|
+ {
|
|
|
+ CreateDirectionalLight();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void HighInstanceTestComponent::OnAllAssetsReadyActivate()
|
|
@@ -271,6 +259,18 @@ namespace AtomSampleViewer
|
|
|
m_modelInstanceData.clear();
|
|
|
}
|
|
|
|
|
|
+ void HighInstanceTestComponent::DestroyLights()
|
|
|
+ {
|
|
|
+ m_directionalLightFeatureProcessor->ReleaseLight(m_directionalLightHandle);
|
|
|
+ m_directionalLightHandle = {};
|
|
|
+ for (int index = 0; index < m_diskLights.size(); ++index)
|
|
|
+ {
|
|
|
+ DiskLightHandle& handle = m_diskLights[index].m_handle;
|
|
|
+ m_diskLightFeatureProcessor->ReleaseLight(handle);
|
|
|
+ handle = {};
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
void HighInstanceTestComponent::DestroyHandles()
|
|
|
{
|
|
|
for (ModelInstanceData& instanceData : m_modelInstanceData)
|
|
@@ -329,6 +329,8 @@ namespace AtomSampleViewer
|
|
|
}
|
|
|
|
|
|
bool currentUseSimpleModels = m_useSimpleModels;
|
|
|
+ bool diskLightsEnabled = m_diskLightsEnabled;
|
|
|
+ bool directionalLightEnabled = m_directionalLightEnabled;
|
|
|
if (m_imguiSidebar.Begin())
|
|
|
{
|
|
|
ImGui::Checkbox("Update Transforms Every Frame", &m_updateTransformEnabled);
|
|
@@ -345,9 +347,41 @@ namespace AtomSampleViewer
|
|
|
|
|
|
ImGui::Checkbox("Use simple models", &m_useSimpleModels);
|
|
|
|
|
|
+ ImGui::Spacing();
|
|
|
+ ImGui::Separator();
|
|
|
+ ImGui::Spacing();
|
|
|
+
|
|
|
+ ImGui::Checkbox("Display SpotLight Debug", &m_drawDiskLightDebug);
|
|
|
+
|
|
|
+ ImGui::Spacing();
|
|
|
+ ImGui::Separator();
|
|
|
+ ImGui::Spacing();
|
|
|
+
|
|
|
+ if (m_testParameters.m_numShadowCastingSpotLights > 0)
|
|
|
+ {
|
|
|
+ ImGui::Checkbox("Enable SpotLights", &m_diskLightsEnabled);
|
|
|
+ }
|
|
|
+ if (m_testParameters.m_activateDirectionalLight)
|
|
|
+ {
|
|
|
+ ImGui::Checkbox("Enable Directional Light", &m_directionalLightEnabled);
|
|
|
+ }
|
|
|
+
|
|
|
m_imguiSidebar.End();
|
|
|
}
|
|
|
|
|
|
+ if(diskLightsEnabled != m_diskLightsEnabled || directionalLightEnabled != m_directionalLightEnabled)
|
|
|
+ {
|
|
|
+ DestroyLights();
|
|
|
+ if (m_testParameters.m_numShadowCastingSpotLights > 0 && m_diskLightsEnabled)
|
|
|
+ {
|
|
|
+ CreateSpotLights();
|
|
|
+ }
|
|
|
+ if(m_testParameters.m_activateDirectionalLight && m_directionalLightEnabled)
|
|
|
+ {
|
|
|
+ CreateDirectionalLight();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if (currentUseSimpleModels != m_useSimpleModels)
|
|
|
{
|
|
|
m_modelBrowser.SetPinnedAssets(m_useSimpleModels?m_simpleModelList:m_expandedModelList);
|
|
@@ -356,17 +390,22 @@ namespace AtomSampleViewer
|
|
|
instanceData.m_modelAssetId = GetRandomModelId();
|
|
|
}
|
|
|
DestroyHandles();
|
|
|
+ DestroyLights();
|
|
|
FinalizeLatticeInstances();
|
|
|
}
|
|
|
+
|
|
|
+ DrawDiskLightDebugObjects();
|
|
|
}
|
|
|
|
|
|
void HighInstanceTestComponent::ResetNoClipController()
|
|
|
{
|
|
|
using namespace AZ;
|
|
|
using namespace AZ::Debug;
|
|
|
+ AZ::Vector3 camPos = AZ::Vector3::CreateFromFloat3(m_testParameters.m_cameraPosition);
|
|
|
Camera::CameraRequestBus::Event(GetCameraEntityId(), &Camera::CameraRequestBus::Events::SetFarClipDistance, 2000.0f);
|
|
|
- NoClipControllerRequestBus::Event(GetCameraEntityId(), &NoClipControllerRequestBus::Events::SetHeading, AZ::DegToRad(-44.722542));
|
|
|
- NoClipControllerRequestBus::Event(GetCameraEntityId(), &NoClipControllerRequestBus::Events::SetPitch, AZ::DegToRad(24.987326));
|
|
|
+ NoClipControllerRequestBus::Event(GetCameraEntityId(), &NoClipControllerRequestBus::Events::SetPosition, camPos);
|
|
|
+ NoClipControllerRequestBus::Event(GetCameraEntityId(), &NoClipControllerRequestBus::Events::SetHeading, AZ::DegToRad(m_testParameters.m_cameraHeadingDeg));
|
|
|
+ NoClipControllerRequestBus::Event(GetCameraEntityId(), &NoClipControllerRequestBus::Events::SetPitch, AZ::DegToRad(m_testParameters.m_cameraPitchDeg));
|
|
|
}
|
|
|
|
|
|
void HighInstanceTestComponent::SaveCameraConfiguration()
|
|
@@ -378,4 +417,129 @@ namespace AtomSampleViewer
|
|
|
{
|
|
|
Camera::CameraRequestBus::Event(GetCameraEntityId(), &Camera::CameraRequestBus::Events::SetFarClipDistance, m_originalFarClipDistance);
|
|
|
}
|
|
|
+
|
|
|
+ void HighInstanceTestComponent::CreateSpotLights()
|
|
|
+ {
|
|
|
+ for (int index = 0; index < m_testParameters.m_numShadowCastingSpotLights; ++index)
|
|
|
+ {
|
|
|
+ CreateSpotLight(index);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ void HighInstanceTestComponent::CreateSpotLight(int index)
|
|
|
+ {
|
|
|
+ Render::DiskLightFeatureProcessorInterface* const featureProcessor = m_diskLightFeatureProcessor;
|
|
|
+ const DiskLightHandle handle = featureProcessor->AcquireLight();
|
|
|
+
|
|
|
+ AZ::Render::PhotometricColor<AZ::Render::PhotometricUnit::Candela> lightColor(m_diskLights[index].m_color * m_testParameters.m_shadowSpotlightIntensity);
|
|
|
+ featureProcessor->SetRgbIntensity(handle, lightColor);
|
|
|
+ featureProcessor->SetAttenuationRadius(handle, m_testParameters.m_shadowSpotlightMaxDistance);
|
|
|
+ featureProcessor->SetConeAngles(
|
|
|
+ handle,
|
|
|
+ DegToRad(m_testParameters.m_shadowSpotlightInnerAngleDeg),
|
|
|
+ DegToRad(m_testParameters.m_shadowSpotlightOuterAngleDeg));
|
|
|
+ featureProcessor->SetShadowsEnabled(handle, true);
|
|
|
+ featureProcessor->SetShadowmapMaxResolution(handle, m_testParameters.m_shadowmapSize);
|
|
|
+ featureProcessor->SetShadowFilterMethod(handle, m_testParameters.m_shadowFilterMethod);
|
|
|
+ featureProcessor->SetFilteringSampleCount(handle, 1);
|
|
|
+
|
|
|
+ const Vector3 aabbOffset = m_diskLights[index].m_relativePosition.GetNormalized() * (0.5f * m_testParameters.m_shadowSpotlightMaxDistance);
|
|
|
+ const Vector3 position = m_worldAabb.GetCenter() + aabbOffset;
|
|
|
+
|
|
|
+ featureProcessor->SetPosition(handle, position);
|
|
|
+ featureProcessor->SetDirection(handle, (-aabbOffset).GetNormalized());
|
|
|
+
|
|
|
+ m_diskLights[index].m_handle = handle;
|
|
|
+ }
|
|
|
+
|
|
|
+ const AZ::Color& HighInstanceTestComponent::GetNextLightColor()
|
|
|
+ {
|
|
|
+ static uint16_t colorIndex = 0;
|
|
|
+ static const AZStd::vector<AZ::Color> colors =
|
|
|
+ {
|
|
|
+ AZ::Colors::Red,
|
|
|
+ AZ::Colors::Green,
|
|
|
+ AZ::Colors::Blue,
|
|
|
+ AZ::Colors::Cyan,
|
|
|
+ AZ::Colors::Fuchsia,
|
|
|
+ AZ::Colors::Yellow,
|
|
|
+ AZ::Colors::SpringGreen
|
|
|
+ };
|
|
|
+
|
|
|
+ const AZ::Color& result = colors[colorIndex];
|
|
|
+ colorIndex = (colorIndex + 1) % colors.size();
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ AZ::Vector3 HighInstanceTestComponent::GetRandomDirection()
|
|
|
+ {
|
|
|
+ return AZ::Vector3(
|
|
|
+ m_random.GetRandomFloat() - 0.5f,
|
|
|
+ m_random.GetRandomFloat() - 0.5f,
|
|
|
+ m_random.GetRandomFloat() - 0.5f).GetNormalized();
|
|
|
+ }
|
|
|
+
|
|
|
+ void HighInstanceTestComponent::BuildDiskLightParameters()
|
|
|
+ {
|
|
|
+ m_random.SetSeed(0);
|
|
|
+ m_diskLights.clear();
|
|
|
+ m_diskLights.reserve(m_testParameters.m_numShadowCastingSpotLights);
|
|
|
+ for (int index = 0; index < m_testParameters.m_numShadowCastingSpotLights; ++index)
|
|
|
+ {
|
|
|
+ m_diskLights.emplace_back(
|
|
|
+ GetNextLightColor(),
|
|
|
+ GetRandomDirection(),
|
|
|
+ m_testParameters.m_shadowmapSize);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ void HighInstanceTestComponent::CreateDirectionalLight()
|
|
|
+ {
|
|
|
+ Render::DirectionalLightFeatureProcessorInterface* featureProcessor = m_directionalLightFeatureProcessor;
|
|
|
+ const DirectionalLightHandle handle = featureProcessor->AcquireLight();
|
|
|
+
|
|
|
+ const auto lightTransform = Transform::CreateLookAt(
|
|
|
+ -m_worldAabb.GetMax(),
|
|
|
+ Vector3::CreateZero());
|
|
|
+ featureProcessor->SetDirection(
|
|
|
+ handle,
|
|
|
+ lightTransform.GetBasis(1));
|
|
|
+
|
|
|
+ featureProcessor->SetRgbIntensity(handle, AZ::Render::PhotometricColor<AZ::Render::PhotometricUnit::Lux>(AZ::Color::CreateOne() * m_testParameters.m_directionalLightIntensity));
|
|
|
+ featureProcessor->SetCascadeCount(handle, m_testParameters.m_numDirectionalLightShadowCascades);
|
|
|
+ featureProcessor->SetShadowmapSize(handle, m_testParameters.m_shadowmapSize);
|
|
|
+ featureProcessor->SetViewFrustumCorrectionEnabled(handle, false);
|
|
|
+ featureProcessor->SetShadowFilterMethod(handle, m_testParameters.m_shadowFilterMethod);
|
|
|
+ featureProcessor->SetFilteringSampleCount(handle, 1);
|
|
|
+ featureProcessor->SetGroundHeight(handle, 0.f);
|
|
|
+
|
|
|
+ m_directionalLightHandle = handle;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ void HighInstanceTestComponent::DrawDiskLightDebugObjects()
|
|
|
+ {
|
|
|
+ if (auto auxGeom = AZ::RPI::AuxGeomFeatureProcessorInterface::GetDrawQueueForScene(m_scene);
|
|
|
+ m_drawDiskLightDebug && auxGeom)
|
|
|
+ {
|
|
|
+ for (int i = 0; i < m_diskLights.size(); ++i)
|
|
|
+ {
|
|
|
+ const auto& light = m_diskLights[i];
|
|
|
+ if (light.m_handle.IsValid())
|
|
|
+ {
|
|
|
+ const Render::DiskLightData& lightData = m_diskLightFeatureProcessor->GetDiskData(light.m_handle);
|
|
|
+ const float lightDistance = sqrt(1.0f/lightData.m_invAttenuationRadiusSquared);
|
|
|
+ AZ::Vector3 position = AZ::Vector3::CreateFromFloat3(lightData.m_position.data());
|
|
|
+ AZ::Vector3 direction = AZ::Vector3::CreateFromFloat3(lightData.m_direction.data()).GetNormalized();
|
|
|
+ position += direction * lightDistance;
|
|
|
+ direction *= -1.0f;
|
|
|
+ float coneSlantLength = lightDistance / lightData.m_cosOuterConeAngle;
|
|
|
+ float farEndCapRadius = sqrt(coneSlantLength * coneSlantLength - lightDistance * lightDistance);
|
|
|
+ auxGeom->DrawCone(position, direction, farEndCapRadius, lightDistance, light.m_color, AZ::RPI::AuxGeomDraw::DrawStyle::Line);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
} // namespace AtomSampleViewer
|