Files
UnrealEngineUWP/Engine/Source/Runtime/Renderer/Private/DebugProbeRendering.cpp
Sebastien Hillaire da61bf4824 Renamed VisualizeIndirectLighting to VisualizeLightingOnProbes and made the name consistent on ui and cvar.
#rb none

#ushell-cherrypick of 16505098 by Sebastien.Hillaire

[CL 16508789 by Sebastien Hillaire in ue5-main branch]
2021-05-31 08:56:02 -04:00

151 lines
5.6 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "DebugProbeRendering.h"
#include "PixelShaderUtils.h"
#include "ShaderParameterStruct.h"
// Changing this causes a full shader recompile
static TAutoConsoleVariable<int32> CVarVisualizeLightingOnProbes(
TEXT("r.VisualizeLightingOnProbes"),
0,
TEXT("Enables debug probes rendering to visualise diffuse/specular lighting (direct and indirect) on simple sphere scattered in the world.") \
TEXT(" 0: disabled.\n")
TEXT(" 1: camera probes only.\n")
TEXT(" 2: world probes only.\n")
TEXT(" 3: camera and world probes.\n")
,
ECVF_RenderThreadSafe);
DECLARE_GPU_STAT(StampDeferredDebugProbe);
class FStampDeferredDebugProbePS : public FGlobalShader
{
DECLARE_GLOBAL_SHADER(FStampDeferredDebugProbePS);
SHADER_USE_PARAMETER_STRUCT(FStampDeferredDebugProbePS, FGlobalShader);
class FRenderVelocity : SHADER_PERMUTATION_BOOL("PERMUTATION_RENDERVELOCITY");
using FPermutationDomain = TShaderPermutationDomain<FRenderVelocity>;
BEGIN_SHADER_PARAMETER_STRUCT(FParameters, )
SHADER_PARAMETER_STRUCT_REF(FViewUniformShaderParameters, ViewUniformBuffer)
SHADER_PARAMETER(int32, DebugProbesMode)
RENDER_TARGET_BINDING_SLOTS()
END_SHADER_PARAMETER_STRUCT()
public:
static FPermutationDomain RemapPermutation(FPermutationDomain PermutationVector)
{
return PermutationVector;
}
static bool ShouldCompilePermutation(const FGlobalShaderPermutationParameters& Parameters)
{
return IsFeatureLevelSupported(Parameters.Platform, ERHIFeatureLevel::SM5) && EnumHasAllFlags(Parameters.Flags, EShaderPermutationFlags::HasEditorOnlyData);
}
static void ModifyCompilationEnvironment(const FGlobalShaderPermutationParameters& Parameters, FShaderCompilerEnvironment& OutEnvironment)
{
FGlobalShader::ModifyCompilationEnvironment(Parameters, OutEnvironment);
}
};
IMPLEMENT_GLOBAL_SHADER(FStampDeferredDebugProbePS, "/Engine/Private/DebugProbes.usf", "MainPS", SF_Pixel);
template<bool bEnableDepthWrite>
static void CommonStampDeferredDebugProbeDrawCall(
FRDGBuilder& GraphBuilder,
const FViewInfo& View,
FStampDeferredDebugProbePS::FParameters* PassParameters,
bool bRenderVelocity = false)
{
PassParameters->ViewUniformBuffer = View.ViewUniformBuffer;
PassParameters->DebugProbesMode = View.Family->EngineShowFlags.VisualizeLightingOnProbes ? 3 : FMath::Clamp(CVarVisualizeLightingOnProbes.GetValueOnRenderThread(), 0, 3);
FStampDeferredDebugProbePS::FPermutationDomain PermutationVector;
PermutationVector.Set<FStampDeferredDebugProbePS::FRenderVelocity>(bRenderVelocity);
TShaderMapRef<FStampDeferredDebugProbePS> PixelShader(View.ShaderMap, PermutationVector);
FPixelShaderUtils::AddFullscreenPass<FStampDeferredDebugProbePS>(
GraphBuilder, View.ShaderMap, RDG_EVENT_NAME("StampDeferredDebugProbePS"),
PixelShader, PassParameters, View.ViewRect,
TStaticBlendState<>::GetRHI(),
TStaticRasterizerState<FM_Solid, CM_None>::GetRHI(),
TStaticDepthStencilState<bEnableDepthWrite, CF_DepthNearOrEqual>::GetRHI());
}
void StampDeferredDebugProbeDepthPS(
FRDGBuilder& GraphBuilder,
TArrayView<const FViewInfo> Views,
const FRDGTextureRef SceneDepthTexture)
{
RDG_EVENT_SCOPE(GraphBuilder, "StampDeferredDebugProbeDepth");
RDG_GPU_STAT_SCOPE(GraphBuilder, StampDeferredDebugProbe);
const bool bVisualizeLightingOnProbes = CVarVisualizeLightingOnProbes.GetValueOnRenderThread() > 0;
for (const FViewInfo& View : Views)
{
if (!(bVisualizeLightingOnProbes || View.Family->EngineShowFlags.VisualizeLightingOnProbes))
{
continue;
}
FStampDeferredDebugProbePS::FParameters* PassParameters = GraphBuilder.AllocParameters<FStampDeferredDebugProbePS::FParameters>();
PassParameters->ViewUniformBuffer = View.ViewUniformBuffer;
PassParameters->RenderTargets.DepthStencil = FDepthStencilBinding(SceneDepthTexture, ERenderTargetLoadAction::ELoad, ERenderTargetLoadAction::ELoad, FExclusiveDepthStencil::DepthWrite_StencilWrite);
CommonStampDeferredDebugProbeDrawCall<true>(GraphBuilder, View, PassParameters);
}
}
void StampDeferredDebugProbeMaterialPS(
FRDGBuilder& GraphBuilder,
TArrayView<const FViewInfo> Views,
const FRenderTargetBindingSlots& BasePassRenderTargets)
{
RDG_EVENT_SCOPE(GraphBuilder, "StampDeferredDebugProbeMaterial");
RDG_GPU_STAT_SCOPE(GraphBuilder, StampDeferredDebugProbe);
const bool bVisualizeLightingOnProbes = CVarVisualizeLightingOnProbes.GetValueOnRenderThread() > 0;
for (const FViewInfo& View : Views)
{
if (!(bVisualizeLightingOnProbes || View.Family->EngineShowFlags.VisualizeLightingOnProbes))
{
continue;
}
FStampDeferredDebugProbePS::FParameters* PassParameters = GraphBuilder.AllocParameters<FStampDeferredDebugProbePS::FParameters>();
PassParameters->RenderTargets = BasePassRenderTargets;
CommonStampDeferredDebugProbeDrawCall<false>(GraphBuilder, View, PassParameters);
}
}
void StampDeferredDebugProbeVelocityPS(
FRDGBuilder& GraphBuilder,
TArrayView<const FViewInfo> Views,
const FRenderTargetBindingSlots& BasePassRenderTargets)
{
RDG_EVENT_SCOPE(GraphBuilder, "StampDeferredDebugProbeVelocity");
RDG_GPU_STAT_SCOPE(GraphBuilder, StampDeferredDebugProbe);
const bool bVisualizeLightingOnProbes = CVarVisualizeLightingOnProbes.GetValueOnRenderThread() > 0;
for (const FViewInfo& View : Views)
{
if (!(bVisualizeLightingOnProbes || View.Family->EngineShowFlags.VisualizeLightingOnProbes))
{
continue;
}
FStampDeferredDebugProbePS::FParameters* PassParameters = GraphBuilder.AllocParameters<FStampDeferredDebugProbePS::FParameters>();
PassParameters->RenderTargets = BasePassRenderTargets;
const bool bRenderVelocity = true;
CommonStampDeferredDebugProbeDrawCall<false>(GraphBuilder, View, PassParameters, bRenderVelocity);
}
}