2019-12-26 14:45:42 -05:00
// Copyright Epic Games, Inc. All Rights Reserved.
2019-06-11 18:27:07 -04:00
# include "ScreenSpaceRayTracing.h"
# include "RenderGraph.h"
# include "PixelShaderUtils.h"
# include "ScreenPass.h"
# include "ScenePrivate.h"
# include "SceneTextureParameters.h"
2021-02-10 05:47:34 -04:00
# include "Strata/Strata.h"
2019-06-11 18:27:07 -04:00
static TAutoConsoleVariable < int32 > CVarSSRQuality (
TEXT ( " r.SSR.Quality " ) ,
3 ,
TEXT ( " Whether to use screen space reflections and at what quality setting. \n " )
TEXT ( " (limits the setting in the post process settings which has a different scale) \n " )
TEXT ( " (costs performance, adds more visual realism but the technique has limits) \n " )
TEXT ( " 0: off (default) \n " )
TEXT ( " 1: low (no glossy) \n " )
TEXT ( " 2: medium (no glossy) \n " )
TEXT ( " 3: high (glossy/using roughness, few samples) \n " )
TEXT ( " 4: very high (likely too slow for real-time) " ) ,
ECVF_Scalability | ECVF_RenderThreadSafe ) ;
2019-09-27 13:37:31 -04:00
int32 GSSRHalfResSceneColor = 0 ;
FAutoConsoleVariableRef CVarSSRHalfResSceneColor (
TEXT ( " r.SSR.HalfResSceneColor " ) ,
GSSRHalfResSceneColor ,
TEXT ( " Use half res scene color as input for SSR. Improves performance without much of a visual quality loss. " ) ,
ECVF_Scalability | ECVF_RenderThreadSafe
) ;
2019-06-11 18:27:07 -04:00
static TAutoConsoleVariable < int32 > CVarSSRTemporal (
TEXT ( " r.SSR.Temporal " ) ,
0 ,
TEXT ( " Defines if we use the temporal smoothing for the screen space reflection \n " )
TEXT ( " 0 is off (for debugging), 1 is on (default) " ) ,
ECVF_RenderThreadSafe ) ;
static TAutoConsoleVariable < int32 > CVarSSRStencil (
TEXT ( " r.SSR.Stencil " ) ,
0 ,
TEXT ( " Defines if we use the stencil prepass for the screen space reflection \n " )
TEXT ( " 0 is off (default), 1 is on " ) ,
ECVF_RenderThreadSafe ) ;
2019-11-13 18:37:16 -05:00
static TAutoConsoleVariable < int32 > CVarSSGILeakFreeReprojection (
TEXT ( " r.SSGI.LeakFreeReprojection " ) , 1 ,
TEXT ( " Whether use a more expensive but leak free reprojection of previous frame's scene color. \n " ) ,
ECVF_RenderThreadSafe ) ;
2019-06-11 18:27:07 -04:00
static TAutoConsoleVariable < int32 > CVarSSGIQuality (
2019-11-04 14:34:48 -05:00
TEXT ( " r.SSGI.Quality " ) , 4 ,
TEXT ( " Quality setting to control number of ray shot with SSGI, between 1 and 4 (defaults to 4). \n " ) ,
2019-06-11 18:27:07 -04:00
ECVF_Scalability | ECVF_RenderThreadSafe ) ;
2020-07-06 18:58:26 -04:00
static TAutoConsoleVariable < float > CVarSSGIMinimumLuminance (
TEXT ( " r.SSGI.MinimumLuminance " ) , 0.5f ,
TEXT ( " " ) ,
ECVF_Scalability | ECVF_RenderThreadSafe ) ;
static TAutoConsoleVariable < int32 > CVarSSGIRejectUncertainRays (
TEXT ( " r.SSGI.RejectUncertainRays " ) , 1 ,
TEXT ( " Rejects the screen space ray if it was uncertain due to going behind screen geometry. " ) ,
ECVF_Scalability | ECVF_RenderThreadSafe ) ;
static TAutoConsoleVariable < int32 > CVarSSGITerminateCertainRay (
TEXT ( " r.SSGI.TerminateCertainRay " ) , 1 ,
TEXT ( " Optimisations that if the screen space ray is certain and didn't find any geometry, don't fallback on otehr tracing technic. " ) ,
ECVF_Scalability | ECVF_RenderThreadSafe ) ;
static TAutoConsoleVariable < float > CVarSSGISkyDistance (
TEXT ( " r.SSGI.SkyDistance " ) , 10000000 ,
TEXT ( " Distance of the sky in KM. " ) ,
ECVF_Scalability | ECVF_RenderThreadSafe ) ;
2019-06-11 18:27:07 -04:00
DECLARE_GPU_STAT_NAMED ( ScreenSpaceReflections , TEXT ( " ScreenSpace Reflections " ) ) ;
DECLARE_GPU_STAT_NAMED ( ScreenSpaceDiffuseIndirect , TEXT ( " Screen Space Diffuse Indirect " ) ) ;
2020-07-06 18:58:26 -04:00
static bool IsScreenSpaceDiffuseIndirectSupported ( EShaderPlatform ShaderPlatform )
{
if ( IsAnyForwardShadingEnabled ( ShaderPlatform ) )
{
return false ;
}
return IsFeatureLevelSupported ( ShaderPlatform , ERHIFeatureLevel : : SM5 ) ;
}
2019-11-13 18:37:16 -05:00
static bool SupportScreenSpaceDiffuseIndirect ( const FViewInfo & View )
{
2021-02-04 15:30:42 -04:00
if ( View . FinalPostProcessSettings . DynamicGlobalIlluminationMethod ! = EDynamicGlobalIlluminationMethod : : ScreenSpace )
2019-11-13 18:37:16 -05:00
{
return false ;
}
int Quality = CVarSSGIQuality . GetValueOnRenderThread ( ) ;
if ( Quality < = 0 )
{
return false ;
}
2020-07-06 18:58:26 -04:00
if ( ! IsScreenSpaceDiffuseIndirectSupported ( View . GetShaderPlatform ( ) ) )
2019-11-13 18:37:16 -05:00
{
return false ;
}
2019-11-13 18:44:57 -05:00
return View . ViewState ! = nullptr ;
2019-11-13 18:37:16 -05:00
}
2020-07-06 18:58:26 -04:00
namespace ScreenSpaceRayTracing
{
2019-11-13 18:37:16 -05:00
bool ShouldKeepBleedFreeSceneColor ( const FViewInfo & View )
{
// TODO(Guillaume): SSR as well.
2021-02-04 15:30:42 -04:00
return CVarSSGILeakFreeReprojection . GetValueOnRenderThread ( ) ! = 0 ;
2019-11-13 18:37:16 -05:00
}
2019-06-11 18:27:07 -04:00
bool ShouldRenderScreenSpaceReflections ( const FViewInfo & View )
{
2022-01-27 21:25:37 -05:00
if ( ! View . Family - > EngineShowFlags . ScreenSpaceReflections
| | View . FinalPostProcessSettings . ReflectionMethod ! = EReflectionMethod : : ScreenSpace
| | HasRayTracedOverlay ( * View . Family )
| | View . bIsReflectionCapture )
2019-06-11 18:27:07 -04:00
{
return false ;
}
if ( ! View . State )
{
// not view state (e.g. thumbnail rendering?), no HZB (no screen space reflections or occlusion culling)
return false ;
}
int SSRQuality = CVarSSRQuality . GetValueOnRenderThread ( ) ;
if ( SSRQuality < = 0 )
{
return false ;
}
if ( View . FinalPostProcessSettings . ScreenSpaceReflectionIntensity < 1.0f )
{
return false ;
}
if ( IsAnyForwardShadingEnabled ( View . GetShaderPlatform ( ) ) )
{
return false ;
}
return true ;
}
2020-07-06 18:58:26 -04:00
bool IsScreenSpaceDiffuseIndirectSupported ( const FViewInfo & View )
2019-06-11 18:27:07 -04:00
{
2019-11-13 18:37:16 -05:00
if ( ! SupportScreenSpaceDiffuseIndirect ( View ) )
2019-11-04 14:34:48 -05:00
{
return false ;
}
2020-07-06 18:58:26 -04:00
return View . PrevViewInfo . ScreenSpaceRayTracingInput . IsValid ( ) ;
2019-06-11 18:27:07 -04:00
}
bool IsSSRTemporalPassRequired ( const FViewInfo & View )
{
check ( ShouldRenderScreenSpaceReflections ( View ) ) ;
if ( ! View . State )
{
return false ;
}
2021-06-23 11:54:40 -04:00
return ! IsTemporalAccumulationBasedMethod ( View . AntiAliasingMethod ) | | CVarSSRTemporal . GetValueOnRenderThread ( ) ! = 0 ;
2019-06-11 18:27:07 -04:00
}
2020-09-08 17:44:06 -04:00
FRDGTextureUAV * CreateScreenSpaceRayTracingDebugUAV ( FRDGBuilder & GraphBuilder , const FRDGTextureDesc & Desc , const TCHAR * Name , bool bClear = false )
2021-05-04 11:25:16 -04:00
# if (!UE_BUILD_SHIPPING && !UE_BUILD_TEST)
2020-09-08 17:44:06 -04:00
{
2020-09-24 00:43:27 -04:00
FRDGTextureDesc DebugDesc = FRDGTextureDesc : : Create2D (
2020-09-08 17:44:06 -04:00
Desc . Extent ,
PF_FloatRGBA ,
FClearValueBinding : : None ,
2020-09-24 00:43:27 -04:00
TexCreate_ShaderResource | TexCreate_UAV ) ;
2020-09-08 17:44:06 -04:00
FRDGTexture * DebugTexture = GraphBuilder . CreateTexture ( DebugDesc , Name ) ;
FRDGTextureUAVRef DebugOutput = GraphBuilder . CreateUAV ( DebugTexture ) ;
if ( bClear )
AddClearUAVPass ( GraphBuilder , DebugOutput , FLinearColor : : Transparent ) ;
return DebugOutput ;
}
# else
{
return nullptr ;
}
# endif
void SetupCommonScreenSpaceRayParameters (
FRDGBuilder & GraphBuilder ,
const FSceneTextureParameters & SceneTextures ,
const ScreenSpaceRayTracing : : FPrevSceneColorMip & PrevSceneColor ,
const FViewInfo & View ,
FCommonScreenSpaceRayParameters * OutParameters )
{
{
// float2 SceneBufferUV;
// float2 PixelPos = SceneBufferUV * View.BufferSizeAndInvSize.xy - View.ViewRect.Min;
// PixelPos *= 0.5 // ReducedSceneColor is half resolution.
// float2 ReducedSceneColorUV = PixelPos / ReducedSceneColor->Extent;
2021-09-22 10:01:48 -04:00
OutParameters - > ColorBufferScaleBias = FVector4f (
2020-09-24 00:43:27 -04:00
0.5f * SceneTextures . SceneDepthTexture - > Desc . Extent . X / float ( PrevSceneColor . SceneColor - > Desc . Extent . X ) ,
0.5f * SceneTextures . SceneDepthTexture - > Desc . Extent . Y / float ( PrevSceneColor . SceneColor - > Desc . Extent . Y ) ,
2020-09-08 17:44:06 -04:00
- 0.5f * View . ViewRect . Min . X / float ( PrevSceneColor . SceneColor - > Desc . Extent . X ) ,
- 0.5f * View . ViewRect . Min . Y / float ( PrevSceneColor . SceneColor - > Desc . Extent . Y ) ) ;
2022-02-02 01:43:41 -05:00
OutParameters - > ReducedColorUVMax = FVector2f (
2020-09-08 17:44:06 -04:00
( 0.5f * View . ViewRect . Width ( ) - 0.5f ) / float ( PrevSceneColor . SceneColor - > Desc . Extent . X ) ,
( 0.5f * View . ViewRect . Height ( ) - 0.5f ) / float ( PrevSceneColor . SceneColor - > Desc . Extent . Y ) ) ;
}
2020-11-04 16:06:33 -04:00
OutParameters - > FurthestHZBTexture = View . HZB ;
2020-09-08 17:44:06 -04:00
OutParameters - > FurthestHZBTextureSampler = TStaticSamplerState < SF_Point > : : GetRHI ( ) ;
OutParameters - > ColorTexture = PrevSceneColor . SceneColor ;
OutParameters - > ColorTextureSampler = TStaticSamplerState < SF_Point > : : GetRHI ( ) ;
OutParameters - > AlphaTexture = PrevSceneColor . SceneAlpha ;
OutParameters - > AlphaTextureSampler = TStaticSamplerState < SF_Point > : : GetRHI ( ) ;
const FVector2D ViewportUVToHZBBufferUV (
float ( View . ViewRect . Width ( ) ) / float ( 2 * View . HZBMipmap0Size . X ) ,
float ( View . ViewRect . Height ( ) ) / float ( 2 * View . HZBMipmap0Size . Y )
) ;
2021-09-22 10:01:48 -04:00
OutParameters - > HZBUvFactorAndInvFactor = FVector4f (
2020-09-08 17:44:06 -04:00
ViewportUVToHZBBufferUV . X ,
ViewportUVToHZBBufferUV . Y ,
1.0f / ViewportUVToHZBBufferUV . X ,
1.0f / ViewportUVToHZBBufferUV . Y ) ;
OutParameters - > ViewUniformBuffer = View . ViewUniformBuffer ;
2020-09-24 00:43:27 -04:00
OutParameters - > DebugOutput = CreateScreenSpaceRayTracingDebugUAV ( GraphBuilder , SceneTextures . SceneDepthTexture - > Desc , TEXT ( " DebugSSRT " ) ) ;
2020-09-08 17:44:06 -04:00
OutParameters - > bRejectUncertainRays = CVarSSGIRejectUncertainRays . GetValueOnRenderThread ( ) ? 1 : 0 ;
OutParameters - > bTerminateCertainRay = CVarSSGITerminateCertainRay . GetValueOnRenderThread ( ) ? 1 : 0 ;
} // SetupCommonScreenSpaceRayParameters()
void SetupCommonScreenSpaceRayParameters (
FRDGBuilder & GraphBuilder ,
const HybridIndirectLighting : : FCommonParameters & CommonDiffuseParameters ,
const ScreenSpaceRayTracing : : FPrevSceneColorMip & PrevSceneColor ,
const FViewInfo & View ,
FCommonScreenSpaceRayParameters * OutParameters )
{
OutParameters - > CommonDiffuseParameters = CommonDiffuseParameters ;
if ( CommonDiffuseParameters . DownscaleFactor = = 2.0f )
{
OutParameters - > PixelPositionToFullResPixel = 2.0f ;
2022-02-02 01:43:41 -05:00
OutParameters - > FullResPixelOffset = FVector2f ( 0.5f , 0.5f ) ; // TODO.
2020-09-08 17:44:06 -04:00
}
else if ( CommonDiffuseParameters . DownscaleFactor = = 1.0f )
{
OutParameters - > PixelPositionToFullResPixel = 1.0f ;
2022-02-02 01:43:41 -05:00
OutParameters - > FullResPixelOffset = FVector2f ( 0.5f , 0.5f ) ;
2020-09-08 17:44:06 -04:00
}
else
{
unimplemented ( ) ;
}
SetupCommonScreenSpaceRayParameters (
GraphBuilder , CommonDiffuseParameters . SceneTextures ,
PrevSceneColor , View ,
/* inout */ OutParameters ) ;
} // SetupCommonScreenSpaceRayParameters()
2020-07-06 18:58:26 -04:00
} // namespace ScreenSpaceRayTracing
2019-09-25 16:23:09 -04:00
bool UseSingleLayerWaterIndirectDraw ( EShaderPlatform ShaderPlatform ) ;
2019-09-25 10:07:18 -04:00
2019-06-11 18:27:07 -04:00
namespace
{
float ComputeRoughnessMaskScale ( const FViewInfo & View , ESSRQuality SSRQuality )
{
float MaxRoughness = FMath : : Clamp ( View . FinalPostProcessSettings . ScreenSpaceReflectionMaxRoughness , 0.01f , 1.0f ) ;
// f(x) = x * Scale + Bias
// f(MaxRoughness) = 0
// f(MaxRoughness/2) = 1
float RoughnessMaskScale = - 2.0f / MaxRoughness ;
return RoughnessMaskScale * ( int32 ( SSRQuality ) < 3 ? 2.0f : 1.0f ) ;
}
FLinearColor ComputeSSRParams ( const FViewInfo & View , ESSRQuality SSRQuality , bool bEnableDiscard )
{
float RoughnessMaskScale = ComputeRoughnessMaskScale ( View , SSRQuality ) ;
float FrameRandom = 0 ;
if ( View . ViewState )
{
2021-06-23 11:54:40 -04:00
bool bTemporalAAIsOn = IsTemporalAccumulationBasedMethod ( View . AntiAliasingMethod ) ;
2019-06-11 18:27:07 -04:00
if ( bTemporalAAIsOn )
{
// usually this number is in the 0..7 range but it depends on the TemporalAA quality
FrameRandom = View . ViewState - > GetCurrentTemporalAASampleIndex ( ) * 1551 ;
}
else
{
// 8 aligns with the temporal smoothing, larger number will do more flickering (power of two for best performance)
FrameRandom = View . ViewState - > GetFrameIndex ( 8 ) * 1551 ;
}
}
return FLinearColor (
FMath : : Clamp ( View . FinalPostProcessSettings . ScreenSpaceReflectionIntensity * 0.01f , 0.0f , 1.0f ) ,
RoughnessMaskScale ,
( float ) bEnableDiscard , // TODO
FrameRandom ) ;
}
2019-09-14 09:45:25 -04:00
BEGIN_SHADER_PARAMETER_STRUCT ( FSSRTTileClassificationParameters , )
SHADER_PARAMETER ( FIntPoint , TileBufferExtent )
SHADER_PARAMETER ( int32 , ViewTileCount )
SHADER_PARAMETER ( int32 , MaxTileCount )
SHADER_PARAMETER_RDG_BUFFER_SRV ( StructuredBuffer < float > , TileClassificationBuffer )
END_SHADER_PARAMETER_STRUCT ( )
2019-06-11 18:27:07 -04:00
BEGIN_SHADER_PARAMETER_STRUCT ( FSSRCommonParameters , )
SHADER_PARAMETER ( FLinearColor , SSRParams )
SHADER_PARAMETER_STRUCT_INCLUDE ( FSceneTextureParameters , SceneTextures )
SHADER_PARAMETER_STRUCT_REF ( FViewUniformShaderParameters , ViewUniformBuffer )
END_SHADER_PARAMETER_STRUCT ( )
2019-09-23 16:26:49 -04:00
BEGIN_SHADER_PARAMETER_STRUCT ( FSSRPassCommonParameters , )
2021-09-22 10:01:48 -04:00
SHADER_PARAMETER ( FVector4f , HZBUvFactorAndInvFactor )
SHADER_PARAMETER ( FVector4f , PrevScreenPositionScaleBias )
2019-09-23 16:26:49 -04:00
SHADER_PARAMETER ( float , PrevSceneColorPreExposureCorrection )
2021-02-11 10:11:04 -04:00
SHADER_PARAMETER ( uint32 , ShouldReflectOnlyWater )
2019-09-23 16:26:49 -04:00
SHADER_PARAMETER_RDG_TEXTURE ( Texture2D , SceneColor )
SHADER_PARAMETER_SAMPLER ( SamplerState , SceneColorSampler )
SHADER_PARAMETER_RDG_TEXTURE ( Texture2D , HZB )
SHADER_PARAMETER_SAMPLER ( SamplerState , HZBSampler )
2020-07-06 18:58:26 -04:00
SHADER_PARAMETER_RDG_TEXTURE_UAV ( RWTexture2D < float4 > , ScreenSpaceRayTracingDebugOutput )
2019-09-23 16:26:49 -04:00
END_SHADER_PARAMETER_STRUCT ( )
2019-06-11 18:27:07 -04:00
2020-07-06 18:58:26 -04:00
enum class ELightingTerm
{
Diffuse ,
Specular ,
MAX
} ;
2019-06-11 18:27:07 -04:00
class FSSRQualityDim : SHADER_PERMUTATION_ENUM_CLASS ( " SSR_QUALITY " , ESSRQuality ) ;
class FSSROutputForDenoiser : SHADER_PERMUTATION_BOOL ( " SSR_OUTPUT_FOR_DENOISER " ) ;
2020-07-06 18:58:26 -04:00
class FLightingTermDim : SHADER_PERMUTATION_ENUM_CLASS ( " DIM_LIGHTING_TERM " , ELightingTerm ) ;
2019-06-11 18:27:07 -04:00
2019-09-14 09:45:25 -04:00
class FSSRTPrevFrameReductionCS : public FGlobalShader
{
DECLARE_GLOBAL_SHADER ( FSSRTPrevFrameReductionCS ) ;
SHADER_USE_PARAMETER_STRUCT ( FSSRTPrevFrameReductionCS , FGlobalShader ) ;
class FLowerMips : SHADER_PERMUTATION_BOOL ( " DIM_LOWER_MIPS " ) ;
2019-11-13 18:37:16 -05:00
class FLeakFree : SHADER_PERMUTATION_BOOL ( " DIM_LEAK_FREE " ) ;
2019-09-14 09:45:25 -04:00
2019-11-13 18:37:16 -05:00
using FPermutationDomain = TShaderPermutationDomain < FLowerMips , FLeakFree > ;
2019-09-14 09:45:25 -04:00
static bool ShouldCompilePermutation ( const FGlobalShaderPermutationParameters & Parameters )
{
return IsFeatureLevelSupported ( Parameters . Platform , ERHIFeatureLevel : : SM5 ) ;
}
BEGIN_SHADER_PARAMETER_STRUCT ( FParameters , )
2021-09-22 10:01:48 -04:00
SHADER_PARAMETER ( FVector4f , PrevBufferBilinearUVMinMax )
SHADER_PARAMETER ( FVector4f , PrevScreenPositionScaleBias )
2021-11-18 14:37:34 -05:00
SHADER_PARAMETER ( FVector2f , ViewportUVToHZBBufferUV )
SHADER_PARAMETER ( FVector2f , ReducedSceneColorSize )
SHADER_PARAMETER ( FVector2f , ReducedSceneColorTexelSize )
SHADER_PARAMETER ( FVector2f , HigherMipBufferBilinearMax )
2019-09-14 09:45:25 -04:00
SHADER_PARAMETER ( float , PrevSceneColorPreExposureCorrection )
SHADER_PARAMETER ( float , MinimumLuminance )
2019-11-13 18:37:16 -05:00
SHADER_PARAMETER ( float , HigherMipDownScaleFactor )
2020-07-06 18:58:26 -04:00
SHADER_PARAMETER ( float , SkyDistance )
2019-09-14 09:45:25 -04:00
2019-11-13 18:37:16 -05:00
SHADER_PARAMETER_RDG_TEXTURE ( Texture2D , PrevSceneColor )
SHADER_PARAMETER_SAMPLER ( SamplerState , PrevSceneColorSampler )
SHADER_PARAMETER_RDG_TEXTURE ( Texture2D , PrevSceneDepth )
SHADER_PARAMETER_SAMPLER ( SamplerState , PrevSceneDepthSampler )
2019-09-14 09:45:25 -04:00
SHADER_PARAMETER_RDG_TEXTURE_SRV ( Texture2D , HigherMipTexture )
2019-11-13 18:37:16 -05:00
SHADER_PARAMETER_RDG_TEXTURE_SRV ( Texture2D , HigherAlphaMipTexture )
2019-09-14 09:45:25 -04:00
SHADER_PARAMETER_SAMPLER ( SamplerState , HigherMipTextureSampler )
2019-11-13 18:37:16 -05:00
SHADER_PARAMETER_SAMPLER ( SamplerState , HigherAlphaMipTextureSampler )
SHADER_PARAMETER_RDG_TEXTURE ( Texture2D , FurthestHZBTexture )
SHADER_PARAMETER_SAMPLER ( SamplerState , FurthestHZBTextureSampler )
2019-09-14 09:45:25 -04:00
SHADER_PARAMETER_STRUCT_INCLUDE ( FSceneTextureParameters , SceneTextures )
SHADER_PARAMETER_STRUCT_REF ( FViewUniformShaderParameters , View )
2019-11-13 18:37:16 -05:00
SHADER_PARAMETER_RDG_TEXTURE_UAV_ARRAY ( RWTexture2D < float4 > , ReducedSceneColorOutput , [ 3 ] )
SHADER_PARAMETER_RDG_TEXTURE_UAV_ARRAY ( RWTexture2D < float > , ReducedSceneAlphaOutput , [ 3 ] )
2019-09-14 09:45:25 -04:00
END_SHADER_PARAMETER_STRUCT ( )
} ;
class FSSRTDiffuseTileClassificationCS : public FGlobalShader
{
DECLARE_GLOBAL_SHADER ( FSSRTDiffuseTileClassificationCS ) ;
SHADER_USE_PARAMETER_STRUCT ( FSSRTDiffuseTileClassificationCS , FGlobalShader ) ;
static bool ShouldCompilePermutation ( const FGlobalShaderPermutationParameters & Parameters )
{
2020-07-06 18:58:26 -04:00
return IsFeatureLevelSupported ( Parameters . Platform , ERHIFeatureLevel : : SM5 ) ;
2019-09-14 09:45:25 -04:00
}
BEGIN_SHADER_PARAMETER_STRUCT ( FParameters , )
2021-11-18 14:37:34 -05:00
SHADER_PARAMETER ( FVector2f , SamplePixelToHZBUV )
2019-09-14 09:45:25 -04:00
SHADER_PARAMETER_RDG_TEXTURE ( Texture2D , ClosestHZBTexture )
SHADER_PARAMETER_SAMPLER ( SamplerState , ClosestHZBTextureSampler )
SHADER_PARAMETER_RDG_TEXTURE ( Texture2D , FurthestHZBTexture )
SHADER_PARAMETER_SAMPLER ( SamplerState , FurthestHZBTextureSampler )
SHADER_PARAMETER_STRUCT_REF ( FViewUniformShaderParameters , View )
SHADER_PARAMETER_STRUCT_INCLUDE ( FSSRTTileClassificationParameters , TileClassificationParameters )
2020-07-06 18:58:26 -04:00
SHADER_PARAMETER_RDG_BUFFER_UAV ( RWStructuredBuffer < float > , TileClassificationBufferOutput )
2019-09-14 09:45:25 -04:00
SHADER_PARAMETER_RDG_TEXTURE_UAV ( RWTexture2D < float4 > , DebugOutput )
END_SHADER_PARAMETER_STRUCT ( )
} ;
2019-06-11 18:27:07 -04:00
class FScreenSpaceReflectionsStencilPS : public FGlobalShader
{
DECLARE_GLOBAL_SHADER ( FScreenSpaceReflectionsStencilPS ) ;
SHADER_USE_PARAMETER_STRUCT ( FScreenSpaceReflectionsStencilPS , FGlobalShader ) ;
2021-02-10 08:49:59 -04:00
using FPermutationDomain = TShaderPermutationDomain < FSSROutputForDenoiser > ;
2019-06-11 18:27:07 -04:00
static bool ShouldCompilePermutation ( const FGlobalShaderPermutationParameters & Parameters )
{
2019-09-14 09:45:25 -04:00
return IsFeatureLevelSupported ( Parameters . Platform , ERHIFeatureLevel : : SM5 ) ;
2019-06-11 18:27:07 -04:00
}
static void ModifyCompilationEnvironment ( const FGlobalShaderPermutationParameters & Parameters , FShaderCompilerEnvironment & OutEnvironment )
{
FGlobalShader : : ModifyCompilationEnvironment ( Parameters , OutEnvironment ) ;
2021-02-10 08:49:59 -04:00
OutEnvironment . SetDefine ( TEXT ( " SSR_QUALITY " ) , uint32 ( 0 ) ) ;
2019-06-11 18:27:07 -04:00
}
BEGIN_SHADER_PARAMETER_STRUCT ( FParameters , )
SHADER_PARAMETER_STRUCT_INCLUDE ( FSSRCommonParameters , CommonParameters )
2021-03-30 02:33:35 -04:00
SHADER_PARAMETER_RDG_UNIFORM_BUFFER ( FStrataGlobalUniformParameters , Strata )
2019-06-11 18:27:07 -04:00
RENDER_TARGET_BINDING_SLOTS ( )
END_SHADER_PARAMETER_STRUCT ( )
} ;
class FScreenSpaceReflectionsPS : public FGlobalShader
{
DECLARE_GLOBAL_SHADER ( FScreenSpaceReflectionsPS ) ;
SHADER_USE_PARAMETER_STRUCT ( FScreenSpaceReflectionsPS , FGlobalShader ) ;
2021-02-10 08:49:59 -04:00
using FPermutationDomain = TShaderPermutationDomain < FSSRQualityDim , FSSROutputForDenoiser > ;
2019-06-11 18:27:07 -04:00
static bool ShouldCompilePermutation ( const FGlobalShaderPermutationParameters & Parameters )
{
FPermutationDomain PermutationVector ( Parameters . PermutationId ) ;
2019-09-14 09:45:25 -04:00
return IsFeatureLevelSupported ( Parameters . Platform , ERHIFeatureLevel : : SM5 ) ;
2019-06-11 18:27:07 -04:00
}
2021-02-10 08:49:59 -04:00
static void ModifyCompilationEnvironment ( const FGlobalShaderPermutationParameters & Parameters , FShaderCompilerEnvironment & OutEnvironment )
{
FGlobalShader : : ModifyCompilationEnvironment ( Parameters , OutEnvironment ) ;
2021-02-18 18:13:28 -04:00
OutEnvironment . SetDefine ( TEXT ( " SUPPORTS_ANISOTROPIC_MATERIALS " ) , FDataDrivenShaderPlatformInfo : : GetSupportsAnisotropicMaterials ( Parameters . Platform ) ) ;
2021-02-10 08:49:59 -04:00
}
2019-06-11 18:27:07 -04:00
BEGIN_SHADER_PARAMETER_STRUCT ( FParameters , )
SHADER_PARAMETER_STRUCT_INCLUDE ( FSSRCommonParameters , CommonParameters )
2019-09-23 16:26:49 -04:00
SHADER_PARAMETER_STRUCT_INCLUDE ( FSSRPassCommonParameters , SSRPassCommonParameter )
2021-03-17 06:03:08 -04:00
RDG_BUFFER_ACCESS ( IndirectDrawParameter , ERHIAccess : : IndirectArgs )
2019-09-25 05:35:49 -04:00
SHADER_PARAMETER_RDG_BUFFER_SRV ( StructuredBuffer < uint > , TileListData ) // FScreenSpaceReflectionsTileVS
2021-03-30 02:33:35 -04:00
SHADER_PARAMETER_RDG_UNIFORM_BUFFER ( FStrataGlobalUniformParameters , Strata )
2019-06-11 18:27:07 -04:00
RENDER_TARGET_BINDING_SLOTS ( )
END_SHADER_PARAMETER_STRUCT ( )
} ;
2019-09-25 05:35:49 -04:00
// This is duplicated from FWaterTileVS because vertex shader should share Parameters structure for everything to be registered correctly in a RDG pass.
class FScreenSpaceReflectionsTileVS : public FGlobalShader
2019-09-23 16:26:49 -04:00
{
2019-09-25 05:35:49 -04:00
DECLARE_GLOBAL_SHADER ( FScreenSpaceReflectionsTileVS ) ;
SHADER_USE_PARAMETER_STRUCT ( FScreenSpaceReflectionsTileVS , FGlobalShader ) ;
2019-09-23 16:26:49 -04:00
2019-09-25 05:35:49 -04:00
using FPermutationDomain = TShaderPermutationDomain < > ;
2020-02-06 13:13:41 -05:00
2019-09-25 05:35:49 -04:00
using FParameters = FScreenSpaceReflectionsPS : : FParameters ; // Sharing parameters for proper registration with RDG
2020-02-06 13:13:41 -05:00
2019-09-25 05:35:49 -04:00
static FPermutationDomain RemapPermutation ( FPermutationDomain PermutationVector )
{
return PermutationVector ;
}
2020-02-06 13:13:41 -05:00
2019-09-23 16:26:49 -04:00
static bool ShouldCompilePermutation ( const FGlobalShaderPermutationParameters & Parameters )
{
2019-09-25 16:23:09 -04:00
return : : UseSingleLayerWaterIndirectDraw ( Parameters . Platform ) ;
2019-09-23 16:26:49 -04:00
}
static void ModifyCompilationEnvironment ( const FGlobalShaderPermutationParameters & Parameters , FShaderCompilerEnvironment & OutEnvironment )
{
2019-09-25 05:35:49 -04:00
OutEnvironment . SetDefine ( TEXT ( " TILE_VERTEX_SHADER " ) , 1.0f ) ;
OutEnvironment . SetDefine ( TEXT ( " WORK_TILE_SIZE " ) , 8 ) ;
2019-09-23 16:26:49 -04:00
FGlobalShader : : ModifyCompilationEnvironment ( Parameters , OutEnvironment ) ;
}
} ;
2020-07-06 18:58:26 -04:00
class FScreenSpaceCastStandaloneRayCS : public FGlobalShader
2019-06-11 18:27:07 -04:00
{
2020-07-06 18:58:26 -04:00
DECLARE_GLOBAL_SHADER ( FScreenSpaceCastStandaloneRayCS ) ;
SHADER_USE_PARAMETER_STRUCT ( FScreenSpaceCastStandaloneRayCS , FGlobalShader )
2019-06-11 18:27:07 -04:00
2019-09-14 09:45:25 -04:00
class FQualityDim : SHADER_PERMUTATION_RANGE_INT ( " QUALITY " , 1 , 4 ) ;
2020-07-06 18:58:26 -04:00
using FPermutationDomain = TShaderPermutationDomain < FQualityDim > ;
2019-06-11 18:27:07 -04:00
2020-07-06 18:58:26 -04:00
BEGIN_SHADER_PARAMETER_STRUCT ( FParameters , )
SHADER_PARAMETER_STRUCT_INCLUDE ( FCommonScreenSpaceRayParameters , CommonParameters )
SHADER_PARAMETER_RDG_TEXTURE_UAV ( RWTexture2D < float4 > , IndirectDiffuseOutput )
SHADER_PARAMETER_RDG_TEXTURE_UAV ( RWTexture2D < float > , AmbientOcclusionOutput )
2019-06-11 18:27:07 -04:00
END_SHADER_PARAMETER_STRUCT ( )
static bool ShouldCompilePermutation ( const FGlobalShaderPermutationParameters & Parameters )
{
2020-07-06 18:58:26 -04:00
return IsScreenSpaceDiffuseIndirectSupported ( Parameters . Platform ) ;
2019-06-11 18:27:07 -04:00
}
} ;
2020-07-06 18:58:26 -04:00
class FSetupScreenSpaceTraceProbeCS : public FGlobalShader
{
DECLARE_GLOBAL_SHADER ( FSetupScreenSpaceTraceProbeCS )
SHADER_USE_PARAMETER_STRUCT ( FSetupScreenSpaceTraceProbeCS , FGlobalShader )
BEGIN_SHADER_PARAMETER_STRUCT ( FParameters , )
SHADER_PARAMETER_STRUCT_INCLUDE ( LumenProbeHierarchy : : FHierarchyParameters , HierarchyParameters )
SHADER_PARAMETER_RDG_BUFFER_UAV ( RWBuffer < uint > , DispatchParametersOutput )
END_SHADER_PARAMETER_STRUCT ( )
static bool ShouldCompilePermutation ( const FGlobalShaderPermutationParameters & Parameters )
{
return IsScreenSpaceDiffuseIndirectSupported ( Parameters . Platform ) ;
}
} ;
class FScreenSpaceTraceProbeCS : public FGlobalShader
{
DECLARE_GLOBAL_SHADER ( FScreenSpaceTraceProbeCS ) ;
SHADER_USE_PARAMETER_STRUCT ( FScreenSpaceTraceProbeCS , FGlobalShader )
BEGIN_SHADER_PARAMETER_STRUCT ( FParameters , )
SHADER_PARAMETER_STRUCT_INCLUDE ( FCommonScreenSpaceRayParameters , CommonParameters )
SHADER_PARAMETER_STRUCT_INCLUDE ( LumenProbeHierarchy : : FHierarchyParameters , HierarchyParameters )
SHADER_PARAMETER_STRUCT_INCLUDE ( LumenProbeHierarchy : : FHierarchyLevelParameters , LevelParameters )
SHADER_PARAMETER ( float , FurthestHZBStartMipLevel )
2021-03-17 06:03:08 -04:00
RDG_BUFFER_ACCESS ( DispatchParameters , ERHIAccess : : IndirectArgs )
2020-07-06 18:58:26 -04:00
SHADER_PARAMETER_RDG_TEXTURE_UAV ( RWTexture2D , ProbeAtlasColorOutput )
SHADER_PARAMETER_RDG_TEXTURE_UAV ( RWTexture2D < uint > , ProbeAtlasSampleMaskOutput )
END_SHADER_PARAMETER_STRUCT ( )
using FPermutationDomain = TShaderPermutationDomain < LumenProbeHierarchy : : FProbeTracingPermutationDim > ;
static bool ShouldCompilePermutation ( const FGlobalShaderPermutationParameters & Parameters )
{
return IsScreenSpaceDiffuseIndirectSupported ( Parameters . Platform ) ;
}
} ;
class FSetupScreenSpaceProbeOcclusionCS : public FGlobalShader
{
DECLARE_GLOBAL_SHADER ( FSetupScreenSpaceProbeOcclusionCS ) ;
SHADER_USE_PARAMETER_STRUCT ( FSetupScreenSpaceProbeOcclusionCS , FGlobalShader )
BEGIN_SHADER_PARAMETER_STRUCT ( FParameters , )
SHADER_PARAMETER ( int32 , MaxTilePerDispatch )
SHADER_PARAMETER_RDG_BUFFER_SRV ( Buffer < uint > , GlobalClassificationCountersBuffer )
SHADER_PARAMETER_RDG_BUFFER_UAV ( RWBuffer < uint > , DispatchParametersOutput )
END_SHADER_PARAMETER_STRUCT ( )
static bool ShouldCompilePermutation ( const FGlobalShaderPermutationParameters & Parameters )
{
return IsScreenSpaceDiffuseIndirectSupported ( Parameters . Platform ) ;
}
static void ModifyCompilationEnvironment ( const FGlobalShaderPermutationParameters & Parameters , FShaderCompilerEnvironment & OutEnvironment )
{
FGlobalShader : : ModifyCompilationEnvironment ( Parameters , OutEnvironment ) ;
OutEnvironment . CompilerFlags . Add ( CFLAG_Wave32 ) ;
}
} ;
class FScreenSpaceCastProbeOcclusionCS : public FGlobalShader
{
DECLARE_GLOBAL_SHADER ( FScreenSpaceCastProbeOcclusionCS ) ;
SHADER_USE_PARAMETER_STRUCT ( FScreenSpaceCastProbeOcclusionCS , FGlobalShader )
BEGIN_SHADER_PARAMETER_STRUCT ( FParameters , )
SHADER_PARAMETER_STRUCT_INCLUDE ( FCommonScreenSpaceRayParameters , CommonParameters )
SHADER_PARAMETER_STRUCT_INCLUDE ( FSSRTTileClassificationParameters , TileClassificationParameters )
SHADER_PARAMETER_STRUCT_INCLUDE ( LumenProbeHierarchy : : FIndirectLightingProbeOcclusionParameters , ProbeOcclusionParameters )
SHADER_PARAMETER_STRUCT_INCLUDE ( LumenProbeHierarchy : : FIndirectLightingProbeOcclusionOutputParameters , ProbeOcclusionOutputParameters )
SHADER_PARAMETER ( int32 , DispatchOffset )
2021-03-17 06:03:08 -04:00
RDG_BUFFER_ACCESS ( DispatchParameters , ERHIAccess : : IndirectArgs )
2020-07-06 18:58:26 -04:00
END_SHADER_PARAMETER_STRUCT ( )
class FTileClassificationDim : SHADER_PERMUTATION_ENUM_CLASS ( " DIM_PROBE_OCCLUSION_CLASSIFICATION " , LumenProbeHierarchy : : EProbeOcclusionClassification ) ;
using FPermutationDomain = TShaderPermutationDomain < FTileClassificationDim > ;
static bool ShouldCompilePermutation ( const FGlobalShaderPermutationParameters & Parameters )
{
return IsScreenSpaceDiffuseIndirectSupported ( Parameters . Platform ) ;
}
static void ModifyCompilationEnvironment ( const FGlobalShaderPermutationParameters & Parameters , FShaderCompilerEnvironment & OutEnvironment )
{
FGlobalShader : : ModifyCompilationEnvironment ( Parameters , OutEnvironment ) ;
OutEnvironment . CompilerFlags . Add ( CFLAG_Wave32 ) ;
}
} ;
2019-09-14 09:45:25 -04:00
IMPLEMENT_GLOBAL_SHADER ( FSSRTPrevFrameReductionCS , " /Engine/Private/SSRT/SSRTPrevFrameReduction.usf " , " MainCS " , SF_Compute ) ;
IMPLEMENT_GLOBAL_SHADER ( FSSRTDiffuseTileClassificationCS , " /Engine/Private/SSRT/SSRTTileClassification.usf " , " MainCS " , SF_Compute ) ;
2019-06-11 18:27:07 -04:00
IMPLEMENT_GLOBAL_SHADER ( FScreenSpaceReflectionsPS , " /Engine/Private/SSRT/SSRTReflections.usf " , " ScreenSpaceReflectionsPS " , SF_Pixel ) ;
2019-09-25 05:35:49 -04:00
IMPLEMENT_GLOBAL_SHADER ( FScreenSpaceReflectionsTileVS , " /Engine/Private/SingleLayerWaterComposite.usf " , " WaterTileVS " , SF_Vertex ) ;
2019-06-11 18:27:07 -04:00
IMPLEMENT_GLOBAL_SHADER ( FScreenSpaceReflectionsStencilPS , " /Engine/Private/SSRT/SSRTReflections.usf " , " ScreenSpaceReflectionsStencilPS " , SF_Pixel ) ;
2020-07-06 18:58:26 -04:00
IMPLEMENT_GLOBAL_SHADER ( FScreenSpaceCastStandaloneRayCS , " /Engine/Private/SSRT/SSRTDiffuseIndirect.usf " , " MainCS " , SF_Compute ) ;
IMPLEMENT_GLOBAL_SHADER ( FSetupScreenSpaceTraceProbeCS , " /Engine/Private/SSRT/SSRTTraceProbe.usf " , " SetupIndirectParametersCS " , SF_Compute ) ;
IMPLEMENT_GLOBAL_SHADER ( FScreenSpaceTraceProbeCS , " /Engine/Private/SSRT/SSRTTraceProbe.usf " , " MainCS " , SF_Compute ) ;
IMPLEMENT_GLOBAL_SHADER ( FSetupScreenSpaceProbeOcclusionCS , " /Engine/Private/SSRT/SSRTTraceProbeOcclusion.usf " , " MainCS " , SF_Compute ) ;
IMPLEMENT_GLOBAL_SHADER ( FScreenSpaceCastProbeOcclusionCS , " /Engine/Private/SSRT/SSRTTraceProbeOcclusion.usf " , " MainCS " , SF_Compute ) ;
2019-06-11 18:27:07 -04:00
void GetSSRShaderOptionsForQuality ( ESSRQuality Quality , IScreenSpaceDenoiser : : FReflectionsRayTracingConfig * OutRayTracingConfigs )
{
if ( Quality = = ESSRQuality : : VisualizeSSR )
{
OutRayTracingConfigs - > RayCountPerPixel = 12 ;
}
else if ( Quality = = ESSRQuality : : Epic )
{
OutRayTracingConfigs - > RayCountPerPixel = 12 ;
}
else if ( Quality = = ESSRQuality : : High )
{
OutRayTracingConfigs - > RayCountPerPixel = 4 ;
}
else if ( Quality = = ESSRQuality : : Medium )
{
OutRayTracingConfigs - > RayCountPerPixel = 1 ;
}
else if ( Quality = = ESSRQuality : : Low )
{
OutRayTracingConfigs - > RayCountPerPixel = 1 ;
}
else
{
check ( 0 ) ;
}
}
2020-07-06 18:58:26 -04:00
FIntPoint GetSSRTGroupSizeForSampleCount ( int32 RayCountPerPixel )
2019-09-14 09:45:25 -04:00
{
2020-07-06 18:58:26 -04:00
FIntPoint GroupCount ( 1 , 1 ) ;
if ( RayCountPerPixel = = 4 )
2019-09-14 09:45:25 -04:00
{
2020-07-06 18:58:26 -04:00
GroupCount = FIntPoint ( 8 , 8 ) ;
2019-09-14 09:45:25 -04:00
}
2020-07-06 18:58:26 -04:00
else if ( RayCountPerPixel = = 8 )
2019-09-14 09:45:25 -04:00
{
2020-07-06 18:58:26 -04:00
GroupCount = FIntPoint ( 8 , 4 ) ;
2019-09-14 09:45:25 -04:00
}
2020-07-06 18:58:26 -04:00
else if ( RayCountPerPixel = = 16 )
2019-09-14 09:45:25 -04:00
{
2020-07-06 18:58:26 -04:00
GroupCount = FIntPoint ( 4 , 4 ) ;
2019-09-14 09:45:25 -04:00
}
2020-07-06 18:58:26 -04:00
else if ( RayCountPerPixel = = 32 )
2019-09-14 09:45:25 -04:00
{
2020-07-06 18:58:26 -04:00
GroupCount = FIntPoint ( 4 , 2 ) ;
2019-09-14 09:45:25 -04:00
}
else
{
check ( 0 ) ;
}
2020-07-06 18:58:26 -04:00
check ( GroupCount . X * GroupCount . Y * RayCountPerPixel = = 256 ) ;
return GroupCount ;
}
void GetSSRTGIShaderOptionsForQuality ( int32 Quality , int32 * OutRayCountPerPixel )
{
if ( Quality = = 1 )
{
* OutRayCountPerPixel = 4 ;
}
else if ( Quality = = 2 )
{
* OutRayCountPerPixel = 8 ;
}
else if ( Quality = = 3 )
{
* OutRayCountPerPixel = 16 ;
}
else if ( Quality = = 4 )
{
* OutRayCountPerPixel = 32 ;
}
else
{
check ( 0 ) ;
}
2019-09-14 09:45:25 -04:00
}
2019-06-11 18:27:07 -04:00
} // namespace
2020-07-06 18:58:26 -04:00
namespace ScreenSpaceRayTracing
{
2019-06-11 18:27:07 -04:00
void GetSSRQualityForView ( const FViewInfo & View , ESSRQuality * OutQuality , IScreenSpaceDenoiser : : FReflectionsRayTracingConfig * OutRayTracingConfigs )
{
check ( ShouldRenderScreenSpaceReflections ( View ) ) ;
int32 SSRQualityCVar = FMath : : Clamp ( CVarSSRQuality . GetValueOnRenderThread ( ) , 0 , int32 ( ESSRQuality : : MAX ) - 1 ) ;
if ( View . Family - > EngineShowFlags . VisualizeSSR )
{
* OutQuality = ESSRQuality : : VisualizeSSR ;
return ;
}
else if ( View . FinalPostProcessSettings . ScreenSpaceReflectionQuality > = 80.0f & & SSRQualityCVar > = 4 )
{
* OutQuality = ESSRQuality : : Epic ;
}
else if ( View . FinalPostProcessSettings . ScreenSpaceReflectionQuality > = 60.0f & & SSRQualityCVar > = 3 )
{
* OutQuality = ESSRQuality : : High ;
}
else if ( View . FinalPostProcessSettings . ScreenSpaceReflectionQuality > = 40.0f & & SSRQualityCVar > = 2 )
{
* OutQuality = ESSRQuality : : Medium ;
}
else
{
* OutQuality = ESSRQuality : : Low ;
}
GetSSRShaderOptionsForQuality ( * OutQuality , OutRayTracingConfigs ) ;
}
2020-07-06 18:58:26 -04:00
FPrevSceneColorMip ReducePrevSceneColorMip (
FRDGBuilder & GraphBuilder ,
const FSceneTextureParameters & SceneTextures ,
const FViewInfo & View )
{
RDG_EVENT_SCOPE ( GraphBuilder , " SSGI SceneColorReduction " ) ;
2020-11-04 16:06:33 -04:00
FRDGTexture * FurthestHZBTexture = View . HZB ;
FRDGTexture * ClosestHZBTexture = View . ClosestHZB ;
2020-07-06 18:58:26 -04:00
// Number of mip skipped at the begining of the mip chain.
const int32 DownSamplingMip = 1 ;
// Number of mip in the mip chain
const int32 kNumMips = 5 ;
2021-12-02 20:48:34 -05:00
bool bUseLeakFree = View . PrevViewInfo . ScreenSpaceRayTracingInput ! = nullptr & & View . PrevViewInfo . DepthBuffer ! = nullptr ;
2020-07-06 18:58:26 -04:00
check ( bUseLeakFree = = true ) ;
// Allocate FPrevSceneColorMip.
FPrevSceneColorMip PrevSceneColorMip ;
{
2020-09-24 00:43:27 -04:00
FIntPoint RequiredSize = SceneTextures . SceneDepthTexture - > Desc . Extent / ( 1 < < DownSamplingMip ) ;
2020-07-06 18:58:26 -04:00
int32 QuantizeMultiple = 1 < < ( kNumMips - 1 ) ;
FIntPoint QuantizedSize = FIntPoint : : DivideAndRoundUp ( RequiredSize , QuantizeMultiple ) ;
2020-09-24 00:43:27 -04:00
FRDGTextureDesc Desc = FRDGTextureDesc : : Create2D (
2020-07-06 18:58:26 -04:00
FIntPoint ( QuantizeMultiple * QuantizedSize . X , QuantizeMultiple * QuantizedSize . Y ) ,
PF_FloatR11G11B10 ,
FClearValueBinding : : None ,
2020-09-24 00:43:27 -04:00
TexCreate_ShaderResource | TexCreate_UAV ) ;
2020-07-06 18:58:26 -04:00
Desc . NumMips = kNumMips ;
PrevSceneColorMip . SceneColor = GraphBuilder . CreateTexture ( Desc , TEXT ( " SSRTReducedSceneColor " ) ) ;
if ( bUseLeakFree )
{
Desc . Format = PF_R8 ;
PrevSceneColorMip . SceneAlpha = GraphBuilder . CreateTexture ( Desc , TEXT ( " SSRTReducedSceneAlpha " ) ) ;
}
}
FSSRTPrevFrameReductionCS : : FParameters DefaultPassParameters ;
{
DefaultPassParameters . SceneTextures = SceneTextures ;
DefaultPassParameters . View = View . ViewUniformBuffer ;
2022-02-02 01:43:41 -05:00
DefaultPassParameters . ReducedSceneColorSize = FVector2f (
2020-07-06 18:58:26 -04:00
PrevSceneColorMip . SceneColor - > Desc . Extent . X , PrevSceneColorMip . SceneColor - > Desc . Extent . Y ) ;
2022-02-02 01:43:41 -05:00
DefaultPassParameters . ReducedSceneColorTexelSize = FVector2f (
2020-07-06 18:58:26 -04:00
1.0f / float ( PrevSceneColorMip . SceneColor - > Desc . Extent . X ) , 1.0f / float ( PrevSceneColorMip . SceneColor - > Desc . Extent . Y ) ) ;
}
{
FSSRTPrevFrameReductionCS : : FParameters * PassParameters = GraphBuilder . AllocParameters < FSSRTPrevFrameReductionCS : : FParameters > ( ) ;
* PassParameters = DefaultPassParameters ;
FIntPoint ViewportOffset ;
FIntPoint ViewportExtent ;
FIntPoint BufferSize ;
if ( bUseLeakFree )
{
BufferSize = View . PrevViewInfo . ScreenSpaceRayTracingInput - > GetDesc ( ) . Extent ;
ViewportOffset = View . PrevViewInfo . ViewRect . Min ;
ViewportExtent = View . PrevViewInfo . ViewRect . Size ( ) ;
PassParameters - > PrevSceneColor = GraphBuilder . RegisterExternalTexture ( View . PrevViewInfo . ScreenSpaceRayTracingInput ) ;
PassParameters - > PrevSceneColorSampler = TStaticSamplerState < SF_Point > : : GetRHI ( ) ;
PassParameters - > PrevSceneDepth = GraphBuilder . RegisterExternalTexture ( View . PrevViewInfo . DepthBuffer ) ;
PassParameters - > PrevSceneDepthSampler = TStaticSamplerState < SF_Bilinear > : : GetRHI ( ) ;
}
else
{
BufferSize = View . PrevViewInfo . TemporalAAHistory . ReferenceBufferSize ;
ViewportOffset = View . PrevViewInfo . TemporalAAHistory . ViewportRect . Min ;
ViewportExtent = View . PrevViewInfo . TemporalAAHistory . ViewportRect . Size ( ) ;
PassParameters - > PrevSceneColor = GraphBuilder . RegisterExternalTexture ( View . PrevViewInfo . TemporalAAHistory . RT [ 0 ] ) ;
PassParameters - > PrevSceneColorSampler = TStaticSamplerState < SF_Bilinear > : : GetRHI ( ) ;
}
float InvBufferSizeX = 1.f / float ( BufferSize . X ) ;
float InvBufferSizeY = 1.f / float ( BufferSize . Y ) ;
2021-09-22 10:01:48 -04:00
PassParameters - > PrevBufferBilinearUVMinMax = FVector4f (
2020-07-06 18:58:26 -04:00
( ViewportOffset . X + 0.5f ) * InvBufferSizeX ,
( ViewportOffset . Y + 0.5f ) * InvBufferSizeY ,
( ViewportOffset . X + ViewportExtent . X - 0.5f ) * InvBufferSizeX ,
( ViewportOffset . Y + ViewportExtent . Y - 0.5f ) * InvBufferSizeY ) ;
PassParameters - > PrevSceneColorPreExposureCorrection = View . PreExposure / View . PrevViewInfo . SceneColorPreExposure ;
PassParameters - > MinimumLuminance = CVarSSGIMinimumLuminance . GetValueOnRenderThread ( ) ;
PassParameters - > SkyDistance = CVarSSGISkyDistance . GetValueOnRenderThread ( ) ;
2021-09-22 10:01:48 -04:00
PassParameters - > PrevScreenPositionScaleBias = FVector4f (
2020-07-06 18:58:26 -04:00
ViewportExtent . X * 0.5f / BufferSize . X ,
- ViewportExtent . Y * 0.5f / BufferSize . Y ,
( ViewportExtent . X * 0.5f + ViewportOffset . X ) / BufferSize . X ,
( ViewportExtent . Y * 0.5f + ViewportOffset . Y ) / BufferSize . Y ) ;
for ( int32 MipLevel = 0 ; MipLevel < ( PassParameters - > ReducedSceneColorOutput . Num ( ) - DownSamplingMip ) ; MipLevel + + )
{
PassParameters - > ReducedSceneColorOutput [ DownSamplingMip + MipLevel ] = GraphBuilder . CreateUAV ( FRDGTextureUAVDesc ( PrevSceneColorMip . SceneColor , MipLevel ) ) ;
if ( PrevSceneColorMip . SceneAlpha )
PassParameters - > ReducedSceneAlphaOutput [ DownSamplingMip + MipLevel ] = GraphBuilder . CreateUAV ( FRDGTextureUAVDesc ( PrevSceneColorMip . SceneAlpha , MipLevel ) ) ;
}
FSSRTPrevFrameReductionCS : : FPermutationDomain PermutationVector ;
PermutationVector . Set < FSSRTPrevFrameReductionCS : : FLowerMips > ( false ) ;
PermutationVector . Set < FSSRTPrevFrameReductionCS : : FLeakFree > ( bUseLeakFree ) ;
TShaderMapRef < FSSRTPrevFrameReductionCS > ComputeShader ( View . ShaderMap , PermutationVector ) ;
FComputeShaderUtils : : AddPass (
GraphBuilder ,
RDG_EVENT_NAME ( " PrevFrameReduction(LeakFree=%i) %dx%d " ,
bUseLeakFree ? 1 : 0 ,
View . ViewRect . Width ( ) , View . ViewRect . Height ( ) ) ,
ComputeShader ,
PassParameters ,
FComputeShaderUtils : : GetGroupCount ( View . ViewRect . Size ( ) , 8 ) ) ;
}
for ( int32 i = 0 ; i < 1 ; i + + )
{
int32 SrcMip = i * 3 + 2 - DownSamplingMip ;
int32 StartDestMip = SrcMip + 1 ;
int32 Divisor = 1 < < ( StartDestMip + DownSamplingMip ) ;
FSSRTPrevFrameReductionCS : : FParameters * PassParameters = GraphBuilder . AllocParameters < FSSRTPrevFrameReductionCS : : FParameters > ( ) ;
* PassParameters = DefaultPassParameters ;
PassParameters - > HigherMipTexture = GraphBuilder . CreateSRV ( FRDGTextureSRVDesc : : CreateForMipLevel ( PrevSceneColorMip . SceneColor , SrcMip ) ) ;
if ( bUseLeakFree )
{
PassParameters - > HigherMipTextureSampler = TStaticSamplerState < SF_Point > : : GetRHI ( ) ;
PassParameters - > HigherAlphaMipTexture = GraphBuilder . CreateSRV ( FRDGTextureSRVDesc : : CreateForMipLevel ( PrevSceneColorMip . SceneAlpha , SrcMip ) ) ;
PassParameters - > HigherAlphaMipTextureSampler = TStaticSamplerState < SF_Point > : : GetRHI ( ) ;
}
else
{
PassParameters - > HigherMipTextureSampler = TStaticSamplerState < SF_Bilinear > : : GetRHI ( ) ;
}
PassParameters - > HigherMipDownScaleFactor = 1 < < ( DownSamplingMip + SrcMip ) ;
2022-02-02 01:43:41 -05:00
PassParameters - > HigherMipBufferBilinearMax = FVector2f (
2020-07-06 18:58:26 -04:00
( 0.5f * View . ViewRect . Width ( ) - 0.5f ) / float ( PrevSceneColorMip . SceneColor - > Desc . Extent . X ) ,
( 0.5f * View . ViewRect . Height ( ) - 0.5f ) / float ( PrevSceneColorMip . SceneColor - > Desc . Extent . Y ) ) ;
2022-02-02 01:43:41 -05:00
PassParameters - > ViewportUVToHZBBufferUV = FVector2f (
2020-07-06 18:58:26 -04:00
float ( View . ViewRect . Width ( ) ) / float ( 2 * View . HZBMipmap0Size . X ) ,
float ( View . ViewRect . Height ( ) ) / float ( 2 * View . HZBMipmap0Size . Y ) ) ;
PassParameters - > FurthestHZBTexture = FurthestHZBTexture ;
PassParameters - > FurthestHZBTextureSampler = TStaticSamplerState < SF_Point > : : GetRHI ( ) ;
for ( int32 MipLevel = 0 ; MipLevel < PassParameters - > ReducedSceneColorOutput . Num ( ) ; MipLevel + + )
{
PassParameters - > ReducedSceneColorOutput [ MipLevel ] = GraphBuilder . CreateUAV ( FRDGTextureUAVDesc ( PrevSceneColorMip . SceneColor , StartDestMip + MipLevel ) ) ;
if ( PrevSceneColorMip . SceneAlpha )
PassParameters - > ReducedSceneAlphaOutput [ MipLevel ] = GraphBuilder . CreateUAV ( FRDGTextureUAVDesc ( PrevSceneColorMip . SceneAlpha , StartDestMip + MipLevel ) ) ;
}
FSSRTPrevFrameReductionCS : : FPermutationDomain PermutationVector ;
PermutationVector . Set < FSSRTPrevFrameReductionCS : : FLowerMips > ( true ) ;
PermutationVector . Set < FSSRTPrevFrameReductionCS : : FLeakFree > ( bUseLeakFree ) ;
TShaderMapRef < FSSRTPrevFrameReductionCS > ComputeShader ( View . ShaderMap , PermutationVector ) ;
ClearUnusedGraphResources ( ComputeShader , PassParameters ) ;
GraphBuilder . AddPass (
RDG_EVENT_NAME ( " PrevFrameReduction(LeakFree=%i) %dx%d " ,
bUseLeakFree ? 1 : 0 ,
View . ViewRect . Width ( ) / Divisor , View . ViewRect . Height ( ) / Divisor ) ,
PassParameters ,
ERDGPassFlags : : Compute ,
[ PassParameters , ComputeShader , & View , Divisor ] ( FRHICommandList & RHICmdList )
{
FComputeShaderUtils : : Dispatch ( RHICmdList , ComputeShader , * PassParameters , FComputeShaderUtils : : GetGroupCount ( View . ViewRect . Size ( ) , 8 * Divisor ) ) ;
} ) ;
}
return PrevSceneColorMip ;
}
FSSRTTileClassificationParameters RenderHorizonTileClassification (
FRDGBuilder & GraphBuilder ,
const FSceneTextureParameters & SceneTextures ,
const FViewInfo & View )
{
2020-09-24 00:43:27 -04:00
FIntPoint SceneTexturesExtent = SceneTextures . SceneDepthTexture - > Desc . Extent ;
2020-07-06 18:58:26 -04:00
2020-11-04 16:06:33 -04:00
FRDGTextureRef FurthestHZBTexture = View . HZB ;
FRDGTextureRef ClosestHZBTexture = View . ClosestHZB ;
2020-07-06 18:58:26 -04:00
FSSRTTileClassificationParameters ClassificationParameters ;
{
FRDGBufferRef TileClassificationBuffer ;
{
FIntPoint MaxTileBufferExtent = FIntPoint : : DivideAndRoundUp ( SceneTexturesExtent , 8 ) ;
int32 MaxTileCount = MaxTileBufferExtent . X * MaxTileBufferExtent . Y ;
ClassificationParameters . TileBufferExtent = FIntPoint : : DivideAndRoundUp ( View . ViewRect . Size ( ) , 8 ) ;
ClassificationParameters . ViewTileCount = ClassificationParameters . TileBufferExtent . X * ClassificationParameters . TileBufferExtent . Y ;
TileClassificationBuffer = GraphBuilder . CreateBuffer (
FRDGBufferDesc : : CreateStructuredDesc ( sizeof ( float ) * 16 , MaxTileCount ) , TEXT ( " SSRTTileClassification " ) ) ;
ClassificationParameters . TileClassificationBuffer = GraphBuilder . CreateSRV ( TileClassificationBuffer ) ;
}
FIntPoint ThreadCount = ClassificationParameters . TileBufferExtent ;
FSSRTDiffuseTileClassificationCS : : FParameters * PassParameters = GraphBuilder . AllocParameters < FSSRTDiffuseTileClassificationCS : : FParameters > ( ) ;
2022-02-02 01:43:41 -05:00
PassParameters - > SamplePixelToHZBUV = FVector2f (
2020-07-06 18:58:26 -04:00
0.5f / float ( FurthestHZBTexture - > Desc . Extent . X ) ,
0.5f / float ( FurthestHZBTexture - > Desc . Extent . Y ) ) ;
PassParameters - > FurthestHZBTexture = FurthestHZBTexture ;
PassParameters - > FurthestHZBTextureSampler = TStaticSamplerState < SF_Point > : : GetRHI ( ) ;
PassParameters - > ClosestHZBTexture = ClosestHZBTexture ;
PassParameters - > ClosestHZBTextureSampler = TStaticSamplerState < SF_Point > : : GetRHI ( ) ;
PassParameters - > View = View . ViewUniformBuffer ;
PassParameters - > TileClassificationParameters = ClassificationParameters ;
PassParameters - > TileClassificationBufferOutput = GraphBuilder . CreateUAV ( TileClassificationBuffer ) ;
{
2020-09-24 00:43:27 -04:00
FRDGTextureDesc DebugDesc = FRDGTextureDesc : : Create2D (
2020-07-06 18:58:26 -04:00
FIntPoint : : DivideAndRoundUp ( SceneTexturesExtent , 8 ) ,
PF_FloatRGBA ,
FClearValueBinding : : Transparent ,
2020-09-24 00:43:27 -04:00
TexCreate_ShaderResource | TexCreate_UAV ) ;
2020-07-06 18:58:26 -04:00
PassParameters - > DebugOutput = GraphBuilder . CreateUAV ( GraphBuilder . CreateTexture ( DebugDesc , TEXT ( " DebugSSRTTiles " ) ) ) ;
}
TShaderMapRef < FSSRTDiffuseTileClassificationCS > ComputeShader ( View . ShaderMap ) ;
FComputeShaderUtils : : AddPass (
GraphBuilder ,
RDG_EVENT_NAME ( " ScreenSpaceDiffuseClassification %dx%d " , ClassificationParameters . TileBufferExtent . X , ClassificationParameters . TileBufferExtent . Y ) ,
ComputeShader ,
PassParameters ,
FComputeShaderUtils : : GetGroupCount ( ClassificationParameters . TileBufferExtent , 8 ) ) ;
}
return ClassificationParameters ;
}
2019-06-11 18:27:07 -04:00
void RenderScreenSpaceReflections (
FRDGBuilder & GraphBuilder ,
const FSceneTextureParameters & SceneTextures ,
const FRDGTextureRef CurrentSceneColor ,
const FViewInfo & View ,
ESSRQuality SSRQuality ,
bool bDenoiser ,
2019-09-23 16:26:49 -04:00
IScreenSpaceDenoiser : : FReflectionsInputs * DenoiserInputs ,
2021-02-11 10:11:04 -04:00
bool bSingleLayerWater ,
2022-03-10 22:02:02 -05:00
FTiledReflection * TiledScreenSpaceReflection )
2019-06-11 18:27:07 -04:00
{
FRDGTextureRef InputColor = CurrentSceneColor ;
if ( SSRQuality ! = ESSRQuality : : VisualizeSSR )
{
if ( View . PrevViewInfo . CustomSSRInput . IsValid ( ) )
{
2021-07-29 13:49:02 -04:00
InputColor = GraphBuilder . RegisterExternalTexture ( View . PrevViewInfo . CustomSSRInput . RT [ 0 ] ) ;
2019-06-11 18:27:07 -04:00
}
2021-06-03 14:09:51 -04:00
else if ( GSSRHalfResSceneColor & & View . PrevViewInfo . HalfResTemporalAAHistory . IsValid ( ) )
{
InputColor = GraphBuilder . RegisterExternalTexture ( View . PrevViewInfo . HalfResTemporalAAHistory ) ;
}
2019-06-11 18:27:07 -04:00
else if ( View . PrevViewInfo . TemporalAAHistory . IsValid ( ) )
{
InputColor = GraphBuilder . RegisterExternalTexture ( View . PrevViewInfo . TemporalAAHistory . RT [ 0 ] ) ;
}
}
2019-09-23 16:26:49 -04:00
const bool SSRStencilPrePass = CVarSSRStencil . GetValueOnRenderThread ( ) ! = 0 & & SSRQuality ! = ESSRQuality : : VisualizeSSR & & TiledScreenSpaceReflection = = nullptr ;
2019-06-11 18:27:07 -04:00
// Alloc inputs for denoising.
{
2020-09-24 00:43:27 -04:00
FRDGTextureDesc Desc = FRDGTextureDesc : : Create2D (
UE5_MAIN: Multi-view-family scene renderer refactor, part 2. Move FSceneTextures singleton out of RDG blackboard and FSceneTexturesConfig global variable singleton, into FViewFamilyInfo. This is necessary to allow multiple view families to render in a single render graph and a single scene renderer call.
* Existing calls to CreateSceneTextureShaderParameters and similar functions use "GetSceneTexturesChecked", which allows for the possibility that they are reached in a code path where scene textures haven't been initialized, and nullptr is returned instead of asserting. The shader parameter setup functions then fill in dummy defaults for that case. The goal was to precisely match the original behavior, which queried the RDG blackboard, and gracefully handled null if scene textures weren't there. This definitely appears to occur in FNiagaraGpuComputeDispatch::ProcessPendingTicksFlush, which can be called with a dummy scene with no scene textures. In the future, I may change this so dummy defaults are filled in for FSceneTextures at construction time, so the structure is never in an uninitialized state, but I would like to set up a test case for the Niagara code path before doing that, and the checks aren't harmful in the meantime.
* I marked as deprecated global functions which query values from FSceneTexturesConfig, but they'll still work with the caveat that if you use multi-view-family rendering, the results will be indeterminate (whatever view family rendered last). There was only one case outside the scene renderer that accessed the globals (depth clear value), which I removed, noting that there is nowhere in the code where we modify the depth clear value from its global default. I would like to permanently deprecate or remove these at some point. Display Cluster is the only code that's currently using the multi-view-family code path, and as a new (still incomplete) feature, third party code can't be using it, and won't be affected.
#jira NONE
#rb chris.kulla zach.bethel mihnea.balta
#preflight 6261aca76119a1a496bd2644
[CL 19873983 by jason hoerner in ue5-main branch]
2022-04-22 17:33:02 -04:00
View . GetSceneTexturesConfig ( ) . Extent ,
2019-06-11 18:27:07 -04:00
PF_FloatRGBA , FClearValueBinding ( FLinearColor ( 0 , 0 , 0 , 0 ) ) ,
2020-09-24 00:43:27 -04:00
TexCreate_RenderTargetable | TexCreate_ShaderResource | TexCreate_UAV ) ;
2019-06-11 18:27:07 -04:00
Desc . Flags | = GFastVRamConfig . SSR ;
DenoiserInputs - > Color = GraphBuilder . CreateTexture ( Desc , TEXT ( " ScreenSpaceReflections " ) ) ;
if ( bDenoiser )
{
Desc . Format = PF_R16F ;
DenoiserInputs - > RayHitDistance = GraphBuilder . CreateTexture ( Desc , TEXT ( " ScreenSpaceReflectionsHitDistance " ) ) ;
}
}
IScreenSpaceDenoiser : : FReflectionsRayTracingConfig RayTracingConfigs ;
GetSSRShaderOptionsForQuality ( SSRQuality , & RayTracingConfigs ) ;
FSSRCommonParameters CommonParameters ;
CommonParameters . SSRParams = ComputeSSRParams ( View , SSRQuality , false ) ;
CommonParameters . ViewUniformBuffer = View . ViewUniformBuffer ;
CommonParameters . SceneTextures = SceneTextures ;
2019-09-23 16:26:49 -04:00
// Pipe down a mid grey texture when not using TAA's history to avoid wrongly reprojecting current scene color as if previous frame's TAA history.
2020-09-24 00:43:27 -04:00
if ( InputColor = = CurrentSceneColor | | ! CommonParameters . SceneTextures . GBufferVelocityTexture )
2019-09-23 16:26:49 -04:00
{
// Technically should be 32767.0f / 65535.0f to perfectly null out DecodeVelocityFromTexture(), but 0.5f is good enough.
2020-09-24 00:43:27 -04:00
CommonParameters . SceneTextures . GBufferVelocityTexture = GraphBuilder . RegisterExternalTexture ( GSystemTextures . MidGreyDummy ) ;
2019-09-23 16:26:49 -04:00
}
2019-06-11 18:27:07 -04:00
FRenderTargetBindingSlots RenderTargets ;
2019-09-14 09:45:25 -04:00
RenderTargets [ 0 ] = FRenderTargetBinding ( DenoiserInputs - > Color , ERenderTargetLoadAction : : ENoAction ) ;
2019-06-11 18:27:07 -04:00
if ( bDenoiser )
{
2019-09-14 09:45:25 -04:00
RenderTargets [ 1 ] = FRenderTargetBinding ( DenoiserInputs - > RayHitDistance , ERenderTargetLoadAction : : ENoAction ) ;
2019-06-11 18:27:07 -04:00
}
// Do a pre pass that output 0, or set a stencil mask to run the more expensive pixel shader.
if ( SSRStencilPrePass )
{
// Also bind the depth buffer
RenderTargets . DepthStencil = FDepthStencilBinding (
2020-09-24 00:43:27 -04:00
SceneTextures . SceneDepthTexture ,
2019-09-14 09:45:25 -04:00
ERenderTargetLoadAction : : ENoAction ,
ERenderTargetLoadAction : : ELoad ,
FExclusiveDepthStencil : : DepthNop_StencilWrite ) ;
2019-06-11 18:27:07 -04:00
FScreenSpaceReflectionsStencilPS : : FPermutationDomain PermutationVector ;
PermutationVector . Set < FSSROutputForDenoiser > ( bDenoiser ) ;
FScreenSpaceReflectionsStencilPS : : FParameters * PassParameters = GraphBuilder . AllocParameters < FScreenSpaceReflectionsStencilPS : : FParameters > ( ) ;
PassParameters - > CommonParameters = CommonParameters ;
2022-04-01 08:35:55 -04:00
PassParameters - > Strata = Strata : : BindStrataGlobalUniformParameters ( View ) ;
2019-06-11 18:27:07 -04:00
PassParameters - > RenderTargets = RenderTargets ;
TShaderMapRef < FScreenSpaceReflectionsStencilPS > PixelShader ( View . ShaderMap , PermutationVector ) ;
2020-02-06 13:13:41 -05:00
ClearUnusedGraphResources ( PixelShader , PassParameters ) ;
2021-07-13 12:38:37 -04:00
RDG_GPU_STAT_SCOPE ( GraphBuilder , ScreenSpaceReflections ) ;
2019-06-11 18:27:07 -04:00
GraphBuilder . AddPass (
RDG_EVENT_NAME ( " SSR StencilSetup %dx%d " , View . ViewRect . Width ( ) , View . ViewRect . Height ( ) ) ,
PassParameters ,
2019-07-19 14:19:12 -04:00
ERDGPassFlags : : Raster ,
2019-06-11 18:27:07 -04:00
[ PassParameters , & View , PixelShader ] ( FRHICommandList & RHICmdList )
{
RHICmdList . SetViewport ( View . ViewRect . Min . X , View . ViewRect . Min . Y , 0.0f , View . ViewRect . Max . X , View . ViewRect . Max . Y , 1.0f ) ;
FGraphicsPipelineStateInitializer GraphicsPSOInit ;
2020-02-06 13:13:41 -05:00
FPixelShaderUtils : : InitFullscreenPipelineState ( RHICmdList , View . ShaderMap , PixelShader , /* out */ GraphicsPSOInit ) ;
2019-06-11 18:27:07 -04:00
// Clobers the stencil to pixel that should not compute SSR
GraphicsPSOInit . DepthStencilState = TStaticDepthStencilState < false , CF_Always , true , CF_Always , SO_Replace , SO_Replace , SO_Replace > : : GetRHI ( ) ;
2021-09-03 12:04:52 -04:00
SetGraphicsPipelineState ( RHICmdList , GraphicsPSOInit , 0x80 ) ;
2020-02-06 13:13:41 -05:00
SetShaderParameters ( RHICmdList , PixelShader , PixelShader . GetPixelShader ( ) , * PassParameters ) ;
2019-06-11 18:27:07 -04:00
FPixelShaderUtils : : DrawFullscreenTriangle ( RHICmdList ) ;
} ) ;
}
// Adds SSR pass.
2019-09-23 16:26:49 -04:00
auto SetSSRParameters = [ & ] ( auto * PassParameters )
2019-06-11 18:27:07 -04:00
{
{
const FVector2D HZBUvFactor (
float ( View . ViewRect . Width ( ) ) / float ( 2 * View . HZBMipmap0Size . X ) ,
float ( View . ViewRect . Height ( ) ) / float ( 2 * View . HZBMipmap0Size . Y ) ) ;
2021-09-22 10:01:48 -04:00
PassParameters - > HZBUvFactorAndInvFactor = FVector4f (
2019-06-11 18:27:07 -04:00
HZBUvFactor . X ,
HZBUvFactor . Y ,
1.0f / HZBUvFactor . X ,
1.0f / HZBUvFactor . Y ) ;
}
{
FIntPoint ViewportOffset = View . ViewRect . Min ;
FIntPoint ViewportExtent = View . ViewRect . Size ( ) ;
2020-09-24 00:43:27 -04:00
FIntPoint BufferSize = SceneTextures . SceneDepthTexture - > Desc . Extent ;
2019-06-11 18:27:07 -04:00
2021-07-29 13:49:02 -04:00
if ( View . PrevViewInfo . CustomSSRInput . IsValid ( ) )
{
ViewportOffset = View . PrevViewInfo . CustomSSRInput . ViewportRect . Min ;
ViewportExtent = View . PrevViewInfo . CustomSSRInput . ViewportRect . Size ( ) ;
BufferSize = View . PrevViewInfo . CustomSSRInput . ReferenceBufferSize ;
ensure ( ViewportExtent . X > 0 & & ViewportExtent . Y > 0 ) ;
ensure ( BufferSize . X > 0 & & BufferSize . Y > 0 ) ;
}
2021-07-16 02:39:37 -04:00
else if ( View . PrevViewInfo . TemporalAAHistory . IsValid ( ) )
2019-06-11 18:27:07 -04:00
{
ViewportOffset = View . PrevViewInfo . TemporalAAHistory . ViewportRect . Min ;
ViewportExtent = View . PrevViewInfo . TemporalAAHistory . ViewportRect . Size ( ) ;
BufferSize = View . PrevViewInfo . TemporalAAHistory . ReferenceBufferSize ;
2020-06-23 18:40:00 -04:00
ensure ( ViewportExtent . X > 0 & & ViewportExtent . Y > 0 ) ;
ensure ( BufferSize . X > 0 & & BufferSize . Y > 0 ) ;
2019-06-11 18:27:07 -04:00
}
FVector2D InvBufferSize ( 1.0f / float ( BufferSize . X ) , 1.0f / float ( BufferSize . Y ) ) ;
2021-09-22 10:01:48 -04:00
PassParameters - > PrevScreenPositionScaleBias = FVector4f (
2019-06-11 18:27:07 -04:00
ViewportExtent . X * 0.5f * InvBufferSize . X ,
- ViewportExtent . Y * 0.5f * InvBufferSize . Y ,
( ViewportExtent . X * 0.5f + ViewportOffset . X ) * InvBufferSize . X ,
( ViewportExtent . Y * 0.5f + ViewportOffset . Y ) * InvBufferSize . Y ) ;
2019-09-23 16:26:49 -04:00
PassParameters - > ScreenSpaceRayTracingDebugOutput = CreateScreenSpaceRayTracingDebugUAV ( GraphBuilder , DenoiserInputs - > Color - > Desc , TEXT ( " DebugSSR " ) , true ) ;
2019-06-11 18:27:07 -04:00
}
PassParameters - > PrevSceneColorPreExposureCorrection = InputColor ! = CurrentSceneColor ? View . PreExposure / View . PrevViewInfo . SceneColorPreExposure : 1.0f ;
2021-02-11 10:11:04 -04:00
PassParameters - > ShouldReflectOnlyWater = bSingleLayerWater ? 1u : 0u ;
2020-02-06 13:13:41 -05:00
2019-06-11 18:27:07 -04:00
PassParameters - > SceneColor = InputColor ;
2019-09-27 13:37:31 -04:00
PassParameters - > SceneColorSampler = GSSRHalfResSceneColor ? TStaticSamplerState < SF_Bilinear > : : GetRHI ( ) : TStaticSamplerState < SF_Point > : : GetRHI ( ) ;
2020-02-06 13:13:41 -05:00
2020-11-04 16:06:33 -04:00
PassParameters - > HZB = View . HZB ;
2019-06-11 18:27:07 -04:00
PassParameters - > HZBSampler = TStaticSamplerState < SF_Point > : : GetRHI ( ) ;
2019-09-23 16:26:49 -04:00
} ;
2019-09-25 05:35:49 -04:00
FScreenSpaceReflectionsPS : : FPermutationDomain PermutationVector ;
PermutationVector . Set < FSSRQualityDim > ( SSRQuality ) ;
PermutationVector . Set < FSSROutputForDenoiser > ( bDenoiser ) ;
2020-02-06 13:13:41 -05:00
2019-09-25 05:35:49 -04:00
FScreenSpaceReflectionsPS : : FParameters * PassParameters = GraphBuilder . AllocParameters < FScreenSpaceReflectionsPS : : FParameters > ( ) ;
PassParameters - > CommonParameters = CommonParameters ;
SetSSRParameters ( & PassParameters - > SSRPassCommonParameter ) ;
2022-04-01 08:35:55 -04:00
PassParameters - > Strata = Strata : : BindStrataGlobalUniformParameters ( View ) ;
2019-09-25 05:35:49 -04:00
PassParameters - > RenderTargets = RenderTargets ;
TShaderMapRef < FScreenSpaceReflectionsPS > PixelShader ( View . ShaderMap , PermutationVector ) ;
2021-07-13 12:38:37 -04:00
RDG_GPU_STAT_SCOPE ( GraphBuilder , ScreenSpaceReflections ) ;
2019-09-23 16:26:49 -04:00
if ( TiledScreenSpaceReflection = = nullptr )
{
2020-02-06 13:13:41 -05:00
ClearUnusedGraphResources ( PixelShader , PassParameters ) ;
2021-07-13 12:38:37 -04:00
2019-06-11 18:27:07 -04:00
GraphBuilder . AddPass (
RDG_EVENT_NAME ( " SSR RayMarch(Quality=%d RayPerPixel=%d%s) %dx%d " ,
SSRQuality , RayTracingConfigs . RayCountPerPixel , bDenoiser ? TEXT ( " DenoiserOutput " ) : TEXT ( " " ) ,
View . ViewRect . Width ( ) , View . ViewRect . Height ( ) ) ,
PassParameters ,
2019-07-19 14:19:12 -04:00
ERDGPassFlags : : Raster ,
2019-06-11 18:27:07 -04:00
[ PassParameters , & View , PixelShader , SSRStencilPrePass ] ( FRHICommandList & RHICmdList )
{
RHICmdList . SetViewport ( View . ViewRect . Min . X , View . ViewRect . Min . Y , 0.0f , View . ViewRect . Max . X , View . ViewRect . Max . Y , 1.0f ) ;
2020-02-06 13:13:41 -05:00
2019-06-11 18:27:07 -04:00
FGraphicsPipelineStateInitializer GraphicsPSOInit ;
2020-02-06 13:13:41 -05:00
FPixelShaderUtils : : InitFullscreenPipelineState ( RHICmdList , View . ShaderMap , PixelShader , /* out */ GraphicsPSOInit ) ;
2019-06-11 18:27:07 -04:00
if ( SSRStencilPrePass )
{
// Clobers the stencil to pixel that should not compute SSR
GraphicsPSOInit . DepthStencilState = TStaticDepthStencilState < false , CF_Always , true , CF_Equal , SO_Keep , SO_Keep , SO_Keep > : : GetRHI ( ) ;
}
2021-09-03 12:04:52 -04:00
SetGraphicsPipelineState ( RHICmdList , GraphicsPSOInit , 0x80 ) ;
2020-02-06 13:13:41 -05:00
SetShaderParameters ( RHICmdList , PixelShader , PixelShader . GetPixelShader ( ) , * PassParameters ) ;
2019-06-11 18:27:07 -04:00
FPixelShaderUtils : : DrawFullscreenTriangle ( RHICmdList ) ;
} ) ;
}
2019-09-23 16:26:49 -04:00
else
{
2019-09-25 05:35:49 -04:00
check ( TiledScreenSpaceReflection - > TileSize = = 8 ) ; // WORK_TILE_SIZE
2019-09-23 16:26:49 -04:00
2019-09-25 05:35:49 -04:00
FScreenSpaceReflectionsTileVS : : FPermutationDomain VsPermutationVector ;
TShaderMapRef < FScreenSpaceReflectionsTileVS > VertexShader ( View . ShaderMap , VsPermutationVector ) ;
2019-09-23 16:26:49 -04:00
2022-04-06 09:58:52 -04:00
PassParameters - > TileListData = TiledScreenSpaceReflection - > TileListDataBufferSRV ;
2022-03-10 22:02:02 -05:00
PassParameters - > IndirectDrawParameter = TiledScreenSpaceReflection - > DrawIndirectParametersBuffer ;
2019-09-23 16:26:49 -04:00
2021-02-18 18:13:28 -04:00
ClearUnusedGraphResources ( VertexShader , PixelShader , PassParameters ) ;
2019-09-25 05:35:49 -04:00
GraphBuilder . AddPass (
2019-09-23 16:26:49 -04:00
RDG_EVENT_NAME ( " SSR RayMarch(Quality=%d RayPerPixel=%d%s) %dx%d " ,
SSRQuality , RayTracingConfigs . RayCountPerPixel , bDenoiser ? TEXT ( " DenoiserOutput " ) : TEXT ( " " ) ,
View . ViewRect . Width ( ) , View . ViewRect . Height ( ) ) ,
2019-09-25 05:35:49 -04:00
PassParameters ,
ERDGPassFlags : : Raster ,
[ PassParameters , & View , VertexShader , PixelShader , SSRStencilPrePass ] ( FRHICommandList & RHICmdList )
{
RHICmdList . SetViewport ( View . ViewRect . Min . X , View . ViewRect . Min . Y , 0.0f , View . ViewRect . Max . X , View . ViewRect . Max . Y , 1.0f ) ;
FGraphicsPipelineStateInitializer GraphicsPSOInit ;
2020-02-06 13:13:41 -05:00
FPixelShaderUtils : : InitFullscreenPipelineState ( RHICmdList , View . ShaderMap , PixelShader , /* out */ GraphicsPSOInit ) ;
2019-09-25 05:35:49 -04:00
if ( SSRStencilPrePass )
{
// Clobers the stencil to pixel that should not compute SSR
GraphicsPSOInit . DepthStencilState = TStaticDepthStencilState < false , CF_Always , true , CF_Equal , SO_Keep , SO_Keep , SO_Keep > : : GetRHI ( ) ;
}
GraphicsPSOInit . PrimitiveType = GRHISupportsRectTopology ? PT_RectList : PT_TriangleList ;
GraphicsPSOInit . BoundShaderState . VertexDeclarationRHI = GEmptyVertexDeclaration . VertexDeclarationRHI ;
2020-02-06 13:13:41 -05:00
GraphicsPSOInit . BoundShaderState . VertexShaderRHI = VertexShader . GetVertexShader ( ) ;
GraphicsPSOInit . BoundShaderState . PixelShaderRHI = PixelShader . GetPixelShader ( ) ;
2019-09-25 05:35:49 -04:00
2021-09-03 12:04:52 -04:00
SetGraphicsPipelineState ( RHICmdList , GraphicsPSOInit , 0x80 ) ;
2020-02-06 13:13:41 -05:00
SetShaderParameters ( RHICmdList , VertexShader , VertexShader . GetVertexShader ( ) , * PassParameters ) ;
SetShaderParameters ( RHICmdList , PixelShader , PixelShader . GetPixelShader ( ) , * PassParameters ) ;
2019-09-25 05:35:49 -04:00
PassParameters - > IndirectDrawParameter - > MarkResourceAsUsed ( ) ;
2020-06-23 18:40:00 -04:00
2019-09-25 05:35:49 -04:00
RHICmdList . DrawPrimitiveIndirect ( PassParameters - > IndirectDrawParameter - > GetIndirectRHICallBuffer ( ) , 0 ) ;
} ) ;
2019-09-23 16:26:49 -04:00
}
2019-06-11 18:27:07 -04:00
} // RenderScreenSpaceReflections()
2020-07-06 18:58:26 -04:00
int32 GetSSGIRayCountPerTracingPixel ( )
2019-06-11 18:27:07 -04:00
{
2020-07-06 18:58:26 -04:00
const int32 Quality = FMath : : Clamp ( CVarSSGIQuality . GetValueOnRenderThread ( ) , 1 , 4 ) ;
2019-06-11 18:27:07 -04:00
2019-09-14 09:45:25 -04:00
int32 RayCountPerPixel ;
2020-07-06 18:58:26 -04:00
GetSSRTGIShaderOptionsForQuality ( Quality , /* out */ & RayCountPerPixel ) ;
2019-06-11 18:27:07 -04:00
2020-07-06 18:58:26 -04:00
return RayCountPerPixel ;
}
IScreenSpaceDenoiser : : FDiffuseIndirectInputs CastStandaloneDiffuseIndirectRays (
FRDGBuilder & GraphBuilder ,
const HybridIndirectLighting : : FCommonParameters & CommonParameters ,
const FPrevSceneColorMip & PrevSceneColor ,
const FViewInfo & View )
{
const int32 Quality = FMath : : Clamp ( CVarSSGIQuality . GetValueOnRenderThread ( ) , 1 , 4 ) ;
int32 RayCountPerPixel ;
GetSSRTGIShaderOptionsForQuality ( Quality , & RayCountPerPixel ) ;
check ( RayCountPerPixel = = CommonParameters . RayCountPerPixel ) ;
FIntPoint GroupSize = GetSSRTGroupSizeForSampleCount ( CommonParameters . RayCountPerPixel ) ;
// Alloc output for the denoiser.
IScreenSpaceDenoiser : : FDiffuseIndirectInputs DenoiserInputs ;
2019-10-01 13:03:04 -04:00
{
2020-09-24 00:43:27 -04:00
FRDGTextureDesc Desc = FRDGTextureDesc : : Create2D (
CommonParameters . SceneTextures . SceneDepthTexture - > Desc . Extent / CommonParameters . DownscaleFactor ,
2020-07-06 18:58:26 -04:00
PF_FloatRGBA ,
FClearValueBinding : : Transparent ,
2020-09-24 00:43:27 -04:00
TexCreate_ShaderResource | TexCreate_UAV ) ;
2020-07-06 18:58:26 -04:00
DenoiserInputs . Color = GraphBuilder . CreateTexture ( Desc , TEXT ( " SSRTDiffuseIndirect " ) ) ;
Desc . Format = PF_R16F ;
2021-03-05 19:27:14 -04:00
Desc . Flags | = TexCreate_RenderTargetable ;
2020-07-06 18:58:26 -04:00
DenoiserInputs . AmbientOcclusionMask = GraphBuilder . CreateTexture ( Desc , TEXT ( " SSRTAmbientOcclusion " ) ) ;
2019-10-01 13:03:04 -04:00
}
2020-07-06 18:58:26 -04:00
FScreenSpaceCastStandaloneRayCS : : FParameters * PassParameters =
GraphBuilder . AllocParameters < FScreenSpaceCastStandaloneRayCS : : FParameters > ( ) ;
2020-09-08 17:44:06 -04:00
ScreenSpaceRayTracing : : SetupCommonScreenSpaceRayParameters ( GraphBuilder , CommonParameters , PrevSceneColor , View , /* out */ & PassParameters - > CommonParameters ) ;
2020-07-06 18:58:26 -04:00
PassParameters - > IndirectDiffuseOutput = GraphBuilder . CreateUAV ( DenoiserInputs . Color ) ;
PassParameters - > AmbientOcclusionOutput = GraphBuilder . CreateUAV ( DenoiserInputs . AmbientOcclusionMask ) ;
2019-10-01 13:03:04 -04:00
2020-07-06 18:58:26 -04:00
FScreenSpaceCastStandaloneRayCS : : FPermutationDomain PermutationVector ;
PermutationVector . Set < FScreenSpaceCastStandaloneRayCS : : FQualityDim > ( Quality ) ;
2019-11-13 18:37:16 -05:00
2020-07-06 18:58:26 -04:00
TShaderMapRef < FScreenSpaceCastStandaloneRayCS > ComputeShader ( View . ShaderMap , PermutationVector ) ;
FComputeShaderUtils : : AddPass (
GraphBuilder ,
RDG_EVENT_NAME ( " SSGI Standalone(Quality=%d RayPerPixel=%d) %dx%d " ,
Quality , CommonParameters . RayCountPerPixel , CommonParameters . TracingViewportSize . X , CommonParameters . TracingViewportSize . Y ) ,
ComputeShader ,
PassParameters ,
FComputeShaderUtils : : GetGroupCount ( CommonParameters . TracingViewportSize , GroupSize ) ) ;
return DenoiserInputs ;
}
void TraceProbe (
FRDGBuilder & GraphBuilder ,
const FViewInfo & View ,
const FSceneTextureParameters & SceneTextures ,
const FPrevSceneColorMip & PrevSceneColor ,
const LumenProbeHierarchy : : FHierarchyParameters & HierarchyParameters ,
const LumenProbeHierarchy : : FIndirectLightingAtlasParameters & IndirectLightingAtlasParameters )
{
RDG_EVENT_SCOPE ( GraphBuilder , " SSGI ProbeTracing " ) ;
FRDGBufferRef DispatchParameters = GraphBuilder . CreateBuffer (
FRDGBufferDesc : : CreateIndirectDesc < FRHIDispatchIndirectParameters > ( LumenProbeHierarchy : : kProbeMaxHierarchyDepth ) ,
TEXT ( " LumenVoxelTraceProbeDispatch " ) ) ;
2019-09-14 09:45:25 -04:00
2019-06-11 18:27:07 -04:00
{
2020-07-06 18:58:26 -04:00
FSetupScreenSpaceTraceProbeCS : : FParameters * PassParameters = GraphBuilder . AllocParameters < FSetupScreenSpaceTraceProbeCS : : FParameters > ( ) ;
PassParameters - > HierarchyParameters = HierarchyParameters ;
PassParameters - > DispatchParametersOutput = GraphBuilder . CreateUAV ( DispatchParameters ) ;
2019-10-01 13:03:04 -04:00
2020-07-06 18:58:26 -04:00
TShaderMapRef < FSetupScreenSpaceTraceProbeCS > ComputeShader ( View . ShaderMap ) ;
2019-09-14 09:45:25 -04:00
FComputeShaderUtils : : AddPass (
GraphBuilder ,
2020-07-06 18:58:26 -04:00
RDG_EVENT_NAME ( " SSGI SetupTraceProbe " ) ,
2020-02-06 13:13:41 -05:00
ComputeShader ,
2019-09-14 09:45:25 -04:00
PassParameters ,
2020-07-06 18:58:26 -04:00
FIntVector ( 1 , 1 , 1 ) ) ;
2019-09-14 09:45:25 -04:00
}
2020-09-24 00:43:27 -04:00
FRDGTextureUAVRef ProbeAtlasColorOutput = GraphBuilder . CreateUAV ( IndirectLightingAtlasParameters . ProbeAtlasColor , ERDGUnorderedAccessViewFlags : : SkipBarrier ) ;
FRDGTextureUAVRef ProbeAtlasSampleMaskOutput = GraphBuilder . CreateUAV ( IndirectLightingAtlasParameters . ProbeAtlasSampleMask , ERDGUnorderedAccessViewFlags : : SkipBarrier ) ;
2020-07-06 18:58:26 -04:00
for ( int32 HierarchyLevelId = 0 ; HierarchyLevelId < HierarchyParameters . HierarchyDepth ; HierarchyLevelId + + )
2019-09-14 09:45:25 -04:00
{
2020-07-06 18:58:26 -04:00
FScreenSpaceTraceProbeCS : : FParameters * PassParameters = GraphBuilder . AllocParameters < FScreenSpaceTraceProbeCS : : FParameters > ( ) ;
2020-09-08 17:44:06 -04:00
ScreenSpaceRayTracing : : SetupCommonScreenSpaceRayParameters ( GraphBuilder , SceneTextures , PrevSceneColor , View , /* out */ & PassParameters - > CommonParameters ) ;
2020-07-06 18:58:26 -04:00
PassParameters - > HierarchyParameters = HierarchyParameters ;
PassParameters - > LevelParameters = LumenProbeHierarchy : : GetLevelParameters ( HierarchyParameters , HierarchyLevelId ) ;
PassParameters - > DispatchParameters = DispatchParameters ;
2019-09-14 09:45:25 -04:00
2020-07-06 18:58:26 -04:00
// Compute the mip level at wich the trace should start from.
2019-10-01 13:03:04 -04:00
{
2020-07-06 18:58:26 -04:00
float ProbePixelRadius = LumenProbeHierarchy : : kProbeHierarchyMinPixelRadius * float ( 1 < < PassParameters - > LevelParameters . LevelId ) ;
float TexelCount = PassParameters - > LevelParameters . LevelResolution * 4 ;
// Amount of noise tolerated by sampling slightly more detailed mip level.
float kTolerableMipNoise = 1.0 ;
PassParameters - > FurthestHZBStartMipLevel = float ( FMath : : FloorToInt ( FMath : : Log2 ( ProbePixelRadius * ( 2.0f * PI / TexelCount ) ) ) ) - kTolerableMipNoise ;
2019-10-01 13:03:04 -04:00
}
2019-09-14 09:45:25 -04:00
2020-07-06 18:58:26 -04:00
PassParameters - > ProbeAtlasColorOutput = ProbeAtlasColorOutput ;
PassParameters - > ProbeAtlasSampleMaskOutput = ProbeAtlasSampleMaskOutput ;
2019-11-13 18:37:16 -05:00
2020-07-06 18:58:26 -04:00
FScreenSpaceTraceProbeCS : : FPermutationDomain PermutationVector ;
PermutationVector . Set < LumenProbeHierarchy : : FProbeTracingPermutationDim > (
LumenProbeHierarchy : : GetProbeTracingPermutation ( PassParameters - > LevelParameters ) ) ;
2019-11-13 18:37:16 -05:00
2020-07-06 18:58:26 -04:00
TShaderMapRef < FScreenSpaceTraceProbeCS > ComputeShader ( View . ShaderMap , PermutationVector ) ;
2019-09-14 09:45:25 -04:00
FComputeShaderUtils : : AddPass (
GraphBuilder ,
2020-07-06 18:58:26 -04:00
RDG_EVENT_NAME ( " SSGI TraceProbe(Level=%d Res=%d SuperSample=%d) " ,
PassParameters - > LevelParameters . LevelId ,
PassParameters - > LevelParameters . LevelResolution ,
PassParameters - > LevelParameters . LevelSuperSampling ) ,
2020-02-06 13:13:41 -05:00
ComputeShader ,
2019-09-14 09:45:25 -04:00
PassParameters ,
2020-07-06 18:58:26 -04:00
DispatchParameters ,
/* IndirectArgOffset = */ sizeof ( FRHIDispatchIndirectParameters ) * HierarchyLevelId ) ;
}
}
void TraceIndirectProbeOcclusion (
FRDGBuilder & GraphBuilder ,
const HybridIndirectLighting : : FCommonParameters & CommonParameters ,
const FPrevSceneColorMip & PrevSceneColor ,
const FViewInfo & View ,
const LumenProbeHierarchy : : FIndirectLightingProbeOcclusionParameters & ProbeOcclusionParameters )
{
using namespace LumenProbeHierarchy ;
RDG_EVENT_SCOPE ( GraphBuilder , " SSGI ProbeOcclusion %dx%d " ,
CommonParameters . TracingViewportSize . X ,
CommonParameters . TracingViewportSize . Y ) ;
FRDGBufferRef DispatchParameters ;
{
DispatchParameters = GraphBuilder . CreateBuffer (
FRDGBufferDesc : : CreateIndirectDesc < FRHIDispatchIndirectParameters > ( int32 ( EProbeOcclusionClassification : : MAX ) * ProbeOcclusionParameters . DispatchCount ) ,
TEXT ( " SSGI.ProbeOcclusionDispatchParameters " ) ) ;
FSetupScreenSpaceProbeOcclusionCS : : FParameters * PassParameters = GraphBuilder . AllocParameters < FSetupScreenSpaceProbeOcclusionCS : : FParameters > ( ) ;
PassParameters - > MaxTilePerDispatch = ProbeOcclusionParameters . MaxTilePerDispatch ;
PassParameters - > GlobalClassificationCountersBuffer = ProbeOcclusionParameters . GlobalClassificationCountersBuffer ;
PassParameters - > DispatchParametersOutput = GraphBuilder . CreateUAV ( DispatchParameters ) ;
TShaderMapRef < FSetupScreenSpaceProbeOcclusionCS > ComputeShader ( View . ShaderMap ) ;
FComputeShaderUtils : : AddPass (
GraphBuilder ,
RDG_EVENT_NAME ( " SetupScreenSpaceProbeOcclusion " ) ,
ComputeShader ,
PassParameters ,
FIntVector ( ProbeOcclusionParameters . DispatchCount , 1 , 1 ) ) ;
2019-09-14 09:45:25 -04:00
}
2019-10-01 13:03:04 -04:00
2020-07-06 18:58:26 -04:00
FScreenSpaceCastProbeOcclusionCS : : FParameters ReferencePassParameters ;
{
2020-09-08 17:44:06 -04:00
ScreenSpaceRayTracing : : SetupCommonScreenSpaceRayParameters ( GraphBuilder , CommonParameters , PrevSceneColor , View , /* out */ & ReferencePassParameters . CommonParameters ) ;
2020-07-06 18:58:26 -04:00
ReferencePassParameters . ProbeOcclusionParameters = ProbeOcclusionParameters ;
ReferencePassParameters . ProbeOcclusionOutputParameters = CreateProbeOcclusionOutputParameters (
2020-09-24 00:43:27 -04:00
GraphBuilder , ProbeOcclusionParameters , ERDGUnorderedAccessViewFlags : : SkipBarrier ) ;
2020-07-06 18:58:26 -04:00
ReferencePassParameters . DispatchParameters = DispatchParameters ;
}
for ( int32 i = 0 ; i < int32 ( EProbeOcclusionClassification : : MAX ) ; i + + )
{
EProbeOcclusionClassification TileClassification = EProbeOcclusionClassification ( i ) ;
FScreenSpaceCastProbeOcclusionCS : : FParameters * PassParameters = GraphBuilder . AllocParameters < FScreenSpaceCastProbeOcclusionCS : : FParameters > ( ) ;
* PassParameters = ReferencePassParameters ;
FScreenSpaceCastProbeOcclusionCS : : FPermutationDomain PermutationVector ;
PermutationVector . Set < FScreenSpaceCastProbeOcclusionCS : : FTileClassificationDim > ( TileClassification ) ;
TShaderMapRef < FScreenSpaceCastProbeOcclusionCS > ComputeShader ( View . ShaderMap , PermutationVector ) ;
ClearUnusedGraphResources ( ComputeShader , PassParameters ) ;
GraphBuilder . AddPass (
RDG_EVENT_NAME ( " SSGI ProbeOcclusion(%s) " , GetEventName ( TileClassification ) ) ,
PassParameters ,
ERDGPassFlags : : Compute ,
[ PassParameters , ComputeShader , i ] ( FRHICommandList & RHICmdList )
{
FScreenSpaceCastProbeOcclusionCS : : FParameters ShaderParameters = * PassParameters ;
ShaderParameters . DispatchParameters - > MarkResourceAsUsed ( ) ;
for ( int32 DispatchId = 0 ; DispatchId < ShaderParameters . ProbeOcclusionParameters . DispatchCount ; DispatchId + + )
{
ShaderParameters . DispatchOffset = DispatchId * ShaderParameters . ProbeOcclusionParameters . MaxTilePerDispatch ;
int32 IndirectArgsOffset = sizeof ( FRHIDispatchIndirectParameters ) * ( i + DispatchId * int32 ( EProbeOcclusionClassification : : MAX ) ) ;
FComputeShaderUtils : : DispatchIndirect (
RHICmdList ,
ComputeShader ,
ShaderParameters ,
ShaderParameters . DispatchParameters - > GetIndirectRHICallBuffer ( ) ,
IndirectArgsOffset ) ;
}
} ) ;
}
}
} // namespace ScreenSpaceRayTracing