LYN-8551 Terrain: Renderer: Create compute pass for clipmaps (#7116)

* Allocate a pass that will be used to generate clipmap

Signed-off-by: jiaweig <51759646+jiaweig-amzn@users.noreply.github.com>

* Fix some small issues

Signed-off-by: jiaweig <51759646+jiaweig-amzn@users.noreply.github.com>

* Rename the pass to avoid future conflict. Move assets to terrain gem.

Signed-off-by: jiaweig <51759646+jiaweig-amzn@users.noreply.github.com>

* Turn the pass off

Signed-off-by: jiaweig <51759646+jiaweig-amzn@users.noreply.github.com>

* Move pass templates to Terrain gem

Signed-off-by: jiaweig <51759646+jiaweig-amzn@users.noreply.github.com>

* move load template to private

Signed-off-by: jiaweig <51759646+jiaweig-amzn@users.noreply.github.com>

* Add macro texture compute pass

Signed-off-by: jiaweig <51759646+jiaweig-amzn@users.noreply.github.com>

* Fix uncleaned code from previous commit

Signed-off-by: jiaweig <51759646+jiaweig-amzn@users.noreply.github.com>
monroegm-disable-blank-issue-2
jiaweig 4 years ago committed by GitHub
parent c6a0d76843
commit 1dd4898713
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -42,6 +42,16 @@
"RayTracingAccelerationStructurePass" "RayTracingAccelerationStructurePass"
] ]
}, },
{
"Name": "TerrainDetailTextureComputePass",
"TemplateName": "TerrainDetailTextureComputePassTemplate",
"Enabled": false
},
{
"Name": "TerrainMacroTextureComputePass",
"TemplateName": "TerrainMacroTextureComputePassTemplate",
"Enabled": false
},
{ {
"Name": "DepthPrePass", "Name": "DepthPrePass",
"TemplateName": "DepthMSAAParentTemplate", "TemplateName": "DepthMSAAParentTemplate",

@ -0,0 +1,52 @@
{
"Type": "JsonSerialization",
"Version": 1,
"ClassName": "PassAsset",
"ClassData": {
// Note: all the data here works as placeholders.
"PassTemplate": {
"Name": "TerrainDetailTextureComputePassTemplate",
"PassClass": "TerrainDetailTextureComputePass",
"Slots": [
{
"Name": "DetailTextureClipmapOutput",
"ShaderInputName": "m_detailTexClipmap",
"SlotType": "Output",
"ScopeAttachmentUsage": "Shader"
}
],
"ImageAttachments": [
{
"Name": "DetailTextureClipmap",
"ImageDescriptor": {
"Format": "R32G32B32A32_FLOAT",
"BindFlags": "3",
"SharedQueueMask": "1",
"Size": {
"Width": 1024,
"Height": 1024
}
}
}
],
"Connections": [
{
"LocalSlot": "DetailTextureClipmapOutput",
"AttachmentRef": {
"Pass": "This",
"Attachment": "DetailTextureClipmap"
}
}
],
"PassData": {
"$type": "Terrain::TerrainDetailTextureComputePassData",
"ShaderAsset": {
"FilePath": "Shaders/Terrain/TerrainDetailTextureComputePass.shader"
},
"Target Thread Count X": 1024,
"Target Thread Count Y": 1024,
"Target Thread Count Z": 1
}
}
}
}

@ -0,0 +1,52 @@
{
"Type": "JsonSerialization",
"Version": 1,
"ClassName": "PassAsset",
"ClassData": {
// Note: all the data here works as placeholders.
"PassTemplate": {
"Name": "TerrainMacroTextureComputePassTemplate",
"PassClass": "TerrainMacroTextureComputePass",
"Slots": [
{
"Name": "MacroTextureClipmapOutput",
"ShaderInputName": "m_macroTexClipmap",
"SlotType": "Output",
"ScopeAttachmentUsage": "Shader"
}
],
"ImageAttachments": [
{
"Name": "MacroTextureClipmap",
"ImageDescriptor": {
"Format": "R32G32B32A32_FLOAT",
"BindFlags": "3",
"SharedQueueMask": "1",
"Size": {
"Width": 1024,
"Height": 1024
}
}
}
],
"Connections": [
{
"LocalSlot": "MacroTextureClipmapOutput",
"AttachmentRef": {
"Pass": "This",
"Attachment": "MacroTextureClipmap"
}
}
],
"PassData": {
"$type": "Terrain::TerrainMacroTextureComputePassData",
"ShaderAsset": {
"FilePath": "Shaders/Terrain/TerrainMacroTextureComputePass.shader"
},
"Target Thread Count X": 1024,
"Target Thread Count Y": 1024,
"Target Thread Count Z": 1
}
}
}
}

@ -0,0 +1,17 @@
{
"Type": "JsonSerialization",
"Version": 1,
"ClassName": "AssetAliasesSourceData",
"ClassData": {
"AssetPaths": [
{
"Name": "TerrainDetailTextureComputePassTemplate",
"Path": "Passes/TerrainDetailTextureComputePass.pass"
},
{
"Name": "TerrainMacroTextureComputePassTemplate",
"Path": "Passes/TerrainMacroTextureComputePass.pass"
}
]
}
}

@ -0,0 +1,18 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include "TerrainDetailTextureComputePassSrg.azsli"
[numthreads(32,32,1)]
void MainCS(
uint3 dispatchThreadID : SV_DispatchThreadID,
uint3 groupID : SV_GroupID,
uint groupIndex : SV_GroupIndex)
{
// Simple code to paint the whole image yellow for debug purpose before we actually write clipmap generation code
PassSrg::m_detailTexClipmap[dispatchThreadID.xy].rgba = float4(1.0, 1.0, 0.0, 1.0);
}

@ -0,0 +1,14 @@
{
"Source": "TerrainDetailTextureComputePass.azsl",
"ProgramSettings":
{
"EntryPoints":
[
{
"name": "MainCS",
"type": "Compute"
}
]
}
}

@ -0,0 +1,16 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include <Atom/Features/SrgSemantics.azsli>
ShaderResourceGroup PassSrg : SRG_PerPass
{
RWTexture2D<float4> m_detailTexClipmap;
}

@ -0,0 +1,18 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include "TerrainMacroTextureComputePassSrg.azsli"
[numthreads(32,32,1)]
void MainCS(
uint3 dispatchThreadID : SV_DispatchThreadID,
uint3 groupID : SV_GroupID,
uint groupIndex : SV_GroupIndex)
{
// Simple code to paint the whole image magenta for debug purpose before we actually write clipmap generation code
PassSrg::m_macroTexClipmap[dispatchThreadID.xy].rgba = float4(1.0, 0.0, 1.0, 1.0);
}

@ -0,0 +1,14 @@
{
"Source": "TerrainMacroTextureComputePass.azsl",
"ProgramSettings":
{
"EntryPoints":
[
{
"name": "MainCS",
"type": "Compute"
}
]
}
}

@ -0,0 +1,16 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include <Atom/Features/SrgSemantics.azsli>
ShaderResourceGroup PassSrg : SRG_PerPass
{
RWTexture2D<float4> m_macroTexClipmap;
}

@ -0,0 +1,55 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include <AzCore/Memory/SystemAllocator.h>
#include <Atom/RPI.Public/Pass/Pass.h>
#include <Atom/RPI.Public/Pass/ComputePass.h>
#include <Atom/RPI.Reflect/Pass/ComputePassData.h>
#include <Atom/RPI.Reflect/Pass/PassDescriptor.h>
namespace Terrain
{
class TerrainFeatureProcessor;
struct TerrainDetailTextureComputePassData
: public AZ::RPI::ComputePassData
{
AZ_RTTI(Terrain::TerrainDetailTextureComputePassData, "{387F7457-16E5-4AA6-8D96-56ED4532CA8D}", AZ::RPI::ComputePassData);
AZ_CLASS_ALLOCATOR(Terrain::TerrainDetailTextureComputePassData, AZ::SystemAllocator, 0);
TerrainDetailTextureComputePassData() = default;
virtual ~TerrainDetailTextureComputePassData() = default;
static void Reflect(AZ::ReflectContext* context);
};
class TerrainDetailTextureComputePass
: public AZ::RPI::ComputePass
{
AZ_RPI_PASS(TerrainDetailTextureComputePass);
public:
AZ_RTTI(Terrain::TerrainDetailTextureComputePass, "{69A8207B-3311-4BB1-BD4E-A08B5E0424B5}", AZ::RPI::ComputePass);
AZ_CLASS_ALLOCATOR(Terrain::TerrainDetailTextureComputePass, AZ::SystemAllocator, 0);
virtual ~TerrainDetailTextureComputePass() = default;
static AZ::RPI::Ptr<TerrainDetailTextureComputePass> Create(const AZ::RPI::PassDescriptor& descriptor);
void SetFeatureProcessor();
void CompileResources(const AZ::RHI::FrameGraphCompileContext& context) override;
private:
TerrainDetailTextureComputePass(const AZ::RPI::PassDescriptor& descriptor);
void BuildCommandListInternal(const AZ::RHI::FrameGraphExecuteContext& context) override;
TerrainFeatureProcessor* m_terrainFeatureProcessor;
};
} // namespace AZ::Render

@ -0,0 +1,55 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include <AzCore/Memory/SystemAllocator.h>
#include <Atom/RPI.Public/Pass/Pass.h>
#include <Atom/RPI.Public/Pass/ComputePass.h>
#include <Atom/RPI.Reflect/Pass/ComputePassData.h>
#include <Atom/RPI.Reflect/Pass/PassDescriptor.h>
namespace Terrain
{
class TerrainFeatureProcessor;
struct TerrainMacroTextureComputePassData
: public AZ::RPI::ComputePassData
{
AZ_RTTI(Terrain::TerrainMacroTextureComputePassData, "{BB11DACF-AF47-402D-92C6-33C644F6F530}", AZ::RPI::ComputePassData);
AZ_CLASS_ALLOCATOR(Terrain::TerrainMacroTextureComputePassData, AZ::SystemAllocator, 0);
TerrainMacroTextureComputePassData() = default;
virtual ~TerrainMacroTextureComputePassData() = default;
static void Reflect(AZ::ReflectContext* context);
};
class TerrainMacroTextureComputePass
: public AZ::RPI::ComputePass
{
AZ_RPI_PASS(TerrainMacroTextureComputePass);
public:
AZ_RTTI(Terrain::TerrainMacroTextureComputePass, "{E493C3D2-D657-49ED-A5B1-A29B2995F6A8}", AZ::RPI::ComputePass);
AZ_CLASS_ALLOCATOR(Terrain::TerrainMacroTextureComputePass, AZ::SystemAllocator, 0);
virtual ~TerrainMacroTextureComputePass() = default;
static AZ::RPI::Ptr<TerrainMacroTextureComputePass> Create(const AZ::RPI::PassDescriptor& descriptor);
void SetFeatureProcessor();
void CompileResources(const AZ::RHI::FrameGraphCompileContext& context) override;
private:
TerrainMacroTextureComputePass(const AZ::RPI::PassDescriptor& descriptor);
void BuildCommandListInternal(const AZ::RHI::FrameGraphExecuteContext& context) override;
TerrainFeatureProcessor* m_terrainFeatureProcessor;
};
} // namespace AZ::Render

@ -14,6 +14,8 @@
#include <AzCore/Serialization/EditContextConstants.inl> #include <AzCore/Serialization/EditContextConstants.inl>
#include <TerrainSystem/TerrainSystem.h> #include <TerrainSystem/TerrainSystem.h>
#include <Atom/RPI.Public/Pass/PassSystemInterface.h>
#include <Terrain/Passes/TerrainDetailTextureComputePass.h>
namespace Terrain namespace Terrain
{ {
@ -63,11 +65,33 @@ namespace Terrain
// every time an entity is added or removed to a level. If this ever changes, the Terrain System ownership could move into // every time an entity is added or removed to a level. If this ever changes, the Terrain System ownership could move into
// the level component. // the level component.
m_terrainSystem = new TerrainSystem(); m_terrainSystem = new TerrainSystem();
auto* passSystem = AZ::RPI::PassSystemInterface::Get();
AZ_Assert(passSystem, "Cannot get the pass system.");
// Setup handler for load pass templates mappings
m_loadTemplatesHandler = AZ::RPI::PassSystemInterface::OnReadyLoadTemplatesEvent::Handler([this]() { this->LoadPassTemplateMappings(); });
passSystem->ConnectEvent(m_loadTemplatesHandler);
// Register terrain system related passes
passSystem->AddPassCreator(AZ::Name("TerrainDetailTextureComputePass"), &TerrainDetailTextureComputePass::Create);
passSystem->AddPassCreator(AZ::Name("TerrainMacroTextureComputePass"), &TerrainDetailTextureComputePass::Create);
} }
void TerrainSystemComponent::Deactivate() void TerrainSystemComponent::Deactivate()
{ {
m_loadTemplatesHandler.Disconnect();
delete m_terrainSystem; delete m_terrainSystem;
m_terrainSystem = nullptr; m_terrainSystem = nullptr;
} }
void TerrainSystemComponent::LoadPassTemplateMappings()
{
auto* passSystem = AZ::RPI::PassSystemInterface::Get();
AZ_Assert(passSystem, "Cannot get the pass system.");
const char* passTemplatesFile = "Passes/TerrainPassTemplates.azasset";
passSystem->LoadPassTemplateMappings(passTemplatesFile);
}
} }

