2019-12-26 14:45:42 -05:00
// Copyright Epic Games, Inc. All Rights Reserved.
2018-12-18 21:41:17 -05:00
# include "DeferredShadingRenderer.h"
2020-04-04 17:18:16 -04:00
# include "SceneRenderTargets.h"
2018-12-18 21:41:17 -05:00
# if RHI_RAYTRACING
# include "ClearQuad.h"
# include "SceneRendering.h"
# include "RenderGraphBuilder.h"
# include "RenderTargetPool.h"
# include "RHIResources.h"
# include "UniformBuffer.h"
# include "VisualizeTexture.h"
# include "RayGenShaderUtils.h"
2019-02-14 14:23:27 -05:00
# include "RaytracingOptions.h"
2019-03-07 11:25:32 -05:00
# include "BuiltInRayTracingShaders.h"
# include "RayTracing/RayTracingMaterialHitShaders.h"
2018-12-18 21:41:17 -05:00
# include "Containers/DynamicRHIResourceArray.h"
2019-06-11 18:27:07 -04:00
# include "SceneTextureParameters.h"
2021-04-12 08:13:15 -04:00
# include "RayTracingDefinitions.h"
2018-12-18 21:41:17 -05:00
2019-03-13 07:14:22 -04:00
static float GRayTracingMaxNormalBias = 0.1f ;
static FAutoConsoleVariableRef CVarRayTracingNormalBias (
TEXT ( " r.RayTracing.NormalBias " ) ,
GRayTracingMaxNormalBias ,
TEXT ( " Sets the max. normal bias used for offseting the ray start position along the normal (default = 0.1, i.e., 1mm) " )
2019-02-14 14:23:27 -05:00
) ;
2019-03-07 11:25:32 -05:00
static int32 GRayTracingShadowsEnableMaterials = 1 ;
static FAutoConsoleVariableRef CVarRayTracingShadowsEnableMaterials (
TEXT ( " r.RayTracing.Shadows.EnableMaterials " ) ,
GRayTracingShadowsEnableMaterials ,
TEXT ( " Enables material shader binding for shadow rays. If this is disabled, then a default trivial shader is used. (default = 1) " )
) ;
2022-03-08 04:49:24 -05:00
static float GRayTracingShadowsAvoidSelfIntersectionTraceDistance = 0.0f ;
static FAutoConsoleVariableRef CVarRayTracingShadowsAvoidSelfIntersectionTraceDistance (
TEXT ( " r.RayTracing.Shadows.AvoidSelfIntersectionTraceDistance " ) ,
GRayTracingShadowsAvoidSelfIntersectionTraceDistance ,
TEXT ( " Max trace distance of epsilon trace to avoid self intersections. If set to 0, epsilon trace will not be used. " )
) ;
2019-03-07 11:25:32 -05:00
static TAutoConsoleVariable < int32 > CVarRayTracingShadowsEnableTwoSidedGeometry (
TEXT ( " r.RayTracing.Shadows.EnableTwoSidedGeometry " ) ,
2019-04-12 11:02:00 -04:00
1 ,
TEXT ( " Enables two-sided geometry when tracing shadow rays (default = 1) " ) ,
2019-03-07 11:25:32 -05:00
ECVF_RenderThreadSafe
) ;
2018-12-18 21:41:17 -05:00
2020-09-24 00:43:27 -04:00
static TAutoConsoleVariable < int32 > CVarRayTracingTransmissionSamplingDistanceCulling (
TEXT ( " r.RayTracing.Transmission.TransmissionSamplingDistanceCulling " ) ,
2021-08-03 11:56:47 -04:00
1 ,
TEXT ( " Enables visibility testing to cull transmission sampling distance (default = 1) " ) ,
2020-09-24 00:43:27 -04:00
ECVF_RenderThreadSafe
) ;
static TAutoConsoleVariable < int32 > CVarRayTracingTransmissionSamplingTechnique (
TEXT ( " r.RayTracing.Transmission.SamplingTechnique " ) ,
2021-08-03 11:56:47 -04:00
1 ,
TEXT ( " 0: Uses constant tracking of an infinite homogeneous medium \n " )
TEXT ( " 1: Uses constant tracking of a finite homogeneous medium whose extent is determined by transmission sampling distance (default) " ) ,
2020-09-24 00:43:27 -04:00
ECVF_RenderThreadSafe
) ;
static TAutoConsoleVariable < int32 > CVarRayTracingTransmissionRejectionSamplingTrials (
TEXT ( " r.RayTracing.Transmission.RejectionSamplingTrials " ) ,
0 ,
TEXT ( " Determines the number of rejection-sampling trials (default = 0) " ) ,
ECVF_RenderThreadSafe
) ;
2020-03-02 04:43:59 -05:00
static TAutoConsoleVariable < int32 > CVarRayTracingShadowsEnableHairVoxel (
TEXT ( " r.RayTracing.Shadows.EnableHairVoxel " ) ,
1 ,
TEXT ( " Enables use of hair voxel data for tracing shadow (default = 1) " ) ,
ECVF_RenderThreadSafe
) ;
2020-09-01 14:07:48 -04:00
static TAutoConsoleVariable < int32 > CVarRayTracingShadowsLODTransitionStart (
TEXT ( " r.RayTracing.Shadows.LODTransitionStart " ) ,
4000.0 , // 40 m
TEXT ( " The start of an LOD transition range (default = 4000) " ) ,
ECVF_RenderThreadSafe
) ;
static TAutoConsoleVariable < int32 > CVarRayTracingShadowsLODTransitionEnd (
TEXT ( " r.RayTracing.Shadows.LODTransitionEnd " ) ,
5000.0f , // 50 m
TEXT ( " The end of an LOD transition range (default = 5000) " ) ,
ECVF_RenderThreadSafe
) ;
2020-10-29 13:38:15 -04:00
static TAutoConsoleVariable < int32 > CVarRayTracingShadowsAcceptFirstHit (
TEXT ( " r.RayTracing.Shadows.AcceptFirstHit " ) ,
2021-08-23 13:59:12 -04:00
1 ,
2020-10-29 13:38:15 -04:00
TEXT ( " Whether to allow shadow rays to terminate early, on first intersected primitive. This may result in worse denoising quality in some cases. (default = 0) " ) ,
ECVF_RenderThreadSafe
) ;
2019-09-14 09:45:25 -04:00
bool EnableRayTracingShadowTwoSidedGeometry ( )
{
return CVarRayTracingShadowsEnableTwoSidedGeometry . GetValueOnRenderThread ( ) ! = 0 ;
}
2018-12-19 12:54:08 -05:00
class FOcclusionRGS : public FGlobalShader
2018-12-18 21:41:17 -05:00
{
2018-12-19 12:54:08 -05:00
DECLARE_GLOBAL_SHADER ( FOcclusionRGS )
SHADER_USE_ROOT_PARAMETER_STRUCT ( FOcclusionRGS , FGlobalShader )
2018-12-18 21:41:17 -05:00
class FLightTypeDim : SHADER_PERMUTATION_INT ( " LIGHT_TYPE " , LightType_MAX ) ;
2022-03-08 04:49:24 -05:00
class FAvoidSelfIntersectionTraceDim : SHADER_PERMUTATION_BOOL ( " AVOID_SELF_INTERSECTION_TRACE " ) ;
2019-10-01 13:03:04 -04:00
class FDenoiserOutputDim : SHADER_PERMUTATION_INT ( " DIM_DENOISER_OUTPUT " , 3 ) ;
2019-10-18 10:22:30 -04:00
class FEnableMultipleSamplesPerPixel : SHADER_PERMUTATION_BOOL ( " ENABLE_MULTIPLE_SAMPLES_PER_PIXEL " ) ;
2019-09-25 13:55:37 -04:00
class FHairLighting : SHADER_PERMUTATION_INT ( " USE_HAIR_LIGHTING " , 2 ) ;
2020-03-02 04:25:41 -05:00
class FEnableTransmissionDim : SHADER_PERMUTATION_INT ( " ENABLE_TRANSMISSION " , 2 ) ;
2018-12-18 21:41:17 -05:00
2022-03-08 04:49:24 -05:00
using FPermutationDomain = TShaderPermutationDomain < FLightTypeDim , FAvoidSelfIntersectionTraceDim , FDenoiserOutputDim , FHairLighting , FEnableMultipleSamplesPerPixel , FEnableTransmissionDim > ;
2018-12-18 21:41:17 -05:00
static bool ShouldCompilePermutation ( const FGlobalShaderPermutationParameters & Parameters )
{
2019-01-02 12:55:50 -05:00
return ShouldCompileRayTracingShadersForProject ( Parameters . Platform ) ;
2018-12-18 21:41:17 -05:00
}
2019-10-18 10:22:30 -04:00
static void ModifyCompilationEnvironment ( const FGlobalShaderPermutationParameters & Parameters , FShaderCompilerEnvironment & OutEnvironment )
{
FGlobalShader : : ModifyCompilationEnvironment ( Parameters , OutEnvironment ) ;
OutEnvironment . SetDefine ( TEXT ( " UE_RAY_TRACING_DYNAMIC_CLOSEST_HIT_SHADER " ) , 0 ) ;
OutEnvironment . SetDefine ( TEXT ( " UE_RAY_TRACING_DYNAMIC_ANY_HIT_SHADER " ) , 1 ) ;
OutEnvironment . SetDefine ( TEXT ( " UE_RAY_TRACING_DYNAMIC_MISS_SHADER " ) , 0 ) ;
FPermutationDomain PermutationVector ( Parameters . PermutationId ) ;
2019-10-18 13:47:16 -04:00
if ( PermutationVector . Get < FLightTypeDim > ( ) = = LightType_Directional & &
PermutationVector . Get < FHairLighting > ( ) = = 0 )
2019-10-18 10:22:30 -04:00
{
OutEnvironment . SetDefine ( TEXT ( " UE_RAY_TRACING_COHERENT_RAYS " ) , 1 ) ;
}
else
{
OutEnvironment . SetDefine ( TEXT ( " UE_RAY_TRACING_COHERENT_RAYS " ) , 0 ) ;
}
}
2018-12-18 21:41:17 -05:00
BEGIN_SHADER_PARAMETER_STRUCT ( FParameters , )
2022-02-22 15:35:01 -05:00
SHADER_PARAMETER_STRUCT_INCLUDE ( ShaderPrint : : FShaderParameters , ShaderPrintParameters )
2018-12-18 21:41:17 -05:00
SHADER_PARAMETER ( uint32 , SamplesPerPixel )
2019-02-14 14:23:27 -05:00
SHADER_PARAMETER ( float , NormalBias )
2019-03-07 11:25:32 -05:00
SHADER_PARAMETER ( uint32 , LightingChannelMask )
SHADER_PARAMETER ( FIntRect , LightScissor )
2019-06-21 14:47:14 -04:00
SHADER_PARAMETER ( FIntPoint , PixelOffset )
2020-02-25 19:31:57 -05:00
SHADER_PARAMETER ( uint32 , bUseHairVoxel )
2020-09-01 14:07:48 -04:00
SHADER_PARAMETER ( float , TraceDistance )
SHADER_PARAMETER ( float , LODTransitionStart )
SHADER_PARAMETER ( float , LODTransitionEnd )
2022-03-08 04:49:24 -05:00
SHADER_PARAMETER ( float , AvoidSelfIntersectionTraceDistance )
2020-09-24 00:43:27 -04:00
SHADER_PARAMETER ( uint32 , bTransmissionSamplingDistanceCulling )
SHADER_PARAMETER ( uint32 , TransmissionSamplingTechnique )
SHADER_PARAMETER ( uint32 , RejectionSamplingTrials )
2020-10-29 13:38:15 -04:00
SHADER_PARAMETER ( uint32 , bAcceptFirstHit )
2021-09-03 11:51:19 -04:00
SHADER_PARAMETER ( uint32 , bTwoSidedGeometry )
2019-03-07 11:25:32 -05:00
2018-12-18 21:41:17 -05:00
SHADER_PARAMETER_STRUCT ( FLightShaderParameters , Light )
2019-06-11 18:27:07 -04:00
SHADER_PARAMETER_STRUCT_INCLUDE ( FSceneTextureParameters , SceneTextures )
2020-09-24 00:43:27 -04:00
SHADER_PARAMETER_STRUCT_INCLUDE ( FSceneLightingChannelParameters , SceneLightingChannels )
2018-12-18 21:41:17 -05:00
2020-02-03 19:40:24 -05:00
SHADER_PARAMETER_RDG_TEXTURE ( Texture2D , HairLightChannelMaskTexture )
2021-07-13 12:38:37 -04:00
SHADER_PARAMETER_TEXTURE ( Texture2D , SSProfilesTexture )
2018-12-18 21:41:17 -05:00
SHADER_PARAMETER_SRV ( RaytracingAccelerationStructure , TLAS )
SHADER_PARAMETER_RDG_TEXTURE_UAV ( RWTexture2D < float4 > , RWOcclusionMaskUAV )
SHADER_PARAMETER_RDG_TEXTURE_UAV ( RWTexture2D < float > , RWRayDistanceUAV )
2020-03-02 04:38:22 -05:00
SHADER_PARAMETER_RDG_TEXTURE_UAV ( RWTexture2D < float4 > , RWSubPixelOcclusionMaskUAV )
2018-12-18 21:41:17 -05:00
SHADER_PARAMETER_STRUCT_REF ( FViewUniformShaderParameters , ViewUniformBuffer )
2021-03-26 04:50:30 -04:00
SHADER_PARAMETER_RDG_UNIFORM_BUFFER ( FHairStrandsViewUniformParameters , HairStrands )
2020-09-24 00:43:27 -04:00
SHADER_PARAMETER_RDG_UNIFORM_BUFFER ( FVirtualVoxelParameters , VirtualVoxel )
2022-02-10 15:58:17 -05:00
SHADER_PARAMETER_RDG_UNIFORM_BUFFER ( FStrataGlobalUniformParameters , Strata )
2018-12-18 21:41:17 -05:00
END_SHADER_PARAMETER_STRUCT ( )
} ;
2018-12-19 12:54:08 -05:00
IMPLEMENT_GLOBAL_SHADER ( FOcclusionRGS , " /Engine/Private/RayTracing/RayTracingOcclusionRGS.usf " , " OcclusionRGS " , SF_RayGen ) ;
2018-12-18 21:41:17 -05:00
2019-03-13 07:14:22 -04:00
float GetRaytracingMaxNormalBias ( )
2019-02-14 14:23:27 -05:00
{
2019-03-13 07:14:22 -04:00
return FMath : : Max ( 0.01f , GRayTracingMaxNormalBias ) ;
2019-02-14 14:23:27 -05:00
}
2022-04-28 15:07:36 -04:00
void FDeferredShadingSceneRenderer : : PrepareRayTracingShadows ( const FViewInfo & View , const FScene & Scene , TArray < FRHIRayTracingShader * > & OutRayGenShaders )
2018-12-18 21:41:17 -05:00
{
2021-08-16 16:57:19 -04:00
// Ray tracing shadows shaders should be properly configured even if r.RayTracing.Shadows is 0 because lights can have raytracing shadows enabled independently of that CVar
2022-05-04 10:05:02 -04:00
// We have to check if ray tracing is enabled on any of the scene lights. The Scene.bHasRayTracedLights is computed using ShouldRenderRayTracingShadowsForLight() helper,
2022-04-28 15:07:36 -04:00
// which handles various override conditions.
2019-03-07 11:25:32 -05:00
2022-05-04 10:05:02 -04:00
if ( Scene . bHasRayTracedLights = = false )
2020-09-24 00:43:27 -04:00
{
return ;
}
2019-03-07 11:25:32 -05:00
const IScreenSpaceDenoiser : : EShadowRequirements DenoiserRequirements [ ] =
2019-02-14 14:23:27 -05:00
{
2019-03-07 11:25:32 -05:00
IScreenSpaceDenoiser : : EShadowRequirements : : Bailout ,
2019-04-15 12:12:58 -04:00
IScreenSpaceDenoiser : : EShadowRequirements : : PenumbraAndAvgOccluder ,
2019-03-07 11:25:32 -05:00
IScreenSpaceDenoiser : : EShadowRequirements : : PenumbraAndClosestOccluder ,
} ;
2019-10-18 14:42:03 -04:00
for ( int32 MultiSPP = 0 ; MultiSPP < 2 ; + + MultiSPP )
2019-03-07 11:25:32 -05:00
{
2020-03-02 04:25:41 -05:00
for ( int32 EnableTransmissionDim = 0 ; EnableTransmissionDim < 2 ; + + EnableTransmissionDim )
2019-03-07 11:25:32 -05:00
{
2020-03-02 04:25:41 -05:00
for ( int32 HairLighting = 0 ; HairLighting < 2 ; + + HairLighting )
2019-10-18 14:42:03 -04:00
{
2022-03-08 04:49:24 -05:00
for ( int32 AvoidSelfIntersectionTrace = 0 ; AvoidSelfIntersectionTrace < 2 ; + + AvoidSelfIntersectionTrace )
2019-10-18 14:42:03 -04:00
{
2022-03-08 04:49:24 -05:00
for ( int32 LightType = 0 ; LightType < LightType_MAX ; + + LightType )
2020-03-02 04:25:41 -05:00
{
2022-03-08 04:49:24 -05:00
for ( IScreenSpaceDenoiser : : EShadowRequirements DenoiserRequirement : DenoiserRequirements )
{
FOcclusionRGS : : FPermutationDomain PermutationVector ;
PermutationVector . Set < FOcclusionRGS : : FLightTypeDim > ( LightType ) ;
PermutationVector . Set < FOcclusionRGS : : FAvoidSelfIntersectionTraceDim > ( ( bool ) AvoidSelfIntersectionTrace ) ;
PermutationVector . Set < FOcclusionRGS : : FDenoiserOutputDim > ( ( int32 ) DenoiserRequirement ) ;
PermutationVector . Set < FOcclusionRGS : : FHairLighting > ( HairLighting ) ;
PermutationVector . Set < FOcclusionRGS : : FEnableMultipleSamplesPerPixel > ( MultiSPP ! = 0 ) ;
PermutationVector . Set < FOcclusionRGS : : FEnableTransmissionDim > ( EnableTransmissionDim ) ;
2019-03-07 11:25:32 -05:00
2022-03-08 04:49:24 -05:00
TShaderMapRef < FOcclusionRGS > RayGenerationShader ( View . ShaderMap , PermutationVector ) ;
OutRayGenShaders . Add ( RayGenerationShader . GetRayTracingShader ( ) ) ;
}
2020-03-02 04:25:41 -05:00
}
2019-10-18 14:42:03 -04:00
}
}
2019-03-07 11:25:32 -05:00
}
2019-02-14 14:23:27 -05:00
}
2019-03-07 11:25:32 -05:00
}
2019-02-14 14:23:27 -05:00
2019-03-07 11:25:32 -05:00
# endif // RHI_RAYTRACING
void FDeferredShadingSceneRenderer : : RenderRayTracingShadows (
FRDGBuilder & GraphBuilder ,
2019-06-11 18:27:07 -04:00
const FSceneTextureParameters & SceneTextures ,
2019-03-07 11:25:32 -05:00
const FViewInfo & View ,
const FLightSceneInfo & LightSceneInfo ,
const IScreenSpaceDenoiser : : FShadowRayTracingConfig & RayTracingConfig ,
2019-09-25 13:55:37 -04:00
const IScreenSpaceDenoiser : : EShadowRequirements DenoiserRequirements ,
2020-09-24 00:43:27 -04:00
FRDGTextureRef LightingChannelsTexture ,
2019-10-18 10:35:06 -04:00
FRDGTextureUAV * OutShadowMaskUAV ,
2020-03-02 04:38:22 -05:00
FRDGTextureUAV * OutRayHitDistanceUAV ,
FRDGTextureUAV * SubPixelRayTracingShadowMaskUAV )
2019-03-07 11:25:32 -05:00
# if RHI_RAYTRACING
{
FLightSceneProxy * LightSceneProxy = LightSceneInfo . Proxy ;
2018-12-18 21:41:17 -05:00
check ( LightSceneProxy ) ;
2019-06-21 14:47:14 -04:00
FIntRect ScissorRect = View . ViewRect ;
FIntPoint PixelOffset = { 0 , 0 } ;
2020-08-11 01:36:57 -04:00
//#UE-95409: Implement support for scissor in multi-view
const bool bClipDispatch = View . Family - > Views . Num ( ) = = 1 ;
2019-03-07 11:25:32 -05:00
if ( LightSceneProxy - > GetScissorRect ( ScissorRect , View , View . ViewRect ) )
{
// Account for scissor being defined on the whole frame viewport while the trace is only on the view subrect
2019-06-22 19:40:09 -04:00
// ScissorRect.Min = ScissorRect.Min;
// ScissorRect.Max = ScissorRect.Max;
2019-03-07 11:25:32 -05:00
}
else
{
2019-06-21 14:47:14 -04:00
ScissorRect = View . ViewRect ;
}
if ( bClipDispatch )
{
PixelOffset = ScissorRect . Min ;
2019-03-07 11:25:32 -05:00
}
2018-12-18 21:41:17 -05:00
// Ray generation pass for shadow occlusion.
{
2021-11-19 06:38:32 -05:00
const bool bUseHairLighting = HairStrands : : HasViewHairStrandsData ( View ) & & HairStrands : : HasViewHairStrandsVoxelData ( View ) ;
const bool bUseHairDeepShadow = HairStrands : : HasViewHairStrandsData ( View ) & & LightSceneProxy - > CastsHairStrandsDeepShadow ( ) ;
2020-02-25 19:31:57 -05:00
2018-12-19 12:54:08 -05:00
FOcclusionRGS : : FParameters * PassParameters = GraphBuilder . AllocParameters < FOcclusionRGS : : FParameters > ( ) ;
2019-10-18 10:35:06 -04:00
PassParameters - > RWOcclusionMaskUAV = OutShadowMaskUAV ;
PassParameters - > RWRayDistanceUAV = OutRayHitDistanceUAV ;
2020-03-02 04:38:22 -05:00
PassParameters - > RWSubPixelOcclusionMaskUAV = SubPixelRayTracingShadowMaskUAV ;
2019-03-07 11:25:32 -05:00
PassParameters - > SamplesPerPixel = RayTracingConfig . RayCountPerPixel ;
2019-03-13 07:14:22 -04:00
PassParameters - > NormalBias = GetRaytracingMaxNormalBias ( ) ;
2019-03-07 11:25:32 -05:00
PassParameters - > LightingChannelMask = LightSceneProxy - > GetLightingChannelMask ( ) ;
2022-01-26 13:56:31 -05:00
{
FLightRenderParameters LightParameters ;
LightSceneProxy - > GetLightShaderParameters ( LightParameters ) ;
LightParameters . MakeShaderParameters ( View . ViewMatrices , PassParameters - > Light ) ;
PassParameters - > Light . SourceRadius * = LightSceneProxy - > GetShadowSourceAngleFactor ( ) ;
}
2020-09-01 14:07:48 -04:00
PassParameters - > TraceDistance = LightSceneProxy - > GetTraceDistance ( ) ;
PassParameters - > LODTransitionStart = CVarRayTracingShadowsLODTransitionStart . GetValueOnRenderThread ( ) ;
PassParameters - > LODTransitionEnd = CVarRayTracingShadowsLODTransitionEnd . GetValueOnRenderThread ( ) ;
2022-03-08 04:49:24 -05:00
PassParameters - > AvoidSelfIntersectionTraceDistance = GRayTracingShadowsAvoidSelfIntersectionTraceDistance ;
2020-10-29 13:38:15 -04:00
PassParameters - > bAcceptFirstHit = CVarRayTracingShadowsAcceptFirstHit . GetValueOnRenderThread ( ) ;
2021-09-03 11:51:19 -04:00
PassParameters - > bTwoSidedGeometry = EnableRayTracingShadowTwoSidedGeometry ( ) ? 1 : 0 ;
2022-05-04 10:41:10 -04:00
PassParameters - > TLAS = View . GetRayTracingSceneLayerViewChecked ( ERayTracingSceneLayer : : Base ) ;
2018-12-18 21:41:17 -05:00
PassParameters - > ViewUniformBuffer = View . ViewUniformBuffer ;
2019-06-11 18:27:07 -04:00
PassParameters - > SceneTextures = SceneTextures ;
2020-09-24 00:43:27 -04:00
PassParameters - > SceneLightingChannels = GetSceneLightingChannelParameters ( GraphBuilder , LightingChannelsTexture ) ;
2019-03-07 11:25:32 -05:00
PassParameters - > LightScissor = ScissorRect ;
2019-06-21 14:47:14 -04:00
PassParameters - > PixelOffset = PixelOffset ;
2021-07-13 12:38:37 -04:00
PassParameters - > SSProfilesTexture = View . RayTracingSubSurfaceProfileTexture ;
2020-09-24 00:43:27 -04:00
PassParameters - > bTransmissionSamplingDistanceCulling = CVarRayTracingTransmissionSamplingDistanceCulling . GetValueOnRenderThread ( ) ;
PassParameters - > TransmissionSamplingTechnique = CVarRayTracingTransmissionSamplingTechnique . GetValueOnRenderThread ( ) ;
PassParameters - > RejectionSamplingTrials = CVarRayTracingTransmissionRejectionSamplingTrials . GetValueOnRenderThread ( ) ;
2022-04-01 08:35:55 -04:00
PassParameters - > Strata = Strata : : BindStrataGlobalUniformParameters ( View ) ;
2020-02-25 19:31:57 -05:00
if ( bUseHairLighting )
2019-09-25 13:55:37 -04:00
{
2020-03-02 04:43:59 -05:00
const bool bUseHairVoxel = CVarRayTracingShadowsEnableHairVoxel . GetValueOnRenderThread ( ) > 0 ;
2021-11-19 06:38:32 -05:00
PassParameters - > bUseHairVoxel = ! bUseHairDeepShadow & & bUseHairVoxel ? 1 : 0 ;
2021-03-26 04:50:30 -04:00
PassParameters - > HairLightChannelMaskTexture = View . HairStrandsViewData . VisibilityData . LightChannelMaskTexture ;
PassParameters - > HairStrands = HairStrands : : BindHairStrandsViewUniformParameters ( View ) ;
PassParameters - > VirtualVoxel = HairStrands : : BindHairStrandsVoxelUniformParameters ( View ) ;
2020-02-25 19:31:57 -05:00
2022-02-22 15:35:01 -05:00
if ( ShaderPrint : : IsEnabled ( View ) )
2020-02-25 19:31:57 -05:00
{
2022-02-22 15:35:01 -05:00
ShaderPrint : : SetParameters ( GraphBuilder , View . ShaderPrintData , PassParameters - > ShaderPrintParameters ) ;
2020-02-25 19:31:57 -05:00
}
2020-02-03 19:40:24 -05:00
}
2018-12-19 12:54:08 -05:00
FOcclusionRGS : : FPermutationDomain PermutationVector ;
PermutationVector . Set < FOcclusionRGS : : FLightTypeDim > ( LightSceneProxy - > GetLightType ( ) ) ;
2022-03-08 04:49:24 -05:00
PermutationVector . Set < FOcclusionRGS : : FAvoidSelfIntersectionTraceDim > ( GRayTracingShadowsAvoidSelfIntersectionTraceDistance > 0.0f ) ;
2019-10-01 13:03:04 -04:00
if ( DenoiserRequirements = = IScreenSpaceDenoiser : : EShadowRequirements : : PenumbraAndAvgOccluder )
2019-03-07 11:25:32 -05:00
{
PermutationVector . Set < FOcclusionRGS : : FDenoiserOutputDim > ( 1 ) ;
}
else if ( DenoiserRequirements = = IScreenSpaceDenoiser : : EShadowRequirements : : PenumbraAndClosestOccluder )
{
2019-10-01 13:03:04 -04:00
PermutationVector . Set < FOcclusionRGS : : FDenoiserOutputDim > ( 2 ) ;
2019-03-07 11:25:32 -05:00
}
else
{
PermutationVector . Set < FOcclusionRGS : : FDenoiserOutputDim > ( 0 ) ;
}
2019-09-25 13:55:37 -04:00
PermutationVector . Set < FOcclusionRGS : : FHairLighting > ( bUseHairLighting ? 1 : 0 ) ;
2018-12-18 21:41:17 -05:00
2019-10-18 10:22:30 -04:00
PermutationVector . Set < FOcclusionRGS : : FEnableMultipleSamplesPerPixel > ( RayTracingConfig . RayCountPerPixel > 1 ) ;
2020-03-02 04:25:41 -05:00
PermutationVector . Set < FOcclusionRGS : : FEnableTransmissionDim > ( LightSceneProxy - > Transmission ( ) ? 1 : 0 ) ;
2019-10-18 10:22:30 -04:00
2018-12-19 12:54:08 -05:00
TShaderMapRef < FOcclusionRGS > RayGenerationShader ( GetGlobalShaderMap ( FeatureLevel ) , PermutationVector ) ;
2018-12-18 21:41:17 -05:00
2020-02-06 13:13:41 -05:00
ClearUnusedGraphResources ( RayGenerationShader , PassParameters ) ;
2019-03-07 11:25:32 -05:00
FIntPoint Resolution ( View . ViewRect . Width ( ) , View . ViewRect . Height ( ) ) ;
2019-06-21 14:47:14 -04:00
if ( bClipDispatch )
{
Resolution = ScissorRect . Size ( ) ;
}
2019-03-07 11:25:32 -05:00
GraphBuilder . AddPass (
2019-06-21 14:47:14 -04:00
RDG_EVENT_NAME ( " RayTracedShadow (spp=%d) %dx%d " , RayTracingConfig . RayCountPerPixel , Resolution . X , Resolution . Y ) ,
2018-12-18 21:41:17 -05:00
PassParameters ,
2019-07-19 14:19:12 -04:00
ERDGPassFlags : : Compute ,
2021-07-26 13:30:37 -04:00
[ this , & View , RayGenerationShader , PassParameters , Resolution ] ( FRHIRayTracingCommandList & RHICmdList )
2019-03-07 11:25:32 -05:00
{
FRayTracingShaderBindingsWriter GlobalResources ;
2020-02-06 13:13:41 -05:00
SetShaderParameters ( GlobalResources , RayGenerationShader , * PassParameters ) ;
2019-03-07 11:25:32 -05:00
2021-03-23 09:21:56 -04:00
FRHIRayTracingScene * RayTracingSceneRHI = View . GetRayTracingSceneChecked ( ) ;
2019-03-07 11:25:32 -05:00
if ( GRayTracingShadowsEnableMaterials )
{
2020-02-06 13:13:41 -05:00
RHICmdList . RayTraceDispatch ( View . RayTracingMaterialPipeline , RayGenerationShader . GetRayTracingShader ( ) , RayTracingSceneRHI , GlobalResources , Resolution . X , Resolution . Y ) ;
2019-03-07 11:25:32 -05:00
}
else
{
FRayTracingPipelineStateInitializer Initializer ;
2021-04-12 08:13:15 -04:00
Initializer . MaxPayloadSizeInBytes = RAY_TRACING_MAX_ALLOWED_PAYLOAD_SIZE ; // sizeof(FPackedMaterialClosestHitPayload)
2019-03-07 11:25:32 -05:00
2020-02-06 13:13:41 -05:00
FRHIRayTracingShader * RayGenShaderTable [ ] = { RayGenerationShader . GetRayTracingShader ( ) } ;
2019-03-07 11:25:32 -05:00
Initializer . SetRayGenShaderTable ( RayGenShaderTable ) ;
2020-02-06 13:13:41 -05:00
FRHIRayTracingShader * HitGroupTable [ ] = { View . ShaderMap - > GetShader < FOpaqueShadowHitGroup > ( ) . GetRayTracingShader ( ) } ;
2019-03-07 11:25:32 -05:00
Initializer . SetHitGroupTable ( HitGroupTable ) ;
Initializer . bAllowHitGroupIndexing = false ; // Use the same hit shader for all geometry in the scene by disabling SBT indexing.
2019-06-11 18:27:07 -04:00
FRayTracingPipelineState * Pipeline = PipelineStateCache : : GetAndOrCreateRayTracingPipelineState ( RHICmdList , Initializer ) ;
2019-03-07 11:25:32 -05:00
2020-02-06 13:13:41 -05:00
RHICmdList . RayTraceDispatch ( Pipeline , RayGenerationShader . GetRayTracingShader ( ) , RayTracingSceneRHI , GlobalResources , Resolution . X , Resolution . Y ) ;
2019-03-07 11:25:32 -05:00
}
} ) ;
2018-12-18 21:41:17 -05:00
}
}
2019-03-07 11:25:32 -05:00
# else // !RHI_RAYTRACING
{
unimplemented ( ) ;
}
# endif
2020-04-02 14:21:21 -04:00
2021-01-11 15:01:33 -04:00
BEGIN_SHADER_PARAMETER_STRUCT ( FDitheredLODFadingOutMaskParameters , )
2021-01-14 05:23:34 -04:00
SHADER_PARAMETER_STRUCT_INCLUDE ( FInstanceCullingDrawParams , InstanceCullingDrawParams )
2021-01-11 15:01:33 -04:00
SHADER_PARAMETER_STRUCT_REF ( FViewUniformShaderParameters , View )
2021-01-14 05:23:34 -04:00
RENDER_TARGET_BINDING_SLOTS ( )
2021-01-11 15:01:33 -04:00
END_SHADER_PARAMETER_STRUCT ( )
2020-09-24 00:43:27 -04:00
void FDeferredShadingSceneRenderer : : RenderDitheredLODFadingOutMask ( FRDGBuilder & GraphBuilder , const FViewInfo & View , FRDGTextureRef SceneDepthTexture )
2020-04-02 14:21:21 -04:00
{
2021-01-11 15:01:33 -04:00
auto * PassParameters = GraphBuilder . AllocParameters < FDitheredLODFadingOutMaskParameters > ( ) ;
PassParameters - > View = View . ViewUniformBuffer ;
2020-09-24 00:43:27 -04:00
PassParameters - > RenderTargets . DepthStencil = FDepthStencilBinding ( SceneDepthTexture , ERenderTargetLoadAction : : ELoad , ERenderTargetLoadAction : : ELoad , FExclusiveDepthStencil : : DepthWrite_StencilWrite ) ;
2020-04-02 14:21:21 -04:00
2021-01-14 15:46:32 -04:00
const_cast < FViewInfo & > ( View ) . ParallelMeshDrawCommandPasses [ EMeshPass : : DitheredLODFadingOutMaskPass ] . BuildRenderingCommands ( GraphBuilder , Scene - > GPUScene , PassParameters - > InstanceCullingDrawParams ) ;
2020-09-24 00:43:27 -04:00
GraphBuilder . AddPass (
RDG_EVENT_NAME ( " DitheredLODFadingOutMask " ) ,
PassParameters ,
ERDGPassFlags : : Raster ,
2021-07-13 12:38:37 -04:00
[ this , & View , PassParameters ] ( FRHICommandList & RHICmdList )
2020-09-24 00:43:27 -04:00
{
RHICmdList . SetScissorRect ( false , 0 , 0 , 0 , 0 ) ;
RHICmdList . SetViewport ( View . ViewRect . Min . X , View . ViewRect . Min . Y , 0.0f , View . ViewRect . Max . X , View . ViewRect . Max . Y , 1.0f ) ;
2021-01-14 05:23:34 -04:00
View . ParallelMeshDrawCommandPasses [ EMeshPass : : DitheredLODFadingOutMaskPass ] . DispatchDraw ( nullptr , RHICmdList , & PassParameters - > InstanceCullingDrawParams ) ;
2020-09-24 00:43:27 -04:00
} ) ;
2020-04-02 14:21:21 -04:00
}