Making terrain query resolution a single float instead of a Vector2 (#7186)
* Making terrain query resolution a single float instead of a Vector2 Signed-off-by: Ken Pruiksma <pruiksma@amazon.com> * Keeping the concept of different x/y step sizes in region queries since that may be useful and is separate from query resolution. Also keeping the concept of different x/y step sizes in physics since that's independent of the terrain gem. Signed-off-by: Ken Pruiksma <pruiksma@amazon.com> * Formatting cleanups Signed-off-by: Ken Pruiksma <pruiksma@amazon.com> * A few more minor cleanups Signed-off-by: Ken Pruiksma <pruiksma@amazon.com> * Added support to convert serialized Vector2 query resolution to a single float. Signed-off-by: Ken Pruiksma <pruiksma@amazon.com> * Switch ray intersection check back to using separate values for x and y resolution Signed-off-by: Ken Pruiksma <pruiksma@amazon.com> * Fixing new unit tests added to use float query resolution. Signed-off-by: Ken Pruiksma <pruiksma@amazon.com> * Updating automated test Signed-off-by: Ken Pruiksma <pruiksma@amazon.com>
This commit is contained in:
+2
-3
@@ -93,7 +93,7 @@ def Terrain_World_ConfigurationWorks():
|
||||
# 5) Set the base Terrain World values
|
||||
world_bounds_max = azmath.Vector3(1100.0, 1100.0, 1100.0)
|
||||
world_bounds_min = azmath.Vector3(10.0, 10.0, 10.0)
|
||||
height_query_resolution = azmath.Vector2(1.0, 1.0)
|
||||
height_query_resolution = 1.0
|
||||
hydra.set_component_property_value(terrain_world_component, "Configuration|World Bounds (Max)", world_bounds_max)
|
||||
hydra.set_component_property_value(terrain_world_component, "Configuration|World Bounds (Min)", world_bounds_min)
|
||||
hydra.set_component_property_value(terrain_world_component, "Configuration|Height Query Resolution (m)", height_query_resolution)
|
||||
@@ -148,7 +148,7 @@ def Terrain_World_ConfigurationWorks():
|
||||
|
||||
# 13) Check height value is the expected one when query resolution is changed
|
||||
testpoint = terrain.TerrainDataRequestBus(bus.Broadcast, 'GetHeightFromFloats', 10.5, 10.5, CLAMP)
|
||||
height_query_resolution = azmath.Vector2(0.5, 0.5)
|
||||
height_query_resolution = 0.5
|
||||
hydra.set_component_property_value(terrain_world_component, "Configuration|Height Query Resolution (m)", height_query_resolution)
|
||||
general.idle_wait_frames(1)
|
||||
testpoint2 = terrain.TerrainDataRequestBus(bus.Broadcast, 'GetHeightFromFloats', 10.5, 10.5, CLAMP)
|
||||
@@ -165,4 +165,3 @@ if __name__ == "__main__":
|
||||
|
||||
from editor_python_test_tools.utils import Report
|
||||
Report.start_test(Terrain_World_ConfigurationWorks)
|
||||
|
||||
|
||||
@@ -317,8 +317,8 @@ void CGameExporter::ExportLevelInfo(const QString& path)
|
||||
root->setAttr("Name", levelName.toUtf8().data());
|
||||
auto terrain = AzFramework::Terrain::TerrainDataRequestBus::FindFirstHandler();
|
||||
const AZ::Aabb terrainAabb = terrain ? terrain->GetTerrainAabb() : AZ::Aabb::CreateFromPoint(AZ::Vector3::CreateZero());
|
||||
const AZ::Vector2 terrainGridResolution = terrain ? terrain->GetTerrainHeightQueryResolution() : AZ::Vector2::CreateOne();
|
||||
const int compiledHeightmapSize = static_cast<int>(terrainAabb.GetXExtent() / terrainGridResolution.GetX());
|
||||
const float terrainGridResolution = terrain ? terrain->GetTerrainHeightQueryResolution() : 1.0f;
|
||||
const int compiledHeightmapSize = static_cast<int>(terrainAabb.GetXExtent() / terrainGridResolution);
|
||||
root->setAttr("HeightmapSize", compiledHeightmapSize);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -378,7 +378,7 @@ namespace Physics
|
||||
m_cachedNativeHeightfield = cachedNativeHeightfield;
|
||||
}
|
||||
|
||||
AZ::Vector2 HeightfieldShapeConfiguration::GetGridResolution() const
|
||||
const AZ::Vector2& HeightfieldShapeConfiguration::GetGridResolution() const
|
||||
{
|
||||
return m_gridResolution;
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ namespace Physics
|
||||
const void* GetCachedNativeHeightfield() const;
|
||||
void* GetCachedNativeHeightfield();
|
||||
void SetCachedNativeHeightfield(void* cachedNativeHeightfield);
|
||||
AZ::Vector2 GetGridResolution() const;
|
||||
const AZ::Vector2& GetGridResolution() const;
|
||||
void SetGridResolution(const AZ::Vector2& gridSpacing);
|
||||
int32_t GetNumColumns() const;
|
||||
void SetNumColumns(int32_t numColumns);
|
||||
@@ -235,7 +235,7 @@ namespace Physics
|
||||
void SetMaxHeightBounds(float maxBounds);
|
||||
|
||||
private:
|
||||
//! The number of meters between each heightfield sample.
|
||||
//! The number of meters between each heightfield sample in x and y.
|
||||
AZ::Vector2 m_gridResolution{ 1.0f };
|
||||
//! The number of columns in the heightfield sample grid.
|
||||
int32_t m_numColumns{ 0 };
|
||||
|
||||
@@ -50,8 +50,8 @@ namespace AzFramework
|
||||
static AZ::Vector3 GetDefaultTerrainNormal() { return AZ::Vector3::CreateAxisZ(); }
|
||||
|
||||
// System-level queries to understand world size and resolution
|
||||
virtual AZ::Vector2 GetTerrainHeightQueryResolution() const = 0;
|
||||
virtual void SetTerrainHeightQueryResolution(AZ::Vector2 queryResolution) = 0;
|
||||
virtual float GetTerrainHeightQueryResolution() const = 0;
|
||||
virtual void SetTerrainHeightQueryResolution(float queryResolution) = 0;
|
||||
|
||||
virtual AZ::Aabb GetTerrainAabb() const = 0;
|
||||
virtual void SetTerrainAabb(const AZ::Aabb& worldBounds) = 0;
|
||||
|
||||
@@ -49,8 +49,8 @@ namespace UnitTest
|
||||
AzFramework::Terrain::TerrainDataRequestBus::Handler::BusDisconnect();
|
||||
}
|
||||
|
||||
MOCK_CONST_METHOD0(GetTerrainHeightQueryResolution, AZ::Vector2());
|
||||
MOCK_METHOD1(SetTerrainHeightQueryResolution, void(AZ::Vector2));
|
||||
MOCK_CONST_METHOD0(GetTerrainHeightQueryResolution, float());
|
||||
MOCK_METHOD1(SetTerrainHeightQueryResolution, void(float));
|
||||
MOCK_CONST_METHOD0(GetTerrainAabb, AZ::Aabb());
|
||||
MOCK_METHOD1(SetTerrainAabb, void(const AZ::Aabb&));
|
||||
MOCK_CONST_METHOD3(GetHeight, float(const AZ::Vector3&, Sampler, bool*));
|
||||
|
||||
@@ -133,7 +133,7 @@ namespace PhysX
|
||||
{
|
||||
physx::PxHeightField* heightfield = nullptr;
|
||||
|
||||
const AZ::Vector2 gridSpacing = heightfieldConfig.GetGridResolution();
|
||||
const AZ::Vector2& gridSpacing = heightfieldConfig.GetGridResolution();
|
||||
|
||||
const int32_t numCols = heightfieldConfig.GetNumColumns();
|
||||
const int32_t numRows = heightfieldConfig.GetNumRows();
|
||||
|
||||
@@ -266,7 +266,7 @@ namespace Terrain
|
||||
LmbrCentral::ShapeComponentRequestsBus::EventResult(m_cachedShapeBounds, GetEntityId(), &LmbrCentral::ShapeComponentRequestsBus::Events::GetEncompassingAabb);
|
||||
|
||||
// Get the height range of the entire world
|
||||
m_cachedHeightQueryResolution = AZ::Vector2(1.0f);
|
||||
m_cachedHeightQueryResolution = 1.0f;
|
||||
AzFramework::Terrain::TerrainDataRequestBus::BroadcastResult(
|
||||
m_cachedHeightQueryResolution, &AzFramework::Terrain::TerrainDataRequestBus::Events::GetTerrainHeightQueryResolution);
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace Terrain
|
||||
|
||||
float m_cachedMinWorldHeight{ 0.0f };
|
||||
float m_cachedMaxWorldHeight{ 0.0f };
|
||||
AZ::Vector2 m_cachedHeightQueryResolution{ 1.0f, 1.0f };
|
||||
float m_cachedHeightQueryResolution{ 1.0f };
|
||||
AZ::Aabb m_cachedShapeBounds;
|
||||
|
||||
// prevent recursion in case user attaches cyclic dependences
|
||||
|
||||
@@ -383,11 +383,11 @@ namespace Terrain
|
||||
|
||||
AZ::Vector2 TerrainPhysicsColliderComponent::GetHeightfieldGridSpacing() const
|
||||
{
|
||||
AZ::Vector2 gridResolution = AZ::Vector2(1.0f);
|
||||
float gridResolution = 1.0f;
|
||||
AzFramework::Terrain::TerrainDataRequestBus::BroadcastResult(
|
||||
gridResolution, &AzFramework::Terrain::TerrainDataRequests::GetTerrainHeightQueryResolution);
|
||||
|
||||
return gridResolution;
|
||||
return AZ::Vector2(gridResolution);
|
||||
}
|
||||
|
||||
void TerrainPhysicsColliderComponent::GetHeightfieldGridSize(int32_t& numColumns, int32_t& numRows) const
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
*/
|
||||
|
||||
#include <Components/TerrainWorldComponent.h>
|
||||
#include <AzCore/Asset/AssetManager.h>
|
||||
#include <AzCore/Asset/AssetManagerBus.h>
|
||||
#include <AzCore/Component/Entity.h>
|
||||
#include <AzCore/Asset/AssetManager.h>
|
||||
#include <AzCore/RTTI/BehaviorContext.h>
|
||||
#include <AzCore/Serialization/EditContext.h>
|
||||
#include <AzCore/Serialization/SerializeContext.h>
|
||||
@@ -17,13 +17,60 @@
|
||||
|
||||
namespace Terrain
|
||||
{
|
||||
|
||||
AZ::JsonSerializationResult::Result JsonTerrainWorldConfigSerializer::Load(
|
||||
void* outputValue, [[maybe_unused]] const AZ::Uuid& outputValueTypeId,
|
||||
const rapidjson::Value& inputValue, AZ::JsonDeserializerContext& context)
|
||||
{
|
||||
namespace JSR = AZ::JsonSerializationResult;
|
||||
|
||||
auto configInstance = reinterpret_cast<TerrainWorldConfig*>(outputValue);
|
||||
AZ_Assert(configInstance, "Output value for JsonTerrainWorldConfigSerializer can't be null.");
|
||||
|
||||
JSR::ResultCode result(JSR::Tasks::ReadField);
|
||||
|
||||
result.Combine(ContinueLoadingFromJsonObjectField(
|
||||
&configInstance->m_worldMin, azrtti_typeid<decltype(configInstance->m_worldMin)>(), inputValue, "WorldMin", context));
|
||||
|
||||
result.Combine(ContinueLoadingFromJsonObjectField(
|
||||
&configInstance->m_worldMax, azrtti_typeid<decltype(configInstance->m_worldMax)>(), inputValue, "WorldMax", context));
|
||||
|
||||
rapidjson::Value::ConstMemberIterator itr = inputValue.FindMember("HeightQueryResolution");
|
||||
if (itr != inputValue.MemberEnd())
|
||||
{
|
||||
if (itr->value.IsArray())
|
||||
{
|
||||
// Version 1 stored a Vector2 (serialized as a json array) to have a separate x and y
|
||||
// query resolution. Now this is only one value, so just take the x value from the Vector2.
|
||||
configInstance->m_heightQueryResolution = itr->value.GetArray().Begin()->GetFloat();
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Combine(ContinueLoadingFromJsonObjectField(
|
||||
&configInstance->m_heightQueryResolution, azrtti_typeid<decltype(configInstance->m_heightQueryResolution)>(), inputValue, "HeightQueryResolution", context));
|
||||
}
|
||||
}
|
||||
|
||||
return context.Report(result,
|
||||
result.GetProcessing() != JSR::Processing::Halted ?
|
||||
"Successfully loaded TerrainWorldConfig information." :
|
||||
"Failed to load TerrainWorldConfig information.");
|
||||
}
|
||||
|
||||
AZ_CLASS_ALLOCATOR_IMPL(JsonTerrainWorldConfigSerializer, AZ::SystemAllocator, 0);
|
||||
|
||||
void TerrainWorldConfig::Reflect(AZ::ReflectContext* context)
|
||||
{
|
||||
if (auto jsonContext = azrtti_cast<AZ::JsonRegistrationContext*>(context))
|
||||
{
|
||||
jsonContext->Serializer<JsonTerrainWorldConfigSerializer>()->HandlesType<TerrainWorldConfig>();
|
||||
}
|
||||
|
||||
AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context);
|
||||
if (serialize)
|
||||
{
|
||||
serialize->Class<TerrainWorldConfig, AZ::ComponentConfig>()
|
||||
->Version(1)
|
||||
->Version(2)
|
||||
->Field("WorldMin", &TerrainWorldConfig::m_worldMin)
|
||||
->Field("WorldMax", &TerrainWorldConfig::m_worldMax)
|
||||
->Field("HeightQueryResolution", &TerrainWorldConfig::m_heightQueryResolution)
|
||||
@@ -131,9 +178,9 @@ namespace Terrain
|
||||
return false;
|
||||
}
|
||||
|
||||
float TerrainWorldConfig::NumberOfSamples(AZ::Vector3* min, AZ::Vector3* max, AZ::Vector2* heightQuery)
|
||||
float TerrainWorldConfig::NumberOfSamples(const AZ::Vector3& min, const AZ::Vector3& max, float heightQuery)
|
||||
{
|
||||
float numberOfSamples = ((max->GetX() - min->GetX()) / heightQuery->GetX()) * ((max->GetY() - min->GetY()) / heightQuery->GetY());
|
||||
float numberOfSamples = ((max.GetX() - min.GetX()) / heightQuery) * ((max.GetY() - min.GetY()) / heightQuery);
|
||||
return numberOfSamples;
|
||||
}
|
||||
|
||||
@@ -151,21 +198,21 @@ namespace Terrain
|
||||
{
|
||||
AZ::Vector3 minValue = *static_cast<AZ::Vector3*>(newValue);
|
||||
|
||||
return DetermineMessage(NumberOfSamples(&minValue, &m_worldMax, &m_heightQueryResolution));
|
||||
return DetermineMessage(NumberOfSamples(minValue, m_worldMax, m_heightQueryResolution));
|
||||
}
|
||||
|
||||
AZ::Outcome<void, AZStd::string> TerrainWorldConfig::ValidateWorldMax(void* newValue, [[maybe_unused]] const AZ::Uuid& valueType)
|
||||
{
|
||||
AZ::Vector3 maxValue = *static_cast<AZ::Vector3*>(newValue);
|
||||
|
||||
return DetermineMessage(NumberOfSamples(&m_worldMin, &maxValue, &m_heightQueryResolution));
|
||||
return DetermineMessage(NumberOfSamples(m_worldMin, maxValue, m_heightQueryResolution));
|
||||
}
|
||||
|
||||
AZ::Outcome<void, AZStd::string> TerrainWorldConfig::ValidateWorldHeight(void* newValue, [[maybe_unused]] const AZ::Uuid& valueType)
|
||||
{
|
||||
AZ::Vector2 heightValue = *static_cast<AZ::Vector2*>(newValue);
|
||||
float heightValue = *static_cast<float*>(newValue);
|
||||
|
||||
return DetermineMessage(NumberOfSamples(&m_worldMin, &m_worldMax, &heightValue));
|
||||
return DetermineMessage(NumberOfSamples(m_worldMin, m_worldMax, heightValue));
|
||||
}
|
||||
|
||||
} // namespace Terrain
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include <AzCore/Asset/AssetCommon.h>
|
||||
#include <AzCore/Component/Component.h>
|
||||
#include <AzCore/Math/Vector3.h>
|
||||
#include <AzCore/Serialization/Json/BaseJsonSerializer.h>
|
||||
#include <AzCore/Serialization/Json/RegistrationContext.h>
|
||||
#include <TerrainSystem/TerrainSystem.h>
|
||||
|
||||
namespace LmbrCentral
|
||||
@@ -21,6 +23,18 @@ namespace LmbrCentral
|
||||
|
||||
namespace Terrain
|
||||
{
|
||||
// Custom JSON serializer for TerrainWorldConfig to handle version conversion
|
||||
class JsonTerrainWorldConfigSerializer : public AZ::BaseJsonSerializer
|
||||
{
|
||||
public:
|
||||
AZ_RTTI(Terrain::JsonTerrainWorldConfigSerializer, "{910BC31F-CD49-488E-8004-227D9FEB5A16}", AZ::BaseJsonSerializer);
|
||||
AZ_CLASS_ALLOCATOR_DECL;
|
||||
|
||||
AZ::JsonSerializationResult::Result Load(
|
||||
void* outputValue, const AZ::Uuid& outputValueTypeId, const rapidjson::Value& inputValue,
|
||||
AZ::JsonDeserializerContext& context) override;
|
||||
};
|
||||
|
||||
class TerrainWorldConfig
|
||||
: public AZ::ComponentConfig
|
||||
{
|
||||
@@ -31,13 +45,13 @@ namespace Terrain
|
||||
|
||||
AZ::Vector3 m_worldMin{ 0.0f, 0.0f, 0.0f };
|
||||
AZ::Vector3 m_worldMax{ 1024.0f, 1024.0f, 1024.0f };
|
||||
AZ::Vector2 m_heightQueryResolution{ 1.0f, 1.0f };
|
||||
float m_heightQueryResolution{ 1.0f };
|
||||
|
||||
private:
|
||||
AZ::Outcome<void, AZStd::string> ValidateWorldMin(void* newValue, const AZ::Uuid& valueType);
|
||||
AZ::Outcome<void, AZStd::string> ValidateWorldMax(void* newValue, const AZ::Uuid& valueType);
|
||||
AZ::Outcome<void, AZStd::string> ValidateWorldHeight(void* newValue, const AZ::Uuid& valueType);
|
||||
float NumberOfSamples(AZ::Vector3* min, AZ::Vector3* max, AZ::Vector2* heightQuery);
|
||||
float NumberOfSamples(const AZ::Vector3& min, const AZ::Vector3& max, float heightQuery);
|
||||
AZ::Outcome<void, AZStd::string> DetermineMessage(float numSamples);
|
||||
|
||||
};
|
||||
|
||||
@@ -227,12 +227,12 @@ namespace Terrain
|
||||
float worldMinZ = worldBounds.GetMin().GetZ();
|
||||
|
||||
// Get the terrain height data resolution
|
||||
AZ::Vector2 heightDataResolution = AZ::Vector2(1.0f);
|
||||
float heightDataResolution = 1.0f;
|
||||
AzFramework::Terrain::TerrainDataRequestBus::BroadcastResult(
|
||||
heightDataResolution, &AzFramework::Terrain::TerrainDataRequests::GetTerrainHeightQueryResolution);
|
||||
|
||||
// Get the size of a wireframe sector in world space
|
||||
const AZ::Vector2 sectorSize = heightDataResolution * SectorSizeInGridPoints;
|
||||
const AZ::Vector2 sectorSize = AZ::Vector2(heightDataResolution * SectorSizeInGridPoints);
|
||||
|
||||
// Try to get the current camera position, or default to (0,0) if we can't.
|
||||
AZ::Vector3 cameraPos = AZ::Vector3::CreateZero();
|
||||
@@ -317,7 +317,7 @@ namespace Terrain
|
||||
|
||||
}
|
||||
|
||||
void TerrainWorldDebuggerComponent::RebuildSectorWireframe(WireframeSector& sector, const AZ::Vector2& gridResolution)
|
||||
void TerrainWorldDebuggerComponent::RebuildSectorWireframe(WireframeSector& sector, float gridResolution)
|
||||
{
|
||||
if (!sector.m_isDirty)
|
||||
{
|
||||
@@ -337,11 +337,11 @@ namespace Terrain
|
||||
// Since we're processing lines based on the grid points and going backwards, this will give us (*--*--*).
|
||||
|
||||
AZ::Aabb region = sector.m_aabb;
|
||||
region.SetMax(region.GetMax() + AZ::Vector3(gridResolution.GetX(), gridResolution.GetY(), 0.0f));
|
||||
region.SetMax(region.GetMax() + AZ::Vector3(gridResolution, gridResolution, 0.0f));
|
||||
|
||||
// We need 4 vertices for each grid point in our sector to hold the _| shape.
|
||||
const size_t numSamplesX = aznumeric_cast<size_t>(ceil(region.GetExtents().GetX() / gridResolution.GetX()));
|
||||
const size_t numSamplesY = aznumeric_cast<size_t>(ceil(region.GetExtents().GetY() / gridResolution.GetY()));
|
||||
const size_t numSamplesX = aznumeric_cast<size_t>(ceil(region.GetExtents().GetX() / gridResolution));
|
||||
const size_t numSamplesY = aznumeric_cast<size_t>(ceil(region.GetExtents().GetY() / gridResolution));
|
||||
sector.m_lineVertices.clear();
|
||||
sector.m_lineVertices.reserve(numSamplesX * numSamplesY * 4);
|
||||
|
||||
@@ -360,8 +360,8 @@ namespace Terrain
|
||||
// there is one.
|
||||
if ((xIndex > 0) && (yIndex > 0))
|
||||
{
|
||||
float x = surfacePoint.m_position.GetX() - gridResolution.GetX();
|
||||
float y = surfacePoint.m_position.GetY() - gridResolution.GetY();
|
||||
float x = surfacePoint.m_position.GetX() - gridResolution;
|
||||
float y = surfacePoint.m_position.GetY() - gridResolution;
|
||||
|
||||
sector.m_lineVertices.emplace_back(AZ::Vector3(x, surfacePoint.m_position.GetY(), previousHeight));
|
||||
sector.m_lineVertices.emplace_back(surfacePoint.m_position);
|
||||
@@ -374,9 +374,10 @@ namespace Terrain
|
||||
previousHeight = surfacePoint.m_position.GetZ();
|
||||
rowHeights[xIndex] = surfacePoint.m_position.GetZ();
|
||||
};
|
||||
|
||||
|
||||
AZ::Vector2 stepSize = AZ::Vector2(gridResolution);
|
||||
AzFramework::Terrain::TerrainDataRequestBus::Broadcast(&AzFramework::Terrain::TerrainDataRequests::ProcessHeightsFromRegion,
|
||||
region, gridResolution, ProcessHeightValue, AzFramework::Terrain::TerrainDataRequests::Sampler::EXACT);
|
||||
region, stepSize, ProcessHeightValue, AzFramework::Terrain::TerrainDataRequests::Sampler::EXACT);
|
||||
}
|
||||
|
||||
void TerrainWorldDebuggerComponent::OnTerrainDataChanged(const AZ::Aabb& dirtyRegion, TerrainDataChangedMask dataChangedMask)
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace Terrain
|
||||
bool m_isDirty{ true };
|
||||
};
|
||||
|
||||
void RebuildSectorWireframe(WireframeSector& sector, const AZ::Vector2& gridResolution);
|
||||
void RebuildSectorWireframe(WireframeSector& sector, float gridResolution);
|
||||
void MarkDirtySectors(const AZ::Aabb& dirtyRegion);
|
||||
void DrawWorldBounds(AzFramework::DebugDisplayRequests& debugDisplay);
|
||||
void DrawWireframe(const AzFramework::ViewportInfo& viewportInfo, AzFramework::DebugDisplayRequests& debugDisplay);
|
||||
|
||||
@@ -377,10 +377,11 @@ AzFramework::RenderGeometry::RayResult TerrainRaycastContext::RayIntersect(
|
||||
const AzFramework::RenderGeometry::RayRequest& ray)
|
||||
{
|
||||
const AZ::Aabb terrainWorldBounds = m_terrainSystem.GetTerrainAabb();
|
||||
const AZ::Vector2 terrainResolution = m_terrainSystem.GetTerrainHeightQueryResolution();
|
||||
const float terrainResolution = m_terrainSystem.GetTerrainHeightQueryResolution();
|
||||
const AZ::Vector2 terrainResolution2d(terrainResolution);
|
||||
AzFramework::RenderGeometry::RayResult rayIntersectionResult;
|
||||
FindNearestIntersectionIterative(m_terrainSystem,
|
||||
terrainResolution,
|
||||
terrainResolution2d,
|
||||
terrainWorldBounds,
|
||||
ray.m_startWorldPosition,
|
||||
ray.m_endWorldPosition,
|
||||
|
||||
@@ -159,11 +159,10 @@ namespace Terrain
|
||||
m_dirtyRegion.AddAabb(regionToUpdate);
|
||||
m_dirtyRegion.Clamp(worldBounds);
|
||||
|
||||
AZ::Vector2 queryResolution2D = AZ::Vector2(1.0f);
|
||||
float queryResolution = 1.0f;
|
||||
AzFramework::Terrain::TerrainDataRequestBus::BroadcastResult(
|
||||
queryResolution2D, &AzFramework::Terrain::TerrainDataRequests::GetTerrainHeightQueryResolution);
|
||||
queryResolution, &AzFramework::Terrain::TerrainDataRequests::GetTerrainHeightQueryResolution);
|
||||
// Currently query resolution is multidimensional but the rendering system only supports this changing in one dimension.
|
||||
float queryResolution = queryResolution2D.GetX();
|
||||
|
||||
m_terrainBounds = worldBounds;
|
||||
m_sampleSpacing = queryResolution;
|
||||
@@ -209,7 +208,7 @@ namespace Terrain
|
||||
|
||||
int32_t xStart = aznumeric_cast<int32_t>(AZStd::ceilf(m_dirtyRegion.GetMin().GetX() / m_sampleSpacing));
|
||||
int32_t yStart = aznumeric_cast<int32_t>(AZStd::ceilf(m_dirtyRegion.GetMin().GetY() / m_sampleSpacing));
|
||||
|
||||
|
||||
AZ::Vector2 stepSize(m_sampleSpacing);
|
||||
AZ::Vector3 maxBound(
|
||||
m_dirtyRegion.GetMax().GetX() + m_sampleSpacing, m_dirtyRegion.GetMax().GetY() + m_sampleSpacing, 0.0f);
|
||||
|
||||
@@ -203,11 +203,10 @@ namespace Terrain
|
||||
AzFramework::Terrain::TerrainDataRequestBus::BroadcastResult(
|
||||
worldBounds, &AzFramework::Terrain::TerrainDataRequests::GetTerrainAabb);
|
||||
|
||||
AZ::Vector2 queryResolution2D = AZ::Vector2(1.0f);
|
||||
float queryResolution = 1.0f;
|
||||
AzFramework::Terrain::TerrainDataRequestBus::BroadcastResult(
|
||||
queryResolution2D, &AzFramework::Terrain::TerrainDataRequests::GetTerrainHeightQueryResolution);
|
||||
queryResolution, &AzFramework::Terrain::TerrainDataRequests::GetTerrainHeightQueryResolution);
|
||||
// Currently query resolution is multidimensional but the rendering system only supports this changing in one dimension.
|
||||
float queryResolution = queryResolution2D.GetX();
|
||||
|
||||
// Sectors need to be rebuilt if the world bounds change in the x/y, or the sample spacing changes.
|
||||
m_rebuildSectors = m_rebuildSectors ||
|
||||
|
||||
@@ -134,7 +134,7 @@ void TerrainSystem::SetTerrainAabb(const AZ::Aabb& worldBounds)
|
||||
m_terrainSettingsDirty = true;
|
||||
}
|
||||
|
||||
void TerrainSystem::SetTerrainHeightQueryResolution(AZ::Vector2 queryResolution)
|
||||
void TerrainSystem::SetTerrainHeightQueryResolution(float queryResolution)
|
||||
{
|
||||
m_requestedSettings.m_heightQueryResolution = queryResolution;
|
||||
m_terrainSettingsDirty = true;
|
||||
@@ -145,7 +145,7 @@ AZ::Aabb TerrainSystem::GetTerrainAabb() const
|
||||
return m_currentSettings.m_worldBounds;
|
||||
}
|
||||
|
||||
AZ::Vector2 TerrainSystem::GetTerrainHeightQueryResolution() const
|
||||
float TerrainSystem::GetTerrainHeightQueryResolution() const
|
||||
{
|
||||
return m_currentSettings.m_heightQueryResolution;
|
||||
}
|
||||
@@ -204,7 +204,7 @@ float TerrainSystem::GetHeightSynchronous(float x, float y, Sampler sampler, boo
|
||||
AZ::Vector2 normalizedDelta;
|
||||
AZ::Vector2 pos0;
|
||||
ClampPosition(x, y, pos0, normalizedDelta);
|
||||
const AZ::Vector2 pos1 = pos0 + m_currentSettings.m_heightQueryResolution;
|
||||
const AZ::Vector2 pos1 = pos0 + AZ::Vector2(m_currentSettings.m_heightQueryResolution);
|
||||
|
||||
const float heightX0Y0 = GetTerrainAreaHeight(pos0.GetX(), pos0.GetY(), terrainExists);
|
||||
const float heightX1Y0 = GetTerrainAreaHeight(pos1.GetX(), pos0.GetY(), terrainExists);
|
||||
@@ -331,11 +331,11 @@ AZ::Vector3 TerrainSystem::GetNormalSynchronous(float x, float y, Sampler sample
|
||||
return outNormal;
|
||||
}
|
||||
}
|
||||
const AZ::Vector2 range = (m_currentSettings.m_heightQueryResolution / 2.0f);
|
||||
const AZ::Vector2 left (x - range.GetX(), y);
|
||||
const AZ::Vector2 right(x + range.GetX(), y);
|
||||
const AZ::Vector2 up (x, y - range.GetY());
|
||||
const AZ::Vector2 down (x, y + range.GetY());
|
||||
float range = m_currentSettings.m_heightQueryResolution / 2.0f;
|
||||
const AZ::Vector2 left (x - range, y);
|
||||
const AZ::Vector2 right(x + range, y);
|
||||
const AZ::Vector2 up (x, y - range);
|
||||
const AZ::Vector2 down (x, y + range);
|
||||
|
||||
AZ::Vector3 v1(up.GetX(), up.GetY(), GetHeightSynchronous(up.GetX(), up.GetY(), sampler, &terrainExists));
|
||||
AZ::Vector3 v2(left.GetX(), left.GetY(), GetHeightSynchronous(left.GetX(), left.GetY(), sampler, &terrainExists));
|
||||
|
||||
@@ -54,8 +54,8 @@ namespace Terrain
|
||||
|
||||
///////////////////////////////////////////
|
||||
// TerrainDataRequestBus::Handler Impl
|
||||
AZ::Vector2 GetTerrainHeightQueryResolution() const override;
|
||||
void SetTerrainHeightQueryResolution(AZ::Vector2 queryResolution) override;
|
||||
float GetTerrainHeightQueryResolution() const override;
|
||||
void SetTerrainHeightQueryResolution(float queryResolution) override;
|
||||
|
||||
AZ::Aabb GetTerrainAabb() const override;
|
||||
void SetTerrainAabb(const AZ::Aabb& worldBounds) override;
|
||||
@@ -213,7 +213,7 @@ namespace Terrain
|
||||
struct TerrainSystemSettings
|
||||
{
|
||||
AZ::Aabb m_worldBounds;
|
||||
AZ::Vector2 m_heightQueryResolution{ 1.0f };
|
||||
float m_heightQueryResolution{ 1.0f };
|
||||
bool m_systemActive{ false };
|
||||
};
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ TEST_F(TerrainHeightGradientListComponentTest, TerrainHeightGradientListReturnsH
|
||||
const float worldMax = 10000.0f;
|
||||
const AZ::Aabb worldAabb = AZ::Aabb::CreateFromMinMax(AZ::Vector3(min), AZ::Vector3(worldMax));
|
||||
NiceMock<UnitTest::MockTerrainDataRequests> mockterrainDataRequests;
|
||||
ON_CALL(mockterrainDataRequests, GetTerrainHeightQueryResolution).WillByDefault(Return(AZ::Vector2(1.0f)));
|
||||
ON_CALL(mockterrainDataRequests, GetTerrainHeightQueryResolution).WillByDefault(Return(1.0f));
|
||||
ON_CALL(mockterrainDataRequests, GetTerrainAabb).WillByDefault(Return(worldAabb));
|
||||
|
||||
// Ensure the cached values in the HeightGradientListComponent are up to date.
|
||||
@@ -198,7 +198,7 @@ TEST_F(TerrainHeightGradientListComponentTest, TerrainHeightGradientListGetHeigh
|
||||
const float worldMax = 10000.0f;
|
||||
const AZ::Aabb worldAabb = AZ::Aabb::CreateFromMinMax(AZ::Vector3(min), AZ::Vector3(worldMax));
|
||||
NiceMock<UnitTest::MockTerrainDataRequests> mockterrainDataRequests;
|
||||
ON_CALL(mockterrainDataRequests, GetTerrainHeightQueryResolution).WillByDefault(Return(AZ::Vector2(1.0f)));
|
||||
ON_CALL(mockterrainDataRequests, GetTerrainHeightQueryResolution).WillByDefault(Return(1.0f));
|
||||
ON_CALL(mockterrainDataRequests, GetTerrainAabb).WillByDefault(Return(worldAabb));
|
||||
|
||||
// Ensure the cached values in the HeightGradientListComponent are up to date.
|
||||
|
||||
@@ -169,7 +169,7 @@ TEST_F(TerrainPhysicsColliderComponentTest, TerrainPhysicsColliderReturnsAligned
|
||||
const AZ::Aabb bounds = AZ::Aabb::CreateFromMinMax(AZ::Vector3(boundsMin), AZ::Vector3(boundsMax));
|
||||
ON_CALL(boxShape, GetEncompassingAabb).WillByDefault(Return(bounds));
|
||||
|
||||
const AZ::Vector2 mockHeightResolution = AZ::Vector2(1.0f);
|
||||
float mockHeightResolution = 1.0f;
|
||||
NiceMock<UnitTest::MockTerrainDataRequests> terrainListener;
|
||||
ON_CALL(terrainListener, GetTerrainHeightQueryResolution).WillByDefault(Return(mockHeightResolution));
|
||||
|
||||
@@ -197,7 +197,7 @@ TEST_F(TerrainPhysicsColliderComponentTest, TerrainPhysicsColliderExpandsMinBoun
|
||||
const AZ::Aabb bounds = AZ::Aabb::CreateFromMinMax(AZ::Vector3(boundsMin), AZ::Vector3(boundsMax));
|
||||
ON_CALL(boxShape, GetEncompassingAabb).WillByDefault(Return(bounds));
|
||||
|
||||
AZ::Vector2 mockHeightResolution = AZ::Vector2(1.0f);
|
||||
float mockHeightResolution = 1.0f;
|
||||
NiceMock<UnitTest::MockTerrainDataRequests> terrainListener;
|
||||
ON_CALL(terrainListener, GetTerrainHeightQueryResolution).WillByDefault(Return(mockHeightResolution));
|
||||
|
||||
@@ -226,7 +226,7 @@ TEST_F(TerrainPhysicsColliderComponentTest, TerrainPhysicsColliderExpandsMaxBoun
|
||||
const AZ::Aabb bounds = AZ::Aabb::CreateFromMinMax(AZ::Vector3(boundsMin), AZ::Vector3(boundsMax));
|
||||
ON_CALL(boxShape, GetEncompassingAabb).WillByDefault(Return(bounds));
|
||||
|
||||
AZ::Vector2 mockHeightResolution = AZ::Vector2(1.0f);
|
||||
float mockHeightResolution = 1.0f;
|
||||
NiceMock<UnitTest::MockTerrainDataRequests> terrainListener;
|
||||
ON_CALL(terrainListener, GetTerrainHeightQueryResolution).WillByDefault(Return(mockHeightResolution));
|
||||
|
||||
@@ -254,7 +254,7 @@ TEST_F(TerrainPhysicsColliderComponentTest, TerrainPhysicsColliderGetHeightsRetu
|
||||
const AZ::Aabb bounds = AZ::Aabb::CreateFromMinMax(AZ::Vector3(boundsMin), AZ::Vector3(boundsMax));
|
||||
ON_CALL(boxShape, GetEncompassingAabb).WillByDefault(Return(bounds));
|
||||
|
||||
AZ::Vector2 mockHeightResolution = AZ::Vector2(1.0f);
|
||||
float mockHeightResolution = 1.0f;
|
||||
NiceMock<UnitTest::MockTerrainDataRequests> terrainListener;
|
||||
ON_CALL(terrainListener, GetTerrainHeightQueryResolution).WillByDefault(Return(mockHeightResolution));
|
||||
ON_CALL(terrainListener, ProcessHeightsFromRegion).WillByDefault(
|
||||
@@ -291,7 +291,7 @@ TEST_F(TerrainPhysicsColliderComponentTest, TerrainPhysicsColliderReturnsRelativ
|
||||
const AZ::Vector3 boundsMax = AZ::Vector3(256.0f, 256.0f, 32768.0f);
|
||||
|
||||
const float mockHeight = 32768.0f;
|
||||
AZ::Vector2 mockHeightResolution = AZ::Vector2(1.0f);
|
||||
float mockHeightResolution = 1.0f;
|
||||
|
||||
NiceMock<UnitTest::MockTerrainDataRequests> terrainListener;
|
||||
ON_CALL(terrainListener, GetTerrainHeightQueryResolution).WillByDefault(Return(mockHeightResolution));
|
||||
@@ -410,7 +410,7 @@ TEST_F(TerrainPhysicsColliderComponentTest, TerrainPhysicsColliderGetHeightsAndM
|
||||
ON_CALL(boxShape, GetEncompassingAabb).WillByDefault(Return(bounds));
|
||||
|
||||
const float mockHeight = 32768.0f;
|
||||
AZ::Vector2 mockHeightResolution = AZ::Vector2(1.0f);
|
||||
float mockHeightResolution = 1.0f;
|
||||
|
||||
AzFramework::SurfaceData::SurfaceTagWeight tagWeight1(tag1, 1.0f);
|
||||
AzFramework::SurfaceData::SurfaceTagWeight tagWeight2(tag2, 1.0f);
|
||||
@@ -490,7 +490,7 @@ TEST_F(TerrainPhysicsColliderComponentTest, TerrainPhysicsColliderDefaultMateria
|
||||
ON_CALL(boxShape, GetEncompassingAabb).WillByDefault(Return(bounds));
|
||||
|
||||
const float mockHeight = 32768.0f;
|
||||
AZ::Vector2 mockHeightResolution = AZ::Vector2(1.0f);
|
||||
float mockHeightResolution = 1.0f;
|
||||
|
||||
AzFramework::SurfaceData::SurfaceTagWeight tagWeight1(tag1, 1.0f);
|
||||
AzFramework::SurfaceData::SurfaceTagWeight tagWeight2(tag2, 1.0f);
|
||||
@@ -554,7 +554,7 @@ TEST_F(TerrainPhysicsColliderComponentTest, TerrainPhysicsColliderDefaultMateria
|
||||
ON_CALL(boxShape, GetEncompassingAabb).WillByDefault(Return(bounds));
|
||||
|
||||
const float mockHeight = 32768.0f;
|
||||
AZ::Vector2 mockHeightResolution = AZ::Vector2(1.0f);
|
||||
float mockHeightResolution = 1.0f;
|
||||
|
||||
const SurfaceData::SurfaceTag tag1 = SurfaceData::SurfaceTag("tag1");
|
||||
AzFramework::SurfaceData::SurfaceTagWeight tagWeight1(tag1, 1.0f);
|
||||
|
||||
@@ -117,7 +117,7 @@ namespace UnitTest
|
||||
// Create a terrain system with reasonable defaults for testing, but with the ability to override the defaults
|
||||
// on a test-by-test basis.
|
||||
AZStd::unique_ptr<Terrain::TerrainSystem> CreateAndActivateTerrainSystem(
|
||||
AZ::Vector2 queryResolution = AZ::Vector2(1.0f),
|
||||
float queryResolution = 1.0f,
|
||||
AZ::Aabb worldBounds = AZ::Aabb::CreateFromMinMax(AZ::Vector3(-128.0f), AZ::Vector3(128.0f)))
|
||||
{
|
||||
// Create the terrain system and give it one tick to fully initialize itself.
|
||||
@@ -216,7 +216,7 @@ namespace UnitTest
|
||||
void RunTerrainApiBenchmark(
|
||||
benchmark::State& state,
|
||||
AZStd::function<void(
|
||||
const AZ::Vector2& queryResolution,
|
||||
float queryResolution,
|
||||
const AZ::Aabb& worldBounds,
|
||||
AzFramework::Terrain::TerrainDataRequests::Sampler sampler)> ApiCaller)
|
||||
{
|
||||
@@ -228,7 +228,7 @@ namespace UnitTest
|
||||
|
||||
// Set up our world bounds and query resolution
|
||||
AZ::Aabb worldBounds = AZ::Aabb::CreateFromMinMax(AZ::Vector3(-boundsRange / 2.0f), AZ::Vector3(boundsRange / 2.0f));
|
||||
AZ::Vector2 queryResolution = AZ::Vector2(1.0f);
|
||||
float queryResolution = 1.0f;
|
||||
|
||||
// Create a Random Gradient to use as our height provider
|
||||
const uint32_t heightRandomSeed = 12345;
|
||||
@@ -281,17 +281,17 @@ namespace UnitTest
|
||||
surfaceGradientShapeRequests.clear();
|
||||
}
|
||||
|
||||
void GenerateInputPositionsList(const AZ::Vector2& queryResolution, const AZ::Aabb& worldBounds, AZStd::vector<AZ::Vector3>& positions)
|
||||
void GenerateInputPositionsList(float queryResolution, const AZ::Aabb& worldBounds, AZStd::vector<AZ::Vector3>& positions)
|
||||
{
|
||||
const size_t numSamplesX = aznumeric_cast<size_t>(ceil(worldBounds.GetExtents().GetX() / queryResolution.GetX()));
|
||||
const size_t numSamplesY = aznumeric_cast<size_t>(ceil(worldBounds.GetExtents().GetY() / queryResolution.GetY()));
|
||||
const size_t numSamplesX = aznumeric_cast<size_t>(ceil(worldBounds.GetExtents().GetX() / queryResolution));
|
||||
const size_t numSamplesY = aznumeric_cast<size_t>(ceil(worldBounds.GetExtents().GetY() / queryResolution));
|
||||
|
||||
for (size_t y = 0; y < numSamplesY; y++)
|
||||
{
|
||||
float fy = aznumeric_cast<float>(worldBounds.GetMin().GetY() + (y * queryResolution.GetY()));
|
||||
float fy = aznumeric_cast<float>(worldBounds.GetMin().GetY() + (y * queryResolution));
|
||||
for (size_t x = 0; x < numSamplesX; x++)
|
||||
{
|
||||
float fx = aznumeric_cast<float>(worldBounds.GetMin().GetX() + (x * queryResolution.GetX()));
|
||||
float fx = aznumeric_cast<float>(worldBounds.GetMin().GetX() + (x * queryResolution));
|
||||
positions.emplace_back(fx, fy, 0.0f);
|
||||
}
|
||||
}
|
||||
@@ -307,7 +307,7 @@ namespace UnitTest
|
||||
// Run the benchmark
|
||||
RunTerrainApiBenchmark(
|
||||
state,
|
||||
[]([[maybe_unused]] const AZ::Vector2& queryResolution, const AZ::Aabb& worldBounds,
|
||||
[]([[maybe_unused]] float queryResolution, const AZ::Aabb& worldBounds,
|
||||
AzFramework::Terrain::TerrainDataRequests::Sampler sampler)
|
||||
{
|
||||
float worldMinZ = worldBounds.GetMin().GetZ();
|
||||
@@ -343,7 +343,7 @@ namespace UnitTest
|
||||
// Run the benchmark
|
||||
RunTerrainApiBenchmark(
|
||||
state,
|
||||
[]([[maybe_unused]] const AZ::Vector2& queryResolution, const AZ::Aabb& worldBounds,
|
||||
[]([[maybe_unused]] float queryResolution, const AZ::Aabb& worldBounds,
|
||||
AzFramework::Terrain::TerrainDataRequests::Sampler sampler)
|
||||
{
|
||||
auto perPositionCallback = []([[maybe_unused]] size_t xIndex, [[maybe_unused]] size_t yIndex,
|
||||
@@ -351,9 +351,10 @@ namespace UnitTest
|
||||
{
|
||||
benchmark::DoNotOptimize(surfacePoint.m_position.GetZ());
|
||||
};
|
||||
|
||||
|
||||
AZ::Vector2 stepSize = AZ::Vector2(queryResolution);
|
||||
AzFramework::Terrain::TerrainDataRequestBus::Broadcast(
|
||||
&AzFramework::Terrain::TerrainDataRequests::ProcessHeightsFromRegion, worldBounds, queryResolution, perPositionCallback, sampler);
|
||||
&AzFramework::Terrain::TerrainDataRequests::ProcessHeightsFromRegion, worldBounds, stepSize, perPositionCallback, sampler);
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -375,7 +376,7 @@ namespace UnitTest
|
||||
// Run the benchmark
|
||||
RunTerrainApiBenchmark(
|
||||
state,
|
||||
[this]([[maybe_unused]] const AZ::Vector2& queryResolution, const AZ::Aabb& worldBounds,
|
||||
[this]([[maybe_unused]] float queryResolution, const AZ::Aabb& worldBounds,
|
||||
AzFramework::Terrain::TerrainDataRequests::Sampler sampler)
|
||||
{
|
||||
AZStd::vector<AZ::Vector3> inPositions;
|
||||
@@ -409,7 +410,7 @@ namespace UnitTest
|
||||
// Run the benchmark
|
||||
RunTerrainApiBenchmark(
|
||||
state,
|
||||
[]([[maybe_unused]] const AZ::Vector2& queryResolution, const AZ::Aabb& worldBounds,
|
||||
[]([[maybe_unused]] float queryResolution, const AZ::Aabb& worldBounds,
|
||||
AzFramework::Terrain::TerrainDataRequests::Sampler sampler)
|
||||
{
|
||||
for (float y = worldBounds.GetMin().GetY(); y < worldBounds.GetMax().GetY(); y += 1.0f)
|
||||
@@ -440,7 +441,7 @@ namespace UnitTest
|
||||
// Run the benchmark
|
||||
RunTerrainApiBenchmark(
|
||||
state,
|
||||
[]([[maybe_unused]] const AZ::Vector2& queryResolution, const AZ::Aabb& worldBounds,
|
||||
[]([[maybe_unused]] float queryResolution, const AZ::Aabb& worldBounds,
|
||||
AzFramework::Terrain::TerrainDataRequests::Sampler sampler)
|
||||
{
|
||||
auto perPositionCallback = []([[maybe_unused]] size_t xIndex, [[maybe_unused]] size_t yIndex,
|
||||
@@ -449,8 +450,9 @@ namespace UnitTest
|
||||
benchmark::DoNotOptimize(surfacePoint.m_normal);
|
||||
};
|
||||
|
||||
AZ::Vector2 stepSize = AZ::Vector2(queryResolution);
|
||||
AzFramework::Terrain::TerrainDataRequestBus::Broadcast(
|
||||
&AzFramework::Terrain::TerrainDataRequests::ProcessNormalsFromRegion, worldBounds, queryResolution, perPositionCallback, sampler);
|
||||
&AzFramework::Terrain::TerrainDataRequests::ProcessNormalsFromRegion, worldBounds, stepSize, perPositionCallback, sampler);
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -469,7 +471,7 @@ namespace UnitTest
|
||||
// Run the benchmark
|
||||
RunTerrainApiBenchmark(
|
||||
state,
|
||||
[this]([[maybe_unused]] const AZ::Vector2& queryResolution, const AZ::Aabb& worldBounds,
|
||||
[this]([[maybe_unused]] float queryResolution, const AZ::Aabb& worldBounds,
|
||||
AzFramework::Terrain::TerrainDataRequests::Sampler sampler)
|
||||
{
|
||||
AZStd::vector<AZ::Vector3> inPositions;
|
||||
@@ -500,7 +502,7 @@ namespace UnitTest
|
||||
// Run the benchmark
|
||||
RunTerrainApiBenchmark(
|
||||
state,
|
||||
[]([[maybe_unused]] const AZ::Vector2& queryResolution, const AZ::Aabb& worldBounds,
|
||||
[]([[maybe_unused]] float queryResolution, const AZ::Aabb& worldBounds,
|
||||
AzFramework::Terrain::TerrainDataRequests::Sampler sampler)
|
||||
{
|
||||
AzFramework::SurfaceData::SurfaceTagWeightList surfaceWeights;
|
||||
@@ -532,7 +534,7 @@ namespace UnitTest
|
||||
// Run the benchmark
|
||||
RunTerrainApiBenchmark(
|
||||
state,
|
||||
[]([[maybe_unused]] const AZ::Vector2& queryResolution, const AZ::Aabb& worldBounds,
|
||||
[]([[maybe_unused]] float queryResolution, const AZ::Aabb& worldBounds,
|
||||
AzFramework::Terrain::TerrainDataRequests::Sampler sampler)
|
||||
{
|
||||
auto perPositionCallback = []([[maybe_unused]] size_t xIndex, [[maybe_unused]] size_t yIndex,
|
||||
@@ -541,8 +543,9 @@ namespace UnitTest
|
||||
benchmark::DoNotOptimize(surfacePoint.m_surfaceTags);
|
||||
};
|
||||
|
||||
AZ::Vector2 stepSize = AZ::Vector2(queryResolution);
|
||||
AzFramework::Terrain::TerrainDataRequestBus::Broadcast(
|
||||
&AzFramework::Terrain::TerrainDataRequests::ProcessSurfaceWeightsFromRegion, worldBounds, queryResolution, perPositionCallback, sampler);
|
||||
&AzFramework::Terrain::TerrainDataRequests::ProcessSurfaceWeightsFromRegion, worldBounds, stepSize, perPositionCallback, sampler);
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -561,7 +564,7 @@ namespace UnitTest
|
||||
// Run the benchmark
|
||||
RunTerrainApiBenchmark(
|
||||
state,
|
||||
[this]([[maybe_unused]] const AZ::Vector2& queryResolution, const AZ::Aabb& worldBounds,
|
||||
[this]([[maybe_unused]] float queryResolution, const AZ::Aabb& worldBounds,
|
||||
AzFramework::Terrain::TerrainDataRequests::Sampler sampler)
|
||||
{
|
||||
AZStd::vector<AZ::Vector3> inPositions;
|
||||
@@ -592,7 +595,7 @@ namespace UnitTest
|
||||
// Run the benchmark
|
||||
RunTerrainApiBenchmark(
|
||||
state,
|
||||
[]([[maybe_unused]] const AZ::Vector2& queryResolution, const AZ::Aabb& worldBounds,
|
||||
[]([[maybe_unused]] float queryResolution, const AZ::Aabb& worldBounds,
|
||||
AzFramework::Terrain::TerrainDataRequests::Sampler sampler)
|
||||
{
|
||||
AzFramework::SurfaceData::SurfacePoint surfacePoint;
|
||||
@@ -624,7 +627,7 @@ namespace UnitTest
|
||||
// Run the benchmark
|
||||
RunTerrainApiBenchmark(
|
||||
state,
|
||||
[]([[maybe_unused]] const AZ::Vector2& queryResolution, const AZ::Aabb& worldBounds,
|
||||
[]([[maybe_unused]] float queryResolution, const AZ::Aabb& worldBounds,
|
||||
AzFramework::Terrain::TerrainDataRequests::Sampler sampler)
|
||||
{
|
||||
auto perPositionCallback = []([[maybe_unused]] size_t xIndex, [[maybe_unused]] size_t yIndex,
|
||||
@@ -633,8 +636,9 @@ namespace UnitTest
|
||||
benchmark::DoNotOptimize(surfacePoint);
|
||||
};
|
||||
|
||||
AZ::Vector2 stepSize = AZ::Vector2(queryResolution);
|
||||
AzFramework::Terrain::TerrainDataRequestBus::Broadcast(
|
||||
&AzFramework::Terrain::TerrainDataRequests::ProcessSurfacePointsFromRegion, worldBounds, queryResolution, perPositionCallback, sampler);
|
||||
&AzFramework::Terrain::TerrainDataRequests::ProcessSurfacePointsFromRegion, worldBounds, stepSize, perPositionCallback, sampler);
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -653,7 +657,7 @@ namespace UnitTest
|
||||
// Run the benchmark
|
||||
RunTerrainApiBenchmark(
|
||||
state,
|
||||
[this]([[maybe_unused]] const AZ::Vector2& queryResolution, const AZ::Aabb& worldBounds,
|
||||
[this]([[maybe_unused]] float queryResolution, const AZ::Aabb& worldBounds,
|
||||
AzFramework::Terrain::TerrainDataRequests::Sampler sampler)
|
||||
{
|
||||
AZStd::vector<AZ::Vector3> inPositions;
|
||||
|
||||
@@ -120,7 +120,7 @@ namespace UnitTest
|
||||
// Create a terrain system with reasonable defaults for testing, but with the ability to override the defaults
|
||||
// on a test-by-test basis.
|
||||
AZStd::unique_ptr<Terrain::TerrainSystem> CreateAndActivateTerrainSystem(
|
||||
AZ::Vector2 queryResolution = AZ::Vector2(1.0f),
|
||||
float queryResolution = 1.0f,
|
||||
AZ::Aabb worldBounds = AZ::Aabb::CreateFromMinMax(AZ::Vector3(-128.0f), AZ::Vector3(128.0f)))
|
||||
{
|
||||
// Create the terrain system and give it one tick to fully initialize itself.
|
||||
@@ -363,8 +363,7 @@ namespace UnitTest
|
||||
|
||||
// Create and activate the terrain system with our testing defaults for world bounds, and a query resolution that exactly matches
|
||||
// the frequency of our sine wave. If our height queries rely on the query resolution, we should always get a value of 0.
|
||||
const AZ::Vector2 queryResolution(frequencyMeters);
|
||||
auto terrainSystem = CreateAndActivateTerrainSystem(queryResolution);
|
||||
auto terrainSystem = CreateAndActivateTerrainSystem(frequencyMeters);
|
||||
|
||||
// Test an arbitrary set of points that should all produce non-zero heights with the EXACT sampler. They're not aligned with the
|
||||
// query resolution, or with the 0 points on the sine wave.
|
||||
@@ -414,7 +413,7 @@ namespace UnitTest
|
||||
|
||||
// Create and activate the terrain system with our testing defaults for world bounds, and a query resolution at 0.25 meter
|
||||
// intervals.
|
||||
const AZ::Vector2 queryResolution(0.25f);
|
||||
const float queryResolution = 0.25f;
|
||||
auto terrainSystem = CreateAndActivateTerrainSystem(queryResolution);
|
||||
|
||||
// Test some points and verify that the results always go "downward", whether they're in positive or negative space.
|
||||
@@ -476,8 +475,7 @@ namespace UnitTest
|
||||
});
|
||||
|
||||
// Create and activate the terrain system with our testing defaults for world bounds, and a query resolution at 1 meter intervals.
|
||||
const AZ::Vector2 queryResolution(frequencyMeters);
|
||||
auto terrainSystem = CreateAndActivateTerrainSystem(queryResolution);
|
||||
auto terrainSystem = CreateAndActivateTerrainSystem(frequencyMeters);
|
||||
|
||||
// Test some points and verify that the results are the expected bilinear filtered result,
|
||||
// whether they're in positive or negative space.
|
||||
@@ -664,8 +662,7 @@ namespace UnitTest
|
||||
});
|
||||
|
||||
// Create and activate the terrain system with our testing defaults for world bounds, and a query resolution at 1 meter intervals.
|
||||
const AZ::Vector2 queryResolution(frequencyMeters);
|
||||
auto terrainSystem = CreateAndActivateTerrainSystem(queryResolution);
|
||||
auto terrainSystem = CreateAndActivateTerrainSystem(frequencyMeters);
|
||||
|
||||
// Test some points and verify that the results are the expected bilinear filtered result,
|
||||
// whether they're in positive or negative space.
|
||||
@@ -762,8 +759,7 @@ namespace UnitTest
|
||||
});
|
||||
|
||||
// Create and activate the terrain system with our testing defaults for world bounds, and a query resolution at 1 meter intervals.
|
||||
const AZ::Vector2 queryResolution(frequencyMeters);
|
||||
auto terrainSystem = CreateAndActivateTerrainSystem(queryResolution);
|
||||
auto terrainSystem = CreateAndActivateTerrainSystem(frequencyMeters);
|
||||
|
||||
const NormalTestPoint testPoints[] = {
|
||||
|
||||
@@ -852,8 +848,7 @@ namespace UnitTest
|
||||
});
|
||||
|
||||
// Create and activate the terrain system with our testing defaults for world bounds, and a query resolution at 1 meter intervals.
|
||||
const AZ::Vector2 queryResolution(frequencyMeters);
|
||||
auto terrainSystem = CreateAndActivateTerrainSystem(queryResolution);
|
||||
auto terrainSystem = CreateAndActivateTerrainSystem(frequencyMeters);
|
||||
|
||||
const AZ::Aabb testRegionBox = AZ::Aabb::CreateFromMinMaxValues(-1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f);
|
||||
const AZ::Vector2 stepSize(1.0f);
|
||||
@@ -911,8 +906,7 @@ namespace UnitTest
|
||||
});
|
||||
|
||||
// Create and activate the terrain system with our testing defaults for world bounds, and a query resolution at 1 meter intervals.
|
||||
const AZ::Vector2 queryResolution(frequencyMeters);
|
||||
auto terrainSystem = CreateAndActivateTerrainSystem(queryResolution);
|
||||
auto terrainSystem = CreateAndActivateTerrainSystem(frequencyMeters);
|
||||
|
||||
const AZ::Aabb testRegionBox = AZ::Aabb::CreateFromMinMaxValues(-1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f);
|
||||
const AZ::Vector2 stepSize(1.0f);
|
||||
@@ -960,7 +954,7 @@ namespace UnitTest
|
||||
});
|
||||
|
||||
// Create and activate the terrain system with our testing defaults for world bounds, and a query resolution at 1 meter intervals.
|
||||
const AZ::Vector2 queryResolution(1.0f);
|
||||
const float queryResolution = 1.0f;
|
||||
auto terrainSystem = CreateAndActivateTerrainSystem(queryResolution);
|
||||
|
||||
const AZ::Aabb testRegionBox = AZ::Aabb::CreateFromMinMaxValues(-3.0f, -3.0f, -1.0f, 3.0f, 3.0f, 1.0f);
|
||||
@@ -1006,7 +1000,7 @@ namespace UnitTest
|
||||
});
|
||||
|
||||
// Create and activate the terrain system with our testing defaults for world bounds, and a query resolution at 1 meter intervals.
|
||||
const AZ::Vector2 queryResolution(1.0f);
|
||||
const float queryResolution = 1.0f;
|
||||
auto terrainSystem = CreateAndActivateTerrainSystem(queryResolution);
|
||||
|
||||
const AZ::Aabb testRegionBox = AZ::Aabb::CreateFromMinMaxValues(-3.0f, -3.0f, -1.0f, 3.0f, 3.0f, 1.0f);
|
||||
|
||||
Reference in New Issue
Block a user