Terrain detail and macro texture support (#4403)
* Terrain feature processor improvements regarding material, mesh, and lod - Now using a material with pbr lighting for terrain. Removed some of the old shader code that wasn't needed anymore - Move heightmap image declaration to the material so it's not needed in the object SRG anymore - Added prototype code (commented out) for smoothing the terrain with a b-spline weighting function - Mesh data is all made with a proper mesh asset now. - Added basic LOD support (no continuous LOD yet, but it does pop between lod levels) - Moved RenderCommon to be accessible publicly. It contains stencil refs that should be public. Signed-off-by: Ken Pruiksma <pruiksma@amazon.com> * Adding more material options to terrain shader Signed-off-by: Ken Pruiksma <pruiksma@amazon.com> * Fixing terrain's per object srg because of changes in the default per object srg. Signed-off-by: Ken Pruiksma <pruiksma@amazon.com> * Added more features to the terrain material. Shader & Material reloads are now handled. Signed-off-by: Ken Pruiksma <pruiksma@amazon.com> * Added stub for terrain render max area setting in the renderer component. Added detail texture tiling setable from the material Signed-off-by: Ken Pruiksma <pruiksma@amazon.com> * Missing change to material type from last commit Signed-off-by: Ken Pruiksma <pruiksma@amazon.com> * Adding macro material in material type and support detail roughness. Signed-off-by: Ken Pruiksma <pruiksma@amazon.com> * Fixing merge issues in terrain material type Signed-off-by: Ken Pruiksma <pruiksma@amazon.com> * Adding more features to the terrain material - Macro color and normals - Detail layer fade out - Reoriented detail normals Signed-off-by: Ken Pruiksma <pruiksma@amazon.com> * Remove line that unintentionally was added back during a rebase & merge. Signed-off-by: Ken Pruiksma <pruiksma@amazon.com> * Fixing previously deleted unused static that came back after a merge. Fixed an issue with macro normals in the terrain shader. Signed-off-by: Ken Pruiksma <pruiksma@amazon.com>
This commit is contained in:
@@ -76,26 +76,24 @@ namespace Terrain
|
||||
|
||||
void TerrainFeatureProcessor::Initialize()
|
||||
{
|
||||
{
|
||||
// Load the terrain material asynchronously
|
||||
const AZStd::string materialFilePath = "Materials/Terrain/DefaultPbrTerrain.azmaterial";
|
||||
m_materialAssetLoader = AZStd::make_unique<AZ::RPI::AssetUtils::AsyncAssetLoader>();
|
||||
*m_materialAssetLoader = AZ::RPI::AssetUtils::AsyncAssetLoader::Create<AZ::RPI::MaterialAsset>(materialFilePath, 0u,
|
||||
[&](AZ::Data::Asset<AZ::Data::AssetData> assetData, bool success) -> void
|
||||
// Load the terrain material asynchronously
|
||||
const AZStd::string materialFilePath = "Materials/Terrain/DefaultPbrTerrain.azmaterial";
|
||||
m_materialAssetLoader = AZStd::make_unique<AZ::RPI::AssetUtils::AsyncAssetLoader>();
|
||||
*m_materialAssetLoader = AZ::RPI::AssetUtils::AsyncAssetLoader::Create<AZ::RPI::MaterialAsset>(materialFilePath, 0u,
|
||||
[&](AZ::Data::Asset<AZ::Data::AssetData> assetData, bool success) -> void
|
||||
{
|
||||
const AZ::Data::Asset<AZ::RPI::MaterialAsset>& materialAsset = static_cast<AZ::Data::Asset<AZ::RPI::MaterialAsset>>(assetData);
|
||||
if (success)
|
||||
{
|
||||
const AZ::Data::Asset<AZ::RPI::MaterialAsset>& materialAsset = static_cast<AZ::Data::Asset<AZ::RPI::MaterialAsset>>(assetData);
|
||||
if (success)
|
||||
m_materialInstance = AZ::RPI::Material::FindOrCreate(assetData);
|
||||
AZ::RPI::MaterialReloadNotificationBus::Handler::BusConnect(materialAsset->GetId());
|
||||
if (!materialAsset->GetObjectSrgLayout())
|
||||
{
|
||||
m_materialInstance = AZ::RPI::Material::FindOrCreate(assetData);
|
||||
if (!materialAsset->GetObjectSrgLayout())
|
||||
{
|
||||
AZ_Error("TerrainFeatureProcessor", false, "No per-object ShaderResourceGroup found on terrain material.");
|
||||
}
|
||||
AZ_Error("TerrainFeatureProcessor", false, "No per-object ShaderResourceGroup found on terrain material.");
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
if (!InitializePatchModel())
|
||||
{
|
||||
AZ_Error(TerrainFPName, false, "Failed to create Terrain render buffers!");
|
||||
@@ -105,10 +103,9 @@ namespace Terrain
|
||||
|
||||
void TerrainFeatureProcessor::Deactivate()
|
||||
{
|
||||
DisableSceneNotification();
|
||||
|
||||
m_patchModel = {};
|
||||
m_areaData = {};
|
||||
AZ::RPI::MaterialReloadNotificationBus::Handler::BusDisconnect();
|
||||
}
|
||||
|
||||
void TerrainFeatureProcessor::Render(const AZ::RPI::FeatureProcessor::RenderPacket& packet)
|
||||
@@ -291,7 +288,7 @@ namespace Terrain
|
||||
AZ::Vector2 sectorCenterXY = AZ::Vector2(sectorData.m_aabb.GetCenter().GetX(), sectorData.m_aabb.GetCenter().GetY());
|
||||
|
||||
float sectorDistance = sectorCenterXY.GetDistance(cameraPositionXY);
|
||||
float lodForCamera = ceilf(AZ::GetMax(0.0f, log2f(sectorDistance / (GridMeters * 4.0f))));
|
||||
float lodForCamera = floorf(AZ::GetMax(0.0f, log2f(sectorDistance / (GridMeters * 4.0f))));
|
||||
lodChoice = AZ::GetMin(lodChoice, aznumeric_cast<uint8_t>(lodForCamera));
|
||||
}
|
||||
}
|
||||
@@ -317,6 +314,7 @@ namespace Terrain
|
||||
|
||||
uint16_t gridVertices = gridSize + 1; // For m_gridSize quads, (m_gridSize + 1) vertices are needed.
|
||||
size_t size = gridVertices * gridVertices;
|
||||
size *= size;
|
||||
|
||||
patchdata.m_positions.reserve(size);
|
||||
patchdata.m_uvs.reserve(size);
|
||||
@@ -432,4 +430,21 @@ namespace Terrain
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
void TerrainFeatureProcessor::OnMaterialReinitialized([[maybe_unused]] const AZ::Data::Instance<AZ::RPI::Material>& material)
|
||||
{
|
||||
for (auto& sectorData : m_sectorData)
|
||||
{
|
||||
for (auto& drawPacket : sectorData.m_drawPackets)
|
||||
{
|
||||
drawPacket.Update(*GetParentScene());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TerrainFeatureProcessor::SetWorldSize([[maybe_unused]] AZ::Vector2 sizeInMeters)
|
||||
{
|
||||
// This will control the max rendering size. Actual terrain size can be much
|
||||
// larger but this will limit how much is rendered.
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user