@ -9,6 +9,7 @@
#pragma once #pragma once
#include <AzCore/Component/Component.h> #include <AzCore/Component/Component.h>
#include <Atom/RPI.Public/Pass/PassSystemInterface.h>
namespace Terrain namespace Terrain
{ {
@ -36,5 +37,11 @@ namespace Terrain
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
TerrainSystem* m_terrainSystem{ nullptr }; TerrainSystem* m_terrainSystem{ nullptr };
private:
//! Used for loading the pass templates of the terrain gem.
AZ::RPI::PassSystemInterface::OnReadyLoadTemplatesEvent::Handler m_loadTemplatesHandler;
void LoadPassTemplateMappings();
}; };
} }

@ -0,0 +1,58 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include <Terrain/Passes/TerrainDetailTextureComputePass.h>
#include <TerrainRenderer/TerrainFeatureProcessor.h>
#include <Atom/RPI.Public/Pass/PassUtils.h>
#include <Atom/RPI.Public/RenderPipeline.h>
#include <Atom/RPI.Public/Scene.h>
namespace Terrain
{
void TerrainDetailTextureComputePassData::Reflect(AZ::ReflectContext* context)
{
if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<Terrain::TerrainDetailTextureComputePassData, AZ::RPI::ComputePassData>()
->Version(1);
}
}
AZ::RPI::Ptr<TerrainDetailTextureComputePass> TerrainDetailTextureComputePass::Create(const AZ::RPI::PassDescriptor& descriptor)
{
AZ::RPI::Ptr<TerrainDetailTextureComputePass> pass = aznew TerrainDetailTextureComputePass(descriptor);
return pass;
}
TerrainDetailTextureComputePass::TerrainDetailTextureComputePass(const AZ::RPI::PassDescriptor& descriptor)
: AZ::RPI::ComputePass(descriptor)
{
const TerrainDetailTextureComputePass* passData = AZ::RPI::PassUtils::GetPassData<TerrainDetailTextureComputePass>(descriptor);
if (passData)
{
// Copy data to pass
}
}
void TerrainDetailTextureComputePass::BuildCommandListInternal(const AZ::RHI::FrameGraphExecuteContext& context)
{
ComputePass::BuildCommandListInternal(context);
}
void TerrainDetailTextureComputePass::SetFeatureProcessor()
{
m_terrainFeatureProcessor = GetRenderPipeline()->GetScene()->GetFeatureProcessor<TerrainFeatureProcessor>();
}
void TerrainDetailTextureComputePass::CompileResources(const AZ::RHI::FrameGraphCompileContext& context)
{
ComputePass::CompileResources(context);
}
} // namespace Terrain

