2020-09-16 04:20:36 -04:00
// Copyright Epic Games, Inc. All Rights Reserved.
# include "Strata.h"
# include "HAL/IConsoleManager.h"
2020-10-13 16:46:31 -04:00
# include "PixelShaderUtils.h"
2020-09-16 04:20:36 -04:00
# include "SceneView.h"
# include "ScenePrivate.h"
# include "SceneRendering.h"
# include "RendererInterface.h"
2020-10-08 03:11:37 -04:00
# include "UniformBuffer.h"
2020-11-05 06:16:12 -04:00
# include "SceneTextureParameters.h"
2021-04-29 17:55:33 -04:00
# include "ScreenPass.h"
2021-11-29 18:03:54 -05:00
# include "ShaderCompiler.h"
2020-09-16 04:20:36 -04:00
2020-11-09 12:06:15 -04:00
//PRAGMA_DISABLE_OPTIMIZATION
2020-09-16 04:20:36 -04:00
// The project setting for Strata
static TAutoConsoleVariable < int32 > CVarStrata (
TEXT ( " r.Strata " ) ,
0 ,
2020-11-20 10:08:04 -04:00
TEXT ( " Enable Strata materials (Beta). " ) ,
2020-09-16 04:20:36 -04:00
ECVF_ReadOnly | ECVF_RenderThreadSafe ) ;
2021-05-25 08:20:38 -04:00
static TAutoConsoleVariable < int32 > CVarStrataBackCompatibility (
TEXT ( " r.StrataBackCompatibility " ) ,
0 ,
TEXT ( " Disables Strata multiple scattering and replaces Chan diffuse by Lambert. " ) ,
ECVF_ReadOnly | ECVF_RenderThreadSafe ) ;
2020-11-20 10:08:04 -04:00
static TAutoConsoleVariable < int32 > CVarStrataBytePerPixel (
TEXT ( " r.Strata.BytesPerPixel " ) ,
80 ,
TEXT ( " Strata allocated byte per pixel to store materials data. Higher value means more complex material can be represented. " ) ,
ECVF_ReadOnly | ECVF_RenderThreadSafe ) ;
2020-09-16 04:20:36 -04:00
2021-02-17 11:12:16 -04:00
static TAutoConsoleVariable < int32 > CVarStrataClassificationDebug (
TEXT ( " r.Strata.Classification.Debug " ) ,
0 ,
2021-04-21 08:10:24 -04:00
TEXT ( " Enable strata classification visualization: 1 shows simple material tiles in green and complex material tiles in red. " ) ,
2021-04-06 02:12:57 -04:00
ECVF_RenderThreadSafe ) ;
2021-11-03 04:18:34 -04:00
static TAutoConsoleVariable < int32 > CVarStrataRoughDiffuse (
TEXT ( " r.Strata.RoughDiffuse " ) ,
1 ,
TEXT ( " Enable Strata rough diffuse model (works only if r.Material.RoughDiffuse is enabled in the project settings). Togglable at runtime " ) ,
ECVF_RenderThreadSafe ) ;
2021-11-07 23:43:01 -05:00
// Transition render settings that will disapear when strata gets enabled
2021-02-15 08:15:16 -04:00
2021-11-07 23:43:01 -05:00
static TAutoConsoleVariable < int32 > CVarMaterialRoughDiffuse (
TEXT ( " r.Material.RoughDiffuse " ) ,
2021-02-23 04:34:03 -04:00
0 ,
2021-11-07 23:43:01 -05:00
TEXT ( " Enable rough diffuse material. " ) ,
ECVF_ReadOnly | ECVF_RenderThreadSafe ) ;
2021-12-06 08:54:37 -05:00
// STRATA_TODO we keep this for now and can remove it once battletested.
static TAutoConsoleVariable < int32 > CVarClearDuringCategorization (
2022-03-31 12:43:49 -04:00
TEXT ( " r.Strata.ClearDuringCategorization " ) ,
2021-12-06 08:54:37 -05:00
1 ,
TEXT ( " TEST. " ) ,
ECVF_RenderThreadSafe ) ;
2021-02-23 04:34:03 -04:00
2022-03-18 13:43:33 -04:00
static TAutoConsoleVariable < int32 > CVarStrataTileOverflow (
2022-03-31 12:43:49 -04:00
TEXT ( " r.Strata.TileOverflow " ) ,
2022-03-18 13:43:33 -04:00
1.f ,
TEXT ( " Scale the number of Strata tile for overflowing tiles containing multi-BSDFs pixels. (0: 0%, 1: 100%. Default 1.0f). " ) ,
2022-03-31 12:43:49 -04:00
ECVF_RenderThreadSafe ) ;
2021-02-15 08:15:16 -04:00
2022-04-12 14:06:17 -04:00
static TAutoConsoleVariable < int32 > CVarStrataDebugMode (
TEXT ( " r.Strata.DebugMode " ) ,
1 ,
TEXT ( " Strata debug view mode. " ) ,
ECVF_RenderThreadSafe ) ;
2020-10-08 03:11:37 -04:00
IMPLEMENT_GLOBAL_SHADER_PARAMETER_STRUCT ( FStrataGlobalUniformParameters , " Strata " ) ;
2022-04-02 14:31:01 -04:00
void FStrataViewData : : Reset ( )
2021-03-30 02:33:35 -04:00
{
2022-04-02 14:31:01 -04:00
* this = FStrataViewData ( ) ;
2022-03-15 09:55:16 -04:00
for ( uint32 i = 0 ; i < EStrataTileType : : ECount ; + + i )
2021-04-06 02:12:57 -04:00
{
ClassificationTileListBuffer [ i ] = nullptr ;
ClassificationTileListBufferUAV [ i ] = nullptr ;
ClassificationTileListBufferSRV [ i ] = nullptr ;
}
2021-03-30 02:33:35 -04:00
}
2022-03-15 09:55:16 -04:00
const TCHAR * ToString ( EStrataTileType Type )
2021-11-07 23:43:01 -05:00
{
switch ( Type )
{
2022-03-16 05:45:43 -04:00
case EStrataTileType : : ESimple : return TEXT ( " Simple " ) ;
case EStrataTileType : : ESingle : return TEXT ( " Single " ) ;
case EStrataTileType : : EComplex : return TEXT ( " Complex " ) ;
case EStrataTileType : : EOpaqueRoughRefraction : return TEXT ( " OpaqueRoughRefraction " ) ;
case EStrataTileType : : ESSSWithoutOpaqueRoughRefraction : return TEXT ( " SSSWithoutOpaqueRoughRefraction " ) ;
2021-11-07 23:43:01 -05:00
}
return TEXT ( " Unknown " ) ;
}
2021-12-07 13:19:49 -05:00
FORCEINLINE bool ClearDuringCategorization ( )
{
return CVarClearDuringCategorization . GetValueOnRenderThread ( ) > 0 ;
}
2021-03-30 02:33:35 -04:00
2020-09-16 16:23:11 -04:00
namespace Strata
{
2021-03-30 05:18:53 -04:00
// Forward declaration
2021-11-26 07:05:41 -05:00
static void AddStrataClearMaterialBufferPass (
FRDGBuilder & GraphBuilder ,
2021-11-29 09:31:58 -05:00
FRDGTextureUAVRef MaterialTextureArrayUAV ,
2021-11-26 07:05:41 -05:00
FRDGTextureUAVRef SSSTextureUAV ,
uint32 MaxBytesPerPixel ,
FIntPoint TiledViewBufferResolution ) ;
2021-02-15 08:15:16 -04:00
2020-09-16 04:20:36 -04:00
bool IsStrataEnabled ( )
{
2021-02-09 18:01:10 -04:00
return CVarStrata . GetValueOnAnyThread ( ) > 0 ;
2020-09-16 04:20:36 -04:00
}
2022-03-18 13:43:33 -04:00
static FIntPoint GetStrataTextureTileResolution ( const FIntPoint & InResolution , float Overflow )
2021-01-27 08:51:50 -04:00
{
2022-03-18 13:43:33 -04:00
FIntPoint Out = InResolution ;
if ( Strata : : IsStrataEnabled ( ) )
{
2022-03-31 13:05:44 -04:00
Out . X = FMath : : DivideAndRoundUp ( Out . X , STRATA_TILE_SIZE ) ;
Out . Y = FMath : : DivideAndRoundUp ( Out . Y , STRATA_TILE_SIZE ) ;
2022-03-18 13:43:33 -04:00
Out . Y + = FMath : : CeilToInt ( Out . Y * FMath : : Clamp ( Overflow , 0.f , 1.0f ) ) ;
}
return Out ;
2021-01-27 08:51:50 -04:00
}
2022-03-18 13:43:33 -04:00
static FIntPoint GetStrataTextureTileResolution ( const FIntPoint & InResolution )
{
return GetStrataTextureTileResolution ( InResolution , CVarStrataTileOverflow . GetValueOnRenderThread ( ) ) ;
}
FIntPoint GetStrataTextureResolution ( const FIntPoint & InResolution )
{
2022-03-31 13:05:44 -04:00
return GetStrataTextureTileResolution ( InResolution ) * STRATA_TILE_SIZE ;
2022-03-18 13:43:33 -04:00
}
2021-02-15 08:15:16 -04:00
2022-04-02 14:31:01 -04:00
static void BindStrataGlobalUniformParameters ( FRDGBuilder & GraphBuilder , FStrataViewData * StrataViewData , FStrataGlobalUniformParameters & OutStrataUniformParameters ) ;
2022-04-01 08:35:55 -04:00
2022-04-02 14:31:01 -04:00
static void InitialiseStrataViewData ( FRDGBuilder & GraphBuilder , FViewInfo & View , FStrataSceneData & SceneData )
2020-09-16 04:20:36 -04:00
{
2022-04-02 14:31:01 -04:00
// Sanity check: the scene data should already exist
check ( SceneData . MaterialTextureArray ! = nullptr ) ;
FStrataViewData & Out = View . StrataViewData ;
Out . Reset ( ) ;
Out . SceneData = & SceneData ;
const FIntPoint ViewResolution ( View . ViewRect . Width ( ) , View . ViewRect . Height ( ) ) ;
if ( IsStrataEnabled ( ) )
{
const FIntPoint TileResolution ( FMath : : DivideAndRoundUp ( ViewResolution . X , STRATA_TILE_SIZE ) , FMath : : DivideAndRoundUp ( ViewResolution . Y , STRATA_TILE_SIZE ) ) ;
const TCHAR * StrataTileListBufferNames [ EStrataTileType : : ECount ] =
{
TEXT ( " Strata.StrataTileListBuffer(Simple) " ) ,
TEXT ( " Strata.StrataTileListBuffer(Single) " ) ,
TEXT ( " Strata.StrataTileListBuffer(Complex) " ) ,
TEXT ( " Strata.StrataTileListBuffer(OpaqueRoughRefraction) " ) ,
TEXT ( " Strata.StrataTileListBuffer(SSSWithoutOpaqueRoughRefraction) " )
} ;
// Tile classification buffers
{
// Indirect draw
Out . ClassificationTileDrawIndirectBuffer = GraphBuilder . CreateBuffer ( FRDGBufferDesc : : CreateIndirectDesc < FRHIDrawIndirectParameters > ( EStrataTileType : : ECount ) , TEXT ( " Strata.StrataTileDrawIndirectBuffer " ) ) ;
Out . ClassificationTileDrawIndirectBufferUAV = GraphBuilder . CreateUAV ( Out . ClassificationTileDrawIndirectBuffer , PF_R32_UINT ) ;
AddClearUAVPass ( GraphBuilder , Out . ClassificationTileDrawIndirectBufferUAV , 0 ) ;
// Indirect dispatch
Out . ClassificationTileDispatchIndirectBuffer = GraphBuilder . CreateBuffer ( FRDGBufferDesc : : CreateIndirectDesc < FRHIDispatchIndirectParameters > ( EStrataTileType : : ECount ) , TEXT ( " Strata.StrataTileDispatchIndirectBuffer " ) ) ;
Out . ClassificationTileDispatchIndirectBufferUAV = GraphBuilder . CreateUAV ( Out . ClassificationTileDispatchIndirectBuffer , PF_R32_UINT ) ;
AddClearUAVPass ( GraphBuilder , Out . ClassificationTileDispatchIndirectBufferUAV , 0 ) ;
for ( uint32 i = 0 ; i < = EStrataTileType : : EComplex ; + + i )
{
Out . ClassificationTileListBuffer [ i ] = GraphBuilder . CreateBuffer ( FRDGBufferDesc : : CreateBufferDesc ( sizeof ( uint32 ) , TileResolution . X * TileResolution . Y ) , StrataTileListBufferNames [ i ] ) ;
Out . ClassificationTileListBufferSRV [ i ] = GraphBuilder . CreateSRV ( Out . ClassificationTileListBuffer [ i ] , PF_R32_UINT ) ;
Out . ClassificationTileListBufferUAV [ i ] = GraphBuilder . CreateUAV ( Out . ClassificationTileListBuffer [ i ] , PF_R32_UINT ) ;
}
}
// Separated subsurface & rough refraction textures (tile data)
{
const bool bIsStrataOpaqueMaterialRoughRefractionEnabled = IsStrataOpaqueMaterialRoughRefractionEnabled ( ) ;
const int32 TileListBufferElementCount = bIsStrataOpaqueMaterialRoughRefractionEnabled ? TileResolution . X * TileResolution . Y : 4 ;
Out . ClassificationTileListBuffer [ EStrataTileType : : EOpaqueRoughRefraction ] = GraphBuilder . CreateBuffer ( FRDGBufferDesc : : CreateBufferDesc ( sizeof ( uint32 ) , TileListBufferElementCount ) , StrataTileListBufferNames [ EStrataTileType : : EOpaqueRoughRefraction ] ) ;
Out . ClassificationTileListBufferSRV [ EStrataTileType : : EOpaqueRoughRefraction ] = GraphBuilder . CreateSRV ( Out . ClassificationTileListBuffer [ EStrataTileType : : EOpaqueRoughRefraction ] , PF_R32_UINT ) ;
Out . ClassificationTileListBufferUAV [ EStrataTileType : : EOpaqueRoughRefraction ] = GraphBuilder . CreateUAV ( Out . ClassificationTileListBuffer [ EStrataTileType : : EOpaqueRoughRefraction ] , PF_R32_UINT ) ;
Out . ClassificationTileListBuffer [ EStrataTileType : : ESSSWithoutOpaqueRoughRefraction ] = GraphBuilder . CreateBuffer ( FRDGBufferDesc : : CreateBufferDesc ( sizeof ( uint32 ) , TileListBufferElementCount ) , StrataTileListBufferNames [ EStrataTileType : : ESSSWithoutOpaqueRoughRefraction ] ) ;
Out . ClassificationTileListBufferSRV [ EStrataTileType : : ESSSWithoutOpaqueRoughRefraction ] = GraphBuilder . CreateSRV ( Out . ClassificationTileListBuffer [ EStrataTileType : : ESSSWithoutOpaqueRoughRefraction ] , PF_R32_UINT ) ;
Out . ClassificationTileListBufferUAV [ EStrataTileType : : ESSSWithoutOpaqueRoughRefraction ] = GraphBuilder . CreateUAV ( Out . ClassificationTileListBuffer [ EStrataTileType : : ESSSWithoutOpaqueRoughRefraction ] , PF_R32_UINT ) ;
}
// BSDF tiles
{
Out . TileCount_Total = GetStrataTextureTileResolution ( ViewResolution ) ;
Out . TileCount_Primary = GetStrataTextureTileResolution ( ViewResolution , 0.f ) ;
Out . TileCount_Overflow = Out . TileCount_Total - Out . TileCount_Primary ;
Out . BSDFTileTexture = GraphBuilder . CreateTexture ( FRDGTextureDesc : : Create2D ( Out . TileCount_Total , PF_R32_UINT , FClearValueBinding : : None , TexCreate_UAV | TexCreate_ShaderResource ) , TEXT ( " Strata.BSDFTiles " ) ) ;
AddClearUAVPass ( GraphBuilder , GraphBuilder . CreateUAV ( Out . BSDFTileTexture ) , 0u ) ;
Out . BSDFTileDispatchIndirectBuffer = GraphBuilder . CreateBuffer ( FRDGBufferDesc : : CreateIndirectDesc < FRHIDispatchIndirectParameters > ( 1 ) , TEXT ( " Strata.StrataBSDFTileDispatchIndirectBuffer " ) ) ;
Out . BSDFTileCountBuffer = GraphBuilder . CreateBuffer ( FRDGBufferDesc : : CreateBufferDesc ( 4 , 1 ) , TEXT ( " Strata.BSDFTileCount " ) ) ;
}
}
// Create the readable uniform buffers
if ( IsStrataEnabled ( ) )
{
FStrataGlobalUniformParameters * StrataUniformParameters = GraphBuilder . AllocParameters < FStrataGlobalUniformParameters > ( ) ;
BindStrataGlobalUniformParameters ( GraphBuilder , & Out , * StrataUniformParameters ) ;
Out . StrataGlobalUniformParameters = GraphBuilder . CreateUniformBuffer ( StrataUniformParameters ) ;
}
}
void InitialiseStrataFrameSceneData ( FRDGBuilder & GraphBuilder , FSceneRenderer & SceneRenderer )
{
FStrataSceneData & Out = SceneRenderer . Scene - > StrataSceneData ;
Out = FStrataSceneData ( ) ;
2020-09-16 04:20:36 -04:00
2021-03-30 05:18:53 -04:00
auto UpdateMaterialBufferToTiledResolution = [ ] ( FIntPoint InBufferSizeXY , FIntPoint & OutMaterialBufferSizeXY )
{
// We need to allocate enough for the tiled memory addressing to always work
2022-03-31 13:05:44 -04:00
OutMaterialBufferSizeXY . X = FMath : : DivideAndRoundUp ( InBufferSizeXY . X , STRATA_TILE_SIZE ) * STRATA_TILE_SIZE ;
OutMaterialBufferSizeXY . Y = FMath : : DivideAndRoundUp ( InBufferSizeXY . Y , STRATA_TILE_SIZE ) * STRATA_TILE_SIZE ;
2021-03-30 05:18:53 -04:00
} ;
FIntPoint MaterialBufferSizeXY ;
UpdateMaterialBufferToTiledResolution ( FIntPoint ( 1 , 1 ) , MaterialBufferSizeXY ) ;
2020-09-16 04:20:36 -04:00
if ( IsStrataEnabled ( ) )
{
2021-03-30 05:18:53 -04:00
FIntPoint SceneTextureExtent = GetSceneTextureExtent ( ) ;
2020-09-16 04:20:36 -04:00
2021-03-30 05:18:53 -04:00
// We need to allocate enough for the tiled memory addressing of material data to always work
UpdateMaterialBufferToTiledResolution ( SceneTextureExtent , MaterialBufferSizeXY ) ;
2020-09-16 04:20:36 -04:00
2021-03-01 05:29:09 -04:00
const uint32 MaterialConservativeByteCountPerPixel = CVarStrataBytePerPixel . GetValueOnAnyThread ( ) ;
2020-11-09 12:06:15 -04:00
const uint32 RoundToValue = 4u ;
2022-04-02 14:31:01 -04:00
Out . MaxBytesPerPixel = FMath : : DivideAndRoundUp ( MaterialConservativeByteCountPerPixel , RoundToValue ) * RoundToValue ;
2021-01-27 08:51:50 -04:00
2020-12-16 19:25:24 -04:00
// Top layer texture
{
2022-04-02 14:31:01 -04:00
Out . TopLayerTexture = GraphBuilder . CreateTexture ( FRDGTextureDesc : : Create2D ( SceneTextureExtent , PF_R32_UINT , FClearValueBinding : : Black , TexCreate_RenderTargetable | TexCreate_ShaderResource ) , TEXT ( " Strata.TopLayerTexture " ) ) ;
2020-12-16 19:25:24 -04:00
}
2021-02-15 08:15:16 -04:00
2021-02-15 08:40:43 -04:00
// SSS texture
{
2022-04-02 14:31:01 -04:00
Out . SSSTexture = GraphBuilder . CreateTexture ( FRDGTextureDesc : : Create2D ( SceneTextureExtent , PF_R32G32_UINT , FClearValueBinding : : Black , TexCreate_DisableDCC | TexCreate_NoFastClear | TexCreate_ShaderResource | TexCreate_UAV ) , TEXT ( " Strata.SSSTexture " ) ) ;
Out . SSSTextureUAV = GraphBuilder . CreateUAV ( Out . SSSTexture ) ;
2021-02-15 08:40:43 -04:00
}
2022-03-15 03:11:08 -04:00
// Separated subsurface and rough refraction textures
{
const bool bIsStrataOpaqueMaterialRoughRefractionEnabled = IsStrataOpaqueMaterialRoughRefractionEnabled ( ) ;
const FIntPoint OpaqueRoughRefractionSceneExtent = bIsStrataOpaqueMaterialRoughRefractionEnabled ? SceneTextureExtent : FIntPoint ( 4 , 4 ) ;
2022-04-02 14:31:01 -04:00
Out . OpaqueRoughRefractionTexture = GraphBuilder . CreateTexture (
2022-03-16 11:42:57 -04:00
FRDGTextureDesc : : Create2D ( OpaqueRoughRefractionSceneExtent , PF_FloatR11G11B10 , FClearValueBinding : : Black , TexCreate_ShaderResource | TexCreate_UAV | TexCreate_RenderTargetable ) , TEXT ( " Strata.OpaqueRoughRefractionTexture " ) ) ;
2022-04-02 14:31:01 -04:00
Out . OpaqueRoughRefractionTextureUAV = GraphBuilder . CreateUAV ( Out . OpaqueRoughRefractionTexture ) ;
2022-03-15 03:11:08 -04:00
2022-04-02 14:31:01 -04:00
Out . SeparatedSubSurfaceSceneColor = GraphBuilder . CreateTexture (
2022-03-15 03:11:08 -04:00
FRDGTextureDesc : : Create2D ( OpaqueRoughRefractionSceneExtent , PF_FloatR11G11B10 , FClearValueBinding : : Black , TexCreate_ShaderResource | TexCreate_UAV | TexCreate_RenderTargetable ) , TEXT ( " Strata.SeparatedSubSurfaceSceneColor " ) ) ;
2022-04-02 14:31:01 -04:00
Out . SeparatedOpaqueRoughRefractionSceneColor = GraphBuilder . CreateTexture (
2022-03-15 03:11:08 -04:00
FRDGTextureDesc : : Create2D ( OpaqueRoughRefractionSceneExtent , PF_FloatR11G11B10 , FClearValueBinding : : Black , TexCreate_ShaderResource | TexCreate_UAV | TexCreate_RenderTargetable ) , TEXT ( " Strata.SeparatedOpaqueRoughRefractionSceneColor " ) ) ;
if ( bIsStrataOpaqueMaterialRoughRefractionEnabled )
{
// Fast clears
2022-04-02 14:31:01 -04:00
AddClearRenderTargetPass ( GraphBuilder , Out . OpaqueRoughRefractionTexture , Out . OpaqueRoughRefractionTexture - > Desc . ClearValue . GetClearColor ( ) ) ;
AddClearRenderTargetPass ( GraphBuilder , Out . SeparatedSubSurfaceSceneColor , Out . SeparatedSubSurfaceSceneColor - > Desc . ClearValue . GetClearColor ( ) ) ;
AddClearRenderTargetPass ( GraphBuilder , Out . SeparatedOpaqueRoughRefractionSceneColor , Out . SeparatedOpaqueRoughRefractionSceneColor - > Desc . ClearValue . GetClearColor ( ) ) ;
2022-03-15 03:11:08 -04:00
}
}
2022-03-18 13:43:33 -04:00
2022-04-02 14:31:01 -04:00
// BSDF offsets
2022-03-18 13:43:33 -04:00
{
2022-04-02 14:31:01 -04:00
Out . BSDFOffsetTexture = GraphBuilder . CreateTexture ( FRDGTextureDesc : : Create2D ( SceneTextureExtent , PF_R32_UINT , FClearValueBinding : : None , TexCreate_UAV | TexCreate_ShaderResource ) , TEXT ( " Strata.BSDFOffsets " ) ) ;
AddClearUAVPass ( GraphBuilder , GraphBuilder . CreateUAV ( Out . BSDFOffsetTexture ) , 0u ) ;
2022-03-21 06:29:05 -04:00
}
2020-09-16 04:20:36 -04:00
}
else
{
2022-04-02 14:31:01 -04:00
Out . MaxBytesPerPixel = 4u * STRATA_BASE_PASS_MRT_OUTPUT_COUNT ;
2020-09-16 04:20:36 -04:00
}
2021-11-29 09:31:58 -05:00
// Create the material data container
FIntPoint SceneTextureExtent = IsStrataEnabled ( ) ? GetSceneTextureExtent ( ) : FIntPoint ( 2 , 2 ) ;
2021-11-29 10:12:58 -05:00
2022-04-02 14:31:01 -04:00
const uint32 SliceCount = FMath : : DivideAndRoundUp ( Out . MaxBytesPerPixel , 4u ) ;
2022-03-25 14:18:22 -04:00
const FRDGTextureDesc MaterialTextureDesc = FRDGTextureDesc : : Create2DArray ( SceneTextureExtent , PF_R32_UINT , FClearValueBinding : : Transparent ,
2022-01-04 12:18:49 -05:00
TexCreate_TargetArraySlicesIndependently | TexCreate_DisableDCC | TexCreate_NoFastClear | TexCreate_RenderTargetable | TexCreate_ShaderResource | TexCreate_UAV , SliceCount , 1 , 1 ) ;
2022-04-02 14:31:01 -04:00
Out . MaterialTextureArray = GraphBuilder . CreateTexture ( MaterialTextureDesc , TEXT ( " Strata.Material " ) ) ;
Out . MaterialTextureArraySRV = GraphBuilder . CreateSRV ( FRDGTextureSRVDesc : : Create ( Out . MaterialTextureArray ) ) ;
Out . MaterialTextureArrayUAV = GraphBuilder . CreateUAV ( FRDGTextureUAVDesc ( Out . MaterialTextureArray , 0 ) ) ;
2020-09-16 04:20:36 -04:00
2022-01-04 12:18:49 -05:00
// See AppendStrataMRTs
check ( STRATA_BASE_PASS_MRT_OUTPUT_COUNT < = SliceCount ) ;
2022-04-02 14:31:01 -04:00
Out . MaterialTextureArrayUAVWithoutRTs = GraphBuilder . CreateUAV ( FRDGTextureUAVDesc ( Out . MaterialTextureArray , 0 , PF_Unknown , STRATA_BASE_PASS_MRT_OUTPUT_COUNT , SliceCount - STRATA_BASE_PASS_MRT_OUTPUT_COUNT ) ) ;
2022-01-04 12:18:49 -05:00
2021-11-03 04:18:34 -04:00
// Rough diffuse model
2022-04-02 14:31:01 -04:00
Out . bRoughDiffuse = CVarStrataRoughDiffuse . GetValueOnRenderThread ( ) > 0 ? 1u : 0u ;
2020-11-02 10:05:56 -04:00
2021-03-30 02:33:35 -04:00
if ( IsStrataEnabled ( ) )
{
2021-11-26 07:05:41 -05:00
AddStrataClearMaterialBufferPass (
GraphBuilder ,
2022-04-02 14:31:01 -04:00
GraphBuilder . CreateUAV ( FRDGTextureUAVDesc ( Out . MaterialTextureArray , 0 ) ) ,
Out . SSSTextureUAV ,
Out . MaxBytesPerPixel ,
2021-11-26 07:05:41 -05:00
MaterialBufferSizeXY ) ;
2021-03-30 02:33:35 -04:00
}
2022-04-02 14:31:01 -04:00
// Initialized view data
for ( int32 ViewIndex = 0 ; ViewIndex < SceneRenderer . Views . Num ( ) ; ViewIndex + + )
2021-03-30 02:33:35 -04:00
{
2022-04-02 14:31:01 -04:00
Strata : : InitialiseStrataViewData ( GraphBuilder , SceneRenderer . Views [ ViewIndex ] , Out ) ;
2021-03-30 06:48:19 -04:00
}
2020-09-16 04:20:36 -04:00
}
2022-04-01 08:35:55 -04:00
void BindStrataBasePassUniformParameters ( FRDGBuilder & GraphBuilder , const FViewInfo & View , FStrataBasePassUniformParameters & OutStrataUniformParameters )
2020-09-16 04:20:36 -04:00
{
2022-04-02 14:31:01 -04:00
const FStrataSceneData * StrataSceneData = View . StrataViewData . SceneData ;
2021-04-10 07:34:33 -04:00
if ( IsStrataEnabled ( ) & & StrataSceneData )
2020-09-16 12:39:51 -04:00
{
2021-11-03 04:18:34 -04:00
OutStrataUniformParameters . bRoughDiffuse = StrataSceneData - > bRoughDiffuse ? 1u : 0u ;
2021-03-30 11:27:24 -04:00
OutStrataUniformParameters . MaxBytesPerPixel = StrataSceneData - > MaxBytesPerPixel ;
2022-01-04 12:18:49 -05:00
OutStrataUniformParameters . MaterialTextureArrayUAVWithoutRTs = StrataSceneData - > MaterialTextureArrayUAVWithoutRTs ;
2021-11-24 10:34:04 -05:00
OutStrataUniformParameters . SSSTextureUAV = StrataSceneData - > SSSTextureUAV ;
2022-03-15 03:11:08 -04:00
OutStrataUniformParameters . OpaqueRoughRefractionTextureUAV = StrataSceneData - > OpaqueRoughRefractionTextureUAV ;
2020-09-16 12:39:51 -04:00
}
else
{
2022-03-15 03:11:08 -04:00
FRDGTextureRef DummyWritableSSSTexture = GraphBuilder . CreateTexture ( FRDGTextureDesc : : Create2D ( FIntPoint ( 1 , 1 ) , PF_R32_UINT , FClearValueBinding : : None , TexCreate_ShaderResource | TexCreate_UAV ) , TEXT ( " Strata.DummyWritableTexture " ) ) ;
FRDGTextureUAVRef DummyWritableSSSTextureUAV = GraphBuilder . CreateUAV ( FRDGTextureUAVDesc ( DummyWritableSSSTexture ) ) ;
FRDGTextureRef DummyWritableRefracTexture = GraphBuilder . CreateTexture ( FRDGTextureDesc : : Create2D ( FIntPoint ( 1 , 1 ) , PF_R8 , FClearValueBinding : : None , TexCreate_ShaderResource | TexCreate_UAV ) , TEXT ( " Strata.DummyWritableTexture " ) ) ;
FRDGTextureUAVRef DummyWritableRefracTextureUAV = GraphBuilder . CreateUAV ( FRDGTextureUAVDesc ( DummyWritableRefracTexture ) ) ;
2021-11-29 09:31:58 -05:00
FRDGTextureRef DummyWritableTextureArray = GraphBuilder . CreateTexture ( FRDGTextureDesc : : Create2DArray ( FIntPoint ( 1 , 1 ) , PF_R32_UINT , FClearValueBinding : : None , TexCreate_ShaderResource | TexCreate_UAV , 1 ) , TEXT ( " Strata.DummyWritableTexture " ) ) ;
FRDGTextureUAVRef DummyWritableTextureArrayUAV = GraphBuilder . CreateUAV ( FRDGTextureUAVDesc ( DummyWritableTextureArray ) ) ;
2021-11-24 10:34:04 -05:00
const FRDGSystemTextures & SystemTextures = FRDGSystemTextures : : Get ( GraphBuilder ) ;
2021-11-03 04:18:34 -04:00
OutStrataUniformParameters . bRoughDiffuse = 0u ;
2020-09-16 12:39:51 -04:00
OutStrataUniformParameters . MaxBytesPerPixel = 0 ;
2022-01-04 12:18:49 -05:00
OutStrataUniformParameters . MaterialTextureArrayUAVWithoutRTs = DummyWritableTextureArrayUAV ;
2022-03-15 03:11:08 -04:00
OutStrataUniformParameters . SSSTextureUAV = DummyWritableSSSTextureUAV ;
OutStrataUniformParameters . OpaqueRoughRefractionTextureUAV = DummyWritableRefracTextureUAV ;
2020-09-16 12:39:51 -04:00
}
2020-09-16 04:20:36 -04:00
}
2022-04-02 14:31:01 -04:00
static void BindStrataGlobalUniformParameters ( FRDGBuilder & GraphBuilder , FStrataViewData * StrataViewData , FStrataGlobalUniformParameters & OutStrataUniformParameters )
2021-11-18 14:37:34 -05:00
{
2022-04-02 14:31:01 -04:00
FStrataSceneData * StrataSceneData = StrataViewData - > SceneData ;
2021-11-18 14:37:34 -05:00
if ( IsStrataEnabled ( ) & & StrataSceneData )
{
OutStrataUniformParameters . bRoughDiffuse = StrataSceneData - > bRoughDiffuse ? 1u : 0u ;
OutStrataUniformParameters . MaxBytesPerPixel = StrataSceneData - > MaxBytesPerPixel ;
2022-03-31 13:05:44 -04:00
OutStrataUniformParameters . TileSize = STRATA_TILE_SIZE ;
OutStrataUniformParameters . TileSizeLog2 = STRATA_TILE_SIZE_DIV_AS_SHIFT ;
2022-04-02 14:31:01 -04:00
OutStrataUniformParameters . TileCount = StrataViewData - > TileCount_Primary ;
2021-12-01 17:11:17 -05:00
OutStrataUniformParameters . MaterialTextureArray = StrataSceneData - > MaterialTextureArray ;
2021-11-26 10:59:06 -05:00
OutStrataUniformParameters . TopLayerTexture = StrataSceneData - > TopLayerTexture ;
2021-11-18 14:37:34 -05:00
OutStrataUniformParameters . SSSTexture = StrataSceneData - > SSSTexture ;
2022-03-15 03:11:08 -04:00
OutStrataUniformParameters . OpaqueRoughRefractionTexture = StrataSceneData - > OpaqueRoughRefractionTexture ;
2022-04-02 14:31:01 -04:00
OutStrataUniformParameters . BSDFTileTexture = StrataViewData - > BSDFTileTexture ;
2022-03-18 13:43:33 -04:00
OutStrataUniformParameters . BSDFOffsetTexture = StrataSceneData - > BSDFOffsetTexture ;
2022-04-02 14:31:01 -04:00
OutStrataUniformParameters . BSDFTileCountBuffer = GraphBuilder . CreateSRV ( StrataViewData - > BSDFTileCountBuffer , PF_R32_UINT ) ;
2021-11-18 14:37:34 -05:00
}
else
{
const FRDGSystemTextures & SystemTextures = FRDGSystemTextures : : Get ( GraphBuilder ) ;
2021-11-29 09:31:58 -05:00
FRDGTextureRef DefaultTextureArray = GSystemTextures . GetDefaultTexture ( GraphBuilder , ETextureDimension : : Texture2DArray , EPixelFormat : : PF_R32_UINT , FClearValueBinding : : Transparent ) ;
2022-03-31 12:43:49 -04:00
FRDGBufferSRVRef DefaultBuffer = GraphBuilder . CreateSRV ( GSystemTextures . GetDefaultBuffer ( GraphBuilder , 4 , 0u ) , PF_R32_UINT ) ;
2021-11-18 14:37:34 -05:00
OutStrataUniformParameters . bRoughDiffuse = 0 ;
OutStrataUniformParameters . MaxBytesPerPixel = 0 ;
2022-03-18 13:43:33 -04:00
OutStrataUniformParameters . TileSize = 0 ;
OutStrataUniformParameters . TileSizeLog2 = 0 ;
OutStrataUniformParameters . TileCount = 0 ;
2021-12-01 17:11:17 -05:00
OutStrataUniformParameters . MaterialTextureArray = DefaultTextureArray ;
2021-11-26 10:59:06 -05:00
OutStrataUniformParameters . TopLayerTexture = SystemTextures . DefaultNormal8Bit ;
2021-11-18 14:37:34 -05:00
OutStrataUniformParameters . SSSTexture = SystemTextures . Black ;
2022-03-15 03:11:08 -04:00
OutStrataUniformParameters . OpaqueRoughRefractionTexture = SystemTextures . Black ;
2022-03-18 13:43:33 -04:00
OutStrataUniformParameters . BSDFTileTexture = SystemTextures . Black ;
OutStrataUniformParameters . BSDFOffsetTexture = SystemTextures . Black ;
2022-03-31 12:43:49 -04:00
OutStrataUniformParameters . BSDFTileCountBuffer = DefaultBuffer ;
2021-11-18 14:37:34 -05:00
}
}
2022-04-01 08:35:55 -04:00
void BindStrataForwardPasslUniformParameters ( FRDGBuilder & GraphBuilder , const FViewInfo & View , FStrataForwardPassUniformParameters & OutStrataUniformParameters )
2021-12-01 17:11:17 -05:00
{
2022-04-02 14:31:01 -04:00
FStrataSceneData * StrataSceneData = View . StrataViewData . SceneData ;
2021-12-01 17:11:17 -05:00
if ( IsStrataEnabled ( ) & & StrataSceneData )
{
OutStrataUniformParameters . bRoughDiffuse = StrataSceneData - > bRoughDiffuse ? 1u : 0u ;
}
else
{
OutStrataUniformParameters . bRoughDiffuse = 0 ;
}
}
2022-04-01 08:35:55 -04:00
TRDGUniformBufferRef < FStrataGlobalUniformParameters > BindStrataGlobalUniformParameters ( const FViewInfo & View )
2020-10-08 03:11:37 -04:00
{
2022-04-02 14:31:01 -04:00
check ( View . StrataViewData . StrataGlobalUniformParameters ! = nullptr | | ! IsStrataEnabled ( ) ) ;
return View . StrataViewData . StrataGlobalUniformParameters ;
2020-10-08 03:11:37 -04:00
}
2020-12-08 09:06:58 -04:00
//////////////////////////////////////////////////////////////////////////
// Debug
2020-10-13 16:46:31 -04:00
2021-04-21 06:47:25 -04:00
# define VISUALIZE_MATERIAL_PASS_COUNT 3
2022-04-12 14:06:17 -04:00
# define MULTIPASS_ENABLE 0
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 CanRunStrataVizualizeMaterial ( 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 IsPCPlatform ( Platform ) ;
}
static bool ShouldCompilePermutation ( const FGlobalShaderPermutationParameters & Parameters )
{
return GetMaxSupportedFeatureLevel ( Parameters . Platform ) > = ERHIFeatureLevel : : SM5 & & Strata : : IsStrataEnabled ( ) & & CanRunStrataVizualizeMaterial ( Parameters . Platform ) ;
}
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 ) ;
OutEnvironment . SetDefine ( TEXT ( " MULTIPASS_ENABLE " ) , MULTIPASS_ENABLE ) ;
}
} ;
IMPLEMENT_GLOBAL_SHADER ( FMaterialPrintInfoCS , " /Engine/Private/Strata/StrataVisualize.usf " , " MaterialPrintInfoCS " , SF_Compute ) ;
2021-04-21 06:47:25 -04:00
2020-10-13 16:46:31 -04:00
class FVisualizeMaterialPS : public FGlobalShader
{
DECLARE_GLOBAL_SHADER ( FVisualizeMaterialPS ) ;
SHADER_USE_PARAMETER_STRUCT ( FVisualizeMaterialPS , FGlobalShader ) ;
2022-04-12 14:06:17 -04:00
using FPermutationDomain = TShaderPermutationDomain < > ;
2020-10-13 16:46:31 -04:00
BEGIN_SHADER_PARAMETER_STRUCT ( FParameters , )
2022-04-12 14:06:17 -04:00
SHADER_PARAMETER ( uint32 , ViewMode )
2020-10-13 16:46:31 -04:00
SHADER_PARAMETER_STRUCT_REF ( FViewUniformShaderParameters , ViewUniformBuffer )
2021-03-30 02:33:35 -04:00
SHADER_PARAMETER_RDG_UNIFORM_BUFFER ( FStrataGlobalUniformParameters , Strata )
2020-11-05 06:16:12 -04:00
SHADER_PARAMETER_STRUCT_INCLUDE ( FSceneTextureParameters , SceneTextures )
2022-02-22 15:35:01 -05:00
SHADER_PARAMETER_STRUCT_INCLUDE ( ShaderPrint : : FShaderParameters , ShaderPrintParameters )
2020-10-13 16:46:31 -04:00
RENDER_TARGET_BINDING_SLOTS ( )
END_SHADER_PARAMETER_STRUCT ( )
static FPermutationDomain RemapPermutation ( FPermutationDomain PermutationVector )
{
return PermutationVector ;
}
2021-02-09 05:03:11 -04:00
static bool CanRunStrataVizualizeMaterial ( 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 IsPCPlatform ( Platform ) ;
}
2020-10-13 16:46:31 -04:00
static bool ShouldCompilePermutation ( const FGlobalShaderPermutationParameters & Parameters )
{
2022-04-12 14:06:17 -04:00
return GetMaxSupportedFeatureLevel ( Parameters . Platform ) > = ERHIFeatureLevel : : SM5 & & Strata : : IsStrataEnabled ( ) & & CanRunStrataVizualizeMaterial ( Parameters . Platform ) ;
2020-10-13 16:46:31 -04:00
}
static void ModifyCompilationEnvironment ( const FGlobalShaderPermutationParameters & Parameters , FShaderCompilerEnvironment & OutEnvironment )
{
FGlobalShader : : ModifyCompilationEnvironment ( Parameters , OutEnvironment ) ;
2020-12-18 16:48:51 -04:00
// Stay debug and skip optimizations to reduce compilation time on this long shader.
OutEnvironment . CompilerFlags . Add ( CFLAG_Debug ) ;
2022-04-12 14:06:17 -04:00
OutEnvironment . SetDefine ( TEXT ( " SHADER_MATERIALVISUALIZE " ) , 1 ) ;
2020-10-13 16:46:31 -04:00
}
} ;
IMPLEMENT_GLOBAL_SHADER ( FVisualizeMaterialPS , " /Engine/Private/Strata/StrataVisualize.usf " , " VisualizeMaterialPS " , SF_Pixel ) ;
2021-02-17 12:02:02 -04:00
static void AddVisualizeMaterialPasses ( FRDGBuilder & GraphBuilder , const FViewInfo & View , FRDGTextureRef SceneColorTexture , EShaderPlatform Platform )
2020-10-13 16:46:31 -04:00
{
FRHIBlendState * PreMultipliedColorTransmittanceBlend = TStaticBlendState < CW_RGB , BO_Add , BF_One , BF_SourceAlpha , BO_Add , BF_Zero , BF_One > : : GetRHI ( ) ;
2021-02-17 12:02:02 -04:00
if ( View . Family - > EngineShowFlags . VisualizeStrataMaterial )
2020-10-13 16:46:31 -04:00
{
2022-02-28 07:53:18 -05:00
if ( ! ShaderPrint : : IsEnabled ( View ) ) { ShaderPrint : : SetEnabled ( true ) ; }
ShaderPrint : : RequestSpaceForLines ( 64 ) ;
2022-04-12 14:06:17 -04:00
ShaderPrint : : RequestSpaceForCharacters ( 1024 ) ;
2022-02-28 07:53:18 -05:00
FSceneTextureParameters SceneTextureParameters = GetSceneTextureParameters ( GraphBuilder ) ;
2020-10-13 16:46:31 -04:00
2022-04-12 14:06:17 -04:00
// Print Material info
2021-02-17 12:02:02 -04:00
{
2022-04-12 14:06:17 -04:00
uint32 BSDFIndex = 0 ;
FRDGBufferUAVRef PrintOffsetBufferUAV = nullptr ;
# if MULTIPASS_ENABLE
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 ( BSDFIndex ; BSDFIndex < MaxBSDFCount ; + + BSDFIndex )
# endif
{
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 ) ;
ShaderPrint : : SetParameters ( GraphBuilder , View . ShaderPrintData , PassParameters - > ShaderPrintParameters ) ;
TShaderMapRef < FMaterialPrintInfoCS > ComputeShader ( View . ShaderMap ) ;
FComputeShaderUtils : : AddPass ( GraphBuilder , RDG_EVENT_NAME ( " Strata::VisualizeMaterial(Print) " ) , ComputeShader , PassParameters , FIntVector ( 1 , 1 , 1 ) ) ;
}
}
// Draw material debug
const uint32 ViewMode = FMath : : Max ( 0 , CVarStrataDebugMode . GetValueOnRenderThread ( ) ) ;
if ( ViewMode > 1 )
{
FVisualizeMaterialPS : : FParameters * PassParameters = GraphBuilder . AllocParameters < FVisualizeMaterialPS : : FParameters > ( ) ;
PassParameters - > ViewUniformBuffer = View . ViewUniformBuffer ;
PassParameters - > ViewMode = ViewMode ;
PassParameters - > Strata = Strata : : BindStrataGlobalUniformParameters ( View ) ;
PassParameters - > SceneTextures = GetSceneTextureParameters ( GraphBuilder ) ;
PassParameters - > RenderTargets [ 0 ] = FRenderTargetBinding ( SceneColorTexture , ERenderTargetLoadAction : : ELoad ) ;
ShaderPrint : : SetParameters ( GraphBuilder , View . ShaderPrintData , PassParameters - > ShaderPrintParameters ) ;
2021-02-17 12:02:02 -04:00
FVisualizeMaterialPS : : FPermutationDomain PermutationVector ;
TShaderMapRef < FVisualizeMaterialPS > PixelShader ( View . ShaderMap , PermutationVector ) ;
2020-11-20 05:37:52 -04:00
2022-04-12 14:06:17 -04:00
FPixelShaderUtils : : AddFullscreenPass < FVisualizeMaterialPS > ( GraphBuilder , View . ShaderMap , RDG_EVENT_NAME ( " Strata::VisualizeMaterial(Draw) " ) , PixelShader , PassParameters , View . ViewRect , PreMultipliedColorTransmittanceBlend ) ;
2020-10-13 16:46:31 -04:00
}
}
}
2021-01-27 08:51:50 -04:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2021-02-09 04:08:35 -04:00
class FStrataClearMaterialBufferCS : public FGlobalShader
{
DECLARE_GLOBAL_SHADER ( FStrataClearMaterialBufferCS ) ;
SHADER_USE_PARAMETER_STRUCT ( FStrataClearMaterialBufferCS , FGlobalShader ) ;
using FPermutationDomain = TShaderPermutationDomain < > ;
BEGIN_SHADER_PARAMETER_STRUCT ( FParameters , )
2021-11-29 09:31:58 -05:00
SHADER_PARAMETER_RDG_TEXTURE_UAV ( RWTexture2DArray < uint > , MaterialTextureArrayUAV )
2021-11-26 07:05:41 -05:00
SHADER_PARAMETER_RDG_TEXTURE_UAV ( RWTexture2D < uint2 > , SSSTextureUAV )
2021-02-09 04:08:35 -04:00
SHADER_PARAMETER ( uint32 , MaxBytesPerPixel )
SHADER_PARAMETER ( FIntPoint , TiledViewBufferResolution )
END_SHADER_PARAMETER_STRUCT ( )
static bool ShouldCompilePermutation ( const FGlobalShaderPermutationParameters & Parameters )
{
return GetMaxSupportedFeatureLevel ( Parameters . Platform ) > = ERHIFeatureLevel : : SM5 & & Strata : : IsStrataEnabled ( ) ;
}
static void ModifyCompilationEnvironment ( const FGlobalShaderPermutationParameters & Parameters , FShaderCompilerEnvironment & OutEnvironment )
{
FGlobalShader : : ModifyCompilationEnvironment ( Parameters , OutEnvironment ) ;
OutEnvironment . SetDefine ( TEXT ( " SHADER_CLEAR_MATERIAL_BUFFER " ) , 1 ) ;
}
} ;
IMPLEMENT_GLOBAL_SHADER ( FStrataClearMaterialBufferCS , " /Engine/Private/Strata/StrataMaterialClassification.usf " , " ClearMaterialBufferMainCS " , SF_Compute ) ;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2022-03-18 13:43:33 -04:00
class FStrataBSDFTilePassCS : public FGlobalShader
{
DECLARE_GLOBAL_SHADER ( FStrataBSDFTilePassCS ) ;
SHADER_USE_PARAMETER_STRUCT ( FStrataBSDFTilePassCS , FGlobalShader ) ;
class FWaveOps : SHADER_PERMUTATION_BOOL ( " PERMUTATION_WAVE_OPS " ) ;
using FPermutationDomain = TShaderPermutationDomain < FWaveOps > ;
BEGIN_SHADER_PARAMETER_STRUCT ( FParameters , )
SHADER_PARAMETER_STRUCT_REF ( FViewUniformShaderParameters , ViewUniformBuffer )
SHADER_PARAMETER ( int32 , bRectPrimitive )
SHADER_PARAMETER ( int32 , TileSizeLog2 )
SHADER_PARAMETER ( FIntPoint , TileCount_Primary )
SHADER_PARAMETER ( FIntPoint , ViewResolution )
SHADER_PARAMETER ( uint32 , MaxBytesPerPixel )
SHADER_PARAMETER_RDG_TEXTURE ( Texture2D , TopLayerTexture )
SHADER_PARAMETER_RDG_TEXTURE_SRV ( Texture2DArray < uint > , MaterialTextureArray )
SHADER_PARAMETER_RDG_TEXTURE_UAV ( RWTexture2D < uint > , RWBSDFTileTexture )
SHADER_PARAMETER_RDG_TEXTURE_UAV ( RWTexture2D < uint > , RWBSDFOffsetTexture )
SHADER_PARAMETER_RDG_BUFFER_UAV ( RWBuffer < uint > , RWBSDFTileCountBuffer )
SHADER_PARAMETER_RDG_BUFFER_SRV ( Buffer < uint > , TileListBuffer )
RDG_BUFFER_ACCESS ( TileIndirectBuffer , ERHIAccess : : IndirectArgs )
END_SHADER_PARAMETER_STRUCT ( )
static bool ShouldCompilePermutation ( const FGlobalShaderPermutationParameters & Parameters )
{
const bool bUseWaveIntrinsics = FDataDrivenShaderPlatformInfo : : GetSupportsWaveOperations ( Parameters . Platform ) ;
FPermutationDomain PermutationVector ( Parameters . PermutationId ) ;
if ( PermutationVector . Get < FWaveOps > ( ) & & ! bUseWaveIntrinsics )
{
return false ;
}
return GetMaxSupportedFeatureLevel ( Parameters . Platform ) > = ERHIFeatureLevel : : SM5 & & Strata : : IsStrataEnabled ( ) ;
}
static void ModifyCompilationEnvironment ( const FGlobalShaderPermutationParameters & Parameters , FShaderCompilerEnvironment & OutEnvironment )
{
FGlobalShader : : ModifyCompilationEnvironment ( Parameters , OutEnvironment ) ;
OutEnvironment . SetDefine ( TEXT ( " SHADER_BSDF_TILE " ) , 1 ) ;
FPermutationDomain PermutationVector ( Parameters . PermutationId ) ;
if ( PermutationVector . Get < FWaveOps > ( ) )
{
OutEnvironment . CompilerFlags . Add ( CFLAG_WaveOperations ) ;
}
}
} ;
IMPLEMENT_GLOBAL_SHADER ( FStrataBSDFTilePassCS , " /Engine/Private/Strata/StrataMaterialClassification.usf " , " BSDFTileMainCS " , SF_Compute ) ;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2021-01-27 08:51:50 -04:00
class FStrataMaterialTileClassificationPassCS : public FGlobalShader
{
DECLARE_GLOBAL_SHADER ( FStrataMaterialTileClassificationPassCS ) ;
SHADER_USE_PARAMETER_STRUCT ( FStrataMaterialTileClassificationPassCS , FGlobalShader ) ;
2021-12-06 08:54:37 -05:00
class FStrataClearDuringCategorization : SHADER_PERMUTATION_BOOL ( " PERMUTATION_STRATA_CLEAR_DURING_CATEGORIZATION " ) ;
2021-11-24 13:13:31 -05:00
class FWaveOps : SHADER_PERMUTATION_BOOL ( " PERMUTATION_WAVE_OPS " ) ;
2021-12-06 08:54:37 -05:00
using FPermutationDomain = TShaderPermutationDomain < FWaveOps , FStrataClearDuringCategorization > ;
2021-01-27 08:51:50 -04:00
BEGIN_SHADER_PARAMETER_STRUCT ( FParameters , )
SHADER_PARAMETER_STRUCT_REF ( FViewUniformShaderParameters , ViewUniformBuffer )
2021-01-28 07:26:46 -04:00
SHADER_PARAMETER ( int32 , bRectPrimitive )
2021-01-29 18:01:50 -04:00
SHADER_PARAMETER ( FIntPoint , ViewResolution )
2021-11-26 10:59:06 -05:00
SHADER_PARAMETER ( uint32 , MaxBytesPerPixel )
2021-11-29 18:42:19 -05:00
SHADER_PARAMETER_RDG_TEXTURE ( Texture2D , TopLayerTexture )
2021-11-29 09:31:58 -05:00
SHADER_PARAMETER_RDG_TEXTURE_SRV ( Texture2DArray < uint > , MaterialTextureArray )
2022-03-18 13:43:33 -04:00
SHADER_PARAMETER_RDG_BUFFER_UAV ( RWBuffer , TileDrawIndirectDataBuffer )
2021-04-06 02:12:57 -04:00
SHADER_PARAMETER_RDG_BUFFER_UAV ( RWBuffer , SimpleTileListDataBuffer )
2021-12-14 10:24:57 -05:00
SHADER_PARAMETER_RDG_BUFFER_UAV ( RWBuffer , SingleTileListDataBuffer )
2021-04-06 02:12:57 -04:00
SHADER_PARAMETER_RDG_BUFFER_UAV ( RWBuffer , ComplexTileListDataBuffer )
2022-03-15 03:11:08 -04:00
SHADER_PARAMETER_RDG_BUFFER_UAV ( RWBuffer , OpaqueRoughRefractionTileListDataBuffer )
2022-03-16 05:45:43 -04:00
SHADER_PARAMETER_RDG_BUFFER_UAV ( RWBuffer , SSSWithoutOpaqueRoughRefractionTileListDataBuffer )
2021-12-06 08:54:37 -05:00
SHADER_PARAMETER_RDG_TEXTURE_UAV ( RWTexture2D < uint2 > , SSSTextureUAV )
2022-03-16 11:42:57 -04:00
SHADER_PARAMETER_RDG_TEXTURE ( Texture2D < float3 > , OpaqueRoughRefractionTexture )
2021-01-27 08:51:50 -04:00
END_SHADER_PARAMETER_STRUCT ( )
static bool ShouldCompilePermutation ( const FGlobalShaderPermutationParameters & Parameters )
{
2021-11-24 13:13:31 -05:00
const bool bUseWaveIntrinsics = FDataDrivenShaderPlatformInfo : : GetSupportsWaveOperations ( Parameters . Platform ) ;
FPermutationDomain PermutationVector ( Parameters . PermutationId ) ;
if ( PermutationVector . Get < FWaveOps > ( ) & & ! bUseWaveIntrinsics )
{
return false ;
}
2021-01-27 08:51:50 -04:00
return GetMaxSupportedFeatureLevel ( Parameters . Platform ) > = ERHIFeatureLevel : : SM5 & & Strata : : IsStrataEnabled ( ) ;
}
static void ModifyCompilationEnvironment ( const FGlobalShaderPermutationParameters & Parameters , FShaderCompilerEnvironment & OutEnvironment )
{
FGlobalShader : : ModifyCompilationEnvironment ( Parameters , OutEnvironment ) ;
OutEnvironment . SetDefine ( TEXT ( " SHADER_TILE_CATEGORIZATION " ) , 1 ) ;
2021-11-24 13:13:31 -05:00
FPermutationDomain PermutationVector ( Parameters . PermutationId ) ;
if ( PermutationVector . Get < FWaveOps > ( ) )
{
OutEnvironment . CompilerFlags . Add ( CFLAG_WaveOperations ) ;
}
2021-01-27 08:51:50 -04:00
}
} ;
IMPLEMENT_GLOBAL_SHADER ( FStrataMaterialTileClassificationPassCS , " /Engine/Private/Strata/StrataMaterialClassification.usf " , " TileMainCS " , SF_Compute ) ;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2022-03-18 13:43:33 -04:00
class FStrataMaterialTilePrepareArgsPassCS : public FGlobalShader
{
DECLARE_GLOBAL_SHADER ( FStrataMaterialTilePrepareArgsPassCS ) ;
SHADER_USE_PARAMETER_STRUCT ( FStrataMaterialTilePrepareArgsPassCS , FGlobalShader ) ;
BEGIN_SHADER_PARAMETER_STRUCT ( FParameters , )
SHADER_PARAMETER_RDG_BUFFER_SRV ( Buffer , TileDrawIndirectDataBuffer )
SHADER_PARAMETER_RDG_BUFFER_UAV ( RWBuffer , TileDispatchIndirectDataBuffer )
END_SHADER_PARAMETER_STRUCT ( )
static bool ShouldCompilePermutation ( const FGlobalShaderPermutationParameters & Parameters )
{
return GetMaxSupportedFeatureLevel ( Parameters . Platform ) > = ERHIFeatureLevel : : SM5 & & Strata : : IsStrataEnabled ( ) ;
}
static void ModifyCompilationEnvironment ( const FGlobalShaderPermutationParameters & Parameters , FShaderCompilerEnvironment & OutEnvironment )
{
FGlobalShader : : ModifyCompilationEnvironment ( Parameters , OutEnvironment ) ;
2022-03-21 06:29:05 -04:00
OutEnvironment . SetDefine ( TEXT ( " SHADER_MATERIAL_TILE_PREPARE_ARGS " ) , 1 ) ;
2022-03-18 13:43:33 -04:00
}
} ;
IMPLEMENT_GLOBAL_SHADER ( FStrataMaterialTilePrepareArgsPassCS , " /Engine/Private/Strata/StrataMaterialClassification.usf " , " ArgsMainCS " , SF_Compute ) ;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2022-03-21 06:29:05 -04:00
class FStrataBSDFTilePrepareArgsPassCS : public FGlobalShader
{
DECLARE_GLOBAL_SHADER ( FStrataBSDFTilePrepareArgsPassCS ) ;
SHADER_USE_PARAMETER_STRUCT ( FStrataBSDFTilePrepareArgsPassCS , FGlobalShader ) ;
BEGIN_SHADER_PARAMETER_STRUCT ( FParameters , )
SHADER_PARAMETER ( FIntPoint , TileCount_Primary )
SHADER_PARAMETER_RDG_BUFFER_SRV ( Buffer , TileDrawIndirectDataBuffer )
SHADER_PARAMETER_RDG_BUFFER_UAV ( RWBuffer , TileDispatchIndirectDataBuffer )
END_SHADER_PARAMETER_STRUCT ( )
static bool ShouldCompilePermutation ( const FGlobalShaderPermutationParameters & Parameters )
{
return GetMaxSupportedFeatureLevel ( Parameters . Platform ) > = ERHIFeatureLevel : : SM5 & & Strata : : IsStrataEnabled ( ) ;
}
static void ModifyCompilationEnvironment ( const FGlobalShaderPermutationParameters & Parameters , FShaderCompilerEnvironment & OutEnvironment )
{
FGlobalShader : : ModifyCompilationEnvironment ( Parameters , OutEnvironment ) ;
OutEnvironment . SetDefine ( TEXT ( " SHADER_BSDF_TILE_PREPARE_ARGS " ) , 1 ) ;
}
} ;
IMPLEMENT_GLOBAL_SHADER ( FStrataBSDFTilePrepareArgsPassCS , " /Engine/Private/Strata/StrataMaterialClassification.usf " , " ArgsMainCS " , SF_Compute ) ;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2021-04-06 02:12:57 -04:00
class FStrataMaterialStencilTaggingPassPS : public FGlobalShader
2021-01-27 08:51:50 -04:00
{
2021-04-06 02:12:57 -04:00
DECLARE_GLOBAL_SHADER ( FStrataMaterialStencilTaggingPassPS ) ;
SHADER_USE_PARAMETER_STRUCT ( FStrataMaterialStencilTaggingPassPS , FGlobalShader ) ;
2021-01-27 08:51:50 -04:00
using FPermutationDomain = TShaderPermutationDomain < > ;
BEGIN_SHADER_PARAMETER_STRUCT ( FParameters , )
2021-04-06 02:12:57 -04:00
SHADER_PARAMETER_STRUCT_INCLUDE ( Strata : : FStrataTilePassVS : : FParameters , VS )
2021-09-22 10:01:48 -04:00
SHADER_PARAMETER ( FVector4f , DebugTileColor )
2021-01-27 08:51:50 -04:00
RENDER_TARGET_BINDING_SLOTS ( )
END_SHADER_PARAMETER_STRUCT ( )
2021-01-28 07:26:46 -04:00
static FPermutationDomain RemapPermutation ( FPermutationDomain PermutationVector )
2021-01-27 08:51:50 -04:00
{
return PermutationVector ;
}
static bool ShouldCompilePermutation ( const FGlobalShaderPermutationParameters & Parameters )
{
return GetMaxSupportedFeatureLevel ( Parameters . Platform ) > = ERHIFeatureLevel : : SM5 & & Strata : : IsStrataEnabled ( ) ;
}
static void ModifyCompilationEnvironment ( const FGlobalShaderPermutationParameters & Parameters , FShaderCompilerEnvironment & OutEnvironment )
{
FGlobalShader : : ModifyCompilationEnvironment ( Parameters , OutEnvironment ) ;
2022-01-04 06:43:29 -05:00
OutEnvironment . SetDefine ( TEXT ( " SHADER_STENCIL_TAGGING_PS " ) , 1 ) ;
2021-01-27 08:51:50 -04:00
}
} ;
2022-03-18 08:20:50 -04:00
IMPLEMENT_GLOBAL_SHADER ( FStrataTilePassVS , " /Engine/Private/Strata/StrataTile.usf " , " StrataTilePassVS " , SF_Vertex ) ;
IMPLEMENT_GLOBAL_SHADER ( FStrataMaterialStencilTaggingPassPS , " /Engine/Private/Strata/StrataTile.usf " , " StencilTaggingMainPS " , SF_Pixel ) ;
2021-01-27 08:51:50 -04:00
2022-03-15 09:55:16 -04:00
static FStrataTileParameter InternalSetTileParameters ( FRDGBuilder * GraphBuilder , const FViewInfo & View , const EStrataTileType TileType )
2022-02-10 04:16:37 -05:00
{
FStrataTileParameter Out ;
2022-04-02 14:31:01 -04:00
if ( TileType ! = EStrataTileType : : ECount )
2022-02-10 04:16:37 -05:00
{
2022-04-02 14:31:01 -04:00
Out . TileListBuffer = View . StrataViewData . ClassificationTileListBufferSRV [ TileType ] ;
Out . TileIndirectBuffer = View . StrataViewData . ClassificationTileDrawIndirectBuffer ;
2022-02-10 04:16:37 -05:00
}
else if ( GraphBuilder )
{
FRDGBufferRef BufferDummy = GSystemTextures . GetDefaultBuffer ( * GraphBuilder , 4 , 0u ) ;
FRDGBufferSRVRef BufferDummySRV = GraphBuilder - > CreateSRV ( BufferDummy , PF_R32_UINT ) ;
Out . TileListBuffer = BufferDummySRV ;
Out . TileIndirectBuffer = BufferDummy ;
}
return Out ;
}
FStrataTilePassVS : : FParameters SetTileParameters (
const FViewInfo & View ,
2022-03-15 09:55:16 -04:00
const EStrataTileType TileType ,
2021-04-06 02:12:57 -04:00
EPrimitiveType & PrimitiveType )
{
2022-02-10 04:16:37 -05:00
FStrataTileParameter Temp = InternalSetTileParameters ( nullptr , View , TileType ) ;
2021-04-06 02:12:57 -04:00
PrimitiveType = GRHISupportsRectTopology ? PT_RectList : PT_TriangleList ;
2022-02-10 04:16:37 -05:00
FStrataTilePassVS : : FParameters Out ;
2022-04-02 14:31:01 -04:00
Out . OutputViewMinRect = FVector2f ( View . CachedViewUniformShaderParameters - > ViewRectMin . X , View . CachedViewUniformShaderParameters - > ViewRectMin . Y ) ;
2022-02-10 04:16:37 -05:00
Out . OutputViewSizeAndInvSize = View . CachedViewUniformShaderParameters - > ViewSizeAndInvSize ;
Out . OutputBufferSizeAndInvSize = View . CachedViewUniformShaderParameters - > BufferSizeAndInvSize ;
Out . ViewScreenToTranslatedWorld = View . CachedViewUniformShaderParameters - > ScreenToTranslatedWorld ;
Out . TileListBuffer = Temp . TileListBuffer ;
Out . TileIndirectBuffer = Temp . TileIndirectBuffer ;
return Out ;
}
FStrataTilePassVS : : FParameters SetTileParameters (
FRDGBuilder & GraphBuilder ,
const FViewInfo & View ,
2022-03-15 09:55:16 -04:00
const EStrataTileType TileType ,
2022-02-10 04:16:37 -05:00
EPrimitiveType & PrimitiveType )
{
FStrataTileParameter Temp = InternalSetTileParameters ( & GraphBuilder , View , TileType ) ;
PrimitiveType = GRHISupportsRectTopology ? PT_RectList : PT_TriangleList ;
FStrataTilePassVS : : FParameters Out ;
2022-04-02 14:31:01 -04:00
Out . OutputViewMinRect = FVector2f ( View . CachedViewUniformShaderParameters - > ViewRectMin . X , View . CachedViewUniformShaderParameters - > ViewRectMin . Y ) ;
2022-02-10 04:16:37 -05:00
Out . OutputViewSizeAndInvSize = View . CachedViewUniformShaderParameters - > ViewSizeAndInvSize ;
Out . OutputBufferSizeAndInvSize = View . CachedViewUniformShaderParameters - > BufferSizeAndInvSize ;
Out . ViewScreenToTranslatedWorld = View . CachedViewUniformShaderParameters - > ScreenToTranslatedWorld ;
Out . TileListBuffer = Temp . TileListBuffer ;
Out . TileIndirectBuffer = Temp . TileIndirectBuffer ;
return Out ;
}
2022-03-15 09:55:16 -04:00
FStrataTileParameter SetTileParameters ( FRDGBuilder & GraphBuilder , const FViewInfo & View , const EStrataTileType TileType )
2022-02-10 04:16:37 -05:00
{
return InternalSetTileParameters ( & GraphBuilder , View , TileType ) ;
2021-04-06 02:12:57 -04:00
}
2022-03-15 09:55:16 -04:00
uint32 TileTypeDrawIndirectArgOffset ( const EStrataTileType Type )
{
check ( Type > = 0 & & Type < EStrataTileType : : ECount ) ;
return GetStrataTileTypeDrawIndirectArgOffset_Byte ( Type ) ;
}
2022-03-18 13:43:33 -04:00
uint32 TileTypeDispatchIndirectArgOffset ( const EStrataTileType Type )
{
check ( Type > = 0 & & Type < EStrataTileType : : ECount ) ;
return GetStrataTileTypeDispatchIndirectArgOffset_Byte ( Type ) ;
}
2022-02-11 11:38:18 -05:00
// Add additionnaly bits for filling/clearing stencil to ensure that the 'Strata' bits are not corrupted by the stencil shadows
// when generating shadow mask. Withouth these 'trailing' bits, the incr./decr. operation would change/corrupt the 'Strata' bits
constexpr uint32 StencilBit_Fast_1 = 0x07u | StencilBit_Fast ;
constexpr uint32 StencilBit_Single_1 = 0x07u | StencilBit_Single ;
constexpr uint32 StencilBit_Complex_1 = 0x07u | StencilBit_Complex ;
2021-04-06 02:12:57 -04:00
static void AddStrataInternalClassificationTilePass (
2021-01-27 08:51:50 -04:00
FRDGBuilder & GraphBuilder ,
const FViewInfo & View ,
2021-02-17 11:12:16 -04:00
const FRDGTextureRef * DepthTexture ,
const FRDGTextureRef * ColorTexture ,
2022-03-15 09:55:16 -04:00
EStrataTileType TileMaterialType ,
2021-04-06 02:12:57 -04:00
const bool bDebug = false )
{
EPrimitiveType StrataTilePrimitiveType = PT_TriangleList ;
2021-01-27 08:51:50 -04:00
const FIntPoint OutputResolution = View . ViewRect . Size ( ) ;
2022-04-02 14:31:01 -04:00
const FIntRect ViewRect = View . ViewRect ;
2021-01-27 08:51:50 -04:00
2021-04-06 02:12:57 -04:00
FStrataMaterialStencilTaggingPassPS : : FParameters * ParametersPS = GraphBuilder . AllocParameters < FStrataMaterialStencilTaggingPassPS : : FParameters > ( ) ;
2022-02-10 04:16:37 -05:00
ParametersPS - > VS = Strata : : SetTileParameters ( GraphBuilder , View , TileMaterialType , StrataTilePrimitiveType ) ;
2021-01-27 08:51:50 -04:00
2021-04-06 05:39:35 -04:00
FStrataTilePassVS : : FPermutationDomain VSPermutationVector ;
2021-04-21 08:10:24 -04:00
VSPermutationVector . Set < FStrataTilePassVS : : FEnableDebug > ( bDebug ) ;
2021-04-06 05:39:35 -04:00
VSPermutationVector . Set < FStrataTilePassVS : : FEnableTexCoordScreenVector > ( false ) ;
TShaderMapRef < FStrataTilePassVS > VertexShader ( View . ShaderMap , VSPermutationVector ) ;
2021-04-06 02:12:57 -04:00
TShaderMapRef < FStrataMaterialStencilTaggingPassPS > PixelShader ( View . ShaderMap ) ;
2021-01-27 08:51:50 -04:00
// For debug purpose
2021-02-17 11:12:16 -04:00
if ( bDebug )
{
2021-04-06 02:12:57 -04:00
check ( ColorTexture ) ;
2021-02-17 11:12:16 -04:00
ParametersPS - > RenderTargets [ 0 ] = FRenderTargetBinding ( * ColorTexture , ERenderTargetLoadAction : : ELoad ) ;
2021-04-21 08:10:24 -04:00
switch ( TileMaterialType )
{
2022-03-16 05:45:43 -04:00
case EStrataTileType : : ESimple : ParametersPS - > DebugTileColor = FVector4f ( 0.0f , 1.0f , 0.0f , 1.0 ) ; break ;
case EStrataTileType : : ESingle : ParametersPS - > DebugTileColor = FVector4f ( 1.0f , 1.0f , 0.0f , 1.0 ) ; break ;
case EStrataTileType : : EComplex : ParametersPS - > DebugTileColor = FVector4f ( 1.0f , 0.0f , 0.0f , 1.0 ) ; break ;
case EStrataTileType : : EOpaqueRoughRefraction : ParametersPS - > DebugTileColor = FVector4f ( 0.0f , 1.0f , 1.0f , 1.0 ) ; break ;
case EStrataTileType : : ESSSWithoutOpaqueRoughRefraction : ParametersPS - > DebugTileColor = FVector4f ( 0.0f , 0.0f , 1.0f , 1.0 ) ; break ;
2021-12-14 10:24:57 -05:00
default : check ( false ) ;
2021-04-21 08:10:24 -04:00
}
2021-02-17 11:12:16 -04:00
}
else
{
check ( DepthTexture ) ;
ParametersPS - > RenderTargets . DepthStencil = FDepthStencilBinding (
* DepthTexture ,
ERenderTargetLoadAction : : ELoad ,
ERenderTargetLoadAction : : ELoad ,
FExclusiveDepthStencil : : DepthNop_StencilWrite ) ;
2021-09-22 10:01:48 -04:00
ParametersPS - > DebugTileColor = FVector4f ( ForceInitToZero ) ;
2021-02-17 11:12:16 -04:00
}
2021-01-27 08:51:50 -04:00
GraphBuilder . AddPass (
2021-12-14 10:24:57 -05:00
RDG_EVENT_NAME ( " Strata::%sClassificationPass(%s) " , bDebug ? TEXT ( " Debug " ) : TEXT ( " Stencil " ) , ToString ( TileMaterialType ) ) ,
2021-01-27 08:51:50 -04:00
ParametersPS ,
ERDGPassFlags : : Raster ,
2022-04-02 14:31:01 -04:00
[ ParametersPS , VertexShader , PixelShader , ViewRect , OutputResolution , StrataTilePrimitiveType , TileMaterialType , bDebug ] ( FRHICommandList & RHICmdList )
2021-01-27 08:51:50 -04:00
{
FGraphicsPipelineStateInitializer GraphicsPSOInit ;
RHICmdList . ApplyCachedRenderTargets ( GraphicsPSOInit ) ;
GraphicsPSOInit . RasterizerState = TStaticRasterizerState < > : : GetRHI ( ) ;
2022-01-06 16:44:09 +00:00
uint32 StencilRef = 0xFF ;
2021-02-17 11:12:16 -04:00
if ( bDebug )
{
2021-04-21 08:10:24 -04:00
// Use premultiplied alpha blending, pixel shader and depth/stencil is off
GraphicsPSOInit . BoundShaderState . PixelShaderRHI = PixelShader . GetPixelShader ( ) ;
GraphicsPSOInit . BlendState = TStaticBlendState < CW_RGBA , BO_Add , BF_One , BF_InverseSourceAlpha , BO_Add , BF_Zero , BF_One > : : GetRHI ( ) ;
2021-02-17 11:12:16 -04:00
GraphicsPSOInit . DepthStencilState = TStaticDepthStencilState < false , CF_Always > : : GetRHI ( ) ;
}
else
{
2022-03-16 05:45:43 -04:00
check ( TileMaterialType ! = EStrataTileType : : ECount & & TileMaterialType ! = EStrataTileType : : EOpaqueRoughRefraction & & TileMaterialType ! = EStrataTileType : : ESSSWithoutOpaqueRoughRefraction ) ;
2022-01-06 16:44:09 +00:00
2022-03-15 09:55:16 -04:00
// No blending and no pixel shader required. Stencil will be written to.
2021-04-21 08:10:24 -04:00
GraphicsPSOInit . BoundShaderState . PixelShaderRHI = nullptr ;
GraphicsPSOInit . BlendState = TStaticBlendState < > : : GetRHI ( ) ;
2022-02-11 05:05:02 -05:00
switch ( TileMaterialType )
{
2022-03-15 09:55:16 -04:00
case EStrataTileType : : ESimple :
2022-01-06 16:44:09 +00:00
{
GraphicsPSOInit . DepthStencilState = TStaticDepthStencilState <
false , CF_Always ,
true , CF_Always , SO_Keep , SO_Keep , SO_Replace ,
false , CF_Always , SO_Keep , SO_Keep , SO_Keep ,
2022-02-11 11:38:18 -05:00
0xFF , StencilBit_Fast_1 > : : GetRHI ( ) ;
StencilRef = StencilBit_Fast_1 ;
2022-01-06 16:44:09 +00:00
}
2022-02-11 05:05:02 -05:00
break ;
2022-03-15 09:55:16 -04:00
case EStrataTileType : : ESingle :
2022-01-06 16:44:09 +00:00
{
GraphicsPSOInit . DepthStencilState = TStaticDepthStencilState <
false , CF_Always ,
true , CF_Always , SO_Keep , SO_Keep , SO_Replace ,
false , CF_Always , SO_Keep , SO_Keep , SO_Keep ,
2022-02-11 11:38:18 -05:00
0xFF , StencilBit_Single_1 > : : GetRHI ( ) ;
StencilRef = StencilBit_Single_1 ;
2022-01-06 16:44:09 +00:00
}
2022-02-11 05:05:02 -05:00
break ;
2022-03-15 09:55:16 -04:00
case EStrataTileType : : EComplex :
2022-02-11 05:05:02 -05:00
{
GraphicsPSOInit . DepthStencilState = TStaticDepthStencilState <
false , CF_Always ,
true , CF_Always , SO_Keep , SO_Keep , SO_Replace ,
false , CF_Always , SO_Keep , SO_Keep , SO_Keep ,
2022-02-11 11:38:18 -05:00
0xFF , StencilBit_Complex_1 > : : GetRHI ( ) ;
StencilRef = StencilBit_Complex_1 ;
2022-02-11 05:05:02 -05:00
}
break ;
}
2021-02-17 11:12:16 -04:00
}
2021-01-27 08:51:50 -04:00
GraphicsPSOInit . BoundShaderState . VertexDeclarationRHI = GFilterVertexDeclaration . VertexDeclarationRHI ;
GraphicsPSOInit . BoundShaderState . VertexShaderRHI = VertexShader . GetVertexShader ( ) ;
2021-04-06 02:12:57 -04:00
GraphicsPSOInit . PrimitiveType = StrataTilePrimitiveType ;
2022-01-06 16:44:09 +00:00
SetGraphicsPipelineState ( RHICmdList , GraphicsPSOInit , StencilRef ) ;
2021-04-06 02:12:57 -04:00
SetShaderParameters ( RHICmdList , VertexShader , VertexShader . GetVertexShader ( ) , ParametersPS - > VS ) ;
2021-11-18 14:37:34 -05:00
if ( bDebug )
{
2022-04-02 14:31:01 -04:00
// Debug rendering is aways done during the post-processing stage, which has an ViewMinRect set to (0,0)
2021-11-18 14:37:34 -05:00
SetShaderParameters ( RHICmdList , PixelShader , PixelShader . GetPixelShader ( ) , * ParametersPS ) ;
2022-04-02 14:31:01 -04:00
RHICmdList . SetViewport ( 0 , 0 , 0.0f , OutputResolution . X , OutputResolution . Y , 1.0f ) ;
}
else
{
RHICmdList . SetViewport ( ViewRect . Min . X , ViewRect . Min . Y , 0.0f , ViewRect . Max . X , ViewRect . Max . Y , 1.0f ) ;
2021-11-18 14:37:34 -05:00
}
2021-01-27 08:51:50 -04:00
RHICmdList . SetStreamSource ( 0 , nullptr , 0 ) ;
2022-03-15 09:55:16 -04:00
RHICmdList . DrawPrimitiveIndirect ( ParametersPS - > VS . TileIndirectBuffer - > GetIndirectRHICallBuffer ( ) , TileTypeDrawIndirectArgOffset ( TileMaterialType ) ) ;
2021-01-27 08:51:50 -04:00
} ) ;
}
void AddStrataStencilPass (
FRDGBuilder & GraphBuilder ,
const TArray < FViewInfo > & Views ,
const FMinimalSceneTextures & SceneTextures )
{
for ( int32 i = 0 ; i < Views . Num ( ) ; + + i )
{
const FViewInfo & View = Views [ i ] ;
2022-03-15 09:55:16 -04:00
AddStrataInternalClassificationTilePass ( GraphBuilder , View , & SceneTextures . Depth . Target , nullptr , EStrataTileType : : ESimple ) ;
AddStrataInternalClassificationTilePass ( GraphBuilder , View , & SceneTextures . Depth . Target , nullptr , EStrataTileType : : ESingle ) ;
AddStrataInternalClassificationTilePass ( GraphBuilder , View , & SceneTextures . Depth . Target , nullptr , EStrataTileType : : EComplex ) ;
2021-02-17 11:12:16 -04:00
}
}
2021-01-27 08:51:50 -04:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2022-04-04 03:13:11 -04:00
void AppendStrataMRTs ( const FSceneRenderer & SceneRenderer , uint32 & RenderTargetCount , TStaticArray < FTextureRenderTargetBinding , MaxSimultaneousRenderTargets > & RenderTargets )
2021-11-29 09:31:58 -05:00
{
if ( Strata : : IsStrataEnabled ( ) & & SceneRenderer . Scene )
{
2021-11-29 18:03:54 -05:00
// If this function changes, update Strata::SetBasePassRenderTargetOutputFormat()
2021-12-06 08:54:37 -05:00
// Add 2 uint for Strata fast path.
// - We must clear the first uint to 0 to identify pixels that have not been written to.
// - We must never clear the second uint, it will only be written/read if needed.
auto AddStrataOutputTarget = [ & ] ( int16 StrataMaterialArraySlice , bool bNeverClear = false )
2021-11-29 09:31:58 -05:00
{
2022-01-04 12:18:49 -05:00
RenderTargets [ RenderTargetCount ] = FTextureRenderTargetBinding ( SceneRenderer . Scene - > StrataSceneData . MaterialTextureArray , StrataMaterialArraySlice , bNeverClear ) ;
2021-11-29 09:31:58 -05:00
RenderTargetCount + + ;
} ;
2022-01-04 12:18:49 -05:00
for ( int i = 0 ; i < STRATA_BASE_PASS_MRT_OUTPUT_COUNT ; + + i )
{
const bool bNeverClear = i ! = 0 ; // Only allow clearing the first slice containing the header
AddStrataOutputTarget ( i , bNeverClear ) ;
}
2021-11-29 09:31:58 -05:00
2021-12-06 08:54:37 -05:00
// Add another MRT for Strata top layer information. We want to follow the usual clear process which can leverage fast clear.
2021-11-29 09:31:58 -05:00
{
2021-12-06 08:54:37 -05:00
RenderTargets [ RenderTargetCount ] = FTextureRenderTargetBinding ( SceneRenderer . Scene - > StrataSceneData . TopLayerTexture ) ;
2021-11-29 09:31:58 -05:00
RenderTargetCount + + ;
} ;
}
}
2021-11-29 18:03:54 -05:00
void SetBasePassRenderTargetOutputFormat ( const EShaderPlatform Platform , FShaderCompilerEnvironment & OutEnvironment )
{
if ( Strata : : IsStrataEnabled ( ) )
{
const FGBufferParams GBufferParams = FShaderCompileUtilities : : FetchGBufferParamsRuntime ( Platform ) ;
const FGBufferInfo BufferInfo = FetchFullGBufferInfo ( GBufferParams ) ;
// Add 2 uint for Strata fast path
OutEnvironment . SetRenderTargetOutputFormat ( BufferInfo . NumTargets + 0 , PF_R32_UINT ) ;
OutEnvironment . SetRenderTargetOutputFormat ( BufferInfo . NumTargets + 1 , PF_R32_UINT ) ;
// Add another MRT for Strata top layer information
OutEnvironment . SetRenderTargetOutputFormat ( BufferInfo . NumTargets + 2 , PF_R32_UINT ) ;
}
}
2021-11-29 09:31:58 -05:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2021-01-27 08:51:50 -04:00
void AddStrataMaterialClassificationPass ( FRDGBuilder & GraphBuilder , const FMinimalSceneTextures & SceneTextures , const TArray < FViewInfo > & Views )
2020-12-08 09:06:58 -04:00
{
2022-03-16 05:59:35 -04:00
RDG_EVENT_SCOPE_CONDITIONAL ( GraphBuilder , IsStrataEnabled ( ) & & Views . Num ( ) > 0 , " Strata::MaterialClassification " ) ;
2020-12-08 09:06:58 -04:00
if ( ! IsStrataEnabled ( ) )
{
return ;
}
for ( int32 i = 0 ; i < Views . Num ( ) ; + + i )
{
const FViewInfo & View = Views [ i ] ;
2022-03-18 13:43:33 -04:00
bool bWaveOps = GRHISupportsWaveOperations & & FDataDrivenShaderPlatformInfo : : GetSupportsWaveOperations ( View . GetShaderPlatform ( ) ) ;
# if PLATFORM_WINDOWS
// Tile reduction requires 64-wide wave
bWaveOps = bWaveOps & & ! IsRHIDeviceNVIDIA ( ) ;
# endif
2020-12-08 09:06:58 -04:00
2022-04-02 14:31:01 -04:00
const FStrataViewData * StrataViewData = & View . StrataViewData ;
const FStrataSceneData * StrataSceneData = View . StrataViewData . SceneData ;
2021-11-24 10:34:04 -05:00
// Tile reduction
2021-01-27 08:51:50 -04:00
{
2021-12-07 13:19:49 -05:00
const bool bClear = ClearDuringCategorization ( ) ;
2021-11-24 13:13:31 -05:00
FStrataMaterialTileClassificationPassCS : : FPermutationDomain PermutationVector ;
2021-12-07 13:19:49 -05:00
PermutationVector . Set < FStrataMaterialTileClassificationPassCS : : FStrataClearDuringCategorization > ( bClear ) ;
2021-11-24 13:13:31 -05:00
PermutationVector . Set < FStrataMaterialTileClassificationPassCS : : FWaveOps > ( bWaveOps ) ;
TShaderMapRef < FStrataMaterialTileClassificationPassCS > ComputeShader ( View . ShaderMap , PermutationVector ) ;
2021-01-27 08:51:50 -04:00
FStrataMaterialTileClassificationPassCS : : FParameters * PassParameters = GraphBuilder . AllocParameters < FStrataMaterialTileClassificationPassCS : : FParameters > ( ) ;
2021-11-26 10:59:06 -05:00
PassParameters - > ViewUniformBuffer = View . ViewUniformBuffer ;
2021-01-28 07:26:46 -04:00
PassParameters - > bRectPrimitive = GRHISupportsRectTopology ? 1 : 0 ;
2021-01-29 18:01:50 -04:00
PassParameters - > ViewResolution = View . ViewRect . Size ( ) ;
2022-04-02 14:31:01 -04:00
PassParameters - > MaxBytesPerPixel = StrataSceneData - > MaxBytesPerPixel ;
PassParameters - > TopLayerTexture = StrataSceneData - > TopLayerTexture ;
PassParameters - > MaterialTextureArray = StrataSceneData - > MaterialTextureArraySRV ;
PassParameters - > SSSTextureUAV = StrataSceneData - > SSSTextureUAV ;
PassParameters - > OpaqueRoughRefractionTexture = StrataSceneData - > OpaqueRoughRefractionTexture ;
PassParameters - > TileDrawIndirectDataBuffer = StrataViewData - > ClassificationTileDrawIndirectBufferUAV ;
PassParameters - > SimpleTileListDataBuffer = StrataViewData - > ClassificationTileListBufferUAV [ EStrataTileType : : ESimple ] ;
PassParameters - > SingleTileListDataBuffer = StrataViewData - > ClassificationTileListBufferUAV [ EStrataTileType : : ESingle ] ;
PassParameters - > ComplexTileListDataBuffer = StrataViewData - > ClassificationTileListBufferUAV [ EStrataTileType : : EComplex ] ;
PassParameters - > OpaqueRoughRefractionTileListDataBuffer = StrataViewData - > ClassificationTileListBufferUAV [ EStrataTileType : : EOpaqueRoughRefraction ] ;
PassParameters - > SSSWithoutOpaqueRoughRefractionTileListDataBuffer = StrataViewData - > ClassificationTileListBufferUAV [ EStrataTileType : : ESSSWithoutOpaqueRoughRefraction ] ;
2021-01-27 08:51:50 -04:00
const uint32 GroupSize = 8 ;
FComputeShaderUtils : : AddPass (
GraphBuilder ,
2021-12-07 13:19:49 -05:00
RDG_EVENT_NAME ( " Strata::MaterialTileClassification(%s%s) " , bWaveOps ? TEXT ( " Wave " ) : TEXT ( " SharedMemory " ) , bClear ? TEXT ( " , Clear " ) : TEXT ( " " ) ) ,
2021-01-27 08:51:50 -04:00
ComputeShader ,
PassParameters ,
2021-11-26 10:59:06 -05:00
FComputeShaderUtils : : GetGroupCount ( PassParameters - > ViewResolution , GroupSize ) ) ;
2021-01-27 08:51:50 -04:00
}
2022-03-18 13:43:33 -04:00
// Tile indirect dispatch args conversion
{
TShaderMapRef < FStrataMaterialTilePrepareArgsPassCS > ComputeShader ( View . ShaderMap ) ;
FStrataMaterialTilePrepareArgsPassCS : : FParameters * PassParameters = GraphBuilder . AllocParameters < FStrataMaterialTilePrepareArgsPassCS : : FParameters > ( ) ;
2022-04-02 14:31:01 -04:00
PassParameters - > TileDrawIndirectDataBuffer = GraphBuilder . CreateSRV ( StrataViewData - > ClassificationTileDrawIndirectBuffer , PF_R32_UINT ) ;
PassParameters - > TileDispatchIndirectDataBuffer = StrataViewData - > ClassificationTileDispatchIndirectBufferUAV ;
2022-03-18 13:43:33 -04:00
FComputeShaderUtils : : AddPass (
GraphBuilder ,
RDG_EVENT_NAME ( " Strata::MaterialTilePrepareArgs " ) ,
ComputeShader ,
PassParameters ,
FIntVector ( 1 , 1 , 1 ) ) ;
}
// Compute BSDF tile index and material read offset
{
2022-04-02 14:31:01 -04:00
FRDGBufferUAVRef RWBSDFTileCountBuffer = GraphBuilder . CreateUAV ( StrataViewData - > BSDFTileCountBuffer , PF_R32_UINT ) ;
2022-03-18 13:43:33 -04:00
AddClearUAVPass ( GraphBuilder , RWBSDFTileCountBuffer , 0u ) ;
FStrataBSDFTilePassCS : : FPermutationDomain PermutationVector ;
PermutationVector . Set < FStrataBSDFTilePassCS : : FWaveOps > ( bWaveOps ) ;
TShaderMapRef < FStrataBSDFTilePassCS > ComputeShader ( View . ShaderMap , PermutationVector ) ;
FStrataBSDFTilePassCS : : FParameters * PassParameters = GraphBuilder . AllocParameters < FStrataBSDFTilePassCS : : FParameters > ( ) ;
PassParameters - > ViewUniformBuffer = View . ViewUniformBuffer ;
2022-03-31 13:05:44 -04:00
PassParameters - > TileSizeLog2 = STRATA_TILE_SIZE_DIV_AS_SHIFT ;
2022-04-02 14:31:01 -04:00
PassParameters - > TileCount_Primary = StrataViewData - > TileCount_Primary ;
2022-03-18 13:43:33 -04:00
PassParameters - > ViewResolution = View . ViewRect . Size ( ) ;
2022-04-02 14:31:01 -04:00
PassParameters - > MaxBytesPerPixel = StrataSceneData - > MaxBytesPerPixel ;
PassParameters - > TopLayerTexture = StrataSceneData - > TopLayerTexture ;
PassParameters - > MaterialTextureArray = StrataSceneData - > MaterialTextureArraySRV ;
PassParameters - > TileListBuffer = StrataViewData - > ClassificationTileListBufferSRV [ EStrataTileType : : EComplex ] ;
PassParameters - > TileIndirectBuffer = StrataViewData - > ClassificationTileDispatchIndirectBuffer ;
2022-03-18 13:43:33 -04:00
2022-04-02 14:31:01 -04:00
PassParameters - > RWBSDFOffsetTexture = GraphBuilder . CreateUAV ( StrataSceneData - > BSDFOffsetTexture ) ;
PassParameters - > RWBSDFTileTexture = GraphBuilder . CreateUAV ( StrataViewData - > BSDFTileTexture ) ;
2022-03-18 13:43:33 -04:00
PassParameters - > RWBSDFTileCountBuffer = RWBSDFTileCountBuffer ;
FComputeShaderUtils : : AddPass (
GraphBuilder ,
RDG_EVENT_NAME ( " Strata::BSDFTileAndOffsets(%s) " , bWaveOps ? TEXT ( " Wave " ) : TEXT ( " SharedMemory " ) ) ,
ComputeShader ,
PassParameters ,
PassParameters - > TileIndirectBuffer ,
TileTypeDispatchIndirectArgOffset ( EStrataTileType : : EComplex ) ) ;
}
2022-03-21 06:29:05 -04:00
// Tile indirect dispatch args conversion
{
TShaderMapRef < FStrataBSDFTilePrepareArgsPassCS > ComputeShader ( View . ShaderMap ) ;
FStrataBSDFTilePrepareArgsPassCS : : FParameters * PassParameters = GraphBuilder . AllocParameters < FStrataBSDFTilePrepareArgsPassCS : : FParameters > ( ) ;
2022-04-02 14:31:01 -04:00
PassParameters - > TileCount_Primary = StrataViewData - > TileCount_Primary ;
PassParameters - > TileDrawIndirectDataBuffer = GraphBuilder . CreateSRV ( StrataViewData - > BSDFTileCountBuffer , PF_R32_UINT ) ;
PassParameters - > TileDispatchIndirectDataBuffer = GraphBuilder . CreateUAV ( StrataViewData - > BSDFTileDispatchIndirectBuffer , PF_R32_UINT ) ;
2022-03-21 06:29:05 -04:00
FComputeShaderUtils : : AddPass (
GraphBuilder ,
RDG_EVENT_NAME ( " Strata::BSDFTilePrepareArgs " ) ,
ComputeShader ,
PassParameters ,
FIntVector ( 1 , 1 , 1 ) ) ;
}
2020-12-08 09:06:58 -04:00
}
}
2021-11-26 07:05:41 -05:00
static void AddStrataClearMaterialBufferPass (
FRDGBuilder & GraphBuilder ,
2021-11-29 09:31:58 -05:00
FRDGTextureUAVRef MaterialTextureArrayUAV ,
2021-11-26 07:05:41 -05:00
FRDGTextureUAVRef SSSTextureUAV ,
uint32 MaxBytesPerPixel ,
FIntPoint TiledViewBufferResolution )
2021-02-09 04:08:35 -04:00
{
2021-12-07 13:19:49 -05:00
if ( ClearDuringCategorization ( ) )
2021-12-06 08:54:37 -05:00
{
return ;
}
2021-02-09 04:08:35 -04:00
TShaderMapRef < FStrataClearMaterialBufferCS > ComputeShader ( GetGlobalShaderMap ( GMaxRHIFeatureLevel ) ) ;
FStrataClearMaterialBufferCS : : FParameters * PassParameters = GraphBuilder . AllocParameters < FStrataClearMaterialBufferCS : : FParameters > ( ) ;
2021-11-29 09:31:58 -05:00
PassParameters - > MaterialTextureArrayUAV = MaterialTextureArrayUAV ;
2021-11-26 07:05:41 -05:00
PassParameters - > SSSTextureUAV = SSSTextureUAV ;
2021-02-09 04:08:35 -04:00
PassParameters - > MaxBytesPerPixel = MaxBytesPerPixel ;
PassParameters - > TiledViewBufferResolution = TiledViewBufferResolution ;
const uint32 GroupSize = 8 ;
FComputeShaderUtils : : AddPass (
GraphBuilder ,
2021-11-07 23:43:01 -05:00
RDG_EVENT_NAME ( " Strata::ClearMaterialBuffer " ) ,
2021-02-09 04:08:35 -04:00
ComputeShader ,
PassParameters ,
FComputeShaderUtils : : GetGroupCount ( TiledViewBufferResolution , GroupSize ) ) ;
}
2021-10-25 20:05:28 -04:00
bool ShouldRenderStrataDebugPasses ( const FViewInfo & View )
2021-02-17 12:02:02 -04:00
{
2021-10-25 20:05:28 -04:00
return IsStrataEnabled ( ) & &
(
( FVisualizeMaterialPS : : CanRunStrataVizualizeMaterial ( View . GetShaderPlatform ( ) ) & & View . Family & & View . Family - > EngineShowFlags . VisualizeStrataMaterial )
2021-12-13 13:31:11 -05:00
| | ( CVarStrataClassificationDebug . GetValueOnAnyThread ( ) > 0 )
2022-03-08 06:34:45 -05:00
| | ShouldRenderStrataRoughRefractionRnD ( )
2021-10-25 20:05:28 -04:00
) ;
}
FScreenPassTexture AddStrataDebugPasses ( FRDGBuilder & GraphBuilder , const FViewInfo & View , FScreenPassTexture & ScreenPassSceneColor )
{
check ( IsStrataEnabled ( ) ) ;
EShaderPlatform Platform = View . GetShaderPlatform ( ) ;
2021-02-17 12:02:02 -04:00
if ( FVisualizeMaterialPS : : CanRunStrataVizualizeMaterial ( Platform ) )
{
2021-11-18 14:37:34 -05:00
RDG_EVENT_SCOPE ( GraphBuilder , " Strata::VisualizeMaterial " ) ;
2021-10-25 20:05:28 -04:00
AddVisualizeMaterialPasses ( GraphBuilder , View , ScreenPassSceneColor . Texture , Platform ) ;
2021-02-17 12:02:02 -04:00
}
2021-04-06 02:12:57 -04:00
const int32 StrataClassificationDebug = CVarStrataClassificationDebug . GetValueOnAnyThread ( ) ;
2021-12-13 13:31:11 -05:00
if ( StrataClassificationDebug > 0 )
2021-02-17 12:02:02 -04:00
{
2021-11-18 14:37:34 -05:00
RDG_EVENT_SCOPE ( GraphBuilder , " Strata::VisualizeClassification " ) ;
2021-10-25 20:05:28 -04:00
const bool bDebugPass = true ;
2022-03-15 09:55:16 -04:00
if ( StrataClassificationDebug > 1 )
{
AddStrataInternalClassificationTilePass ( GraphBuilder , View , nullptr , & ScreenPassSceneColor . Texture , EStrataTileType : : EOpaqueRoughRefraction , bDebugPass ) ;
2022-03-16 05:45:43 -04:00
AddStrataInternalClassificationTilePass ( GraphBuilder , View , nullptr , & ScreenPassSceneColor . Texture , EStrataTileType : : ESSSWithoutOpaqueRoughRefraction , bDebugPass ) ;
2022-03-15 09:55:16 -04:00
}
else
{
AddStrataInternalClassificationTilePass ( GraphBuilder , View , nullptr , & ScreenPassSceneColor . Texture , EStrataTileType : : ESimple , bDebugPass ) ;
AddStrataInternalClassificationTilePass ( GraphBuilder , View , nullptr , & ScreenPassSceneColor . Texture , EStrataTileType : : ESingle , bDebugPass ) ;
AddStrataInternalClassificationTilePass ( GraphBuilder , View , nullptr , & ScreenPassSceneColor . Texture , EStrataTileType : : EComplex , bDebugPass ) ;
}
2021-02-17 12:02:02 -04:00
}
2022-03-08 06:34:45 -05:00
StrataRoughRefractionRnD ( GraphBuilder , View , ScreenPassSceneColor ) ;
2021-10-25 20:05:28 -04:00
return MoveTemp ( ScreenPassSceneColor ) ;
2021-02-17 12:02:02 -04:00
}
2021-11-26 10:59:06 -05:00
} // namespace Strata