Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,102 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzCore/EBus/EBus.h>
#include <AzCore/Math/Aabb.h>
namespace Terrain
{
class Viewport2D
{
public:
int m_topLeftX = 0;
int m_topLeftY = 0;
int m_width = 0;
int m_height = 0;
Viewport2D() = default;
Viewport2D(const Viewport2D&) = default;
Viewport2D& operator=(const Viewport2D&) = default;
Viewport2D(int topLeftX, int topLeftY, int width, int height)
: m_topLeftX(topLeftX)
, m_topLeftY(topLeftY)
, m_width(width)
, m_height(height)
{
}
};
// External height map data requests
class HeightmapDataRequestInfo
{
public:
HeightmapDataRequestInfo() = default;
HeightmapDataRequestInfo(const HeightmapDataRequestInfo& rhs) = default;
HeightmapDataRequestInfo& operator=(const HeightmapDataRequestInfo& rhs) = default;
HeightmapDataRequestInfo(int viewportTopLeftX, int viewportTopLeftY, int viewportWidth, int viewportHeight, float metersPerPixel, AZ::Vector2 worldMin, AZ::Vector2 worldMax)
: m_viewport(viewportTopLeftX, viewportTopLeftY, viewportWidth, viewportHeight)
, m_metersPerPixel(metersPerPixel)
, m_worldMin(worldMin)
, m_worldMax(worldMax)
{
}
float GetMetersPerPixel() const
{
return m_metersPerPixel;
}
AZ::Vector2 GetWorldMin() const
{
return m_worldMin;
}
AZ::Vector2 GetWorldMax() const
{
return m_worldMax;
}
AZ::Vector2 GetWorldWidth() const
{
return (m_worldMax - m_worldMin);
}
Viewport2D GetViewport() const
{
return m_viewport;
}
private:
Viewport2D m_viewport;
AZ::Vector2 m_worldMin = AZ::Vector2(0.0f, 0.0f);
AZ::Vector2 m_worldMax = AZ::Vector2(0.0f, 0.0f);
float m_metersPerPixel = 1.0f;
};
class HeightmapDataNotifications
: public AZ::EBusTraits
{
public:
//////////////////////////////////////////////////////////////////////////
// EBusTraits overrides
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple;
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
//////////////////////////////////////////////////////////////////////////
virtual void OnTerrainHeightDataChanged(const AZ::Aabb& dirtyRegion) = 0;
};
using HeightmapDataNotificationBus = AZ::EBus<HeightmapDataNotifications>;
}
@@ -0,0 +1,56 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzCore/EBus/EBus.h>
#include <AzCore/std/string/string_view.h>
class CShader;
namespace Terrain
{
class TerrainDataRequests
: public AZ::EBusTraits
{
public:
//////////////////////////////////////////////////////////////////////////
// EBusTraits overrides
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
using MutexType = AZStd::recursive_mutex;
//////////////////////////////////////////////////////////////////////////
virtual float GetHeightSynchronous(float x, float y) = 0;
virtual AZ::Vector3 GetNormalSynchronous(float x, float y) = 0;
virtual CShader* GetTerrainHeightGeneratorShader() const = 0;
virtual CShader* GetTerrainMaterialCompositingShader() const = 0;
};
using TerrainDataRequestBus = AZ::EBus<TerrainDataRequests>;
class TerrainShaderRequests
: public AZ::EBusTraits
{
public:
//////////////////////////////////////////////////////////////////////////
// EBusTraits overrides
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
using MutexType = AZStd::recursive_mutex;
//////////////////////////////////////////////////////////////////////////
virtual void RefreshShader(const AZStd::string_view name, CShader* shader) = 0;
virtual void ReleaseShader(CShader* shader) const = 0;
};
using TerrainShaderRequestBus = AZ::EBus<TerrainShaderRequests>;
}
@@ -0,0 +1,82 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzCore/Math/Vector2.h>
#include <AzCore/std/functional.h>
#include <AzCore/std/smart_ptr/shared_ptr.h>
#include <AzCore/EBus/EBus.h>
#include "HeightmapDataBus.h"
class CShader;
namespace Terrain
{
// This interface defines how the renderer can access the terrain system to set up state and gather information before rendering height maps
class TerrainProviderRequests
: public AZ::EBusTraits
{
public:
//////////////////////////////////////////////////////////////////////////
// EBusTraits overrides
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
//! allows multiple threads to call
using MutexType = AZStd::recursive_mutex;
//////////////////////////////////////////////////////////////////////////
// world properties
virtual AZ::Vector3 GetWorldSize() = 0;
virtual AZ::Vector3 GetRegionSize() = 0;
virtual AZ::Vector3 GetWorldOrigin() = 0;
virtual AZ::Vector2 GetHeightRange() = 0;
// utility
virtual void GetRegionIndex(const AZ::Vector2& worldMin, const AZ::Vector2& worldMax, int& regionIndexX, int& regionIndexY) = 0;
virtual float GetHeightAtIndexedPosition([[maybe_unused]] int ix, [[maybe_unused]] int iy) { return 64.0f; }
virtual float GetHeightAtWorldPosition([[maybe_unused]] float fx, [[maybe_unused]] float fy) { return 64.0f; }
virtual unsigned char GetSurfaceTypeAtIndexedPosition([[maybe_unused]] int ix, [[maybe_unused]] int iy) { return 0; }
};
using TerrainProviderRequestBus = AZ::EBus<TerrainProviderRequests>;
// This class exists for the terrain system to inject data into the renderer for generating the GPU-side terrain height map
struct CRETerrainContext
{
// Tract map
virtual void OnTractVersionUpdate() = 0;
CShader* m_currentShader = nullptr;
};
class TerrainProviderNotifications
: public AZ::EBusTraits
{
public:
//////////////////////////////////////////////////////////////////////////
// EBusTraits overrides
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
//! allows multiple threads to call
using MutexType = AZStd::recursive_mutex;
//////////////////////////////////////////////////////////////////////////
// interface to be implemented by the game, invoked by the terrain render element
// pull settings from the world cache, so the next accessors are accurate
virtual void SynchronizeSettings(CRETerrainContext* context) = 0;
};
using TerrainProviderNotificationBus = AZ::EBus<TerrainProviderNotifications>;
}
@@ -0,0 +1,37 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzCore/EBus/EBus.h>
namespace Terrain
{
class TerrainRendererRequests
: public AZ::EBusTraits
{
public:
//////////////////////////////////////////////////////////////////////////
// EBusTraits overrides
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
//////////////////////////////////////////////////////////////////////////
//! allows multiple threads to call
using MutexType = AZStd::recursive_mutex;
// Query state of the terrain renderer
// Returns true once the terrain renderer has fulfilled most data requests and is ready for rendering
virtual bool IsReady() = 0;
};
using TerrainRendererRequestBus = AZ::EBus<TerrainRendererRequests>;
}
@@ -0,0 +1,122 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzCore/EBus/EBus.h>
#include <AzCore/std/containers/vector.h>
#include <AzCore/std/containers/fixed_vector.h>
struct IMaterial;
class ITexture;
namespace Terrain
{
struct MacroMaterial
{
// Textures
_smart_ptr<ITexture> m_macroColorMap = nullptr;
_smart_ptr<ITexture> m_macroGlossMap = nullptr;
_smart_ptr<ITexture> m_macroNormalMap = nullptr;
// Material Params
AZ::Color m_macroColorMapColor;
float m_macroGlossMapScale = 1.0f;
float m_macroNormalMapScale = 1.0f;
float m_macroSpecReflectance = 0.03f;
void Clear()
{
m_macroColorMap = nullptr;
m_macroGlossMap = nullptr;
m_macroNormalMap = nullptr;
m_macroColorMapColor = AZ::Color(1.0f);
m_macroGlossMapScale = 1.0f;
m_macroNormalMapScale = 1.0f;
m_macroSpecReflectance = 0.03f;
}
};
struct TerrainMaterialLayer
{
_smart_ptr<IMaterial> m_material = nullptr;
_smart_ptr<ITexture> m_splatTexture = nullptr;
TerrainMaterialLayer(_smart_ptr<IMaterial> material, _smart_ptr<ITexture> splatTexture)
: m_material(material)
, m_splatTexture(splatTexture)
{
}
};
struct RegionMaterials
{
MacroMaterial m_macroMaterial;
AZStd::vector<TerrainMaterialLayer> m_materialLayers;
_smart_ptr<IMaterial> m_defaultMaterial = nullptr;
RegionMaterials& operator=(const RegionMaterials& rhs) = default;
void Clear()
{
m_materialLayers.clear();
m_defaultMaterial = nullptr;
m_macroMaterial.Clear();
}
};
const AZ::u32 kMaxRegionsPerTerrainMaterialRequest = 16;
typedef AZStd::pair<int, int> RegionIndex;
typedef AZStd::fixed_vector<RegionIndex, kMaxRegionsPerTerrainMaterialRequest> RegionIndexVector;
typedef AZStd::fixed_vector<RegionMaterials, kMaxRegionsPerTerrainMaterialRequest> RegionMaterialVector;
enum class RequestResult
{
NoAssetsForRegion,
Loading,
Success
};
class WorldMaterialRequests
: public AZ::EBusTraits
{
public:
//////////////////////////////////////////////////////////////////////////
// EBusTraits overrides
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
//////////////////////////////////////////////////////////////////////////
//! allows multiple threads to call
using MutexType = AZStd::recursive_mutex;
virtual void LoadWorld(const AZStd::string& worldName, int regionSize) = 0;
virtual RequestResult RequestRegionMaterials(const RegionIndexVector& regions, RegionMaterialVector& outRegionMaterials) = 0;
// Parameters:
// int tileX, tileY : Region tile indices
// Returns:
// bool : If true, region material data is loaded and exists. outMacroMaterial will be modified with the respective macro material data
// If false, no region material data has been loaded or exists for the given tile (may still have invalid material layers).
virtual RequestResult GetMacroMaterial(int tileX, int tileY, MacroMaterial& outMacroMaterial) = 0;
virtual void GetTerrainPOMParameters(float& pomHeightBias, float& pomDisplacement, float& selfShadowStrength) = 0;
//Get the surface type at a given position. If not loaded yet, returns "loadingMaterial".
virtual AZStd::string_view GetSurfaceTypeAtPosition(AZ::Vector2 position) = 0;
};
using WorldMaterialRequestBus = AZ::EBus<WorldMaterialRequests>;
} // namespace Terrain