@ -0,0 +1,58 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include <Terrain/Passes/TerrainMacroTextureComputePass.h>
#include <TerrainRenderer/TerrainFeatureProcessor.h>
#include <Atom/RPI.Public/Pass/PassUtils.h>
#include <Atom/RPI.Public/RenderPipeline.h>
#include <Atom/RPI.Public/Scene.h>
namespace Terrain
{
void TerrainMacroTextureComputePassData::Reflect(AZ::ReflectContext* context)
{
if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<Terrain::TerrainMacroTextureComputePassData, AZ::RPI::ComputePassData>()
->Version(1);
}
}
AZ::RPI::Ptr<TerrainMacroTextureComputePass> TerrainMacroTextureComputePass::Create(const AZ::RPI::PassDescriptor& descriptor)
{
AZ::RPI::Ptr<TerrainMacroTextureComputePass> pass = aznew TerrainMacroTextureComputePass(descriptor);
return pass;
}
TerrainMacroTextureComputePass::TerrainMacroTextureComputePass(const AZ::RPI::PassDescriptor& descriptor)
: AZ::RPI::ComputePass(descriptor)
{
const TerrainMacroTextureComputePass* passData = AZ::RPI::PassUtils::GetPassData<TerrainMacroTextureComputePass>(descriptor);
if (passData)
{
// Copy data to pass
}
}
void TerrainMacroTextureComputePass::BuildCommandListInternal(const AZ::RHI::FrameGraphExecuteContext& context)
{
ComputePass::BuildCommandListInternal(context);
}
void TerrainMacroTextureComputePass::SetFeatureProcessor()
{
m_terrainFeatureProcessor = GetRenderPipeline()->GetScene()->GetFeatureProcessor<TerrainFeatureProcessor>();
}
void TerrainMacroTextureComputePass::CompileResources(const AZ::RHI::FrameGraphCompileContext& context)
{
ComputePass::CompileResources(context);
}
} // namespace Terrain

