2022-04-13 09:51:33 -04:00
// Copyright Epic Games, Inc. All Rights Reserved.
# include "Strata.h"
# include "SceneTextureParameters.h"
# include "SceneRendering.h"
# include "ScreenPass.h"
# include "ShaderCompiler.h"
# include "PixelShaderUtils.h"
2022-04-20 09:59:26 -04:00
# include "BasePassRendering.h"
2022-04-20 15:12:05 -04:00
# include "IndirectLightRendering.h"
2022-10-27 02:52:45 -04:00
# include "StrataVisualizationData.h"
2022-04-13 09:51:33 -04:00
2022-04-14 03:13:39 -04:00
static TAutoConsoleVariable < int32 > CVarStrataDebugAdvancedVisualizationShaders (
TEXT ( " r.Strata.Debug.AdvancedVisualizationShaders " ) ,
0 ,
TEXT ( " Enable advanced strata material debug visualization shaders. Base pass shaders can output such advanced data. " ) ,
ECVF_ReadOnly | ECVF_RenderThreadSafe ) ;
2022-08-31 05:33:41 -04:00
bool IsStrataAdvancedVisualizationShadersEnabled ( )
{
return CVarStrataDebugAdvancedVisualizationShaders . GetValueOnRenderThread ( ) > 0 ;
}
2022-04-13 09:51:33 -04:00
namespace Strata
{
// Forward declarations
void AddStrataInternalClassificationTilePass (
FRDGBuilder & GraphBuilder ,
const FViewInfo & View ,
const FRDGTextureRef * DepthTexture ,
const FRDGTextureRef * ColorTexture ,
EStrataTileType TileMaterialType ,
const bool bDebug ) ;
2022-04-14 14:28:02 -04:00
static bool StrataDebugVisualizationCanRunOnPlatform ( EShaderPlatform Platform )
{
// On some consoles, this ALU heavy shader (and with optimisation disables for the sake of low compilation time) would spill registers. So only keep it for the editor.
return GetMaxSupportedFeatureLevel ( Platform ) > = ERHIFeatureLevel : : SM5 & & IsPCPlatform ( Platform ) ;
}
2022-04-13 09:51:33 -04:00
class FMaterialPrintInfoCS : public FGlobalShader
{
DECLARE_GLOBAL_SHADER ( FMaterialPrintInfoCS ) ;
SHADER_USE_PARAMETER_STRUCT ( FMaterialPrintInfoCS , FGlobalShader ) ;
using FPermutationDomain = TShaderPermutationDomain < > ;
BEGIN_SHADER_PARAMETER_STRUCT ( FParameters , )
SHADER_PARAMETER ( uint32 , BSDFIndex )
SHADER_PARAMETER_STRUCT_REF ( FViewUniformShaderParameters , ViewUniformBuffer )
SHADER_PARAMETER_RDG_UNIFORM_BUFFER ( FStrataGlobalUniformParameters , Strata )
SHADER_PARAMETER_STRUCT_INCLUDE ( FSceneTextureParameters , SceneTextures )
SHADER_PARAMETER_STRUCT_INCLUDE ( ShaderPrint : : FShaderParameters , ShaderPrintParameters )
SHADER_PARAMETER_RDG_BUFFER_UAV ( RWBuffer < uint > , RWPositionOffsetBuffer )
END_SHADER_PARAMETER_STRUCT ( )
static FPermutationDomain RemapPermutation ( FPermutationDomain PermutationVector )
{
return PermutationVector ;
}
static bool ShouldCompilePermutation ( const FGlobalShaderPermutationParameters & Parameters )
{
2022-04-14 14:28:02 -04:00
return Strata : : IsStrataEnabled ( ) & & StrataDebugVisualizationCanRunOnPlatform ( Parameters . Platform ) & & EnumHasAllFlags ( Parameters . Flags , EShaderPermutationFlags : : HasEditorOnlyData ) ;
2022-04-13 09:51:33 -04:00
}
static void ModifyCompilationEnvironment ( const FGlobalShaderPermutationParameters & Parameters , FShaderCompilerEnvironment & OutEnvironment )
{
FGlobalShader : : ModifyCompilationEnvironment ( Parameters , OutEnvironment ) ;
// Stay debug and skip optimizations to reduce compilation time on this long shader.
OutEnvironment . CompilerFlags . Add ( CFLAG_Debug ) ;
OutEnvironment . SetDefine ( TEXT ( " SHADER_MATERIALPRINT " ) , 1 ) ;
}
} ;
IMPLEMENT_GLOBAL_SHADER ( FMaterialPrintInfoCS , " /Engine/Private/Strata/StrataVisualize.usf " , " MaterialPrintInfoCS " , SF_Compute ) ;
2022-10-27 09:52:35 -04:00
class FVisualizeMaterialCountPS : public FGlobalShader
2022-04-13 09:51:33 -04:00
{
2022-10-27 09:52:35 -04:00
DECLARE_GLOBAL_SHADER ( FVisualizeMaterialCountPS ) ;
SHADER_USE_PARAMETER_STRUCT ( FVisualizeMaterialCountPS , FGlobalShader ) ;
2022-04-13 09:51:33 -04:00
using FPermutationDomain = TShaderPermutationDomain < > ;
BEGIN_SHADER_PARAMETER_STRUCT ( FParameters , )
SHADER_PARAMETER ( uint32 , ViewMode )
SHADER_PARAMETER_STRUCT_REF ( FViewUniformShaderParameters , ViewUniformBuffer )
SHADER_PARAMETER_RDG_UNIFORM_BUFFER ( FStrataGlobalUniformParameters , Strata )
SHADER_PARAMETER_STRUCT_INCLUDE ( FSceneTextureParameters , SceneTextures )
SHADER_PARAMETER_STRUCT_INCLUDE ( ShaderPrint : : FShaderParameters , ShaderPrintParameters )
RENDER_TARGET_BINDING_SLOTS ( )
END_SHADER_PARAMETER_STRUCT ( )
static FPermutationDomain RemapPermutation ( FPermutationDomain PermutationVector )
{
return PermutationVector ;
}
static bool ShouldCompilePermutation ( const FGlobalShaderPermutationParameters & Parameters )
{
2022-04-14 14:28:02 -04:00
return Strata : : IsStrataEnabled ( ) & & StrataDebugVisualizationCanRunOnPlatform ( Parameters . Platform ) & & EnumHasAllFlags ( Parameters . Flags , EShaderPermutationFlags : : HasEditorOnlyData ) ;
2022-04-13 09:51:33 -04:00
}
static void ModifyCompilationEnvironment ( const FGlobalShaderPermutationParameters & Parameters , FShaderCompilerEnvironment & OutEnvironment )
{
FGlobalShader : : ModifyCompilationEnvironment ( Parameters , OutEnvironment ) ;
// Stay debug and skip optimizations to reduce compilation time on this long shader.
OutEnvironment . CompilerFlags . Add ( CFLAG_Debug ) ;
2022-10-27 09:52:35 -04:00
OutEnvironment . SetDefine ( TEXT ( " SHADER_MATERIALCOUNT " ) , 1 ) ;
2022-04-13 09:51:33 -04:00
}
} ;
2022-10-27 09:52:35 -04:00
IMPLEMENT_GLOBAL_SHADER ( FVisualizeMaterialCountPS , " /Engine/Private/Strata/StrataVisualize.usf " , " VisualizeMaterialPS " , SF_Pixel ) ;
class FStrataSystemInfoCS : public FGlobalShader
{
DECLARE_GLOBAL_SHADER ( FStrataSystemInfoCS ) ;
SHADER_USE_PARAMETER_STRUCT ( FStrataSystemInfoCS , FGlobalShader ) ;
using FPermutationDomain = TShaderPermutationDomain < > ;
BEGIN_SHADER_PARAMETER_STRUCT ( FParameters , )
SHADER_PARAMETER ( uint32 , bAdvancedDebugEnabled )
SHADER_PARAMETER ( uint32 , bEnergyConservation )
SHADER_PARAMETER ( uint32 , bEnergyPreservation )
SHADER_PARAMETER ( uint32 , bDbufferPass )
SHADER_PARAMETER ( uint32 , ClassificationCMask )
SHADER_PARAMETER ( uint32 , ClassificationAsync )
SHADER_PARAMETER ( uint32 , Classification8bits )
SHADER_PARAMETER ( uint32 , bRoughRefraction )
2022-10-27 13:24:29 -04:00
SHADER_PARAMETER ( uint32 , bTileOverflowUseMaterialData )
SHADER_PARAMETER ( float , TileOverflowRatio )
2022-10-27 09:52:35 -04:00
SHADER_PARAMETER_RDG_BUFFER_SRV ( Buffer < uint > , ClassificationTileDrawIndirectBuffer )
SHADER_PARAMETER_STRUCT_REF ( FViewUniformShaderParameters , ViewUniformBuffer )
SHADER_PARAMETER_RDG_UNIFORM_BUFFER ( FStrataGlobalUniformParameters , Strata )
SHADER_PARAMETER_STRUCT_INCLUDE ( FSceneTextureParameters , SceneTextures )
SHADER_PARAMETER_STRUCT_INCLUDE ( ShaderPrint : : FShaderParameters , ShaderPrintParameters )
END_SHADER_PARAMETER_STRUCT ( )
static FPermutationDomain RemapPermutation ( FPermutationDomain PermutationVector )
{
return PermutationVector ;
}
static bool ShouldCompilePermutation ( const FGlobalShaderPermutationParameters & Parameters )
{
return Strata : : IsStrataEnabled ( ) & & StrataDebugVisualizationCanRunOnPlatform ( Parameters . Platform ) & & EnumHasAllFlags ( Parameters . Flags , EShaderPermutationFlags : : HasEditorOnlyData ) ;
}
static void ModifyCompilationEnvironment ( const FGlobalShaderPermutationParameters & Parameters , FShaderCompilerEnvironment & OutEnvironment )
{
FGlobalShader : : ModifyCompilationEnvironment ( Parameters , OutEnvironment ) ;
// Stay debug and skip optimizations to reduce compilation time on this long shader.
OutEnvironment . CompilerFlags . Add ( CFLAG_Debug ) ;
OutEnvironment . SetDefine ( TEXT ( " SHADER_SYSTEMINFO " ) , 1 ) ;
}
} ;
IMPLEMENT_GLOBAL_SHADER ( FStrataSystemInfoCS , " /Engine/Private/Strata/StrataVisualize.usf " , " MainCS " , SF_Compute ) ;
2022-04-13 09:51:33 -04:00
2022-04-14 14:28:02 -04:00
class FMaterialDebugStrataTreeCS : public FGlobalShader
{
DECLARE_GLOBAL_SHADER ( FMaterialDebugStrataTreeCS ) ;
SHADER_USE_PARAMETER_STRUCT ( FMaterialDebugStrataTreeCS , FGlobalShader ) ;
using FPermutationDomain = TShaderPermutationDomain < > ;
BEGIN_SHADER_PARAMETER_STRUCT ( FParameters , )
SHADER_PARAMETER_STRUCT_REF ( FViewUniformShaderParameters , ViewUniformBuffer )
SHADER_PARAMETER_RDG_UNIFORM_BUFFER ( FStrataGlobalUniformParameters , Strata )
SHADER_PARAMETER_STRUCT_INCLUDE ( ShaderPrint : : FShaderParameters , ShaderPrintParameters )
END_SHADER_PARAMETER_STRUCT ( )
static FPermutationDomain RemapPermutation ( FPermutationDomain PermutationVector )
{
return PermutationVector ;
}
static bool ShouldCompilePermutation ( const FGlobalShaderPermutationParameters & Parameters )
{
return Strata : : IsStrataEnabled ( ) & & StrataDebugVisualizationCanRunOnPlatform ( Parameters . Platform ) & & EnumHasAllFlags ( Parameters . Flags , EShaderPermutationFlags : : HasEditorOnlyData ) ;
}
static void ModifyCompilationEnvironment ( const FGlobalShaderPermutationParameters & Parameters , FShaderCompilerEnvironment & OutEnvironment )
{
FGlobalShader : : ModifyCompilationEnvironment ( Parameters , OutEnvironment ) ;
// Stay debug and skip optimizations to reduce compilation time on this long shader.
OutEnvironment . CompilerFlags . Add ( CFLAG_Debug ) ;
2022-04-23 09:11:34 -04:00
OutEnvironment . SetDefine ( TEXT ( " SHADER_DEBUGSTRATATREE_CS " ) , 1 ) ;
2022-04-14 14:28:02 -04:00
}
} ;
IMPLEMENT_GLOBAL_SHADER ( FMaterialDebugStrataTreeCS , " /Engine/Private/Strata/StrataVisualize.usf " , " MaterialDebugStrataTreeCS " , SF_Compute ) ;
class FMaterialDebugStrataTreePS : public FGlobalShader
{
DECLARE_GLOBAL_SHADER ( FMaterialDebugStrataTreePS ) ;
SHADER_USE_PARAMETER_STRUCT ( FMaterialDebugStrataTreePS , FGlobalShader ) ;
using FPermutationDomain = TShaderPermutationDomain < > ;
BEGIN_SHADER_PARAMETER_STRUCT ( FParameters , )
SHADER_PARAMETER_STRUCT_REF ( FViewUniformShaderParameters , ViewUniformBuffer )
SHADER_PARAMETER_RDG_UNIFORM_BUFFER ( FStrataGlobalUniformParameters , Strata )
2022-04-20 09:59:26 -04:00
SHADER_PARAMETER_STRUCT_REF ( FReflectionUniformParameters , ReflectionStruct )
SHADER_PARAMETER_STRUCT_REF ( FReflectionCaptureShaderData , ReflectionCapture )
SHADER_PARAMETER_RDG_UNIFORM_BUFFER ( FForwardLightData , ForwardLightData )
2022-04-20 15:12:05 -04:00
SHADER_PARAMETER_STRUCT_INCLUDE ( FSkyDiffuseLightingParameters , SkyDiffuseLighting )
2022-04-14 14:28:02 -04:00
RENDER_TARGET_BINDING_SLOTS ( )
END_SHADER_PARAMETER_STRUCT ( )
static FPermutationDomain RemapPermutation ( FPermutationDomain PermutationVector )
{
return PermutationVector ;
}
static bool ShouldCompilePermutation ( const FGlobalShaderPermutationParameters & Parameters )
{
return Strata : : IsStrataEnabled ( ) & & StrataDebugVisualizationCanRunOnPlatform ( Parameters . Platform ) & & EnumHasAllFlags ( Parameters . Flags , EShaderPermutationFlags : : HasEditorOnlyData ) ;
}
static void ModifyCompilationEnvironment ( const FGlobalShaderPermutationParameters & Parameters , FShaderCompilerEnvironment & OutEnvironment )
{
FGlobalShader : : ModifyCompilationEnvironment ( Parameters , OutEnvironment ) ;
// Stay debug and skip optimizations to reduce compilation time on this long shader.
OutEnvironment . CompilerFlags . Add ( CFLAG_Debug ) ;
2022-04-20 09:59:26 -04:00
OutEnvironment . SetDefine ( TEXT ( " SHADER_DEBUGSTRATATREE_PS " ) , 1 ) ;
2022-04-14 14:28:02 -04:00
}
} ;
IMPLEMENT_GLOBAL_SHADER ( FMaterialDebugStrataTreePS , " /Engine/Private/Strata/StrataVisualize.usf " , " MaterialDebugStrataTreePS " , SF_Pixel ) ;
2022-10-27 02:52:45 -04:00
static void AddVisualizeMaterialPropertiesPasses ( FRDGBuilder & GraphBuilder , const FViewInfo & View , FScreenPassTexture & ScreenPassSceneColor , EShaderPlatform Platform )
2022-04-13 09:51:33 -04:00
{
2022-10-27 02:52:45 -04:00
// Force ShaderPrint on.
ShaderPrint : : SetEnabled ( true ) ;
ShaderPrint : : RequestSpaceForLines ( 1024 ) ;
ShaderPrint : : RequestSpaceForCharacters ( 1024 ) ;
FRDGBufferUAVRef PrintOffsetBufferUAV = nullptr ;
FRDGBufferRef PrintOffsetBuffer = GraphBuilder . CreateBuffer ( FRDGBufferDesc : : CreateBufferDesc ( 4 , 2 ) , TEXT ( " Strata.DebugPrintPositionOffset " ) ) ;
PrintOffsetBufferUAV = GraphBuilder . CreateUAV ( PrintOffsetBuffer , PF_R32_UINT ) ;
AddClearUAVPass ( GraphBuilder , PrintOffsetBufferUAV , 50u ) ;
const uint32 MaxBSDFCount = 8 ;
for ( uint32 BSDFIndex = 0 ; BSDFIndex < MaxBSDFCount ; + + BSDFIndex )
{
FMaterialPrintInfoCS : : FParameters * PassParameters = GraphBuilder . AllocParameters < FMaterialPrintInfoCS : : FParameters > ( ) ;
PassParameters - > BSDFIndex = BSDFIndex ;
PassParameters - > RWPositionOffsetBuffer = PrintOffsetBufferUAV ;
PassParameters - > ViewUniformBuffer = View . ViewUniformBuffer ;
PassParameters - > Strata = Strata : : BindStrataGlobalUniformParameters ( View ) ;
PassParameters - > SceneTextures = GetSceneTextureParameters ( GraphBuilder , View ) ;
ShaderPrint : : SetParameters ( GraphBuilder , View . ShaderPrintData , PassParameters - > ShaderPrintParameters ) ;
TShaderMapRef < FMaterialPrintInfoCS > ComputeShader ( View . ShaderMap ) ;
FComputeShaderUtils : : AddPass ( GraphBuilder , RDG_EVENT_NAME ( " Strata::VisualizeMaterial(Print, BSDF=%d) " , BSDFIndex ) , ComputeShader , PassParameters , FIntVector ( 1 , 1 , 1 ) ) ;
}
}
static void AddVisualizeMaterialCountPasses ( FRDGBuilder & GraphBuilder , const FViewInfo & View , FScreenPassTexture & ScreenPassSceneColor , EShaderPlatform Platform )
{
ShaderPrint : : SetEnabled ( true ) ;
ShaderPrint : : RequestSpaceForLines ( 1024 ) ;
ShaderPrint : : RequestSpaceForCharacters ( 1024 ) ;
2022-04-21 08:13:06 -04:00
FRDGTextureRef SceneColorTexture = ScreenPassSceneColor . Texture ;
2022-04-13 09:51:33 -04:00
FRHIBlendState * PreMultipliedColorTransmittanceBlend = TStaticBlendState < CW_RGB , BO_Add , BF_One , BF_SourceAlpha , BO_Add , BF_Zero , BF_One > : : GetRHI ( ) ;
2022-10-27 02:52:45 -04:00
2022-10-27 09:52:35 -04:00
FVisualizeMaterialCountPS : : FParameters * PassParameters = GraphBuilder . AllocParameters < FVisualizeMaterialCountPS : : FParameters > ( ) ;
2022-10-27 02:52:45 -04:00
PassParameters - > ViewUniformBuffer = View . ViewUniformBuffer ;
PassParameters - > ViewMode = 2 ;
PassParameters - > Strata = Strata : : BindStrataGlobalUniformParameters ( View ) ;
PassParameters - > SceneTextures = GetSceneTextureParameters ( GraphBuilder , View ) ;
PassParameters - > RenderTargets [ 0 ] = FRenderTargetBinding ( SceneColorTexture , ERenderTargetLoadAction : : ELoad ) ;
ShaderPrint : : SetParameters ( GraphBuilder , View . ShaderPrintData , PassParameters - > ShaderPrintParameters ) ;
2022-10-27 09:52:35 -04:00
FVisualizeMaterialCountPS : : FPermutationDomain PermutationVector ;
TShaderMapRef < FVisualizeMaterialCountPS > PixelShader ( View . ShaderMap , PermutationVector ) ;
2022-10-27 02:52:45 -04:00
2022-10-27 09:52:35 -04:00
FPixelShaderUtils : : AddFullscreenPass < FVisualizeMaterialCountPS > ( GraphBuilder , View . ShaderMap , RDG_EVENT_NAME ( " Strata::VisualizeMaterial(Draw) " ) , PixelShader , PassParameters , ScreenPassSceneColor . ViewRect , PreMultipliedColorTransmittanceBlend ) ;
}
2022-10-27 13:24:29 -04:00
float GetStrataTileOverflowRatio ( const FViewInfo & View ) ;
2022-10-27 09:52:35 -04:00
bool IsClassificationCoord8bits ( ) ;
bool IsClassificationAsync ( ) ;
bool SupportsCMask ( const FStaticShaderPlatform InPlatform ) ;
2022-10-27 13:24:29 -04:00
bool DoesStrataTileOverflowUseMaterialData ( ) ;
2022-10-27 09:52:35 -04:00
static void AddVisualizeSystemInfoPasses ( FRDGBuilder & GraphBuilder , const FViewInfo & View , FScreenPassTexture & ScreenPassSceneColor , EShaderPlatform Platform )
{
// Force ShaderPrint on.
ShaderPrint : : SetEnabled ( true ) ;
ShaderPrint : : RequestSpaceForLines ( 1024 ) ;
ShaderPrint : : RequestSpaceForCharacters ( 1024 ) ;
FStrataSystemInfoCS : : FParameters * PassParameters = GraphBuilder . AllocParameters < FStrataSystemInfoCS : : FParameters > ( ) ;
PassParameters - > bAdvancedDebugEnabled = IsStrataAdvancedVisualizationShadersEnabled ( ) ? 1u : 0u ;
PassParameters - > bEnergyConservation = View . ViewState ? View . ViewState - > ShadingEnergyConservationData . bEnergyConservation : false ; ;
PassParameters - > bEnergyPreservation = View . ViewState ? View . ViewState - > ShadingEnergyConservationData . bEnergyPreservation : false ; ;
PassParameters - > bDbufferPass = IsStrataDbufferPassEnabled ( View . GetShaderPlatform ( ) ) ? 1 : 0 ;
PassParameters - > ClassificationCMask = SupportsCMask ( View . GetShaderPlatform ( ) ) ? 1 : 0 ;
PassParameters - > ClassificationAsync = IsClassificationAsync ( ) ? 1 : 0 ;
PassParameters - > Classification8bits = IsClassificationCoord8bits ( ) ? 1 : 0 ;
2022-10-27 13:24:29 -04:00
PassParameters - > TileOverflowRatio = GetStrataTileOverflowRatio ( View ) ;
PassParameters - > bTileOverflowUseMaterialData = DoesStrataTileOverflowUseMaterialData ( ) ? 1 : 0 ;
2022-10-27 09:52:35 -04:00
PassParameters - > bRoughRefraction = IsStrataOpaqueMaterialRoughRefractionEnabled ( ) ? 1 : 0 ;
PassParameters - > ClassificationTileDrawIndirectBuffer = GraphBuilder . CreateSRV ( View . StrataViewData . ClassificationTileDrawIndirectBuffer , PF_R32_UINT ) ;
PassParameters - > ViewUniformBuffer = View . ViewUniformBuffer ;
PassParameters - > Strata = Strata : : BindStrataGlobalUniformParameters ( View ) ;
PassParameters - > SceneTextures = GetSceneTextureParameters ( GraphBuilder , View ) ;
ShaderPrint : : SetParameters ( GraphBuilder , View . ShaderPrintData , PassParameters - > ShaderPrintParameters ) ;
TShaderMapRef < FStrataSystemInfoCS > ComputeShader ( View . ShaderMap ) ;
FComputeShaderUtils : : AddPass ( GraphBuilder , RDG_EVENT_NAME ( " Strata::VisualizeSystemInfo " ) , ComputeShader , PassParameters , FIntVector ( 1 , 1 , 1 ) ) ;
2022-10-27 02:52:45 -04:00
}
// Draw each material layer independently
static void AddVisualizeAdvancedMaterialPasses ( FRDGBuilder & GraphBuilder , const FViewInfo & View , FScreenPassTexture & ScreenPassSceneColor , EShaderPlatform Platform )
{
if ( ! IsStrataAdvancedVisualizationShadersEnabled ( ) )
2022-04-13 09:51:33 -04:00
{
2022-10-27 02:52:45 -04:00
return ;
}
2022-04-13 09:51:33 -04:00
2022-10-27 02:52:45 -04:00
ShaderPrint : : SetEnabled ( true ) ;
ShaderPrint : : RequestSpaceForLines ( 1024 ) ;
ShaderPrint : : RequestSpaceForCharacters ( 1024 ) ;
2022-04-14 03:13:39 -04:00
2022-10-27 02:52:45 -04:00
FRDGTextureRef SceneColorTexture = ScreenPassSceneColor . Texture ;
FRHIBlendState * PreMultipliedColorTransmittanceBlend = TStaticBlendState < CW_RGB , BO_Add , BF_One , BF_SourceAlpha , BO_Add , BF_Zero , BF_One > : : GetRHI ( ) ;
{
FMaterialDebugStrataTreeCS : : FParameters * PassParameters = GraphBuilder . AllocParameters < FMaterialDebugStrataTreeCS : : FParameters > ( ) ;
PassParameters - > ViewUniformBuffer = View . ViewUniformBuffer ;
PassParameters - > Strata = Strata : : BindStrataGlobalUniformParameters ( View ) ;
ShaderPrint : : SetParameters ( GraphBuilder , View . ShaderPrintData , PassParameters - > ShaderPrintParameters ) ;
2022-04-13 09:51:33 -04:00
2022-10-27 02:52:45 -04:00
TShaderMapRef < FMaterialDebugStrataTreeCS > ComputeShader ( View . ShaderMap ) ;
FComputeShaderUtils : : AddPass ( GraphBuilder , RDG_EVENT_NAME ( " Strata::StrataAdvancedVisualization(Print) " ) , ComputeShader , PassParameters , FIntVector ( 1 , 1 , 1 ) ) ;
}
{
FMaterialDebugStrataTreePS : : FParameters * PassParameters = GraphBuilder . AllocParameters < FMaterialDebugStrataTreePS : : FParameters > ( ) ;
PassParameters - > ViewUniformBuffer = View . ViewUniformBuffer ;
PassParameters - > Strata = Strata : : BindStrataGlobalUniformParameters ( View ) ;
PassParameters - > ReflectionStruct = CreateReflectionUniformBuffer ( View , UniformBuffer_SingleFrame ) ;
PassParameters - > ReflectionCapture = View . ReflectionCaptureUniformBuffer ;
PassParameters - > ForwardLightData = View . ForwardLightingResources . ForwardLightUniformBuffer ;
PassParameters - > RenderTargets [ 0 ] = FRenderTargetBinding ( SceneColorTexture , ERenderTargetLoadAction : : ELoad ) ;
const float DynamicBentNormalAO = 0.0f ;
FSkyLightSceneProxy * NullSkyLight = nullptr ;
PassParameters - > SkyDiffuseLighting = GetSkyDiffuseLightingParameters ( NullSkyLight , DynamicBentNormalAO ) ;
FMaterialDebugStrataTreePS : : FPermutationDomain PermutationVector ;
TShaderMapRef < FMaterialDebugStrataTreePS > PixelShader ( View . ShaderMap , PermutationVector ) ;
FPixelShaderUtils : : AddFullscreenPass < FMaterialDebugStrataTreePS > ( GraphBuilder , View . ShaderMap , RDG_EVENT_NAME ( " Strata::StrataAdvancedVisualization(Draw) " ) , PixelShader , PassParameters , ScreenPassSceneColor . ViewRect , PreMultipliedColorTransmittanceBlend ) ;
}
}
bool ShouldRenderStrataRoughRefractionRnD ( ) ;
void StrataRoughRefractionRnD ( FRDGBuilder & GraphBuilder , const FViewInfo & View , FScreenPassTexture & ScreenPassSceneColor ) ;
static FStrataVisualizationData : : FViewMode GetStrataVisualizeMode ( const FViewInfo & View )
{
FStrataVisualizationData : : FViewMode Out = FStrataVisualizationData : : FViewMode : : None ;
if ( IsStrataEnabled ( ) & & StrataDebugVisualizationCanRunOnPlatform ( View . GetShaderPlatform ( ) ) )
{
// Variable defined in StrataVisualizationData.h/.cpp
static const auto CVarStrataViewMode = IConsoleManager : : Get ( ) . FindConsoleVariable ( FStrataVisualizationData : : GetVisualizeConsoleCommandName ( ) ) ;
const uint32 ViewMode = CVarStrataViewMode & & CVarStrataViewMode - > AsVariableInt ( ) ? CVarStrataViewMode - > AsVariableInt ( ) - > GetValueOnRenderThread ( ) : 0 ;
switch ( ViewMode )
2022-04-13 09:51:33 -04:00
{
2022-10-27 02:52:45 -04:00
case 1 : return FStrataVisualizationData : : FViewMode : : MaterialProperties ;
case 2 : return FStrataVisualizationData : : FViewMode : : MaterialCount ;
case 3 : return FStrataVisualizationData : : FViewMode : : AdvancedMaterialProperties ;
case 4 : return FStrataVisualizationData : : FViewMode : : MaterialClassification ;
case 5 : return FStrataVisualizationData : : FViewMode : : DecalClassification ;
case 6 : return FStrataVisualizationData : : FViewMode : : RoughRefractionClassification ;
2022-10-27 13:24:29 -04:00
case 7 : return FStrataVisualizationData : : FViewMode : : StrataInfo ;
2022-04-13 09:51:33 -04:00
}
2022-10-27 02:52:45 -04:00
const FStrataVisualizationData & VisualizationData = GetStrataVisualizationData ( ) ;
if ( View . Family & & View . Family - > EngineShowFlags . VisualizeStrata )
2022-04-13 09:51:33 -04:00
{
2022-10-27 02:52:45 -04:00
Out = VisualizationData . GetViewMode ( View . CurrentStrataVisualizationMode ) ;
2022-04-14 03:13:39 -04:00
}
2022-04-13 09:51:33 -04:00
}
2022-10-27 02:52:45 -04:00
return Out ;
2022-04-13 09:51:33 -04:00
}
bool ShouldRenderStrataDebugPasses ( const FViewInfo & View )
{
2022-10-27 02:52:45 -04:00
return GetStrataVisualizeMode ( View ) ! = FStrataVisualizationData : : FViewMode : : None | | ShouldRenderStrataRoughRefractionRnD ( ) ;
2022-04-13 09:51:33 -04:00
}
FScreenPassTexture AddStrataDebugPasses ( FRDGBuilder & GraphBuilder , const FViewInfo & View , FScreenPassTexture & ScreenPassSceneColor )
{
check ( IsStrataEnabled ( ) ) ;
2022-10-27 02:52:45 -04:00
const FStrataVisualizationData : : FViewMode DebugMode = GetStrataVisualizeMode ( View ) ;
if ( DebugMode ! = FStrataVisualizationData : : FViewMode : : None )
2022-04-13 09:51:33 -04:00
{
RDG_EVENT_SCOPE ( GraphBuilder , " Strata::VisualizeMaterial " ) ;
const bool bDebugPass = true ;
2022-10-27 02:52:45 -04:00
if ( DebugMode = = FStrataVisualizationData : : FViewMode : : MaterialProperties )
{
AddVisualizeMaterialPropertiesPasses ( GraphBuilder , View , ScreenPassSceneColor , View . GetShaderPlatform ( ) ) ;
}
if ( DebugMode = = FStrataVisualizationData : : FViewMode : : MaterialCount )
{
AddVisualizeMaterialCountPasses ( GraphBuilder , View , ScreenPassSceneColor , View . GetShaderPlatform ( ) ) ;
}
if ( DebugMode = = FStrataVisualizationData : : FViewMode : : AdvancedMaterialProperties )
{
AddVisualizeAdvancedMaterialPasses ( GraphBuilder , View , ScreenPassSceneColor , View . GetShaderPlatform ( ) ) ;
}
2022-10-27 09:52:35 -04:00
else if ( DebugMode = = FStrataVisualizationData : : FViewMode : : StrataInfo )
{
AddVisualizeSystemInfoPasses ( GraphBuilder , View , ScreenPassSceneColor , View . GetShaderPlatform ( ) ) ;
}
2022-10-27 02:52:45 -04:00
else if ( DebugMode = = FStrataVisualizationData : : FViewMode : : DecalClassification )
2022-09-20 09:05:17 -04:00
{
2022-10-27 09:52:35 -04:00
if ( IsStrataDbufferPassEnabled ( View . GetShaderPlatform ( ) ) )
{
AddStrataInternalClassificationTilePass ( GraphBuilder , View , nullptr , & ScreenPassSceneColor . Texture , EStrataTileType : : EDecalSimple , bDebugPass ) ;
AddStrataInternalClassificationTilePass ( GraphBuilder , View , nullptr , & ScreenPassSceneColor . Texture , EStrataTileType : : EDecalSingle , bDebugPass ) ;
AddStrataInternalClassificationTilePass ( GraphBuilder , View , nullptr , & ScreenPassSceneColor . Texture , EStrataTileType : : EDecalComplex , bDebugPass ) ;
}
2022-09-20 09:05:17 -04:00
}
2022-10-27 02:52:45 -04:00
else if ( DebugMode = = FStrataVisualizationData : : FViewMode : : RoughRefractionClassification )
2022-04-13 09:51:33 -04:00
{
2022-10-27 09:52:35 -04:00
if ( IsStrataOpaqueMaterialRoughRefractionEnabled ( ) )
{
AddStrataInternalClassificationTilePass ( GraphBuilder , View , nullptr , & ScreenPassSceneColor . Texture , EStrataTileType : : EOpaqueRoughRefraction , bDebugPass ) ;
AddStrataInternalClassificationTilePass ( GraphBuilder , View , nullptr , & ScreenPassSceneColor . Texture , EStrataTileType : : EOpaqueRoughRefractionSSSWithout , bDebugPass ) ;
}
2022-04-13 09:51:33 -04:00
}
2022-10-27 02:52:45 -04:00
else if ( DebugMode = = FStrataVisualizationData : : FViewMode : : MaterialClassification )
2022-04-13 09:51:33 -04:00
{
AddStrataInternalClassificationTilePass ( GraphBuilder , View , nullptr , & ScreenPassSceneColor . Texture , EStrataTileType : : EComplex , bDebugPass ) ;
2022-05-06 15:08:26 -04:00
AddStrataInternalClassificationTilePass ( GraphBuilder , View , nullptr , & ScreenPassSceneColor . Texture , EStrataTileType : : ESingle , bDebugPass ) ;
AddStrataInternalClassificationTilePass ( GraphBuilder , View , nullptr , & ScreenPassSceneColor . Texture , EStrataTileType : : ESimple , bDebugPass ) ;
2022-04-13 09:51:33 -04:00
}
}
StrataRoughRefractionRnD ( GraphBuilder , View , ScreenPassSceneColor ) ;
return MoveTemp ( ScreenPassSceneColor ) ;
}
} // namespace Strata