2020-09-15 17:20:22 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#if WITH_EDITOR
|
|
|
|
|
|
|
|
|
|
#include "PostProcess/PostProcessVisualizeLevelInstance.h"
|
|
|
|
|
#include "PostProcess/PostProcessCompositeEditorPrimitives.h"
|
|
|
|
|
#include "SceneTextureParameters.h"
|
|
|
|
|
#include "CanvasTypes.h"
|
|
|
|
|
#include "RenderTargetTemp.h"
|
|
|
|
|
#include "ClearQuad.h"
|
2021-01-14 05:23:34 -04:00
|
|
|
#include "ScenePrivate.h"
|
2020-09-15 17:20:22 -04:00
|
|
|
|
|
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
class FVisualizeLevelInstancePS : public FEditorPrimitiveShader
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
DECLARE_GLOBAL_SHADER(FVisualizeLevelInstancePS);
|
|
|
|
|
SHADER_USE_PARAMETER_STRUCT(FVisualizeLevelInstancePS, FEditorPrimitiveShader);
|
|
|
|
|
|
|
|
|
|
BEGIN_SHADER_PARAMETER_STRUCT(FParameters, )
|
|
|
|
|
SHADER_PARAMETER_STRUCT_REF(FViewUniformShaderParameters, View)
|
|
|
|
|
SHADER_PARAMETER_STRUCT(FScreenPassTextureViewportParameters, Color)
|
|
|
|
|
SHADER_PARAMETER_STRUCT(FScreenPassTextureViewportParameters, Depth)
|
2021-04-26 11:28:05 -04:00
|
|
|
SHADER_PARAMETER(FScreenTransform, ColorToDepth)
|
2020-09-15 17:20:22 -04:00
|
|
|
SHADER_PARAMETER_RDG_TEXTURE(Texture2D, ColorTexture)
|
|
|
|
|
SHADER_PARAMETER_SAMPLER(SamplerState, ColorSampler)
|
|
|
|
|
SHADER_PARAMETER_RDG_TEXTURE(Texture2D, DepthTexture)
|
|
|
|
|
SHADER_PARAMETER_SAMPLER(SamplerState, DepthSampler)
|
|
|
|
|
SHADER_PARAMETER_RDG_TEXTURE(Texture2D, EditorPrimitivesDepth)
|
|
|
|
|
SHADER_PARAMETER_RDG_TEXTURE_SRV(Texture2D, EditorPrimitivesStencil)
|
|
|
|
|
RENDER_TARGET_BINDING_SLOTS()
|
|
|
|
|
END_SHADER_PARAMETER_STRUCT()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
IMPLEMENT_GLOBAL_SHADER(FVisualizeLevelInstancePS, "/Engine/Private/PostProcessVisualizeLevelInstance.usf", "MainPS", SF_Pixel);
|
|
|
|
|
} //! namespace
|
|
|
|
|
|
2021-01-14 05:23:34 -04:00
|
|
|
|
|
|
|
|
BEGIN_SHADER_PARAMETER_STRUCT(FVisualizeLevelInstancePassPassParameters, )
|
|
|
|
|
SHADER_PARAMETER_STRUCT_INCLUDE(FSceneTextureShaderParameters, SceneTextures)
|
|
|
|
|
SHADER_PARAMETER_STRUCT_INCLUDE(FNaniteVisualizeLevelInstanceParameters, NaniteVisualizeLevelInstanceParameters)
|
|
|
|
|
SHADER_PARAMETER_STRUCT_INCLUDE(FInstanceCullingDrawParams, InstanceCullingDrawParams)
|
|
|
|
|
RENDER_TARGET_BINDING_SLOTS()
|
|
|
|
|
END_SHADER_PARAMETER_STRUCT()
|
|
|
|
|
|
2020-09-15 17:20:22 -04:00
|
|
|
FScreenPassTexture AddVisualizeLevelInstancePass(FRDGBuilder& GraphBuilder, const FViewInfo& View, const FVisualizeLevelInstanceInputs& Inputs, const Nanite::FRasterResults *NaniteRasterResults)
|
|
|
|
|
{
|
|
|
|
|
check(Inputs.SceneColor.IsValid());
|
|
|
|
|
check(Inputs.SceneDepth.IsValid());
|
|
|
|
|
|
|
|
|
|
const bool bNaniteEnabled = DoesPlatformSupportNanite(GMaxRHIShaderPlatform); // TODO: Respect r.Nanite
|
|
|
|
|
|
|
|
|
|
RDG_EVENT_SCOPE(GraphBuilder, "EditorVisualizeLevelInstance");
|
|
|
|
|
|
UE5_MAIN: Multi-view-family scene renderer refactor, part 2. Move FSceneTextures singleton out of RDG blackboard and FSceneTexturesConfig global variable singleton, into FViewFamilyInfo. This is necessary to allow multiple view families to render in a single render graph and a single scene renderer call.
* Existing calls to CreateSceneTextureShaderParameters and similar functions use "GetSceneTexturesChecked", which allows for the possibility that they are reached in a code path where scene textures haven't been initialized, and nullptr is returned instead of asserting. The shader parameter setup functions then fill in dummy defaults for that case. The goal was to precisely match the original behavior, which queried the RDG blackboard, and gracefully handled null if scene textures weren't there. This definitely appears to occur in FNiagaraGpuComputeDispatch::ProcessPendingTicksFlush, which can be called with a dummy scene with no scene textures. In the future, I may change this so dummy defaults are filled in for FSceneTextures at construction time, so the structure is never in an uninitialized state, but I would like to set up a test case for the Niagara code path before doing that, and the checks aren't harmful in the meantime.
* I marked as deprecated global functions which query values from FSceneTexturesConfig, but they'll still work with the caveat that if you use multi-view-family rendering, the results will be indeterminate (whatever view family rendered last). There was only one case outside the scene renderer that accessed the globals (depth clear value), which I removed, noting that there is nowhere in the code where we modify the depth clear value from its global default. I would like to permanently deprecate or remove these at some point. Display Cluster is the only code that's currently using the multi-view-family code path, and as a new (still incomplete) feature, third party code can't be using it, and won't be affected.
#jira NONE
#rb chris.kulla zach.bethel mihnea.balta
#preflight 6261aca76119a1a496bd2644
[CL 19873983 by jason hoerner in ue5-main branch]
2022-04-22 17:33:02 -04:00
|
|
|
const uint32 NumSamples = View.GetSceneTexturesConfig().NumSamples;
|
2020-09-15 17:20:22 -04:00
|
|
|
|
|
|
|
|
// Patch uniform buffers with updated state for rendering the outline mesh draw commands.
|
2021-01-11 14:49:16 -04:00
|
|
|
const FViewInfo* EditorView = CreateEditorPrimitiveView(View, Inputs.SceneColor.ViewRect, NumSamples);
|
2020-09-15 17:20:22 -04:00
|
|
|
|
|
|
|
|
FRDGTextureRef DepthStencilTexture = nullptr;
|
|
|
|
|
|
|
|
|
|
// Generate custom depth / stencil for outline shapes.
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
FRDGTextureDesc DepthStencilDesc = Inputs.SceneColor.Texture->Desc;
|
|
|
|
|
DepthStencilDesc.Reset();
|
|
|
|
|
DepthStencilDesc.Format = PF_DepthStencil;
|
|
|
|
|
// This is a reversed Z depth surface, so 0.0f is the far plane.
|
|
|
|
|
DepthStencilDesc.ClearValue = FClearValueBinding((float)ERHIZBuffer::FarPlane, 0);
|
2020-09-24 00:43:27 -04:00
|
|
|
DepthStencilDesc.Flags = TexCreate_DepthStencilTargetable | TexCreate_ShaderResource;
|
2021-01-11 14:49:16 -04:00
|
|
|
DepthStencilDesc.NumSamples = NumSamples;
|
2020-09-15 17:20:22 -04:00
|
|
|
|
|
|
|
|
DepthStencilTexture = GraphBuilder.CreateTexture(DepthStencilDesc, TEXT("LevelInstanceDepth"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FScene* Scene = View.Family->Scene->GetRenderScene();
|
|
|
|
|
|
|
|
|
|
const FScreenPassTextureViewport SceneColorViewport(Inputs.SceneColor);
|
|
|
|
|
|
2021-01-14 05:23:34 -04:00
|
|
|
auto* PassParameters = GraphBuilder.AllocParameters<FVisualizeLevelInstancePassPassParameters>();
|
2020-09-15 17:20:22 -04:00
|
|
|
if (bNaniteEnabled)
|
|
|
|
|
{
|
2021-01-14 05:23:34 -04:00
|
|
|
Nanite::GetEditorVisualizeLevelInstancePassParameters(GraphBuilder, *Scene, View, SceneColorViewport.Rect, NaniteRasterResults, &PassParameters->NaniteVisualizeLevelInstanceParameters);
|
2020-09-15 17:20:22 -04:00
|
|
|
}
|
|
|
|
|
|
2021-01-14 15:46:32 -04:00
|
|
|
const_cast<FViewInfo&>(View).ParallelMeshDrawCommandPasses[EMeshPass::EditorLevelInstance].BuildRenderingCommands(GraphBuilder, Scene->GPUScene, PassParameters->InstanceCullingDrawParams);
|
|
|
|
|
|
2022-03-23 19:30:55 -04:00
|
|
|
PassParameters->NaniteVisualizeLevelInstanceParameters.View = EditorView->ViewUniformBuffer;
|
2020-09-24 00:43:27 -04:00
|
|
|
PassParameters->SceneTextures = Inputs.SceneTextures;
|
2020-09-15 17:20:22 -04:00
|
|
|
PassParameters->RenderTargets.DepthStencil = FDepthStencilBinding(
|
|
|
|
|
DepthStencilTexture,
|
|
|
|
|
ERenderTargetLoadAction::EClear,
|
|
|
|
|
ERenderTargetLoadAction::EClear,
|
|
|
|
|
FExclusiveDepthStencil::DepthWrite_StencilWrite);
|
|
|
|
|
|
|
|
|
|
GraphBuilder.AddPass(
|
|
|
|
|
RDG_EVENT_NAME("LevelInstanceDepth %dx%d", SceneColorViewport.Rect.Width(), SceneColorViewport.Rect.Height()),
|
|
|
|
|
PassParameters,
|
|
|
|
|
ERDGPassFlags::Raster,
|
2021-07-13 12:38:27 -04:00
|
|
|
[&View, SceneColorViewport, DepthStencilTexture, NaniteRasterResults, PassParameters, bNaniteEnabled](FRHICommandListImmediate& RHICmdList)
|
2020-09-15 17:20:22 -04:00
|
|
|
{
|
|
|
|
|
RHICmdList.SetViewport(SceneColorViewport.Rect.Min.X, SceneColorViewport.Rect.Min.Y, 0.0f, SceneColorViewport.Rect.Max.X, SceneColorViewport.Rect.Max.Y, 1.0f);
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
SCOPED_DRAW_EVENT(RHICmdList, EditorLevelInstance);
|
|
|
|
|
|
|
|
|
|
// Run LevelInstance pass on static elements
|
2021-01-14 05:23:34 -04:00
|
|
|
View.ParallelMeshDrawCommandPasses[EMeshPass::EditorLevelInstance].DispatchDraw(nullptr, RHICmdList, &PassParameters->InstanceCullingDrawParams);
|
2020-09-15 17:20:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Render Nanite mesh outlines after regular meshes
|
|
|
|
|
if (bNaniteEnabled)
|
|
|
|
|
{
|
2021-01-14 05:23:34 -04:00
|
|
|
Nanite::DrawEditorVisualizeLevelInstance(RHICmdList, View, SceneColorViewport.Rect, PassParameters->NaniteVisualizeLevelInstanceParameters);
|
2020-09-15 17:20:22 -04:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FScreenPassRenderTarget Output = Inputs.OverrideOutput;
|
|
|
|
|
|
|
|
|
|
if (!Output.IsValid())
|
|
|
|
|
{
|
|
|
|
|
Output = FScreenPassRenderTarget::CreateFromInput(GraphBuilder, Inputs.SceneColor, View.GetOverwriteLoadAction(), TEXT("LevelInstanceColor"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Render grey-post process effect.
|
|
|
|
|
{
|
|
|
|
|
const FScreenPassTextureViewport OutputViewport(Output);
|
|
|
|
|
const FScreenPassTextureViewport ColorViewport(Inputs.SceneColor);
|
|
|
|
|
const FScreenPassTextureViewport DepthViewport(Inputs.SceneDepth);
|
|
|
|
|
|
|
|
|
|
FRHISamplerState* PointClampSampler = TStaticSamplerState<SF_Point, AM_Clamp, AM_Clamp, AM_Clamp>::GetRHI();
|
2022-03-23 19:30:55 -04:00
|
|
|
FRHISamplerState* BilinearClampSampler = TStaticSamplerState<SF_Bilinear, AM_Clamp, AM_Clamp, AM_Clamp>::GetRHI();
|
2020-09-15 17:20:22 -04:00
|
|
|
|
|
|
|
|
FVisualizeLevelInstancePS::FParameters* PassParameters = GraphBuilder.AllocParameters<FVisualizeLevelInstancePS::FParameters>();
|
|
|
|
|
PassParameters->RenderTargets[0] = Output.GetRenderTargetBinding();
|
|
|
|
|
PassParameters->View = View.ViewUniformBuffer;
|
|
|
|
|
PassParameters->Color = GetScreenPassTextureViewportParameters(ColorViewport);
|
|
|
|
|
PassParameters->Depth = GetScreenPassTextureViewportParameters(DepthViewport);
|
2021-04-26 11:28:05 -04:00
|
|
|
PassParameters->ColorToDepth = FScreenTransform::ChangeTextureUVCoordinateFromTo(ColorViewport, DepthViewport);
|
2020-09-15 17:20:22 -04:00
|
|
|
PassParameters->ColorTexture = Inputs.SceneColor.Texture;
|
|
|
|
|
PassParameters->ColorSampler = PointClampSampler;
|
|
|
|
|
PassParameters->DepthTexture = Inputs.SceneDepth.Texture;
|
2022-03-23 19:30:55 -04:00
|
|
|
PassParameters->DepthSampler = BilinearClampSampler;
|
2020-09-15 17:20:22 -04:00
|
|
|
PassParameters->EditorPrimitivesDepth = DepthStencilTexture;
|
|
|
|
|
PassParameters->EditorPrimitivesStencil = GraphBuilder.CreateSRV(FRDGTextureSRVDesc::CreateWithPixelFormat(DepthStencilTexture, PF_X24_G8));
|
|
|
|
|
|
|
|
|
|
FVisualizeLevelInstancePS::FPermutationDomain PermutationVector;
|
2021-01-11 14:49:16 -04:00
|
|
|
PermutationVector.Set<FVisualizeLevelInstancePS::FSampleCountDimension>(NumSamples);
|
2020-09-15 17:20:22 -04:00
|
|
|
|
|
|
|
|
TShaderMapRef<FVisualizeLevelInstancePS> PixelShader(View.ShaderMap, PermutationVector);
|
|
|
|
|
|
|
|
|
|
AddDrawScreenPass(
|
|
|
|
|
GraphBuilder,
|
|
|
|
|
RDG_EVENT_NAME("LevelInstanceColor %dx%d", OutputViewport.Rect.Width(), OutputViewport.Rect.Height()),
|
|
|
|
|
View,
|
|
|
|
|
OutputViewport,
|
|
|
|
|
ColorViewport,
|
|
|
|
|
PixelShader,
|
|
|
|
|
PassParameters);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return MoveTemp(Output);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|