@ -6,12 +6,13 @@
* *
*/ */
#include <Terrain/Passes/TerrainDetailTextureComputePass.h>
#include <Terrain/Passes/TerrainMacroTextureComputePass.h>
#include <TerrainRenderer/TerrainFeatureProcessor.h> #include <TerrainRenderer/TerrainFeatureProcessor.h>
#include <Atom/Utils/Utils.h> #include <Atom/Utils/Utils.h>
#include <Atom/RHI/RHISystemInterface.h> #include <Atom/RHI/RHISystemInterface.h>
#include <Atom/RPI.Reflect/Asset/AssetUtils.h>
#include <Atom/RPI.Public/RPIUtils.h> #include <Atom/RPI.Public/RPIUtils.h>
#include <Atom/RPI.Public/Scene.h> #include <Atom/RPI.Public/Scene.h>
#include <Atom/RPI.Public/View.h> #include <Atom/RPI.Public/View.h>
@ -21,9 +22,6 @@
#include <Atom/RPI.Public/Pass/PassFilter.h> #include <Atom/RPI.Public/Pass/PassFilter.h>
#include <Atom/RPI.Public/Pass/PassSystemInterface.h> #include <Atom/RPI.Public/Pass/PassSystemInterface.h>
#include <Atom/RPI.Public/Pass/RasterPass.h> #include <Atom/RPI.Public/Pass/RasterPass.h>
#include <Atom/RPI.Reflect/Asset/AssetUtils.h>
#include <Atom/Feature/RenderCommon.h> #include <Atom/Feature/RenderCommon.h>
#include <SurfaceData/SurfaceDataSystemRequestBus.h> #include <SurfaceData/SurfaceDataSystemRequestBus.h>
@ -55,6 +53,9 @@ namespace Terrain
->Version(0) ->Version(0)
; ;
} }
TerrainDetailTextureComputePassData::Reflect(context);
TerrainMacroTextureComputePassData::Reflect(context);
} }
void TerrainFeatureProcessor::Activate() void TerrainFeatureProcessor::Activate()

