2020-07-06 18:58:26 -04:00
// Copyright Epic Games, Inc. All Rights Reserved.
/*=============================================================================
VirtualShadowMapProjection . cpp
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
# include "VirtualShadowMapProjection.h"
# include "CoreMinimal.h"
# include "Stats/Stats.h"
# include "RHI.h"
# include "RenderResource.h"
# include "RendererInterface.h"
# include "Shader.h"
# include "StaticBoundShaderState.h"
# include "SceneUtils.h"
# include "RHIStaticStates.h"
# include "LightSceneInfo.h"
# include "GlobalShader.h"
# include "SceneRenderTargetParameters.h"
# include "ShadowRendering.h"
# include "DeferredShadingRenderer.h"
# include "PixelShaderUtils.h"
# include "ShadowRendering.h"
# include "SceneRendering.h"
# include "VirtualShadowMapClipmap.h"
2021-03-16 11:33:44 -04:00
# include "HairStrands/HairStrandsData.h"
2020-07-06 18:58:26 -04:00
static TAutoConsoleVariable < float > CVarContactShadowLength (
2021-02-18 13:44:36 -04:00
TEXT ( " r.Shadow.Virtual.ContactShadowLength " ) ,
2021-01-08 22:26:52 -04:00
0.02f ,
2020-07-06 18:58:26 -04:00
TEXT ( " Length of the screen space contact shadow trace (smart shadow bias) before the virtual shadow map lookup. " ) ,
ECVF_RenderThreadSafe
) ;
2021-04-22 16:30:49 -04:00
static TAutoConsoleVariable < float > CVarNormalBias (
TEXT ( " r.Shadow.Virtual.NormalBias " ) ,
0.5f ,
TEXT ( " Receiver offset along surface normal for shadow lookup. Scaled by distance to camera. " )
2021-01-08 22:26:52 -04:00
TEXT ( " Higher values avoid artifacts on surfaces nearly parallel to the light, but also visibility offset shadows and increase the chance of hitting unmapped pages. " ) ,
ECVF_RenderThreadSafe
) ;
2021-01-25 18:20:37 -04:00
TAutoConsoleVariable < int32 > CVarVirtualShadowOnePassProjection (
2021-02-18 13:44:36 -04:00
TEXT ( " r.Shadow.Virtual.OnePassProjection " ) ,
2021-01-25 18:20:37 -04:00
0 ,
TEXT ( " Single pass projects all local VSMs culled with the light grid. Used in conjunction with clustered deferred shading. " ) ,
ECVF_RenderThreadSafe
) ;
2021-02-05 15:55:43 -04:00
static TAutoConsoleVariable < int32 > CVarSMRTRayCountLocal (
2021-02-18 13:44:36 -04:00
TEXT ( " r.Shadow.Virtual.SMRT.RayCountLocal " ) ,
2021-03-15 22:06:28 -04:00
7 ,
2021-02-05 15:55:43 -04:00
TEXT ( " Ray count for shadow map tracing of local lights. 0 = disabled. " ) ,
ECVF_RenderThreadSafe
) ;
static TAutoConsoleVariable < int32 > CVarSMRTSamplesPerRayLocal (
2021-02-18 13:44:36 -04:00
TEXT ( " r.Shadow.Virtual.SMRT.SamplesPerRayLocal " ) ,
2021-03-15 22:06:28 -04:00
8 ,
2021-02-05 15:55:43 -04:00
TEXT ( " Shadow map samples per ray for local lights " ) ,
ECVF_RenderThreadSafe
) ;
static TAutoConsoleVariable < float > CVarSMRTMaxRayAngleFromLight (
2021-02-18 13:44:36 -04:00
TEXT ( " r.Shadow.Virtual.SMRT.MaxRayAngleFromLight " ) ,
2021-02-05 15:55:43 -04:00
0.03f ,
TEXT ( " Max angle (in radians) a ray is allowed to span from the light's perspective for local lights. " )
TEXT ( " Smaller angles limit the screen space size of shadow penumbra. " )
TEXT ( " Larger angles lead to more noise. " ) ,
ECVF_RenderThreadSafe
) ;
2020-12-16 17:57:13 -04:00
static TAutoConsoleVariable < int32 > CVarSMRTRayCountDirectional (
2021-02-18 13:44:36 -04:00
TEXT ( " r.Shadow.Virtual.SMRT.RayCountDirectional " ) ,
2021-03-29 15:53:16 -04:00
7 ,
2020-12-16 17:57:13 -04:00
TEXT ( " Ray count for shadow map tracing of directional lights. 0 = disabled. " ) ,
ECVF_RenderThreadSafe
) ;
static TAutoConsoleVariable < int32 > CVarSMRTSamplesPerRayDirectional (
2021-02-18 13:44:36 -04:00
TEXT ( " r.Shadow.Virtual.SMRT.SamplesPerRayDirectional " ) ,
2021-03-15 22:06:28 -04:00
8 ,
2020-12-16 17:57:13 -04:00
TEXT ( " Shadow map samples per ray for directional lights " ) ,
ECVF_RenderThreadSafe
) ;
static TAutoConsoleVariable < float > CVarSMRTRayLengthScaleDirectional (
2021-02-18 13:44:36 -04:00
TEXT ( " r.Shadow.Virtual.SMRT.RayLengthScaleDirectional " ) ,
2021-03-15 22:06:28 -04:00
1.5f ,
2020-12-16 17:57:13 -04:00
TEXT ( " Length of ray to shoot for directional lights, scaled by distance to camera. " )
TEXT ( " Shorter rays limit the screen space size of shadow penumbra. " )
TEXT ( " Longer rays require more samples to avoid shadows disconnecting from contact points. " ) ,
ECVF_RenderThreadSafe
) ;
2021-01-27 21:04:55 -04:00
static TAutoConsoleVariable < int32 > CVarSMRTAdaptiveRayCount (
2021-02-18 13:44:36 -04:00
TEXT ( " r.Shadow.Virtual.SMRT.AdaptiveRayCount " ) ,
2021-01-27 21:04:55 -04:00
1 ,
TEXT ( " Shoot fewer rays in fully shadowed and unshadowed regions. Currently only supported with OnePassProjection. " ) ,
ECVF_RenderThreadSafe
) ;
2020-07-06 18:58:26 -04:00
// Composite denoised shadow projection mask onto the light's shadow mask
// Basically just a copy shader with a special blend mode
class FVirtualShadowMapProjectionCompositePS : public FGlobalShader
{
DECLARE_GLOBAL_SHADER ( FVirtualShadowMapProjectionCompositePS ) ;
SHADER_USE_PARAMETER_STRUCT ( FVirtualShadowMapProjectionCompositePS , FGlobalShader ) ;
2021-03-15 22:06:28 -04:00
BEGIN_SHADER_PARAMETER_STRUCT ( FParameters , )
2021-04-26 15:47:32 -04:00
SHADER_PARAMETER_RDG_TEXTURE ( Texture2D < float4 > , InputShadowFactor )
2021-03-15 22:06:28 -04:00
RENDER_TARGET_BINDING_SLOTS ( )
END_SHADER_PARAMETER_STRUCT ( )
2020-07-06 18:58:26 -04:00
2020-08-19 14:22:37 -04:00
static bool ShouldCompilePermutation ( const FGlobalShaderPermutationParameters & Parameters )
{
return DoesPlatformSupportNanite ( Parameters . Platform ) ;
}
2020-07-06 18:58:26 -04:00
static void ModifyCompilationEnvironment ( const FGlobalShaderPermutationParameters & Parameters , FShaderCompilerEnvironment & OutEnvironment )
{
// Required right now due to where the shader function lives, but not actually used
FVirtualShadowMapArray : : SetShaderDefines ( OutEnvironment ) ;
}
} ;
IMPLEMENT_GLOBAL_SHADER ( FVirtualShadowMapProjectionCompositePS , " /Engine/Private/VirtualShadowMaps/VirtualShadowMapProjection.usf " , " VirtualShadowMapCompositePS " , SF_Pixel ) ;
void CompositeVirtualShadowMapMask (
FRDGBuilder & GraphBuilder ,
const FIntRect ScissorRect ,
2021-03-15 22:06:28 -04:00
const FRDGTextureRef Input ,
2020-07-06 18:58:26 -04:00
FRDGTextureRef OutputShadowMaskTexture )
{
auto ShaderMap = GetGlobalShaderMap ( GMaxRHIFeatureLevel ) ;
2021-03-15 22:06:28 -04:00
FVirtualShadowMapProjectionCompositePS : : FParameters * PassParameters = GraphBuilder . AllocParameters < FVirtualShadowMapProjectionCompositePS : : FParameters > ( ) ;
2021-04-26 15:47:32 -04:00
PassParameters - > InputShadowFactor = Input ;
2020-07-06 18:58:26 -04:00
PassParameters - > RenderTargets [ 0 ] = FRenderTargetBinding ( OutputShadowMaskTexture , ERenderTargetLoadAction : : ELoad ) ;
// See FProjectedShadowInfo::GetBlendStateForProjection, but we don't want any of the special cascade behavior, etc. as this is a post-denoised mask.
FRHIBlendState * BlendState = TStaticBlendState < CW_BA , BO_Min , BF_One , BF_One , BO_Min , BF_One , BF_One > : : GetRHI ( ) ;
auto PixelShader = ShaderMap - > GetShader < FVirtualShadowMapProjectionCompositePS > ( ) ;
ValidateShaderParameters ( PixelShader , * PassParameters ) ;
FPixelShaderUtils : : AddFullscreenPass ( GraphBuilder ,
ShaderMap ,
2021-04-26 15:47:32 -04:00
RDG_EVENT_NAME ( " MaskComposite " ) ,
2020-07-06 18:58:26 -04:00
PixelShader ,
PassParameters ,
ScissorRect ,
BlendState ) ;
}
2021-01-25 18:20:37 -04:00
2021-03-15 22:06:28 -04:00
2021-01-25 18:20:37 -04:00
class FVirtualShadowMapProjectionCS : public FGlobalShader
{
DECLARE_GLOBAL_SHADER ( FVirtualShadowMapProjectionCS ) ;
SHADER_USE_PARAMETER_STRUCT ( FVirtualShadowMapProjectionCS , FGlobalShader )
2021-03-15 22:06:28 -04:00
class FDirectionalLightDim : SHADER_PERMUTATION_BOOL ( " DIRECTIONAL_LIGHT " ) ;
2021-02-22 20:13:11 -04:00
class FSMRTAdaptiveRayCountDim : SHADER_PERMUTATION_BOOL ( " SMRT_ADAPTIVE_RAY_COUNT " ) ;
class FTwoPhysicalTexturesDim : SHADER_PERMUTATION_BOOL ( " TWO_PHYSICAL_TEXTURES " ) ;
2021-03-15 22:06:28 -04:00
class FOnePassProjectionDim : SHADER_PERMUTATION_BOOL ( " ONE_PASS_PROJECTION " ) ;
2021-03-28 14:38:43 -04:00
class FHairStrandsDim : SHADER_PERMUTATION_BOOL ( " HAS_HAIR_STRANDS " ) ;
2021-05-20 19:32:20 -04:00
class FDebugOutputDim : SHADER_PERMUTATION_BOOL ( " DEBUG_OUTPUT " ) ;
2021-03-15 22:06:28 -04:00
2021-02-22 20:13:11 -04:00
using FPermutationDomain = TShaderPermutationDomain <
2021-03-15 22:06:28 -04:00
FDirectionalLightDim ,
FOnePassProjectionDim ,
2021-02-22 20:13:11 -04:00
FSMRTAdaptiveRayCountDim ,
2021-03-28 14:38:43 -04:00
FTwoPhysicalTexturesDim ,
2021-05-20 19:32:20 -04:00
FHairStrandsDim ,
FDebugOutputDim > ;
2021-01-27 21:04:55 -04:00
2021-01-25 18:20:37 -04:00
BEGIN_SHADER_PARAMETER_STRUCT ( FParameters , )
2021-03-08 23:14:54 -04:00
SHADER_PARAMETER_STRUCT_INCLUDE ( FVirtualShadowMapSamplingParameters , SamplingParameters )
2021-01-25 18:20:37 -04:00
SHADER_PARAMETER_RDG_UNIFORM_BUFFER ( FSceneTextureUniformParameters , SceneTexturesStruct )
2021-03-16 11:33:44 -04:00
SHADER_PARAMETER_RDG_UNIFORM_BUFFER ( FHairStrandsViewUniformParameters , HairStrands )
2021-03-28 14:38:43 -04:00
SHADER_PARAMETER_RDG_UNIFORM_BUFFER ( FVirtualVoxelParameters , HairStrandsVoxel )
SHADER_PARAMETER_STRUCT_REF ( FViewUniformShaderParameters , View )
2021-03-15 22:06:28 -04:00
SHADER_PARAMETER ( FIntVector4 , ProjectionRect )
2021-01-25 18:20:37 -04:00
SHADER_PARAMETER ( float , ContactShadowLength )
2021-04-22 16:30:49 -04:00
SHADER_PARAMETER ( float , NormalBias )
2021-03-15 22:06:28 -04:00
SHADER_PARAMETER ( uint32 , SMRTRayCount )
SHADER_PARAMETER ( uint32 , SMRTSamplesPerRay )
2021-01-25 18:20:37 -04:00
SHADER_PARAMETER ( float , SMRTRayLengthScale )
2021-02-05 15:55:43 -04:00
SHADER_PARAMETER ( float , SMRTCotMaxRayAngleFromLight )
2021-03-16 11:33:44 -04:00
SHADER_PARAMETER ( uint32 , InputType )
2021-03-15 22:06:28 -04:00
// One pass projection parameters
SHADER_PARAMETER_STRUCT_REF ( FForwardLightData , ForwardLightData )
2021-05-20 19:32:20 -04:00
SHADER_PARAMETER_RDG_BUFFER_SRV ( StructuredBuffer < uint > , VirtualShadowMapIdRemap ) // TODO: Move to VSM UB? Per-view though
2021-03-15 22:06:28 -04:00
SHADER_PARAMETER_RDG_TEXTURE_UAV ( RWTexture2D < uint > , RWShadowMaskBits )
// Pass per light parameters
SHADER_PARAMETER_STRUCT ( FLightShaderParameters , Light )
SHADER_PARAMETER ( int32 , LightUniformVirtualShadowMapId )
2021-04-26 15:47:32 -04:00
SHADER_PARAMETER_RDG_TEXTURE_UAV ( RWTexture2D , RWShadowFactor )
2021-05-20 19:32:20 -04:00
// Debug output
SHADER_PARAMETER_RDG_BUFFER_SRV ( StructuredBuffer < FPhysicalPageMetaData > , PhysicalPageMetaData )
SHADER_PARAMETER ( int32 , DebugOutputType )
SHADER_PARAMETER ( int32 , DebugVirtualShadowMapId )
SHADER_PARAMETER_RDG_TEXTURE_UAV ( RWTexture2D , RWDebug )
2021-01-25 18:20:37 -04:00
END_SHADER_PARAMETER_STRUCT ( )
static void ModifyCompilationEnvironment ( const FGlobalShaderPermutationParameters & Parameters , FShaderCompilerEnvironment & OutEnvironment )
{
FGlobalShader : : ModifyCompilationEnvironment ( Parameters , OutEnvironment ) ;
FVirtualShadowMapArray : : SetShaderDefines ( OutEnvironment ) ;
FForwardLightingParameters : : ModifyCompilationEnvironment ( Parameters . Platform , OutEnvironment ) ;
2021-01-28 22:04:53 -04:00
FPermutationDomain PermutationVector ( Parameters . PermutationId ) ;
if ( PermutationVector . Get < FSMRTAdaptiveRayCountDim > ( ) )
{
OutEnvironment . CompilerFlags . Add ( CFLAG_WaveOperations ) ;
}
2021-03-11 22:07:24 -04:00
OutEnvironment . CompilerFlags . Add ( CFLAG_Wave32 ) ;
OutEnvironment . CompilerFlags . Add ( CFLAG_AllowRealTypes ) ;
2021-01-25 18:20:37 -04:00
}
2021-01-26 08:59:57 -04:00
static bool ShouldCompilePermutation ( const FGlobalShaderPermutationParameters & Parameters )
{
2021-03-15 22:06:28 -04:00
FPermutationDomain PermutationVector ( Parameters . PermutationId ) ;
// Directional lights are always in separate passes as forward light data structure currently
// only contains a single single directional light.
if ( PermutationVector . Get < FDirectionalLightDim > ( ) & & PermutationVector . Get < FOnePassProjectionDim > ( ) )
{
return false ;
}
2021-01-26 08:59:57 -04:00
return DoesPlatformSupportNanite ( Parameters . Platform ) ;
}
2021-01-25 18:20:37 -04:00
} ;
IMPLEMENT_GLOBAL_SHADER ( FVirtualShadowMapProjectionCS , " /Engine/Private/VirtualShadowMaps/VirtualShadowMapProjection.usf " , " VirtualShadowMapProjection " , SF_Compute ) ;
2021-04-22 16:30:49 -04:00
static float GetNormalBiasForShader ( )
{
return CVarNormalBias . GetValueOnRenderThread ( ) / 1000.0f ;
}
2021-02-22 20:13:11 -04:00
extern int32 GVirtualShadowMapAtomicWrites ;
2021-03-15 22:06:28 -04:00
static void RenderVirtualShadowMapProjectionCommon (
2021-01-25 18:20:37 -04:00
FRDGBuilder & GraphBuilder ,
const FMinimalSceneTextures & SceneTextures ,
const FViewInfo & View ,
FVirtualShadowMapArray & VirtualShadowMapArray ,
2021-03-15 22:06:28 -04:00
const FIntRect ProjectionRect ,
2021-03-16 11:33:44 -04:00
EVirtualShadowMapProjectionInputType InputType ,
2021-03-15 22:06:28 -04:00
FRDGTextureRef OutputTexture ,
const FLightSceneProxy * LightProxy = nullptr ,
int32 VirtualShadowMapId = INDEX_NONE )
2021-01-25 18:20:37 -04:00
{
2021-03-28 14:38:43 -04:00
// Use hair strands data (i.e., hair voxel tracing) only for Gbuffer input for casting hair shadow onto opaque geometry.
2021-05-06 05:46:35 -04:00
const bool bHasHairStrandsData = HairStrands : : HasViewHairStrandsData ( View ) ;
2021-05-20 19:32:20 -04:00
const bool bAdaptiveRayCount = GRHISupportsWaveOperations & & CVarSMRTAdaptiveRayCount . GetValueOnRenderThread ( ) ! = 0 ;
2021-03-28 14:38:43 -04:00
2021-01-25 18:20:37 -04:00
FVirtualShadowMapProjectionCS : : FParameters * PassParameters = GraphBuilder . AllocParameters < FVirtualShadowMapProjectionCS : : FParameters > ( ) ;
2021-03-08 23:14:54 -04:00
PassParameters - > SamplingParameters = VirtualShadowMapArray . GetSamplingParameters ( GraphBuilder ) ;
2021-01-25 18:20:37 -04:00
PassParameters - > SceneTexturesStruct = SceneTextures . UniformBuffer ;
PassParameters - > View = View . ViewUniformBuffer ;
2021-03-15 22:06:28 -04:00
PassParameters - > ProjectionRect = FIntVector4 ( ProjectionRect . Min . X , ProjectionRect . Min . Y , ProjectionRect . Max . X , ProjectionRect . Max . Y ) ;
2021-01-25 18:20:37 -04:00
PassParameters - > ContactShadowLength = CVarContactShadowLength . GetValueOnRenderThread ( ) ;
2021-04-22 16:30:49 -04:00
PassParameters - > NormalBias = GetNormalBiasForShader ( ) ;
2021-03-16 11:33:44 -04:00
PassParameters - > InputType = uint32 ( InputType ) ;
2021-03-28 14:38:43 -04:00
if ( bHasHairStrandsData )
{
2021-05-06 05:46:35 -04:00
PassParameters - > HairStrands = HairStrands : : BindHairStrandsViewUniformParameters ( View ) ;
2021-03-28 14:38:43 -04:00
PassParameters - > HairStrandsVoxel = HairStrands : : BindHairStrandsVoxelUniformParameters ( View ) ;
}
2021-01-25 18:20:37 -04:00
2021-03-15 22:06:28 -04:00
bool bDirectionalLight = false ;
bool bOnePassProjection = LightProxy = = nullptr ;
if ( bOnePassProjection )
{
// One pass projection
PassParameters - > ForwardLightData = View . ForwardLightingResources - > ForwardLightDataUniformBuffer ;
PassParameters - > VirtualShadowMapIdRemap = GraphBuilder . CreateSRV ( VirtualShadowMapArray . VirtualShadowMapIdRemapRDG [ 0 ] ) ; // FIXME Index proper view
PassParameters - > RWShadowMaskBits = GraphBuilder . CreateUAV ( OutputTexture ) ;
}
else
{
// Pass per light
bDirectionalLight = LightProxy - > GetLightType ( ) = = LightType_Directional ;
FLightShaderParameters LightParameters ;
LightProxy - > GetLightShaderParameters ( LightParameters ) ;
PassParameters - > Light = LightParameters ;
PassParameters - > LightUniformVirtualShadowMapId = VirtualShadowMapId ;
2021-04-26 15:47:32 -04:00
PassParameters - > RWShadowFactor = GraphBuilder . CreateUAV ( OutputTexture ) ;
2021-03-15 22:06:28 -04:00
}
if ( bDirectionalLight )
{
PassParameters - > SMRTRayCount = CVarSMRTRayCountDirectional . GetValueOnRenderThread ( ) ;
PassParameters - > SMRTSamplesPerRay = CVarSMRTSamplesPerRayDirectional . GetValueOnRenderThread ( ) ;
PassParameters - > SMRTRayLengthScale = CVarSMRTRayLengthScaleDirectional . GetValueOnRenderThread ( ) ;
PassParameters - > SMRTCotMaxRayAngleFromLight = 0.0f ; // unused in this path
}
else
{
PassParameters - > SMRTRayCount = CVarSMRTRayCountLocal . GetValueOnRenderThread ( ) ;
PassParameters - > SMRTSamplesPerRay = CVarSMRTSamplesPerRayLocal . GetValueOnRenderThread ( ) ;
PassParameters - > SMRTRayLengthScale = 0.0f ; // unused in this path
PassParameters - > SMRTCotMaxRayAngleFromLight = 1.0f / FMath : : Tan ( CVarSMRTMaxRayAngleFromLight . GetValueOnRenderThread ( ) ) ;
}
2021-01-27 21:04:55 -04:00
2021-05-20 19:32:20 -04:00
bool bDebugOutput = false ;
# if !UE_BUILD_SHIPPING
if ( VirtualShadowMapArray . DebugVisualizationProjectionOutput & & InputType = = EVirtualShadowMapProjectionInputType : : GBuffer )
{
bDebugOutput = true ;
PassParameters - > DebugOutputType = VirtualShadowMapArray . DebugOutputType ;
PassParameters - > DebugVirtualShadowMapId = VirtualShadowMapArray . DebugVirtualShadowMapId ;
PassParameters - > PhysicalPageMetaData = GraphBuilder . CreateSRV ( VirtualShadowMapArray . PhysicalPageMetaDataRDG ) ;
PassParameters - > RWDebug = GraphBuilder . CreateUAV ( VirtualShadowMapArray . DebugVisualizationProjectionOutput ) ;
}
# endif
2021-02-09 17:01:35 -04:00
2021-01-27 21:04:55 -04:00
FVirtualShadowMapProjectionCS : : FPermutationDomain PermutationVector ;
2021-03-15 22:06:28 -04:00
PermutationVector . Set < FVirtualShadowMapProjectionCS : : FDirectionalLightDim > ( bDirectionalLight ) ;
PermutationVector . Set < FVirtualShadowMapProjectionCS : : FOnePassProjectionDim > ( bOnePassProjection ) ;
2021-02-09 17:01:35 -04:00
PermutationVector . Set < FVirtualShadowMapProjectionCS : : FSMRTAdaptiveRayCountDim > ( bAdaptiveRayCount ) ;
2021-02-22 20:13:11 -04:00
PermutationVector . Set < FVirtualShadowMapProjectionCS : : FTwoPhysicalTexturesDim > ( GVirtualShadowMapAtomicWrites = = 0 ) ;
2021-05-20 19:32:20 -04:00
PermutationVector . Set < FVirtualShadowMapProjectionCS : : FHairStrandsDim > ( bHasHairStrandsData ? 1 : 0 ) ;
PermutationVector . Set < FVirtualShadowMapProjectionCS : : FDebugOutputDim > ( bDebugOutput ) ;
2021-01-27 21:04:55 -04:00
auto ComputeShader = View . ShaderMap - > GetShader < FVirtualShadowMapProjectionCS > ( PermutationVector ) ;
2021-03-15 22:06:28 -04:00
ClearUnusedGraphResources ( ComputeShader , PassParameters ) ;
ValidateShaderParameters ( ComputeShader , * PassParameters ) ;
2021-01-25 18:20:37 -04:00
2021-03-15 22:06:28 -04:00
const FIntPoint GroupCount = FIntPoint : : DivideAndRoundUp ( ProjectionRect . Size ( ) , 8 ) ;
2021-01-25 18:20:37 -04:00
FComputeShaderUtils : : AddPass (
GraphBuilder ,
2021-05-20 19:32:20 -04:00
RDG_EVENT_NAME ( " VirtualShadowMapProjection(RayCount:%s,Input:%s%s) " ,
2021-03-28 14:38:43 -04:00
bAdaptiveRayCount ? TEXT ( " Adaptive " ) : TEXT ( " Static " ) ,
2021-05-20 19:32:20 -04:00
( InputType = = EVirtualShadowMapProjectionInputType : : HairStrands ) ? TEXT ( " HairStrands " ) : TEXT ( " GBuffer " ) ,
bDebugOutput ? TEXT ( " ,Debug " ) : TEXT ( " " ) ) ,
2021-01-25 18:20:37 -04:00
ComputeShader ,
PassParameters ,
FIntVector ( GroupCount . X , GroupCount . Y , 1 )
) ;
2021-01-27 21:04:55 -04:00
}
2021-03-15 22:06:28 -04:00
FRDGTextureRef RenderVirtualShadowMapProjectionOnePass (
FRDGBuilder & GraphBuilder ,
const FMinimalSceneTextures & SceneTextures ,
const FViewInfo & View ,
2021-03-31 14:18:27 -04:00
FVirtualShadowMapArray & VirtualShadowMapArray ,
EVirtualShadowMapProjectionInputType InputType )
2021-03-15 22:06:28 -04:00
{
FIntRect ProjectionRect = View . ViewRect ;
const FRDGTextureDesc ShadowMaskDesc = FRDGTextureDesc : : Create2D (
SceneTextures . Config . Extent ,
PF_R32_UINT ,
FClearValueBinding : : None ,
TexCreate_ShaderResource | TexCreate_UAV ) ;
2021-03-31 14:18:27 -04:00
FRDGTextureRef ShadowMaskBits = GraphBuilder . CreateTexture ( ShadowMaskDesc , InputType = = EVirtualShadowMapProjectionInputType : : HairStrands ? TEXT ( " ShadowMaskBits(HairStrands) " ) : TEXT ( " ShadowMaskBits(Gbuffer) " ) ) ;
2021-03-15 22:06:28 -04:00
RenderVirtualShadowMapProjectionCommon (
GraphBuilder ,
SceneTextures ,
View ,
VirtualShadowMapArray ,
ProjectionRect ,
2021-03-31 14:18:27 -04:00
InputType ,
2021-03-15 22:06:28 -04:00
ShadowMaskBits ) ;
return ShadowMaskBits ;
}
2021-04-26 15:47:32 -04:00
static FRDGTextureRef CreateShadowFactorTexture ( FRDGBuilder & GraphBuilder , FIntPoint Extent )
2021-03-15 22:06:28 -04:00
{
const FLinearColor ClearColor ( 0.0f , 0.0f , 0.0f , 0.0f ) ;
FRDGTextureDesc Desc = FRDGTextureDesc : : Create2D (
Extent ,
2021-04-26 15:47:32 -04:00
PF_R32_FLOAT ,
2021-03-15 22:06:28 -04:00
FClearValueBinding ( ClearColor ) ,
TexCreate_ShaderResource | TexCreate_UAV ) ;
2021-04-26 15:47:32 -04:00
FRDGTextureRef Texture = GraphBuilder . CreateTexture ( Desc , TEXT ( " Shadow.Virtual.ShadowFactor " ) ) ;
2021-03-15 22:06:28 -04:00
AddClearUAVPass ( GraphBuilder , GraphBuilder . CreateUAV ( Texture ) , ClearColor ) ;
return Texture ;
}
FRDGTextureRef RenderVirtualShadowMapProjection (
FRDGBuilder & GraphBuilder ,
const FMinimalSceneTextures & SceneTextures ,
const FViewInfo & View ,
FVirtualShadowMapArray & VirtualShadowMapArray ,
const FIntRect ScissorRect ,
2021-03-16 11:33:44 -04:00
EVirtualShadowMapProjectionInputType InputType ,
2021-03-15 22:06:28 -04:00
FProjectedShadowInfo * ShadowInfo )
2021-05-20 19:32:20 -04:00
{
2021-04-26 15:47:32 -04:00
FRDGTextureRef OutputTexture = CreateShadowFactorTexture ( GraphBuilder , SceneTextures . Config . Extent ) ;
2021-03-15 22:06:28 -04:00
RenderVirtualShadowMapProjectionCommon (
GraphBuilder ,
SceneTextures ,
View ,
VirtualShadowMapArray ,
ScissorRect ,
2021-03-16 11:33:44 -04:00
InputType ,
2021-04-26 15:47:32 -04:00
OutputTexture ,
2021-03-15 22:06:28 -04:00
ShadowInfo - > GetLightSceneInfo ( ) . Proxy ,
ShadowInfo - > VirtualShadowMaps [ 0 ] - > ID ) ;
2021-04-26 15:47:32 -04:00
return OutputTexture ;
2021-03-15 22:06:28 -04:00
}
FRDGTextureRef RenderVirtualShadowMapProjection (
FRDGBuilder & GraphBuilder ,
const FMinimalSceneTextures & SceneTextures ,
const FViewInfo & View ,
FVirtualShadowMapArray & VirtualShadowMapArray ,
const FIntRect ScissorRect ,
2021-03-16 11:33:44 -04:00
EVirtualShadowMapProjectionInputType InputType ,
2021-03-15 22:06:28 -04:00
const TSharedPtr < FVirtualShadowMapClipmap > & Clipmap )
{
2021-04-26 15:47:32 -04:00
FRDGTextureRef OutputTexture = CreateShadowFactorTexture ( GraphBuilder , SceneTextures . Config . Extent ) ;
2021-03-15 22:06:28 -04:00
RenderVirtualShadowMapProjectionCommon (
GraphBuilder ,
SceneTextures ,
View ,
VirtualShadowMapArray ,
ScissorRect ,
2021-03-16 11:33:44 -04:00
InputType ,
2021-04-26 15:47:32 -04:00
OutputTexture ,
2021-03-15 22:06:28 -04:00
Clipmap - > GetLightSceneInfo ( ) . Proxy ,
Clipmap - > GetVirtualShadowMap ( ) - > ID ) ;
2021-04-26 15:47:32 -04:00
return OutputTexture ;
2021-03-15 22:06:28 -04:00
}