@ -9,6 +9,8 @@
set(FILES set(FILES
Include/Terrain/Ebuses/TerrainAreaSurfaceRequestBus.h Include/Terrain/Ebuses/TerrainAreaSurfaceRequestBus.h
Include/Terrain/TerrainDataConstants.h Include/Terrain/TerrainDataConstants.h
Include/Terrain/Passes/TerrainDetailTextureComputePass.h
Include/Terrain/Passes/TerrainMacroTextureComputePass.h
Source/Components/TerrainHeightGradientListComponent.cpp Source/Components/TerrainHeightGradientListComponent.cpp
Source/Components/TerrainHeightGradientListComponent.h Source/Components/TerrainHeightGradientListComponent.h
Source/Components/TerrainLayerSpawnerComponent.cpp Source/Components/TerrainLayerSpawnerComponent.cpp
@ -39,6 +41,8 @@ set(FILES
Source/TerrainRenderer/BindlessImageArrayHandler.h Source/TerrainRenderer/BindlessImageArrayHandler.h
Source/TerrainRenderer/ClipmapBounds.cpp Source/TerrainRenderer/ClipmapBounds.cpp
Source/TerrainRenderer/ClipmapBounds.h Source/TerrainRenderer/ClipmapBounds.h
Source/TerrainRenderer/Passes/TerrainDetailTextureComputePass.cpp
Source/TerrainRenderer/Passes/TerrainMacroTextureComputePass.cpp
Source/TerrainRenderer/TerrainFeatureProcessor.cpp Source/TerrainRenderer/TerrainFeatureProcessor.cpp
Source/TerrainRenderer/TerrainFeatureProcessor.h Source/TerrainRenderer/TerrainFeatureProcessor.h
Source/TerrainRenderer/TerrainDetailMaterialManager.cpp Source/TerrainRenderer/TerrainDetailMaterialManager.cpp

Loading…
Cancel
Save