2014-12-07 19:09:38 -05:00
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
2014-06-03 15:53:13 -04:00
/*=============================================================================
2014-09-03 18:17:19 -04:00
DistanceFieldSurfaceCacheLighting . cpp
2014-06-03 15:53:13 -04:00
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
# include "RendererPrivate.h"
# include "ScenePrivate.h"
# include "UniformBuffer.h"
# include "ShaderParameters.h"
# include "PostProcessing.h"
# include "SceneFilterRendering.h"
# include "DistanceFieldLightingShared.h"
2014-09-18 15:13:07 -04:00
# include "DistanceFieldSurfaceCacheLighting.h"
2014-12-16 20:00:22 -05:00
# include "DistanceFieldGlobalIllumination.h"
2014-06-03 15:53:13 -04:00
# include "PostProcessAmbientOcclusion.h"
2014-06-05 16:38:54 -04:00
# include "RHICommandList.h"
2014-08-21 06:03:00 -04:00
# include "SceneUtils.h"
2014-09-27 01:24:53 -04:00
# include "OneColorShader.h"
2014-12-16 20:00:22 -05:00
# include "BasePassRendering.h"
2015-02-06 23:31:19 -05:00
# include "HeightfieldLighting.h"
2014-06-03 15:53:13 -04:00
int32 GDistanceFieldAO = 1 ;
FAutoConsoleVariableRef CVarDistanceFieldAO (
TEXT ( " r.DistanceFieldAO " ) ,
GDistanceFieldAO ,
TEXT ( " Whether the distance field AO feature is allowed, which is used to implement shadows of Movable sky lights from static meshes. " ) ,
2014-12-15 15:29:48 -05:00
ECVF_Scalability | ECVF_RenderThreadSafe
2014-06-03 15:53:13 -04:00
) ;
2014-12-16 20:00:22 -05:00
bool IsDistanceFieldGIAllowed ( const FViewInfo & View )
{
2015-03-30 17:48:16 -04:00
return DoesPlatformSupportDistanceFieldGI ( View . GetShaderPlatform ( ) )
& & ( View . Family - > EngineShowFlags . VisualizeDistanceFieldGI | | ( View . Family - > EngineShowFlags . DistanceFieldGI & & GDistanceFieldGI & & View . Family - > EngineShowFlags . GlobalIllumination ) ) ;
2014-12-16 20:00:22 -05:00
}
2014-11-21 21:37:13 -05:00
2014-09-26 17:07:59 -04:00
int32 GAOPowerOfTwoBetweenLevels = 2 ;
FAutoConsoleVariableRef CVarAOPowerOfTwoBetweenLevels (
TEXT ( " r.AOPowerOfTwoBetweenLevels " ) ,
GAOPowerOfTwoBetweenLevels ,
TEXT ( " Power of two in resolution between refinement levels of the surface cache " ) ,
ECVF_Cheat | ECVF_RenderThreadSafe
) ;
2014-06-03 15:53:13 -04:00
int32 GAOMinLevel = 1 ;
FAutoConsoleVariableRef CVarAOMinLevel (
TEXT ( " r.AOMinLevel " ) ,
GAOMinLevel ,
TEXT ( " Smallest downsample power of 4 to use for surface cache population. \n " )
TEXT ( " The default is 1, which means every 8 full resolution pixels (BaseDownsampleFactor(2) * 4^1) will be checked for a valid interpolation from the cache or shaded. \n " )
TEXT ( " Going down to 0 gives less aliasing, and removes the need for gap filling, but costs a lot. " ) ,
ECVF_Cheat | ECVF_RenderThreadSafe
) ;
2015-01-29 14:46:20 -05:00
int32 GAOMaxLevel = FMath : : Min ( 2 , GAOMaxSupportedLevel ) ;
2014-06-03 15:53:13 -04:00
FAutoConsoleVariableRef CVarAOMaxLevel (
TEXT ( " r.AOMaxLevel " ) ,
GAOMaxLevel ,
TEXT ( " Largest downsample power of 4 to use for surface cache population. " ) ,
ECVF_Cheat | ECVF_RenderThreadSafe
) ;
int32 GAOReuseAcrossFrames = 1 ;
FAutoConsoleVariableRef CVarAOReuseAcrossFrames (
TEXT ( " r.AOReuseAcrossFrames " ) ,
GAOReuseAcrossFrames ,
TEXT ( " Whether to allow reusing surface cache results across frames. " ) ,
ECVF_Cheat | ECVF_RenderThreadSafe
) ;
2014-12-16 20:00:22 -05:00
float GAOTrimOldRecordsFraction = .2f ;
2014-06-03 15:53:13 -04:00
FAutoConsoleVariableRef CVarAOTrimOldRecordsFraction (
TEXT ( " r.AOTrimOldRecordsFraction " ) ,
GAOTrimOldRecordsFraction ,
TEXT ( " When r.AOReuseAcrossFrames is enabled, this is the fraction of the last frame's surface cache records that will not be reused. \n " )
TEXT ( " Low settings provide better performance, while values closer to 1 give faster lighting updates when dynamic scene changes are happening. " ) ,
ECVF_Cheat | ECVF_RenderThreadSafe
) ;
int32 GAOFillGaps = 1 ;
FAutoConsoleVariableRef CVarAOFillGaps (
TEXT ( " r.AOFillGaps " ) ,
GAOFillGaps ,
TEXT ( " Whether to fill in pixels using a screen space filter that had no valid world space interpolation weight from surface cache samples. \n " )
TEXT ( " This is needed whenever r.AOMinLevel is not 0. " ) ,
ECVF_Cheat | ECVF_RenderThreadSafe
) ;
2015-04-03 18:56:44 -04:00
int32 GAOFillGapsHighQuality = 1 ;
FAutoConsoleVariableRef CVarAOFillGapsHighQuality (
TEXT ( " r.AOFillGapsHighQuality " ) ,
GAOFillGapsHighQuality ,
TEXT ( " Whether to use the higher quality gap filling method that does a 5x5 gather, or the cheaper method that just looks up the 4 grid samples. " ) ,
ECVF_Cheat | ECVF_RenderThreadSafe
) ;
2014-06-03 15:53:13 -04:00
int32 GAOUseHistory = 1 ;
FAutoConsoleVariableRef CVarAOUseHistory (
TEXT ( " r.AOUseHistory " ) ,
GAOUseHistory ,
TEXT ( " Whether to apply a temporal filter to the distance field AO, which reduces flickering but also adds trails when occluders are moving. " ) ,
ECVF_Cheat | ECVF_RenderThreadSafe
) ;
2015-04-03 18:56:44 -04:00
int32 GAOHistoryStabilityPass = 1 ;
FAutoConsoleVariableRef CVarAOHistoryStabilityPass (
TEXT ( " r.AOHistoryStabilityPass " ) ,
GAOHistoryStabilityPass ,
TEXT ( " Whether to gather stable results to fill in holes in the temporal reprojection. Adds some GPU cost but improves temporal stability with foliage. " ) ,
ECVF_Cheat | ECVF_RenderThreadSafe
) ;
2014-06-03 15:53:13 -04:00
float GAOHistoryWeight = .7f ;
FAutoConsoleVariableRef CVarAOHistoryWeight (
TEXT ( " r.AOHistoryWeight " ) ,
GAOHistoryWeight ,
TEXT ( " Amount of last frame's AO to lerp into the final result. Higher values increase stability, lower values have less streaking under occluder movement. " ) ,
ECVF_Cheat | ECVF_RenderThreadSafe
) ;
2015-03-30 17:48:16 -04:00
float GAOHistoryDistanceThreshold = 20 ;
FAutoConsoleVariableRef CVarAOHistoryDistanceThreshold (
TEXT ( " r.AOHistoryDistanceThreshold " ) ,
GAOHistoryDistanceThreshold ,
TEXT ( " World space distance threshold needed to discard last frame's DFAO results. Lower values reduce ghosting from characters when near a wall but increase flickering artifacts. " ) ,
ECVF_Cheat | ECVF_RenderThreadSafe
) ;
2014-06-03 15:53:13 -04:00
float GAORecordRadiusScale = .3f ;
FAutoConsoleVariableRef CVarAORecordRadiusScale (
TEXT ( " r.AORecordRadiusScale " ) ,
GAORecordRadiusScale ,
TEXT ( " Scale applied to the minimum occluder distance to produce the record radius. This effectively controls how dense shading samples are. " ) ,
ECVF_Cheat | ECVF_RenderThreadSafe
) ;
2014-09-26 17:07:59 -04:00
float GAOInterpolationRadiusScale = 1.3f ;
2014-06-03 15:53:13 -04:00
FAutoConsoleVariableRef CVarAOInterpolationRadiusScale (
TEXT ( " r.AOInterpolationRadiusScale " ) ,
GAOInterpolationRadiusScale ,
TEXT ( " Scale applied to record radii during the final interpolation pass. Values larger than 1 result in world space smoothing. " ) ,
ECVF_Cheat | ECVF_RenderThreadSafe
) ;
float GAOMinPointBehindPlaneAngle = 4 ;
FAutoConsoleVariableRef CVarAOMinPointBehindPlaneAngle (
TEXT ( " r.AOMinPointBehindPlaneAngle " ) ,
GAOMinPointBehindPlaneAngle ,
TEXT ( " Minimum angle that a point can lie behind a record and still be considered valid. \n " )
TEXT ( " This threshold helps reduce leaking that happens when interpolating records in front of the shading point, ignoring occluders in between. " ) ,
ECVF_Cheat | ECVF_RenderThreadSafe
) ;
2014-09-26 17:07:59 -04:00
float GAOInterpolationMaxAngle = 15 ;
2014-06-03 15:53:13 -04:00
FAutoConsoleVariableRef CVarAOInterpolationMaxAngle (
TEXT ( " r.AOInterpolationMaxAngle " ) ,
GAOInterpolationMaxAngle ,
TEXT ( " Largest angle allowed between the shading point's normal and a nearby record's normal. " ) ,
ECVF_Cheat | ECVF_RenderThreadSafe
) ;
float GAOInterpolationAngleScale = 1.5f ;
FAutoConsoleVariableRef CVarAOInterpolationAngleScale (
TEXT ( " r.AOInterpolationAngleScale " ) ,
GAOInterpolationAngleScale ,
TEXT ( " Scale applied to angle error during the final interpolation pass. Values larger than 1 result in smoothing. " ) ,
ECVF_Cheat | ECVF_RenderThreadSafe
) ;
float GAOStepExponentScale = .5f ;
FAutoConsoleVariableRef CVarAOStepExponentScale (
TEXT ( " r.AOStepExponentScale " ) ,
GAOStepExponentScale ,
TEXT ( " Exponent used to distribute AO samples along a cone direction. " ) ,
ECVF_Cheat | ECVF_RenderThreadSafe
) ;
float GAOMaxViewDistance = 10000 ;
FAutoConsoleVariableRef CVarAOMaxViewDistance (
TEXT ( " r.AOMaxViewDistance " ) ,
GAOMaxViewDistance ,
TEXT ( " The maximum distance that AO will be computed at. " ) ,
ECVF_Cheat | ECVF_RenderThreadSafe
) ;
2015-04-21 13:39:25 -04:00
float GAOViewFadeDistanceScale = .7f ;
2015-01-29 14:46:20 -05:00
FAutoConsoleVariableRef CVarAOViewFadeDistanceScale (
TEXT ( " r.AOViewFadeDistanceScale " ) ,
GAOViewFadeDistanceScale ,
TEXT ( " Distance over which AO will fade out as it approaches r.AOMaxViewDistance, as a fraction of r.AOMaxViewDistance. " ) ,
ECVF_Cheat | ECVF_RenderThreadSafe
) ;
2014-06-03 15:53:13 -04:00
int32 GAOScatterTileCulling = 1 ;
FAutoConsoleVariableRef CVarAOScatterTileCulling (
TEXT ( " r.AOScatterTileCulling " ) ,
GAOScatterTileCulling ,
TEXT ( " Whether to use the rasterizer for binning occluder objects into screenspace tiles. " ) ,
ECVF_Cheat | ECVF_RenderThreadSafe
) ;
2015-04-03 18:56:44 -04:00
int32 GAOComputeShaderNormalCalculation = 0 ;
2014-06-03 15:53:13 -04:00
FAutoConsoleVariableRef CVarAOComputeShaderNormalCalculation (
TEXT ( " r.AOComputeShaderNormalCalculation " ) ,
GAOComputeShaderNormalCalculation ,
TEXT ( " Whether to use the compute shader version of the distance field normal computation. " ) ,
ECVF_Cheat | ECVF_RenderThreadSafe
) ;
2014-06-04 17:01:43 -04:00
int32 GAOSampleSet = 1 ;
FAutoConsoleVariableRef CVarAOSampleSet (
TEXT ( " r.AOSampleSet " ) ,
GAOSampleSet ,
TEXT ( " 0 = Original set, 1 = Relaxed set " ) ,
ECVF_Cheat | ECVF_RenderThreadSafe
) ;
2014-09-26 17:07:59 -04:00
int32 GAOInterpolationStencilTesting = 1 ;
FAutoConsoleVariableRef CVarAOInterpolationStencilTesting (
TEXT ( " r.AOInterpolationStencilTesting " ) ,
GAOInterpolationStencilTesting ,
TEXT ( " Whether to stencil out distant pixels from the interpolation splat pass, useful for debugging " ) ,
ECVF_Cheat | ECVF_RenderThreadSafe
) ;
2015-04-03 18:56:44 -04:00
int32 GAOInterpolationDepthTesting = 1 ;
2014-09-26 17:07:59 -04:00
FAutoConsoleVariableRef CVarAOInterpolationDepthTesting (
TEXT ( " r.AOInterpolationDepthTesting " ) ,
GAOInterpolationDepthTesting ,
TEXT ( " Whether to use depth testing during the interpolation splat pass, useful for debugging " ) ,
ECVF_Cheat | ECVF_RenderThreadSafe
) ;
2014-11-21 21:37:13 -05:00
int32 GAOOverwriteSceneColor = 0 ;
FAutoConsoleVariableRef CVarAOOverwriteSceneColor (
TEXT ( " r.AOOverwriteSceneColor " ) ,
GAOOverwriteSceneColor ,
TEXT ( " " ) ,
ECVF_Cheat | ECVF_RenderThreadSafe
) ;
2015-01-29 14:46:20 -05:00
DEFINE_LOG_CATEGORY ( LogDistanceField ) ;
2014-06-03 15:53:13 -04:00
IMPLEMENT_UNIFORM_BUFFER_STRUCT ( FAOSampleData2 , TEXT ( " AOSamples2 " ) ) ;
FIntPoint GetBufferSizeForAO ( )
{
2014-09-26 17:07:59 -04:00
return FIntPoint : : DivideAndRoundDown ( GSceneRenderTargets . GetBufferSizeXY ( ) , GAODownsampleFactor ) ;
2014-06-03 15:53:13 -04:00
}
2014-06-04 17:01:43 -04:00
// Sample set restricted to not self-intersect a surface based on cone angle .475882232
// Coverage of hemisphere = 0.755312979
const FVector SpacedVectors9 [ ] =
{
FVector ( - 0.573257625 , 0.625250816 , 0.529563010 ) ,
FVector ( 0.253354192 , - 0.840093017 , 0.479640961 ) ,
FVector ( - 0.421664953 , - 0.718063235 , 0.553700149 ) ,
FVector ( 0.249163717 , 0.796005428 , 0.551627457 ) ,
FVector ( 0.375082791 , 0.295851320 , 0.878512800 ) ,
FVector ( - 0.217619032 , 0.00193520682 , 0.976031899 ) ,
FVector ( - 0.852834642 , 0.0111727007 , 0.522061586 ) ,
FVector ( 0.745701790 , 0.239393353 , 0.621787369 ) ,
FVector ( - 0.151036426 , - 0.465937436 , 0.871831656 )
} ;
// Generated from SpacedVectors9 by applying repulsion forces until convergence
const FVector RelaxedSpacedVectors9 [ ] =
{
FVector ( - 0.467612 , 0.739424 , 0.484347 ) ,
FVector ( 0.517459 , - 0.705440 , 0.484346 ) ,
FVector ( - 0.419848 , - 0.767551 , 0.484347 ) ,
FVector ( 0.343077 , 0.804802 , 0.484347 ) ,
FVector ( 0.364239 , 0.244290 , 0.898695 ) ,
FVector ( - 0.381547 , 0.185815 , 0.905481 ) ,
FVector ( - 0.870176 , - 0.090559 , 0.484347 ) ,
FVector ( 0.874448 , 0.027390 , 0.484346 ) ,
FVector ( 0.032967 , - 0.435625 , 0.899524 )
} ;
void GetSpacedVectors ( TArray < FVector , TInlineAllocator < 9 > > & OutVectors )
{
OutVectors . Empty ( ARRAY_COUNT ( SpacedVectors9 ) ) ;
if ( GAOSampleSet = = 0 )
{
for ( int32 i = 0 ; i < ARRAY_COUNT ( SpacedVectors9 ) ; i + + )
{
OutVectors . Add ( SpacedVectors9 [ i ] ) ;
}
}
else
{
for ( int32 i = 0 ; i < ARRAY_COUNT ( RelaxedSpacedVectors9 ) ; i + + )
{
OutVectors . Add ( RelaxedSpacedVectors9 [ i ] ) ;
}
}
}
2014-06-03 15:53:13 -04:00
// Cone half angle derived from each cone covering an equal solid angle
float GAOConeHalfAngle = FMath : : Acos ( 1 - 1.0f / ( float ) ARRAY_COUNT ( SpacedVectors9 ) ) ;
// Number of AO sample positions along each cone
// Must match shader code
uint32 GAONumConeSteps = 10 ;
2014-09-26 17:07:59 -04:00
class FCircleVertexBuffer : public FVertexBuffer
{
public :
int32 NumSections ;
FCircleVertexBuffer ( )
{
NumSections = 8 ;
}
virtual void InitRHI ( ) override
{
// Used as a non-indexed triangle list, so 3 vertices per triangle
const uint32 Size = 3 * NumSections * sizeof ( FScreenVertex ) ;
FRHIResourceCreateInfo CreateInfo ;
VertexBufferRHI = RHICreateVertexBuffer ( Size , BUF_Static , CreateInfo ) ;
void * Buffer = RHILockVertexBuffer ( VertexBufferRHI , 0 , Size , RLM_WriteOnly ) ;
FScreenVertex * DestVertex = ( FScreenVertex * ) Buffer ;
const float RadiansPerRingSegment = PI / ( float ) NumSections ;
// Boost the effective radius so that the edges of the circle approximation lie on the circle, instead of the vertices
const float Radius = 1.0f / FMath : : Cos ( RadiansPerRingSegment ) ;
for ( int32 SectionIndex = 0 ; SectionIndex < NumSections ; SectionIndex + + )
{
float Fraction = SectionIndex / ( float ) NumSections ;
float CurrentAngle = Fraction * 2 * PI ;
float NextAngle = ( ( SectionIndex + 1 ) / ( float ) NumSections ) * 2 * PI ;
FVector2D CurrentPosition ( Radius * FMath : : Cos ( CurrentAngle ) , Radius * FMath : : Sin ( CurrentAngle ) ) ;
FVector2D NextPosition ( Radius * FMath : : Cos ( NextAngle ) , Radius * FMath : : Sin ( NextAngle ) ) ;
DestVertex [ SectionIndex * 3 + 0 ] . Position = FVector2D ( 0 , 0 ) ;
DestVertex [ SectionIndex * 3 + 0 ] . UV = CurrentPosition ;
DestVertex [ SectionIndex * 3 + 1 ] . Position = FVector2D ( 0 , 0 ) ;
DestVertex [ SectionIndex * 3 + 1 ] . UV = NextPosition ;
DestVertex [ SectionIndex * 3 + 2 ] . Position = FVector2D ( 0 , 0 ) ;
DestVertex [ SectionIndex * 3 + 2 ] . UV = FVector2D ( .5f , .5f ) ;
}
RHIUnlockVertexBuffer ( VertexBufferRHI ) ;
}
} ;
2014-06-03 15:53:13 -04:00
TGlobalResource < FCircleVertexBuffer > GCircleVertexBuffer ;
2014-11-21 22:32:16 -05:00
TGlobalResource < FDistanceFieldObjectBufferResource > GAOCulledObjectBuffers ;
2015-01-29 14:46:20 -05:00
TGlobalResource < FTemporaryIrradianceCacheResources > GTemporaryIrradianceCacheResources ;
2014-09-18 15:13:07 -04:00
void FTileIntersectionResources : : InitDynamicRHI ( )
{
TileConeAxisAndCos . Initialize ( sizeof ( float ) * 4 , TileDimensions . X * TileDimensions . Y , PF_A32B32G32R32F , BUF_Static ) ;
TileConeDepthRanges . Initialize ( sizeof ( float ) * 4 , TileDimensions . X * TileDimensions . Y , PF_A32B32G32R32F , BUF_Static ) ;
TileHeadDataUnpacked . Initialize ( sizeof ( uint32 ) , TileDimensions . X * TileDimensions . Y * 4 , PF_R32_UINT , BUF_Static ) ;
TileHeadData . Initialize ( sizeof ( uint32 ) * 4 , TileDimensions . X * TileDimensions . Y , PF_R32G32B32A32_UINT , BUF_Static ) ;
//@todo - handle max exceeded
2014-11-21 22:32:16 -05:00
TileArrayData . Initialize ( sizeof ( uint32 ) , GMaxNumObjectsPerTile * TileDimensions . X * TileDimensions . Y * 3 , PF_R32_UINT , BUF_Static ) ;
2014-09-18 15:13:07 -04:00
TileArrayNextAllocation . Initialize ( sizeof ( uint32 ) , 1 , PF_R32_UINT , BUF_Static ) ;
}
2014-06-03 15:53:13 -04:00
2014-09-26 17:07:59 -04:00
void OnClearSurfaceCache ( UWorld * InWorld )
2014-06-03 15:53:13 -04:00
{
FlushRenderingCommands ( ) ;
FScene * Scene = ( FScene * ) InWorld - > Scene ;
if ( Scene & & Scene - > SurfaceCacheResources )
{
Scene - > SurfaceCacheResources - > bClearedResources = false ;
}
}
FAutoConsoleCommandWithWorld ClearCacheConsoleCommand (
TEXT ( " r.AOClearCache " ) ,
TEXT ( " " ) ,
2014-09-26 17:07:59 -04:00
FConsoleCommandWithWorldDelegate : : CreateStatic ( OnClearSurfaceCache )
2014-06-03 15:53:13 -04:00
) ;
2015-01-29 14:46:20 -05:00
bool bListMemoryNextFrame = false ;
2014-11-21 22:32:16 -05:00
2015-01-29 14:46:20 -05:00
void OnListMemory ( UWorld * InWorld )
2014-11-21 22:32:16 -05:00
{
2015-01-29 14:46:20 -05:00
bListMemoryNextFrame = true ;
}
2014-11-21 22:32:16 -05:00
2015-01-29 14:46:20 -05:00
FAutoConsoleCommandWithWorld ListMemoryConsoleCommand (
TEXT ( " r.AOListMemory " ) ,
TEXT ( " " ) ,
FConsoleCommandWithWorldDelegate : : CreateStatic ( OnListMemory )
) ;
2014-11-21 22:32:16 -05:00
class FCullObjectsForViewCS : public FGlobalShader
{
DECLARE_SHADER_TYPE ( FCullObjectsForViewCS , Global )
public :
static bool ShouldCache ( EShaderPlatform Platform )
{
return IsFeatureLevelSupported ( Platform , ERHIFeatureLevel : : SM5 ) & & DoesPlatformSupportDistanceFieldAO ( Platform ) ;
}
static void ModifyCompilationEnvironment ( EShaderPlatform Platform , FShaderCompilerEnvironment & OutEnvironment )
{
FGlobalShader : : ModifyCompilationEnvironment ( Platform , OutEnvironment ) ;
OutEnvironment . SetDefine ( TEXT ( " UPDATEOBJECTS_THREADGROUP_SIZE " ) , UpdateObjectsGroupSize ) ;
}
FCullObjectsForViewCS ( const ShaderMetaType : : CompiledShaderInitializerType & Initializer )
: FGlobalShader ( Initializer )
{
ObjectBufferParameters . Bind ( Initializer . ParameterMap ) ;
ObjectIndirectArguments . Bind ( Initializer . ParameterMap , TEXT ( " ObjectIndirectArguments " ) ) ;
CulledObjectBounds . Bind ( Initializer . ParameterMap , TEXT ( " CulledObjectBounds " ) ) ;
CulledObjectData . Bind ( Initializer . ParameterMap , TEXT ( " CulledObjectData " ) ) ;
CulledObjectBoxBounds . Bind ( Initializer . ParameterMap , TEXT ( " CulledObjectBoxBounds " ) ) ;
AOParameters . Bind ( Initializer . ParameterMap ) ;
2014-11-24 17:38:29 -05:00
NumConvexHullPlanes . Bind ( Initializer . ParameterMap , TEXT ( " NumConvexHullPlanes " ) ) ;
2014-11-21 22:32:16 -05:00
ViewFrustumConvexHull . Bind ( Initializer . ParameterMap , TEXT ( " ViewFrustumConvexHull " ) ) ;
ObjectBoundingGeometryIndexCount . Bind ( Initializer . ParameterMap , TEXT ( " ObjectBoundingGeometryIndexCount " ) ) ;
}
FCullObjectsForViewCS ( )
{
}
void SetParameters ( FRHICommandList & RHICmdList , const FScene * Scene , const FSceneView & View , const FDistanceFieldAOParameters & Parameters )
{
FComputeShaderRHIParamRef ShaderRHI = GetComputeShader ( ) ;
FGlobalShader : : SetParameters ( RHICmdList , ShaderRHI , View ) ;
ObjectBufferParameters . Set ( RHICmdList , ShaderRHI , * ( Scene - > DistanceFieldSceneData . ObjectBuffers ) , Scene - > DistanceFieldSceneData . NumObjectsInBuffer ) ;
ObjectIndirectArguments . SetBuffer ( RHICmdList , ShaderRHI , GAOCulledObjectBuffers . Buffers . ObjectIndirectArguments ) ;
CulledObjectBounds . SetBuffer ( RHICmdList , ShaderRHI , GAOCulledObjectBuffers . Buffers . Bounds ) ;
CulledObjectData . SetBuffer ( RHICmdList , ShaderRHI , GAOCulledObjectBuffers . Buffers . Data ) ;
CulledObjectBoxBounds . SetBuffer ( RHICmdList , ShaderRHI , GAOCulledObjectBuffers . Buffers . BoxBounds ) ;
AOParameters . Set ( RHICmdList , ShaderRHI , Parameters ) ;
2014-11-24 17:38:29 -05:00
// Shader assumes max 6
2014-12-16 20:00:22 -05:00
check ( View . ViewFrustum . Planes . Num ( ) < = 6 ) ;
2014-11-24 17:38:29 -05:00
SetShaderValue ( RHICmdList , ShaderRHI , NumConvexHullPlanes , View . ViewFrustum . Planes . Num ( ) ) ;
2014-11-21 22:32:16 -05:00
SetShaderValueArray ( RHICmdList , ShaderRHI , ViewFrustumConvexHull , View . ViewFrustum . Planes . GetData ( ) , View . ViewFrustum . Planes . Num ( ) ) ;
SetShaderValue ( RHICmdList , ShaderRHI , ObjectBoundingGeometryIndexCount , StencilingGeometry : : GLowPolyStencilSphereIndexBuffer . GetIndexCount ( ) ) ;
}
void UnsetParameters ( FRHICommandList & RHICmdList )
{
ObjectBufferParameters . UnsetParameters ( RHICmdList , GetComputeShader ( ) ) ;
ObjectIndirectArguments . UnsetUAV ( RHICmdList , GetComputeShader ( ) ) ;
CulledObjectBounds . UnsetUAV ( RHICmdList , GetComputeShader ( ) ) ;
CulledObjectData . UnsetUAV ( RHICmdList , GetComputeShader ( ) ) ;
CulledObjectBoxBounds . UnsetUAV ( RHICmdList , GetComputeShader ( ) ) ;
}
virtual bool Serialize ( FArchive & Ar )
{
bool bShaderHasOutdatedParameters = FGlobalShader : : Serialize ( Ar ) ;
Ar < < ObjectBufferParameters ;
Ar < < ObjectIndirectArguments ;
Ar < < CulledObjectBounds ;
Ar < < CulledObjectData ;
Ar < < CulledObjectBoxBounds ;
Ar < < AOParameters ;
2014-11-24 17:38:29 -05:00
Ar < < NumConvexHullPlanes ;
2014-11-21 22:32:16 -05:00
Ar < < ViewFrustumConvexHull ;
Ar < < ObjectBoundingGeometryIndexCount ;
return bShaderHasOutdatedParameters ;
}
private :
FDistanceFieldObjectBufferParameters ObjectBufferParameters ;
FRWShaderParameter ObjectIndirectArguments ;
FRWShaderParameter CulledObjectBounds ;
FRWShaderParameter CulledObjectData ;
FRWShaderParameter CulledObjectBoxBounds ;
FAOParameters AOParameters ;
2014-11-24 17:38:29 -05:00
FShaderParameter NumConvexHullPlanes ;
2014-11-21 22:32:16 -05:00
FShaderParameter ViewFrustumConvexHull ;
FShaderParameter ObjectBoundingGeometryIndexCount ;
} ;
IMPLEMENT_SHADER_TYPE ( , FCullObjectsForViewCS , TEXT ( " DistanceFieldSurfaceCacheLightingCompute " ) , TEXT ( " CullObjectsForViewCS " ) , SF_Compute ) ;
2014-06-03 15:53:13 -04:00
/** */
class FBuildTileConesCS : public FGlobalShader
{
DECLARE_SHADER_TYPE ( FBuildTileConesCS , Global )
public :
static bool ShouldCache ( EShaderPlatform Platform )
{
2014-06-26 15:53:01 -04:00
return IsFeatureLevelSupported ( Platform , ERHIFeatureLevel : : SM5 ) & & DoesPlatformSupportDistanceFieldAO ( Platform ) ;
2014-06-03 15:53:13 -04:00
}
static void ModifyCompilationEnvironment ( EShaderPlatform Platform , FShaderCompilerEnvironment & OutEnvironment )
{
FGlobalShader : : ModifyCompilationEnvironment ( Platform , OutEnvironment ) ;
OutEnvironment . SetDefine ( TEXT ( " THREADGROUP_SIZEX " ) , GDistanceFieldAOTileSizeX ) ;
OutEnvironment . SetDefine ( TEXT ( " THREADGROUP_SIZEY " ) , GDistanceFieldAOTileSizeY ) ;
2014-09-11 18:30:45 -04:00
OutEnvironment . SetDefine ( TEXT ( " NUM_CONE_DIRECTIONS " ) , NumConeSampleDirections ) ;
2014-06-03 15:53:13 -04:00
OutEnvironment . SetDefine ( TEXT ( " DOWNSAMPLE_FACTOR " ) , GAODownsampleFactor ) ;
// To reduce shader compile time of compute shaders with shared memory, doesn't have an impact on generated code with current compiler (June 2010 DX SDK)
OutEnvironment . CompilerFlags . Add ( CFLAG_StandardOptimization ) ;
}
FBuildTileConesCS ( const ShaderMetaType : : CompiledShaderInitializerType & Initializer )
: FGlobalShader ( Initializer )
{
DeferredParameters . Bind ( Initializer . ParameterMap ) ;
AOParameters . Bind ( Initializer . ParameterMap ) ;
TileConeAxisAndCos . Bind ( Initializer . ParameterMap , TEXT ( " TileConeAxisAndCos " ) ) ;
TileConeDepthRanges . Bind ( Initializer . ParameterMap , TEXT ( " TileConeDepthRanges " ) ) ;
TileHeadDataUnpacked . Bind ( Initializer . ParameterMap , TEXT ( " TileHeadDataUnpacked " ) ) ;
NumGroups . Bind ( Initializer . ParameterMap , TEXT ( " NumGroups " ) ) ;
ViewDimensionsParameter . Bind ( Initializer . ParameterMap , TEXT ( " ViewDimensions " ) ) ;
2015-04-03 18:56:44 -04:00
DistanceFieldNormalTexture . Bind ( Initializer . ParameterMap , TEXT ( " DistanceFieldNormalTexture " ) ) ;
DistanceFieldNormalSampler . Bind ( Initializer . ParameterMap , TEXT ( " DistanceFieldNormalSampler " ) ) ;
2014-06-03 15:53:13 -04:00
}
FBuildTileConesCS ( )
{
}
2015-04-03 18:56:44 -04:00
void SetParameters ( FRHICommandList & RHICmdList , const FSceneView & View , FSceneRenderTargetItem & DistanceFieldNormal , FScene * Scene , FVector2D NumGroupsValue , const FDistanceFieldAOParameters & Parameters )
2014-06-03 15:53:13 -04:00
{
FComputeShaderRHIParamRef ShaderRHI = GetComputeShader ( ) ;
2014-06-05 16:38:54 -04:00
FGlobalShader : : SetParameters ( RHICmdList , ShaderRHI , View ) ;
DeferredParameters . Set ( RHICmdList , ShaderRHI , View ) ;
2014-08-28 13:54:31 -04:00
AOParameters . Set ( RHICmdList , ShaderRHI , Parameters ) ;
2014-06-03 15:53:13 -04:00
FTileIntersectionResources * TileIntersectionResources = ( ( FSceneViewState * ) View . State ) - > AOTileIntersectionResources ;
2014-06-05 16:38:54 -04:00
TileConeAxisAndCos . SetBuffer ( RHICmdList , ShaderRHI , TileIntersectionResources - > TileConeAxisAndCos ) ;
TileConeDepthRanges . SetBuffer ( RHICmdList , ShaderRHI , TileIntersectionResources - > TileConeDepthRanges ) ;
TileHeadDataUnpacked . SetBuffer ( RHICmdList , ShaderRHI , TileIntersectionResources - > TileHeadDataUnpacked ) ;
2014-06-03 15:53:13 -04:00
2014-06-05 16:38:54 -04:00
SetShaderValue ( RHICmdList , ShaderRHI , ViewDimensionsParameter , View . ViewRect ) ;
2014-06-03 15:53:13 -04:00
2014-06-05 16:38:54 -04:00
SetShaderValue ( RHICmdList , ShaderRHI , NumGroups , NumGroupsValue ) ;
2015-04-03 18:56:44 -04:00
SetTextureParameter (
RHICmdList ,
ShaderRHI ,
DistanceFieldNormalTexture ,
DistanceFieldNormalSampler ,
TStaticSamplerState < SF_Point , AM_Clamp , AM_Clamp , AM_Clamp > : : GetRHI ( ) ,
DistanceFieldNormal . ShaderResourceTexture
) ;
2014-06-03 15:53:13 -04:00
}
2014-06-10 07:29:49 -04:00
void UnsetParameters ( FRHICommandList & RHICmdList )
2014-06-03 15:53:13 -04:00
{
2014-06-05 16:38:54 -04:00
TileConeAxisAndCos . UnsetUAV ( RHICmdList , GetComputeShader ( ) ) ;
TileConeDepthRanges . UnsetUAV ( RHICmdList , GetComputeShader ( ) ) ;
TileHeadDataUnpacked . UnsetUAV ( RHICmdList , GetComputeShader ( ) ) ;
2014-06-03 15:53:13 -04:00
}
virtual bool Serialize ( FArchive & Ar )
{
bool bShaderHasOutdatedParameters = FGlobalShader : : Serialize ( Ar ) ;
Ar < < DeferredParameters ;
Ar < < AOParameters ;
Ar < < TileConeAxisAndCos ;
Ar < < TileConeDepthRanges ;
Ar < < TileHeadDataUnpacked ;
Ar < < NumGroups ;
Ar < < ViewDimensionsParameter ;
2015-04-03 18:56:44 -04:00
Ar < < DistanceFieldNormalTexture ;
Ar < < DistanceFieldNormalSampler ;
2014-06-03 15:53:13 -04:00
return bShaderHasOutdatedParameters ;
}
private :
FDeferredPixelShaderParameters DeferredParameters ;
FAOParameters AOParameters ;
FRWShaderParameter TileConeAxisAndCos ;
FRWShaderParameter TileConeDepthRanges ;
FRWShaderParameter TileHeadDataUnpacked ;
FShaderParameter ViewDimensionsParameter ;
FShaderParameter NumGroups ;
2015-04-03 18:56:44 -04:00
FShaderResourceParameter DistanceFieldNormalTexture ;
FShaderResourceParameter DistanceFieldNormalSampler ;
2014-06-03 15:53:13 -04:00
} ;
IMPLEMENT_SHADER_TYPE ( , FBuildTileConesCS , TEXT ( " DistanceFieldSurfaceCacheLightingCompute " ) , TEXT ( " BuildTileConesMain " ) , SF_Compute ) ;
/** */
class FObjectCullVS : public FGlobalShader
{
DECLARE_SHADER_TYPE ( FObjectCullVS , Global ) ;
public :
static bool ShouldCache ( EShaderPlatform Platform )
{
2014-06-26 15:53:01 -04:00
return IsFeatureLevelSupported ( Platform , ERHIFeatureLevel : : SM5 ) & & DoesPlatformSupportDistanceFieldAO ( Platform ) ;
2014-06-03 15:53:13 -04:00
}
static void ModifyCompilationEnvironment ( EShaderPlatform Platform , FShaderCompilerEnvironment & OutEnvironment )
{
FGlobalShader : : ModifyCompilationEnvironment ( Platform , OutEnvironment ) ;
}
FObjectCullVS ( const ShaderMetaType : : CompiledShaderInitializerType & Initializer ) :
FGlobalShader ( Initializer )
{
ObjectParameters . Bind ( Initializer . ParameterMap ) ;
AOParameters . Bind ( Initializer . ParameterMap ) ;
ConservativeRadiusScale . Bind ( Initializer . ParameterMap , TEXT ( " ConservativeRadiusScale " ) ) ;
}
FObjectCullVS ( ) { }
2014-11-21 22:32:16 -05:00
void SetParameters ( FRHICommandList & RHICmdList , const FSceneView & View , const FDistanceFieldAOParameters & Parameters )
2014-06-03 15:53:13 -04:00
{
const FVertexShaderRHIParamRef ShaderRHI = GetVertexShader ( ) ;
2014-06-05 16:38:54 -04:00
FGlobalShader : : SetParameters ( RHICmdList , ShaderRHI , View ) ;
2014-06-03 15:53:13 -04:00
2014-11-21 22:32:16 -05:00
ObjectParameters . Set ( RHICmdList , ShaderRHI , GAOCulledObjectBuffers . Buffers ) ;
2014-08-28 13:54:31 -04:00
AOParameters . Set ( RHICmdList , ShaderRHI , Parameters ) ;
2014-06-03 15:53:13 -04:00
const int32 NumRings = StencilingGeometry : : GLowPolyStencilSphereVertexBuffer . GetNumRings ( ) ;
const float RadiansPerRingSegment = PI / ( float ) NumRings ;
// Boost the effective radius so that the edges of the sphere approximation lie on the sphere, instead of the vertices
const float ConservativeRadiusScaleValue = 1.0f / FMath : : Cos ( RadiansPerRingSegment ) ;
2014-06-05 16:38:54 -04:00
SetShaderValue ( RHICmdList , ShaderRHI , ConservativeRadiusScale , ConservativeRadiusScaleValue ) ;
2014-06-03 15:53:13 -04:00
}
2015-04-01 07:20:55 -04:00
virtual bool Serialize ( FArchive & Ar ) override
2014-06-03 15:53:13 -04:00
{
bool bShaderHasOutdatedParameters = FGlobalShader : : Serialize ( Ar ) ;
Ar < < ObjectParameters ;
Ar < < AOParameters ;
Ar < < ConservativeRadiusScale ;
return bShaderHasOutdatedParameters ;
}
private :
2014-11-21 22:32:16 -05:00
FDistanceFieldCulledObjectBufferParameters ObjectParameters ;
2014-06-03 15:53:13 -04:00
FAOParameters AOParameters ;
FShaderParameter ConservativeRadiusScale ;
} ;
IMPLEMENT_SHADER_TYPE ( , FObjectCullVS , TEXT ( " DistanceFieldSurfaceCacheLighting " ) , TEXT ( " ObjectCullVS " ) , SF_Vertex ) ;
class FObjectCullPS : public FGlobalShader
{
DECLARE_SHADER_TYPE ( FObjectCullPS , Global ) ;
public :
static bool ShouldCache ( EShaderPlatform Platform )
{
2014-06-26 15:53:01 -04:00
return IsFeatureLevelSupported ( Platform , ERHIFeatureLevel : : SM5 ) & & DoesPlatformSupportDistanceFieldAO ( Platform ) ;
2014-06-03 15:53:13 -04:00
}
static void ModifyCompilationEnvironment ( EShaderPlatform Platform , FShaderCompilerEnvironment & OutEnvironment )
{
FGlobalShader : : ModifyCompilationEnvironment ( Platform , OutEnvironment ) ;
OutEnvironment . SetDefine ( TEXT ( " DOWNSAMPLE_FACTOR " ) , GAODownsampleFactor ) ;
}
/** Default constructor. */
FObjectCullPS ( ) { }
/** Initialization constructor. */
FObjectCullPS ( const ShaderMetaType : : CompiledShaderInitializerType & Initializer )
: FGlobalShader ( Initializer )
{
AOParameters . Bind ( Initializer . ParameterMap ) ;
TileHeadDataUnpacked . Bind ( Initializer . ParameterMap , TEXT ( " TileHeadDataUnpacked " ) ) ;
TileArrayData . Bind ( Initializer . ParameterMap , TEXT ( " TileArrayData " ) ) ;
TileConeAxisAndCos . Bind ( Initializer . ParameterMap , TEXT ( " TileConeAxisAndCos " ) ) ;
TileConeDepthRanges . Bind ( Initializer . ParameterMap , TEXT ( " TileConeDepthRanges " ) ) ;
NumGroups . Bind ( Initializer . ParameterMap , TEXT ( " NumGroups " ) ) ;
}
2014-08-28 13:54:31 -04:00
void SetParameters ( FRHICommandList & RHICmdList , const FSceneView & View , FVector2D NumGroupsValue , const FDistanceFieldAOParameters & Parameters )
2014-06-03 15:53:13 -04:00
{
const FPixelShaderRHIParamRef ShaderRHI = GetPixelShader ( ) ;
2014-06-05 16:38:54 -04:00
FGlobalShader : : SetParameters ( RHICmdList , ShaderRHI , View ) ;
2014-08-28 13:54:31 -04:00
AOParameters . Set ( RHICmdList , ShaderRHI , Parameters ) ;
2014-06-03 15:53:13 -04:00
FTileIntersectionResources * TileIntersectionResources = ( ( FSceneViewState * ) View . State ) - > AOTileIntersectionResources ;
2014-06-05 16:38:54 -04:00
SetSRVParameter ( RHICmdList , ShaderRHI , TileConeAxisAndCos , TileIntersectionResources - > TileConeAxisAndCos . SRV ) ;
SetSRVParameter ( RHICmdList , ShaderRHI , TileConeDepthRanges , TileIntersectionResources - > TileConeDepthRanges . SRV ) ;
2014-06-03 15:53:13 -04:00
2014-06-05 16:38:54 -04:00
SetShaderValue ( RHICmdList , ShaderRHI , NumGroups , NumGroupsValue ) ;
2014-06-03 15:53:13 -04:00
}
void GetUAVs ( const FSceneView & View , TArray < FUnorderedAccessViewRHIParamRef > & UAVs )
{
FTileIntersectionResources * TileIntersectionResources = ( ( FSceneViewState * ) View . State ) - > AOTileIntersectionResources ;
int32 MaxIndex = FMath : : Max ( TileHeadDataUnpacked . GetUAVIndex ( ) , TileArrayData . GetUAVIndex ( ) ) ;
UAVs . AddZeroed ( MaxIndex + 1 ) ;
if ( TileHeadDataUnpacked . IsBound ( ) )
{
UAVs [ TileHeadDataUnpacked . GetUAVIndex ( ) ] = TileIntersectionResources - > TileHeadDataUnpacked . UAV ;
}
if ( TileArrayData . IsBound ( ) )
{
UAVs [ TileArrayData . GetUAVIndex ( ) ] = TileIntersectionResources - > TileArrayData . UAV ;
}
check ( UAVs . Num ( ) > 0 ) ;
}
// FShader interface.
2015-04-01 07:20:55 -04:00
virtual bool Serialize ( FArchive & Ar ) override
2014-06-03 15:53:13 -04:00
{
bool bShaderHasOutdatedParameters = FGlobalShader : : Serialize ( Ar ) ;
Ar < < AOParameters ;
Ar < < TileHeadDataUnpacked ;
Ar < < TileArrayData ;
Ar < < TileConeAxisAndCos ;
Ar < < TileConeDepthRanges ;
Ar < < NumGroups ;
return bShaderHasOutdatedParameters ;
}
private :
FAOParameters AOParameters ;
FRWShaderParameter TileHeadDataUnpacked ;
FRWShaderParameter TileArrayData ;
FShaderResourceParameter TileConeAxisAndCos ;
FShaderResourceParameter TileConeDepthRanges ;
FShaderParameter NumGroups ;
} ;
IMPLEMENT_SHADER_TYPE ( , FObjectCullPS , TEXT ( " DistanceFieldSurfaceCacheLighting " ) , TEXT ( " ObjectCullPS " ) , SF_Pixel ) ;
/** */
class FDistanceFieldBuildTileListCS : public FGlobalShader
{
DECLARE_SHADER_TYPE ( FDistanceFieldBuildTileListCS , Global )
public :
static bool ShouldCache ( EShaderPlatform Platform )
{
2014-06-26 15:53:01 -04:00
return IsFeatureLevelSupported ( Platform , ERHIFeatureLevel : : SM5 ) & & DoesPlatformSupportDistanceFieldAO ( Platform ) ;
2014-06-03 15:53:13 -04:00
}
static void ModifyCompilationEnvironment ( EShaderPlatform Platform , FShaderCompilerEnvironment & OutEnvironment )
{
FGlobalShader : : ModifyCompilationEnvironment ( Platform , OutEnvironment ) ;
OutEnvironment . SetDefine ( TEXT ( " THREADGROUP_SIZEX " ) , GDistanceFieldAOTileSizeX ) ;
OutEnvironment . SetDefine ( TEXT ( " THREADGROUP_SIZEY " ) , GDistanceFieldAOTileSizeY ) ;
2014-09-11 18:30:45 -04:00
OutEnvironment . SetDefine ( TEXT ( " NUM_CONE_DIRECTIONS " ) , NumConeSampleDirections ) ;
2014-06-03 15:53:13 -04:00
OutEnvironment . SetDefine ( TEXT ( " DOWNSAMPLE_FACTOR " ) , GAODownsampleFactor ) ;
// To reduce shader compile time of compute shaders with shared memory, doesn't have an impact on generated code with current compiler (June 2010 DX SDK)
OutEnvironment . CompilerFlags . Add ( CFLAG_StandardOptimization ) ;
}
FDistanceFieldBuildTileListCS ( const ShaderMetaType : : CompiledShaderInitializerType & Initializer )
: FGlobalShader ( Initializer )
{
DeferredParameters . Bind ( Initializer . ParameterMap ) ;
ObjectParameters . Bind ( Initializer . ParameterMap ) ;
AOParameters . Bind ( Initializer . ParameterMap ) ;
TileHeadData . Bind ( Initializer . ParameterMap , TEXT ( " TileHeadData " ) ) ;
TileArrayData . Bind ( Initializer . ParameterMap , TEXT ( " TileArrayData " ) ) ;
TileArrayNextAllocation . Bind ( Initializer . ParameterMap , TEXT ( " TileArrayNextAllocation " ) ) ;
NumGroups . Bind ( Initializer . ParameterMap , TEXT ( " NumGroups " ) ) ;
ViewDimensionsParameter . Bind ( Initializer . ParameterMap , TEXT ( " ViewDimensions " ) ) ;
}
FDistanceFieldBuildTileListCS ( )
{
}
2014-11-21 22:32:16 -05:00
void SetParameters ( FRHICommandList & RHICmdList , const FSceneView & View , FScene * Scene , FVector2D NumGroupsValue , const FDistanceFieldAOParameters & Parameters )
2014-06-03 15:53:13 -04:00
{
FComputeShaderRHIParamRef ShaderRHI = GetComputeShader ( ) ;
2014-06-05 16:38:54 -04:00
FGlobalShader : : SetParameters ( RHICmdList , ShaderRHI , View ) ;
DeferredParameters . Set ( RHICmdList , ShaderRHI , View ) ;
2014-11-21 22:32:16 -05:00
ObjectParameters . Set ( RHICmdList , ShaderRHI , GAOCulledObjectBuffers . Buffers ) ;
2014-08-28 13:54:31 -04:00
AOParameters . Set ( RHICmdList , ShaderRHI , Parameters ) ;
2014-06-03 15:53:13 -04:00
FTileIntersectionResources * TileIntersectionResources = ( ( FSceneViewState * ) View . State ) - > AOTileIntersectionResources ;
2014-06-05 16:38:54 -04:00
TileHeadData . SetBuffer ( RHICmdList , ShaderRHI , TileIntersectionResources - > TileHeadData ) ;
TileArrayData . SetBuffer ( RHICmdList , ShaderRHI , TileIntersectionResources - > TileArrayData ) ;
TileArrayNextAllocation . SetBuffer ( RHICmdList , ShaderRHI , TileIntersectionResources - > TileArrayNextAllocation ) ;
2014-06-03 15:53:13 -04:00
2014-06-05 16:38:54 -04:00
SetShaderValue ( RHICmdList , ShaderRHI , ViewDimensionsParameter , View . ViewRect ) ;
2014-06-03 15:53:13 -04:00
2014-06-05 16:38:54 -04:00
SetShaderValue ( RHICmdList , ShaderRHI , NumGroups , NumGroupsValue ) ;
2014-06-03 15:53:13 -04:00
}
2014-06-10 07:29:49 -04:00
void UnsetParameters ( FRHICommandList & RHICmdList )
2014-06-03 15:53:13 -04:00
{
2014-06-05 16:38:54 -04:00
TileHeadData . UnsetUAV ( RHICmdList , GetComputeShader ( ) ) ;
TileArrayData . UnsetUAV ( RHICmdList , GetComputeShader ( ) ) ;
TileArrayNextAllocation . UnsetUAV ( RHICmdList , GetComputeShader ( ) ) ;
2014-06-03 15:53:13 -04:00
}
2015-04-01 07:20:55 -04:00
virtual bool Serialize ( FArchive & Ar ) override
2014-06-03 15:53:13 -04:00
{
bool bShaderHasOutdatedParameters = FGlobalShader : : Serialize ( Ar ) ;
Ar < < DeferredParameters ;
Ar < < ObjectParameters ;
Ar < < AOParameters ;
Ar < < TileHeadData ;
Ar < < TileArrayData ;
Ar < < TileArrayNextAllocation ;
Ar < < NumGroups ;
Ar < < ViewDimensionsParameter ;
return bShaderHasOutdatedParameters ;
}
private :
FDeferredPixelShaderParameters DeferredParameters ;
2014-11-21 22:32:16 -05:00
FDistanceFieldCulledObjectBufferParameters ObjectParameters ;
2014-06-03 15:53:13 -04:00
FAOParameters AOParameters ;
FRWShaderParameter TileHeadData ;
FRWShaderParameter TileArrayData ;
FRWShaderParameter TileArrayNextAllocation ;
FShaderParameter ViewDimensionsParameter ;
FShaderParameter NumGroups ;
} ;
IMPLEMENT_SHADER_TYPE ( , FDistanceFieldBuildTileListCS , TEXT ( " DistanceFieldSurfaceCacheLightingCompute " ) , TEXT ( " DistanceFieldAOBuildTileListMain " ) , SF_Compute ) ;
class FAOLevelParameters
{
public :
void Bind ( const FShaderParameterMap & ParameterMap )
{
CurrentLevelDownsampleFactor . Bind ( ParameterMap , TEXT ( " CurrentLevelDownsampleFactor " ) ) ;
AOBufferSize . Bind ( ParameterMap , TEXT ( " AOBufferSize " ) ) ;
DownsampleFactorToBaseLevel . Bind ( ParameterMap , TEXT ( " DownsampleFactorToBaseLevel " ) ) ;
BaseLevelTexelSize . Bind ( ParameterMap , TEXT ( " BaseLevelTexelSize " ) ) ;
}
template < typename TParamRef >
2014-06-10 07:29:49 -04:00
void Set ( FRHICommandList & RHICmdList , const TParamRef & ShaderRHI , const FSceneView & View , int32 CurrentLevelDownsampleFactorValue )
2014-06-03 15:53:13 -04:00
{
2014-06-05 16:38:54 -04:00
SetShaderValue ( RHICmdList , ShaderRHI , CurrentLevelDownsampleFactor , CurrentLevelDownsampleFactorValue ) ;
2014-06-03 15:53:13 -04:00
// Round up, to match render target allocation
2014-09-26 19:53:37 -04:00
const FVector2D AOBufferSizeValue = FIntPoint : : DivideAndRoundUp ( GSceneRenderTargets . GetBufferSizeXY ( ) , CurrentLevelDownsampleFactorValue ) ;
2014-06-05 16:38:54 -04:00
SetShaderValue ( RHICmdList , ShaderRHI , AOBufferSize , AOBufferSizeValue ) ;
2014-06-03 15:53:13 -04:00
2014-06-05 16:38:54 -04:00
SetShaderValue ( RHICmdList , ShaderRHI , DownsampleFactorToBaseLevel , CurrentLevelDownsampleFactorValue / GAODownsampleFactor ) ;
2014-06-03 15:53:13 -04:00
2014-09-26 19:53:37 -04:00
const FIntPoint DownsampledBufferSize = GetBufferSizeForAO ( ) ;
2014-06-03 15:53:13 -04:00
const FVector2D BaseLevelBufferSizeValue ( 1.0f / DownsampledBufferSize . X , 1.0f / DownsampledBufferSize . Y ) ;
2014-06-05 16:38:54 -04:00
SetShaderValue ( RHICmdList , ShaderRHI , BaseLevelTexelSize , BaseLevelBufferSizeValue ) ;
2014-06-03 15:53:13 -04:00
}
friend FArchive & operator < < ( FArchive & Ar , FAOLevelParameters & P )
{
2014-06-06 14:14:50 -04:00
Ar < < P . CurrentLevelDownsampleFactor < < P . AOBufferSize < < P . DownsampleFactorToBaseLevel < < P . BaseLevelTexelSize ;
2014-06-03 15:53:13 -04:00
return Ar ;
}
private :
FShaderParameter CurrentLevelDownsampleFactor ;
FShaderParameter AOBufferSize ;
FShaderParameter DownsampleFactorToBaseLevel ;
FShaderParameter BaseLevelTexelSize ;
} ;
class FComputeDistanceFieldNormalPS : public FGlobalShader
{
DECLARE_SHADER_TYPE ( FComputeDistanceFieldNormalPS , Global ) ;
public :
static bool ShouldCache ( EShaderPlatform Platform )
{
2014-06-26 15:53:01 -04:00
return IsFeatureLevelSupported ( Platform , ERHIFeatureLevel : : SM5 ) & & DoesPlatformSupportDistanceFieldAO ( Platform ) ;
2014-06-03 15:53:13 -04:00
}
static void ModifyCompilationEnvironment ( EShaderPlatform Platform , FShaderCompilerEnvironment & OutEnvironment )
{
OutEnvironment . SetDefine ( TEXT ( " DOWNSAMPLE_FACTOR " ) , GAODownsampleFactor ) ;
OutEnvironment . SetDefine ( TEXT ( " THREADGROUP_SIZEX " ) , GDistanceFieldAOTileSizeX ) ;
OutEnvironment . SetDefine ( TEXT ( " THREADGROUP_SIZEY " ) , GDistanceFieldAOTileSizeY ) ;
}
/** Default constructor. */
FComputeDistanceFieldNormalPS ( ) { }
/** Initialization constructor. */
FComputeDistanceFieldNormalPS ( const ShaderMetaType : : CompiledShaderInitializerType & Initializer )
: FGlobalShader ( Initializer )
{
DeferredParameters . Bind ( Initializer . ParameterMap ) ;
AOParameters . Bind ( Initializer . ParameterMap ) ;
}
2014-11-21 22:32:16 -05:00
void SetParameters ( FRHICommandList & RHICmdList , const FSceneView & View , const FDistanceFieldAOParameters & Parameters )
2014-06-03 15:53:13 -04:00
{
const FPixelShaderRHIParamRef ShaderRHI = GetPixelShader ( ) ;
2014-06-05 16:38:54 -04:00
FGlobalShader : : SetParameters ( RHICmdList , ShaderRHI , View ) ;
2014-08-28 13:54:31 -04:00
AOParameters . Set ( RHICmdList , ShaderRHI , Parameters ) ;
2014-06-05 16:38:54 -04:00
DeferredParameters . Set ( RHICmdList , ShaderRHI , View ) ;
2014-06-03 15:53:13 -04:00
}
// FShader interface.
2015-04-01 07:20:55 -04:00
virtual bool Serialize ( FArchive & Ar ) override
2014-06-03 15:53:13 -04:00
{
bool bShaderHasOutdatedParameters = FGlobalShader : : Serialize ( Ar ) ;
Ar < < DeferredParameters ;
Ar < < AOParameters ;
return bShaderHasOutdatedParameters ;
}
private :
FDeferredPixelShaderParameters DeferredParameters ;
FAOParameters AOParameters ;
} ;
IMPLEMENT_SHADER_TYPE ( , FComputeDistanceFieldNormalPS , TEXT ( " DistanceFieldSurfaceCacheLighting " ) , TEXT ( " ComputeDistanceFieldNormalPS " ) , SF_Pixel ) ;
class FComputeDistanceFieldNormalCS : public FGlobalShader
{
DECLARE_SHADER_TYPE ( FComputeDistanceFieldNormalCS , Global ) ;
public :
static bool ShouldCache ( EShaderPlatform Platform )
{
2014-06-26 15:53:01 -04:00
return IsFeatureLevelSupported ( Platform , ERHIFeatureLevel : : SM5 ) & & DoesPlatformSupportDistanceFieldAO ( Platform ) ;
2014-06-03 15:53:13 -04:00
}
static void ModifyCompilationEnvironment ( EShaderPlatform Platform , FShaderCompilerEnvironment & OutEnvironment )
{
OutEnvironment . SetDefine ( TEXT ( " DOWNSAMPLE_FACTOR " ) , GAODownsampleFactor ) ;
OutEnvironment . SetDefine ( TEXT ( " THREADGROUP_SIZEX " ) , GDistanceFieldAOTileSizeX ) ;
OutEnvironment . SetDefine ( TEXT ( " THREADGROUP_SIZEY " ) , GDistanceFieldAOTileSizeY ) ;
}
/** Default constructor. */
FComputeDistanceFieldNormalCS ( ) { }
/** Initialization constructor. */
FComputeDistanceFieldNormalCS ( const ShaderMetaType : : CompiledShaderInitializerType & Initializer )
: FGlobalShader ( Initializer )
{
DistanceFieldNormal . Bind ( Initializer . ParameterMap , TEXT ( " DistanceFieldNormal " ) ) ;
DeferredParameters . Bind ( Initializer . ParameterMap ) ;
AOParameters . Bind ( Initializer . ParameterMap ) ;
}
2014-11-21 22:32:16 -05:00
void SetParameters ( FRHICommandList & RHICmdList , const FSceneView & View , FSceneRenderTargetItem & DistanceFieldNormalValue , const FDistanceFieldAOParameters & Parameters )
2014-06-03 15:53:13 -04:00
{
const FComputeShaderRHIParamRef ShaderRHI = GetComputeShader ( ) ;
2014-06-05 16:38:54 -04:00
FGlobalShader : : SetParameters ( RHICmdList , ShaderRHI , View ) ;
2014-06-03 15:53:13 -04:00
2014-06-05 16:38:54 -04:00
DistanceFieldNormal . SetTexture ( RHICmdList , ShaderRHI , DistanceFieldNormalValue . ShaderResourceTexture , DistanceFieldNormalValue . UAV ) ;
2014-08-28 13:54:31 -04:00
AOParameters . Set ( RHICmdList , ShaderRHI , Parameters ) ;
2014-06-05 16:38:54 -04:00
DeferredParameters . Set ( RHICmdList , ShaderRHI , View ) ;
2014-06-03 15:53:13 -04:00
}
2014-06-10 07:29:49 -04:00
void UnsetParameters ( FRHICommandList & RHICmdList )
2014-06-03 15:53:13 -04:00
{
2014-06-05 16:38:54 -04:00
DistanceFieldNormal . UnsetUAV ( RHICmdList , GetComputeShader ( ) ) ;
2014-06-03 15:53:13 -04:00
}
// FShader interface.
2015-04-01 07:20:55 -04:00
virtual bool Serialize ( FArchive & Ar ) override
2014-06-03 15:53:13 -04:00
{
bool bShaderHasOutdatedParameters = FGlobalShader : : Serialize ( Ar ) ;
Ar < < DistanceFieldNormal ;
Ar < < DeferredParameters ;
Ar < < AOParameters ;
return bShaderHasOutdatedParameters ;
}
private :
FRWShaderParameter DistanceFieldNormal ;
2014-11-21 22:32:16 -05:00
FDistanceFieldCulledObjectBufferParameters ObjectParameters ;
2014-06-03 15:53:13 -04:00
FShaderParameter UVToTileHead ;
FDeferredPixelShaderParameters DeferredParameters ;
FAOParameters AOParameters ;
} ;
IMPLEMENT_SHADER_TYPE ( , FComputeDistanceFieldNormalCS , TEXT ( " DistanceFieldSurfaceCacheLighting " ) , TEXT ( " ComputeDistanceFieldNormalCS " ) , SF_Compute ) ;
2014-11-21 22:32:16 -05:00
void ComputeDistanceFieldNormal ( FRHICommandListImmediate & RHICmdList , const TArray < FViewInfo > & Views , FSceneRenderTargetItem & DistanceFieldNormal , const FDistanceFieldAOParameters & Parameters )
2014-06-03 15:53:13 -04:00
{
if ( GAOComputeShaderNormalCalculation )
{
2014-06-12 07:13:34 -04:00
SetRenderTarget ( RHICmdList , NULL , NULL ) ;
2014-06-03 15:53:13 -04:00
for ( int32 ViewIndex = 0 ; ViewIndex < Views . Num ( ) ; ViewIndex + + )
{
const FViewInfo & View = Views [ ViewIndex ] ;
uint32 GroupSizeX = FMath : : DivideAndRoundUp ( View . ViewRect . Size ( ) . X / GAODownsampleFactor , GDistanceFieldAOTileSizeX ) ;
uint32 GroupSizeY = FMath : : DivideAndRoundUp ( View . ViewRect . Size ( ) . Y / GAODownsampleFactor , GDistanceFieldAOTileSizeY ) ;
{
2014-10-20 10:43:43 -04:00
SCOPED_DRAW_EVENT ( RHICmdList , ComputeNormalCS ) ;
2014-08-28 06:22:54 -04:00
TShaderMapRef < FComputeDistanceFieldNormalCS > ComputeShader ( View . ShaderMap ) ;
2014-06-03 15:53:13 -04:00
2014-06-12 07:13:34 -04:00
RHICmdList . SetComputeShader ( ComputeShader - > GetComputeShader ( ) ) ;
2014-11-21 22:32:16 -05:00
ComputeShader - > SetParameters ( RHICmdList , View , DistanceFieldNormal , Parameters ) ;
2014-06-05 16:38:54 -04:00
DispatchComputeShader ( RHICmdList , * ComputeShader , GroupSizeX , GroupSizeY , 1 ) ;
2014-06-03 15:53:13 -04:00
2014-06-05 16:38:54 -04:00
ComputeShader - > UnsetParameters ( RHICmdList ) ;
2014-06-03 15:53:13 -04:00
}
}
}
else
{
2014-06-12 07:13:34 -04:00
SetRenderTarget ( RHICmdList , DistanceFieldNormal . TargetableTexture , NULL ) ;
2014-06-03 15:53:13 -04:00
for ( int32 ViewIndex = 0 ; ViewIndex < Views . Num ( ) ; ViewIndex + + )
{
const FViewInfo & View = Views [ ViewIndex ] ;
2014-10-20 10:43:43 -04:00
SCOPED_DRAW_EVENT ( RHICmdList , ComputeNormal ) ;
2014-06-03 15:53:13 -04:00
2014-07-10 21:07:13 -04:00
RHICmdList . SetViewport ( 0 , 0 , 0.0f , View . ViewRect . Width ( ) / GAODownsampleFactor , View . ViewRect . Height ( ) / GAODownsampleFactor , 1.0f ) ;
2014-06-12 07:13:34 -04:00
RHICmdList . SetRasterizerState ( TStaticRasterizerState < FM_Solid , CM_None > : : GetRHI ( ) ) ;
RHICmdList . SetDepthStencilState ( TStaticDepthStencilState < false , CF_Always > : : GetRHI ( ) ) ;
RHICmdList . SetBlendState ( TStaticBlendState < > : : GetRHI ( ) ) ;
2014-08-28 06:22:54 -04:00
TShaderMapRef < FPostProcessVS > VertexShader ( View . ShaderMap ) ;
TShaderMapRef < FComputeDistanceFieldNormalPS > PixelShader ( View . ShaderMap ) ;
2014-06-03 15:53:13 -04:00
static FGlobalBoundShaderState BoundShaderState ;
2014-06-27 11:07:13 -04:00
2014-08-28 06:22:54 -04:00
SetGlobalBoundShaderState ( RHICmdList , View . FeatureLevel , BoundShaderState , GFilterVertexDeclaration . VertexDeclarationRHI , * VertexShader , * PixelShader ) ;
2014-06-03 15:53:13 -04:00
2014-11-21 22:32:16 -05:00
PixelShader - > SetParameters ( RHICmdList , View , Parameters ) ;
2014-06-03 15:53:13 -04:00
DrawRectangle (
2014-06-12 07:13:34 -04:00
RHICmdList ,
2014-06-03 15:53:13 -04:00
0 , 0 ,
View . ViewRect . Width ( ) / GAODownsampleFactor , View . ViewRect . Height ( ) / GAODownsampleFactor ,
2014-07-10 21:07:13 -04:00
0 , 0 ,
2014-06-03 15:53:13 -04:00
View . ViewRect . Width ( ) , View . ViewRect . Height ( ) ,
FIntPoint ( View . ViewRect . Width ( ) / GAODownsampleFactor , View . ViewRect . Height ( ) / GAODownsampleFactor ) ,
GSceneRenderTargets . GetBufferSizeXY ( ) ,
* VertexShader ) ;
}
}
}
class FSetupCopyIndirectArgumentsCS : public FGlobalShader
{
DECLARE_SHADER_TYPE ( FSetupCopyIndirectArgumentsCS , Global )
public :
static bool ShouldCache ( EShaderPlatform Platform )
{
2014-06-26 15:53:01 -04:00
return IsFeatureLevelSupported ( Platform , ERHIFeatureLevel : : SM5 ) & & DoesPlatformSupportDistanceFieldAO ( Platform ) ;
2014-06-03 15:53:13 -04:00
}
static void ModifyCompilationEnvironment ( EShaderPlatform Platform , FShaderCompilerEnvironment & OutEnvironment )
{
FGlobalShader : : ModifyCompilationEnvironment ( Platform , OutEnvironment ) ;
OutEnvironment . CompilerFlags . Add ( CFLAG_StandardOptimization ) ;
}
FSetupCopyIndirectArgumentsCS ( const ShaderMetaType : : CompiledShaderInitializerType & Initializer )
: FGlobalShader ( Initializer )
{
DrawParameters . Bind ( Initializer . ParameterMap , TEXT ( " DrawParameters " ) ) ;
DispatchParameters . Bind ( Initializer . ParameterMap , TEXT ( " DispatchParameters " ) ) ;
2015-03-30 17:48:16 -04:00
ScatterDrawParameters . Bind ( Initializer . ParameterMap , TEXT ( " ScatterDrawParameters " ) ) ;
2014-06-03 15:53:13 -04:00
TrimFraction . Bind ( Initializer . ParameterMap , TEXT ( " TrimFraction " ) ) ;
}
FSetupCopyIndirectArgumentsCS ( )
{
}
2014-06-10 07:29:49 -04:00
void SetParameters ( FRHICommandList & RHICmdList , const FSceneView & View , int32 DepthLevel )
2014-06-03 15:53:13 -04:00
{
FComputeShaderRHIParamRef ShaderRHI = GetComputeShader ( ) ;
2014-06-05 16:38:54 -04:00
FGlobalShader : : SetParameters ( RHICmdList , ShaderRHI , View ) ;
2014-06-03 15:53:13 -04:00
const FScene * Scene = ( const FScene * ) View . Family - > Scene ;
FSurfaceCacheResources & SurfaceCacheResources = * Scene - > SurfaceCacheResources ;
2014-06-05 16:38:54 -04:00
SetSRVParameter ( RHICmdList , ShaderRHI , DrawParameters , SurfaceCacheResources . Level [ DepthLevel ] - > ScatterDrawParameters . SRV ) ;
2014-06-03 15:53:13 -04:00
2014-06-05 16:38:54 -04:00
DispatchParameters . SetBuffer ( RHICmdList , ShaderRHI , SurfaceCacheResources . DispatchParameters ) ;
2015-03-30 17:48:16 -04:00
ScatterDrawParameters . SetBuffer ( RHICmdList , ShaderRHI , SurfaceCacheResources . TempResources - > ScatterDrawParameters ) ;
2015-01-29 14:46:20 -05:00
SetShaderValue ( RHICmdList , ShaderRHI , TrimFraction , GAOTrimOldRecordsFraction ) ;
2014-06-03 15:53:13 -04:00
}
2014-06-10 07:29:49 -04:00
void UnsetParameters ( FRHICommandList & RHICmdList )
2014-06-03 15:53:13 -04:00
{
2014-06-05 16:38:54 -04:00
DispatchParameters . UnsetUAV ( RHICmdList , GetComputeShader ( ) ) ;
2015-03-30 17:48:16 -04:00
ScatterDrawParameters . UnsetUAV ( RHICmdList , GetComputeShader ( ) ) ;
2014-06-03 15:53:13 -04:00
}
2015-04-01 07:20:55 -04:00
virtual bool Serialize ( FArchive & Ar ) override
2014-06-03 15:53:13 -04:00
{
bool bShaderHasOutdatedParameters = FGlobalShader : : Serialize ( Ar ) ;
Ar < < DrawParameters ;
Ar < < DispatchParameters ;
2015-03-30 17:48:16 -04:00
Ar < < ScatterDrawParameters ;
2014-06-03 15:53:13 -04:00
Ar < < TrimFraction ;
return bShaderHasOutdatedParameters ;
}
private :
FShaderResourceParameter DrawParameters ;
FRWShaderParameter DispatchParameters ;
2015-03-30 17:48:16 -04:00
FRWShaderParameter ScatterDrawParameters ;
2014-06-03 15:53:13 -04:00
FShaderParameter TrimFraction ;
} ;
IMPLEMENT_SHADER_TYPE ( , FSetupCopyIndirectArgumentsCS , TEXT ( " DistanceFieldSurfaceCacheLightingCompute " ) , TEXT ( " SetupCopyIndirectArgumentsCS " ) , SF_Compute ) ;
2014-11-21 21:37:13 -05:00
template < bool bSupportIrradiance >
class TCopyIrradianceCacheSamplesCS : public FGlobalShader
2014-06-03 15:53:13 -04:00
{
2014-11-21 21:37:13 -05:00
DECLARE_SHADER_TYPE ( TCopyIrradianceCacheSamplesCS , Global )
2014-06-03 15:53:13 -04:00
public :
static bool ShouldCache ( EShaderPlatform Platform )
{
2014-06-26 15:53:01 -04:00
return IsFeatureLevelSupported ( Platform , ERHIFeatureLevel : : SM5 ) & & DoesPlatformSupportDistanceFieldAO ( Platform ) ;
2014-06-03 15:53:13 -04:00
}
static void ModifyCompilationEnvironment ( EShaderPlatform Platform , FShaderCompilerEnvironment & OutEnvironment )
{
FGlobalShader : : ModifyCompilationEnvironment ( Platform , OutEnvironment ) ;
OutEnvironment . CompilerFlags . Add ( CFLAG_StandardOptimization ) ;
2014-11-21 21:37:13 -05:00
OutEnvironment . SetDefine ( TEXT ( " SUPPORT_IRRADIANCE " ) , bSupportIrradiance ? TEXT ( " 1 " ) : TEXT ( " 0 " ) ) ;
2014-06-03 15:53:13 -04:00
}
2014-11-21 21:37:13 -05:00
TCopyIrradianceCacheSamplesCS ( const ShaderMetaType : : CompiledShaderInitializerType & Initializer )
2014-06-03 15:53:13 -04:00
: FGlobalShader ( Initializer )
{
IrradianceCachePositionRadius . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceCachePositionRadius " ) ) ;
IrradianceCacheNormal . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceCacheNormal " ) ) ;
OccluderRadius . Bind ( Initializer . ParameterMap , TEXT ( " OccluderRadius " ) ) ;
IrradianceCacheBentNormal . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceCacheBentNormal " ) ) ;
2014-11-21 21:37:13 -05:00
IrradianceCacheIrradiance . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceCacheIrradiance " ) ) ;
2014-06-03 15:53:13 -04:00
IrradianceCacheTileCoordinate . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceCacheTileCoordinate " ) ) ;
DrawParameters . Bind ( Initializer . ParameterMap , TEXT ( " DrawParameters " ) ) ;
CopyIrradianceCachePositionRadius . Bind ( Initializer . ParameterMap , TEXT ( " CopyIrradianceCachePositionRadius " ) ) ;
CopyIrradianceCacheNormal . Bind ( Initializer . ParameterMap , TEXT ( " CopyIrradianceCacheNormal " ) ) ;
CopyOccluderRadius . Bind ( Initializer . ParameterMap , TEXT ( " CopyOccluderRadius " ) ) ;
CopyIrradianceCacheBentNormal . Bind ( Initializer . ParameterMap , TEXT ( " CopyIrradianceCacheBentNormal " ) ) ;
2014-11-21 21:37:13 -05:00
CopyIrradianceCacheIrradiance . Bind ( Initializer . ParameterMap , TEXT ( " CopyIrradianceCacheIrradiance " ) ) ;
2014-06-03 15:53:13 -04:00
CopyIrradianceCacheTileCoordinate . Bind ( Initializer . ParameterMap , TEXT ( " CopyIrradianceCacheTileCoordinate " ) ) ;
ScatterDrawParameters . Bind ( Initializer . ParameterMap , TEXT ( " ScatterDrawParameters " ) ) ;
TrimFraction . Bind ( Initializer . ParameterMap , TEXT ( " TrimFraction " ) ) ;
}
2014-11-21 21:37:13 -05:00
TCopyIrradianceCacheSamplesCS ( )
2014-06-03 15:53:13 -04:00
{
}
2014-06-10 07:29:49 -04:00
void SetParameters ( FRHICommandList & RHICmdList , const FSceneView & View , int32 DepthLevel )
2014-06-03 15:53:13 -04:00
{
FComputeShaderRHIParamRef ShaderRHI = GetComputeShader ( ) ;
2014-06-05 16:38:54 -04:00
FGlobalShader : : SetParameters ( RHICmdList , ShaderRHI , View ) ;
2014-06-03 15:53:13 -04:00
const FScene * Scene = ( const FScene * ) View . Family - > Scene ;
FSurfaceCacheResources & SurfaceCacheResources = * Scene - > SurfaceCacheResources ;
2014-06-05 16:38:54 -04:00
SetSRVParameter ( RHICmdList , ShaderRHI , IrradianceCachePositionRadius , SurfaceCacheResources . Level [ DepthLevel ] - > PositionAndRadius . SRV ) ;
SetSRVParameter ( RHICmdList , ShaderRHI , IrradianceCacheNormal , SurfaceCacheResources . Level [ DepthLevel ] - > Normal . SRV ) ;
SetSRVParameter ( RHICmdList , ShaderRHI , OccluderRadius , SurfaceCacheResources . Level [ DepthLevel ] - > OccluderRadius . SRV ) ;
SetSRVParameter ( RHICmdList , ShaderRHI , IrradianceCacheBentNormal , SurfaceCacheResources . Level [ DepthLevel ] - > BentNormal . SRV ) ;
2014-11-21 21:37:13 -05:00
SetSRVParameter ( RHICmdList , ShaderRHI , IrradianceCacheIrradiance , SurfaceCacheResources . Level [ DepthLevel ] - > Irradiance . SRV ) ;
2014-06-05 16:38:54 -04:00
SetSRVParameter ( RHICmdList , ShaderRHI , IrradianceCacheTileCoordinate , SurfaceCacheResources . Level [ DepthLevel ] - > TileCoordinate . SRV ) ;
SetSRVParameter ( RHICmdList , ShaderRHI , DrawParameters , SurfaceCacheResources . Level [ DepthLevel ] - > ScatterDrawParameters . SRV ) ;
2014-06-03 15:53:13 -04:00
2014-06-05 16:38:54 -04:00
CopyIrradianceCachePositionRadius . SetBuffer ( RHICmdList , ShaderRHI , SurfaceCacheResources . TempResources - > PositionAndRadius ) ;
CopyIrradianceCacheNormal . SetBuffer ( RHICmdList , ShaderRHI , SurfaceCacheResources . TempResources - > Normal ) ;
CopyOccluderRadius . SetBuffer ( RHICmdList , ShaderRHI , SurfaceCacheResources . TempResources - > OccluderRadius ) ;
CopyIrradianceCacheBentNormal . SetBuffer ( RHICmdList , ShaderRHI , SurfaceCacheResources . TempResources - > BentNormal ) ;
2014-11-21 21:37:13 -05:00
CopyIrradianceCacheIrradiance . SetBuffer ( RHICmdList , ShaderRHI , SurfaceCacheResources . TempResources - > Irradiance ) ;
2014-06-05 16:38:54 -04:00
CopyIrradianceCacheTileCoordinate . SetBuffer ( RHICmdList , ShaderRHI , SurfaceCacheResources . TempResources - > TileCoordinate ) ;
ScatterDrawParameters . SetBuffer ( RHICmdList , ShaderRHI , SurfaceCacheResources . TempResources - > ScatterDrawParameters ) ;
2014-06-03 15:53:13 -04:00
2015-01-29 14:46:20 -05:00
SetShaderValue ( RHICmdList , ShaderRHI , TrimFraction , GAOTrimOldRecordsFraction ) ;
2014-06-03 15:53:13 -04:00
}
2014-06-10 07:29:49 -04:00
void UnsetParameters ( FRHICommandList & RHICmdList )
2014-06-03 15:53:13 -04:00
{
2014-06-05 16:38:54 -04:00
CopyIrradianceCachePositionRadius . UnsetUAV ( RHICmdList , GetComputeShader ( ) ) ;
CopyIrradianceCacheNormal . UnsetUAV ( RHICmdList , GetComputeShader ( ) ) ;
CopyOccluderRadius . UnsetUAV ( RHICmdList , GetComputeShader ( ) ) ;
CopyIrradianceCacheBentNormal . UnsetUAV ( RHICmdList , GetComputeShader ( ) ) ;
2015-01-29 14:46:20 -05:00
CopyIrradianceCacheIrradiance . UnsetUAV ( RHICmdList , GetComputeShader ( ) ) ;
2014-06-05 16:38:54 -04:00
CopyIrradianceCacheTileCoordinate . UnsetUAV ( RHICmdList , GetComputeShader ( ) ) ;
ScatterDrawParameters . UnsetUAV ( RHICmdList , GetComputeShader ( ) ) ;
2014-06-03 15:53:13 -04:00
}
2015-04-01 07:20:55 -04:00
virtual bool Serialize ( FArchive & Ar ) override
2014-06-03 15:53:13 -04:00
{
bool bShaderHasOutdatedParameters = FGlobalShader : : Serialize ( Ar ) ;
Ar < < IrradianceCachePositionRadius ;
Ar < < IrradianceCacheNormal ;
Ar < < OccluderRadius ;
Ar < < IrradianceCacheBentNormal ;
2014-11-21 21:37:13 -05:00
Ar < < IrradianceCacheIrradiance ;
2014-06-03 15:53:13 -04:00
Ar < < IrradianceCacheTileCoordinate ;
Ar < < DrawParameters ;
Ar < < CopyIrradianceCachePositionRadius ;
Ar < < CopyIrradianceCacheNormal ;
Ar < < CopyOccluderRadius ;
Ar < < CopyIrradianceCacheBentNormal ;
2014-11-21 21:37:13 -05:00
Ar < < CopyIrradianceCacheIrradiance ;
2014-06-03 15:53:13 -04:00
Ar < < CopyIrradianceCacheTileCoordinate ;
Ar < < ScatterDrawParameters ;
Ar < < TrimFraction ;
return bShaderHasOutdatedParameters ;
}
private :
FShaderResourceParameter IrradianceCachePositionRadius ;
FShaderResourceParameter IrradianceCacheNormal ;
FShaderResourceParameter OccluderRadius ;
FShaderResourceParameter IrradianceCacheBentNormal ;
2014-11-21 21:37:13 -05:00
FShaderResourceParameter IrradianceCacheIrradiance ;
2014-06-03 15:53:13 -04:00
FShaderResourceParameter IrradianceCacheTileCoordinate ;
FShaderResourceParameter DrawParameters ;
FRWShaderParameter CopyIrradianceCachePositionRadius ;
FRWShaderParameter CopyIrradianceCacheNormal ;
FRWShaderParameter CopyOccluderRadius ;
FRWShaderParameter CopyIrradianceCacheBentNormal ;
2014-11-21 21:37:13 -05:00
FRWShaderParameter CopyIrradianceCacheIrradiance ;
2014-06-03 15:53:13 -04:00
FRWShaderParameter CopyIrradianceCacheTileCoordinate ;
FRWShaderParameter ScatterDrawParameters ;
FShaderParameter TrimFraction ;
} ;
2014-11-21 21:37:13 -05:00
IMPLEMENT_SHADER_TYPE ( template < > , TCopyIrradianceCacheSamplesCS < true > , TEXT ( " DistanceFieldSurfaceCacheLightingCompute " ) , TEXT ( " CopyIrradianceCacheSamplesCS " ) , SF_Compute ) ;
IMPLEMENT_SHADER_TYPE ( template < > , TCopyIrradianceCacheSamplesCS < false > , TEXT ( " DistanceFieldSurfaceCacheLightingCompute " ) , TEXT ( " CopyIrradianceCacheSamplesCS " ) , SF_Compute ) ;
2014-06-03 15:53:13 -04:00
class FSaveStartIndexCS : public FGlobalShader
{
DECLARE_SHADER_TYPE ( FSaveStartIndexCS , Global )
public :
static bool ShouldCache ( EShaderPlatform Platform )
{
2014-06-26 15:53:01 -04:00
return IsFeatureLevelSupported ( Platform , ERHIFeatureLevel : : SM5 ) & & DoesPlatformSupportDistanceFieldAO ( Platform ) ;
2014-06-03 15:53:13 -04:00
}
FSaveStartIndexCS ( const ShaderMetaType : : CompiledShaderInitializerType & Initializer )
: FGlobalShader ( Initializer )
{
DrawParameters . Bind ( Initializer . ParameterMap , TEXT ( " DrawParameters " ) ) ;
SavedStartIndex . Bind ( Initializer . ParameterMap , TEXT ( " SavedStartIndex " ) ) ;
}
FSaveStartIndexCS ( )
{
}
2014-06-10 07:29:49 -04:00
void SetParameters ( FRHICommandList & RHICmdList , const FSceneView & View , int32 DepthLevel )
2014-06-03 15:53:13 -04:00
{
FComputeShaderRHIParamRef ShaderRHI = GetComputeShader ( ) ;
2014-06-05 16:38:54 -04:00
FGlobalShader : : SetParameters ( RHICmdList , ShaderRHI , View ) ;
2014-06-03 15:53:13 -04:00
const FScene * Scene = ( const FScene * ) View . Family - > Scene ;
FSurfaceCacheResources & SurfaceCacheResources = * Scene - > SurfaceCacheResources ;
2014-06-05 16:38:54 -04:00
SetSRVParameter ( RHICmdList , ShaderRHI , DrawParameters , SurfaceCacheResources . Level [ DepthLevel ] - > ScatterDrawParameters . SRV ) ;
SavedStartIndex . SetBuffer ( RHICmdList , ShaderRHI , SurfaceCacheResources . Level [ DepthLevel ] - > SavedStartIndex ) ;
2014-06-03 15:53:13 -04:00
}
2014-06-10 07:29:49 -04:00
void UnsetParameters ( FRHICommandList & RHICmdList )
2014-06-03 15:53:13 -04:00
{
2014-06-05 16:38:54 -04:00
SavedStartIndex . UnsetUAV ( RHICmdList , GetComputeShader ( ) ) ;
2014-06-03 15:53:13 -04:00
}
virtual bool Serialize ( FArchive & Ar )
{
bool bShaderHasOutdatedParameters = FGlobalShader : : Serialize ( Ar ) ;
Ar < < DrawParameters ;
Ar < < SavedStartIndex ;
return bShaderHasOutdatedParameters ;
}
private :
FShaderResourceParameter DrawParameters ;
FRWShaderParameter SavedStartIndex ;
} ;
IMPLEMENT_SHADER_TYPE ( , FSaveStartIndexCS , TEXT ( " DistanceFieldSurfaceCacheLightingCompute " ) , TEXT ( " SaveStartIndexCS " ) , SF_Compute ) ;
class FPopulateCacheCS : public FGlobalShader
{
DECLARE_SHADER_TYPE ( FPopulateCacheCS , Global )
public :
static bool ShouldCache ( EShaderPlatform Platform )
{
2014-06-26 15:53:01 -04:00
return IsFeatureLevelSupported ( Platform , ERHIFeatureLevel : : SM5 ) & & DoesPlatformSupportDistanceFieldAO ( Platform ) ;
2014-06-03 15:53:13 -04:00
}
static void ModifyCompilationEnvironment ( EShaderPlatform Platform , FShaderCompilerEnvironment & OutEnvironment )
{
FGlobalShader : : ModifyCompilationEnvironment ( Platform , OutEnvironment ) ;
OutEnvironment . SetDefine ( TEXT ( " THREADGROUP_SIZEX " ) , GDistanceFieldAOTileSizeX ) ;
OutEnvironment . SetDefine ( TEXT ( " THREADGROUP_SIZEY " ) , GDistanceFieldAOTileSizeY ) ;
2014-09-11 18:30:45 -04:00
OutEnvironment . SetDefine ( TEXT ( " NUM_CONE_DIRECTIONS " ) , NumConeSampleDirections ) ;
2014-06-03 15:53:13 -04:00
OutEnvironment . SetDefine ( TEXT ( " DOWNSAMPLE_FACTOR " ) , GAODownsampleFactor ) ;
// To reduce shader compile time of compute shaders with shared memory, doesn't have an impact on generated code with current compiler (June 2010 DX SDK)
OutEnvironment . CompilerFlags . Add ( CFLAG_StandardOptimization ) ;
}
FPopulateCacheCS ( const ShaderMetaType : : CompiledShaderInitializerType & Initializer )
: FGlobalShader ( Initializer )
{
DeferredParameters . Bind ( Initializer . ParameterMap ) ;
AOParameters . Bind ( Initializer . ParameterMap ) ;
IrradianceCachePositionRadius . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceCachePositionRadius " ) ) ;
IrradianceCacheNormal . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceCacheNormal " ) ) ;
IrradianceCacheTileCoordinate . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceCacheTileCoordinate " ) ) ;
ScatterDrawParameters . Bind ( Initializer . ParameterMap , TEXT ( " ScatterDrawParameters " ) ) ;
ViewDimensionsParameter . Bind ( Initializer . ParameterMap , TEXT ( " ViewDimensions " ) ) ;
ThreadToCulledTile . Bind ( Initializer . ParameterMap , TEXT ( " ThreadToCulledTile " ) ) ;
TileListGroupSize . Bind ( Initializer . ParameterMap , TEXT ( " TileListGroupSize " ) ) ;
2014-09-26 17:07:59 -04:00
NumCircleSections . Bind ( Initializer . ParameterMap , TEXT ( " NumCircleSections " ) ) ;
2014-06-03 15:53:13 -04:00
DistanceFieldNormalTexture . Bind ( Initializer . ParameterMap , TEXT ( " DistanceFieldNormalTexture " ) ) ;
DistanceFieldNormalSampler . Bind ( Initializer . ParameterMap , TEXT ( " DistanceFieldNormalSampler " ) ) ;
IrradianceCacheSplatTexture . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceCacheSplatTexture " ) ) ;
IrradianceCacheSplatSampler . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceCacheSplatSampler " ) ) ;
AOLevelParameters . Bind ( Initializer . ParameterMap ) ;
}
FPopulateCacheCS ( )
{
}
2014-08-28 13:54:31 -04:00
void SetParameters (
FRHICommandList & RHICmdList ,
const FSceneView & View ,
FSceneRenderTargetItem & DistanceFieldAOIrradianceCacheSplat ,
FSceneRenderTargetItem & DistanceFieldNormal ,
int32 DownsampleFactorValue ,
int32 DepthLevel ,
FIntPoint TileListGroupSizeValue ,
const FDistanceFieldAOParameters & Parameters )
2014-06-03 15:53:13 -04:00
{
FComputeShaderRHIParamRef ShaderRHI = GetComputeShader ( ) ;
2014-06-05 16:38:54 -04:00
FGlobalShader : : SetParameters ( RHICmdList , ShaderRHI , View ) ;
DeferredParameters . Set ( RHICmdList , ShaderRHI , View ) ;
2014-08-28 13:54:31 -04:00
AOParameters . Set ( RHICmdList , ShaderRHI , Parameters ) ;
2014-06-05 16:38:54 -04:00
AOLevelParameters . Set ( RHICmdList , ShaderRHI , View , DownsampleFactorValue ) ;
2014-06-03 15:53:13 -04:00
const FScene * Scene = ( const FScene * ) View . Family - > Scene ;
FSurfaceCacheResources & SurfaceCacheResources = * Scene - > SurfaceCacheResources ;
2014-06-05 16:38:54 -04:00
IrradianceCachePositionRadius . SetBuffer ( RHICmdList , ShaderRHI , SurfaceCacheResources . Level [ DepthLevel ] - > PositionAndRadius ) ;
IrradianceCacheNormal . SetBuffer ( RHICmdList , ShaderRHI , SurfaceCacheResources . Level [ DepthLevel ] - > Normal ) ;
IrradianceCacheTileCoordinate . SetBuffer ( RHICmdList , ShaderRHI , SurfaceCacheResources . Level [ DepthLevel ] - > TileCoordinate ) ;
ScatterDrawParameters . SetBuffer ( RHICmdList , ShaderRHI , SurfaceCacheResources . Level [ DepthLevel ] - > ScatterDrawParameters ) ;
2014-06-03 15:53:13 -04:00
2014-06-05 16:38:54 -04:00
SetShaderValue ( RHICmdList , ShaderRHI , ViewDimensionsParameter , View . ViewRect ) ;
2014-06-03 15:53:13 -04:00
2014-06-04 17:01:43 -04:00
FAOSampleData2 AOSampleData ;
2014-06-03 15:53:13 -04:00
2014-06-04 17:01:43 -04:00
TArray < FVector , TInlineAllocator < 9 > > SampleDirections ;
GetSpacedVectors ( SampleDirections ) ;
for ( int32 SampleIndex = 0 ; SampleIndex < NumConeSampleDirections ; SampleIndex + + )
2014-06-03 15:53:13 -04:00
{
2014-06-04 17:01:43 -04:00
AOSampleData . SampleDirections [ SampleIndex ] = FVector4 ( SampleDirections [ SampleIndex ] ) ;
}
2014-06-03 15:53:13 -04:00
2014-06-05 16:38:54 -04:00
SetUniformBufferParameterImmediate ( RHICmdList , ShaderRHI , GetUniformBufferParameter < FAOSampleData2 > ( ) , AOSampleData ) ;
2014-06-03 15:53:13 -04:00
FVector2D ThreadToCulledTileValue ( DownsampleFactorValue / ( float ) ( GAODownsampleFactor * GDistanceFieldAOTileSizeX ) , DownsampleFactorValue / ( float ) ( GAODownsampleFactor * GDistanceFieldAOTileSizeY ) ) ;
2014-06-05 16:38:54 -04:00
SetShaderValue ( RHICmdList , ShaderRHI , ThreadToCulledTile , ThreadToCulledTileValue ) ;
2014-06-03 15:53:13 -04:00
2014-06-05 16:38:54 -04:00
SetShaderValue ( RHICmdList , ShaderRHI , TileListGroupSize , TileListGroupSizeValue ) ;
2014-06-03 15:53:13 -04:00
2014-09-26 17:07:59 -04:00
SetShaderValue ( RHICmdList , ShaderRHI , NumCircleSections , GCircleVertexBuffer . NumSections ) ;
2014-06-03 15:53:13 -04:00
SetTextureParameter (
2014-06-05 16:38:54 -04:00
RHICmdList ,
2014-06-03 15:53:13 -04:00
ShaderRHI ,
DistanceFieldNormalTexture ,
DistanceFieldNormalSampler ,
TStaticSamplerState < SF_Point , AM_Clamp , AM_Clamp , AM_Clamp > : : GetRHI ( ) ,
DistanceFieldNormal . ShaderResourceTexture
) ;
SetTextureParameter (
2014-06-05 16:38:54 -04:00
RHICmdList ,
2014-06-03 15:53:13 -04:00
ShaderRHI ,
IrradianceCacheSplatTexture ,
IrradianceCacheSplatSampler ,
TStaticSamplerState < SF_Point , AM_Clamp , AM_Clamp , AM_Clamp > : : GetRHI ( ) ,
DistanceFieldAOIrradianceCacheSplat . ShaderResourceTexture
) ;
}
2014-06-10 07:29:49 -04:00
void UnsetParameters ( FRHICommandList & RHICmdList )
2014-06-03 15:53:13 -04:00
{
2014-06-05 16:38:54 -04:00
IrradianceCachePositionRadius . UnsetUAV ( RHICmdList , GetComputeShader ( ) ) ;
IrradianceCacheNormal . UnsetUAV ( RHICmdList , GetComputeShader ( ) ) ;
IrradianceCacheTileCoordinate . UnsetUAV ( RHICmdList , GetComputeShader ( ) ) ;
ScatterDrawParameters . UnsetUAV ( RHICmdList , GetComputeShader ( ) ) ;
2014-06-03 15:53:13 -04:00
}
virtual bool Serialize ( FArchive & Ar )
{
bool bShaderHasOutdatedParameters = FGlobalShader : : Serialize ( Ar ) ;
Ar < < DeferredParameters ;
Ar < < AOParameters ;
Ar < < AOLevelParameters ;
Ar < < IrradianceCachePositionRadius ;
Ar < < IrradianceCacheNormal ;
Ar < < IrradianceCacheTileCoordinate ;
Ar < < ScatterDrawParameters ;
Ar < < ViewDimensionsParameter ;
Ar < < ThreadToCulledTile ;
Ar < < TileListGroupSize ;
2014-09-26 17:07:59 -04:00
Ar < < NumCircleSections ;
2014-06-03 15:53:13 -04:00
Ar < < DistanceFieldNormalTexture ;
Ar < < DistanceFieldNormalSampler ;
Ar < < IrradianceCacheSplatTexture ;
Ar < < IrradianceCacheSplatSampler ;
return bShaderHasOutdatedParameters ;
}
private :
FDeferredPixelShaderParameters DeferredParameters ;
FAOParameters AOParameters ;
FAOLevelParameters AOLevelParameters ;
FRWShaderParameter IrradianceCachePositionRadius ;
FRWShaderParameter IrradianceCacheNormal ;
FRWShaderParameter IrradianceCacheTileCoordinate ;
FRWShaderParameter ScatterDrawParameters ;
FShaderParameter ViewDimensionsParameter ;
FShaderParameter ThreadToCulledTile ;
FShaderParameter TileListGroupSize ;
2014-09-26 17:07:59 -04:00
FShaderParameter NumCircleSections ;
2014-06-03 15:53:13 -04:00
FShaderResourceParameter DistanceFieldNormalTexture ;
FShaderResourceParameter DistanceFieldNormalSampler ;
FShaderResourceParameter IrradianceCacheSplatTexture ;
FShaderResourceParameter IrradianceCacheSplatSampler ;
} ;
IMPLEMENT_SHADER_TYPE ( , FPopulateCacheCS , TEXT ( " DistanceFieldSurfaceCacheLightingCompute " ) , TEXT ( " PopulateCacheCS " ) , SF_Compute ) ;
2014-12-01 12:44:34 -05:00
IMPLEMENT_SHADER_TYPE ( template < > , TSetupFinalGatherIndirectArgumentsCS < true > , TEXT ( " DistanceFieldSurfaceCacheLightingCompute " ) , TEXT ( " SetupFinalGatherIndirectArgumentsCS " ) , SF_Compute ) ;
IMPLEMENT_SHADER_TYPE ( template < > , TSetupFinalGatherIndirectArgumentsCS < false > , TEXT ( " DistanceFieldSurfaceCacheLightingCompute " ) , TEXT ( " SetupFinalGatherIndirectArgumentsCS " ) , SF_Compute ) ;
2014-06-03 15:53:13 -04:00
2014-11-21 21:37:13 -05:00
class FDebugBuffer : public FRenderResource
2014-06-03 15:53:13 -04:00
{
2014-11-21 21:37:13 -05:00
public :
virtual void InitDynamicRHI ( ) override
{
2014-11-24 12:51:53 -05:00
if ( GMaxRHIFeatureLevel > = ERHIFeatureLevel : : SM5 )
{
DebugData . Initialize ( sizeof ( float ) * 4 , 50 , PF_A32B32G32R32F , BUF_Static ) ;
}
2014-11-21 21:37:13 -05:00
}
virtual void ReleaseDynamicRHI ( ) override
{
2014-11-24 12:51:53 -05:00
if ( GMaxRHIFeatureLevel > = ERHIFeatureLevel : : SM5 )
{
DebugData . Release ( ) ;
}
2014-11-21 21:37:13 -05:00
}
FRWBuffer DebugData ;
} ;
TGlobalResource < FDebugBuffer > GDebugBuffer ;
template < bool bSupportIrradiance >
2015-01-29 14:46:20 -05:00
class TConeTraceOcclusionCS : public FGlobalShader
2014-11-21 21:37:13 -05:00
{
2015-01-29 14:46:20 -05:00
DECLARE_SHADER_TYPE ( TConeTraceOcclusionCS , Global )
2014-06-03 15:53:13 -04:00
public :
static bool ShouldCache ( EShaderPlatform Platform )
{
2014-06-26 15:53:01 -04:00
return IsFeatureLevelSupported ( Platform , ERHIFeatureLevel : : SM5 ) & & DoesPlatformSupportDistanceFieldAO ( Platform ) ;
2014-06-03 15:53:13 -04:00
}
static void ModifyCompilationEnvironment ( EShaderPlatform Platform , FShaderCompilerEnvironment & OutEnvironment )
{
FGlobalShader : : ModifyCompilationEnvironment ( Platform , OutEnvironment ) ;
2014-09-11 18:30:45 -04:00
OutEnvironment . SetDefine ( TEXT ( " NUM_CONE_DIRECTIONS " ) , NumConeSampleDirections ) ;
2014-06-03 15:53:13 -04:00
OutEnvironment . SetDefine ( TEXT ( " DOWNSAMPLE_FACTOR " ) , GAODownsampleFactor ) ;
2014-11-21 21:37:13 -05:00
OutEnvironment . SetDefine ( TEXT ( " SUPPORT_IRRADIANCE " ) , bSupportIrradiance ? TEXT ( " 1 " ) : TEXT ( " 0 " ) ) ;
2014-06-03 15:53:13 -04:00
// To reduce shader compile time of compute shaders with shared memory, doesn't have an impact on generated code with current compiler (June 2010 DX SDK)
OutEnvironment . CompilerFlags . Add ( CFLAG_StandardOptimization ) ;
}
2015-01-29 14:46:20 -05:00
TConeTraceOcclusionCS ( const ShaderMetaType : : CompiledShaderInitializerType & Initializer )
2014-06-03 15:53:13 -04:00
: FGlobalShader ( Initializer )
{
DeferredParameters . Bind ( Initializer . ParameterMap ) ;
ObjectParameters . Bind ( Initializer . ParameterMap ) ;
AOParameters . Bind ( Initializer . ParameterMap ) ;
IrradianceCachePositionRadius . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceCachePositionRadius " ) ) ;
IrradianceCacheNormal . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceCacheNormal " ) ) ;
OccluderRadius . Bind ( Initializer . ParameterMap , TEXT ( " OccluderRadius " ) ) ;
2014-12-01 12:44:34 -05:00
RecordConeVisibility . Bind ( Initializer . ParameterMap , TEXT ( " RecordConeVisibility " ) ) ;
2014-12-16 20:00:22 -05:00
RecordConeData . Bind ( Initializer . ParameterMap , TEXT ( " RecordConeData " ) ) ;
2014-11-21 21:37:13 -05:00
DebugBuffer . Bind ( Initializer . ParameterMap , TEXT ( " DebugBuffer " ) ) ;
2014-06-03 15:53:13 -04:00
IrradianceCacheTileCoordinate . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceCacheTileCoordinate " ) ) ;
ScatterDrawParameters . Bind ( Initializer . ParameterMap , TEXT ( " ScatterDrawParameters " ) ) ;
SavedStartIndex . Bind ( Initializer . ParameterMap , TEXT ( " SavedStartIndex " ) ) ;
ViewDimensionsParameter . Bind ( Initializer . ParameterMap , TEXT ( " ViewDimensions " ) ) ;
ThreadToCulledTile . Bind ( Initializer . ParameterMap , TEXT ( " ThreadToCulledTile " ) ) ;
TileHeadData . Bind ( Initializer . ParameterMap , TEXT ( " TileHeadData " ) ) ;
TileHeadDataUnpacked . Bind ( Initializer . ParameterMap , TEXT ( " TileHeadDataUnpacked " ) ) ;
TileArrayData . Bind ( Initializer . ParameterMap , TEXT ( " TileArrayData " ) ) ;
TileListGroupSize . Bind ( Initializer . ParameterMap , TEXT ( " TileListGroupSize " ) ) ;
2014-06-06 14:14:50 -04:00
TanConeHalfAngle . Bind ( Initializer . ParameterMap , TEXT ( " TanConeHalfAngle " ) ) ;
2014-06-03 15:53:13 -04:00
BentNormalNormalizeFactor . Bind ( Initializer . ParameterMap , TEXT ( " BentNormalNormalizeFactor " ) ) ;
DistanceFieldAtlasTexelSize . Bind ( Initializer . ParameterMap , TEXT ( " DistanceFieldAtlasTexelSize " ) ) ;
DistanceFieldNormalTexture . Bind ( Initializer . ParameterMap , TEXT ( " DistanceFieldNormalTexture " ) ) ;
DistanceFieldNormalSampler . Bind ( Initializer . ParameterMap , TEXT ( " DistanceFieldNormalSampler " ) ) ;
IrradianceCacheSplatTexture . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceCacheSplatTexture " ) ) ;
IrradianceCacheSplatSampler . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceCacheSplatSampler " ) ) ;
AOLevelParameters . Bind ( Initializer . ParameterMap ) ;
RecordRadiusScale . Bind ( Initializer . ParameterMap , TEXT ( " RecordRadiusScale " ) ) ;
}
2015-01-29 14:46:20 -05:00
TConeTraceOcclusionCS ( )
2014-06-03 15:53:13 -04:00
{
}
2014-08-28 13:54:31 -04:00
void SetParameters (
FRHICommandList & RHICmdList ,
const FSceneView & View ,
FSceneRenderTargetItem & DistanceFieldAOIrradianceCacheSplat ,
FSceneRenderTargetItem & DistanceFieldNormal ,
int32 DownsampleFactorValue ,
int32 DepthLevel ,
FIntPoint TileListGroupSizeValue ,
const FDistanceFieldAOParameters & Parameters )
2014-06-03 15:53:13 -04:00
{
FComputeShaderRHIParamRef ShaderRHI = GetComputeShader ( ) ;
2014-06-05 16:38:54 -04:00
FGlobalShader : : SetParameters ( RHICmdList , ShaderRHI , View ) ;
DeferredParameters . Set ( RHICmdList , ShaderRHI , View ) ;
2014-11-21 22:32:16 -05:00
ObjectParameters . Set ( RHICmdList , ShaderRHI , GAOCulledObjectBuffers . Buffers ) ;
2014-08-28 13:54:31 -04:00
AOParameters . Set ( RHICmdList , ShaderRHI , Parameters ) ;
2014-06-05 16:38:54 -04:00
AOLevelParameters . Set ( RHICmdList , ShaderRHI , View , DownsampleFactorValue ) ;
2014-06-03 15:53:13 -04:00
const FScene * Scene = ( const FScene * ) View . Family - > Scene ;
FSurfaceCacheResources & SurfaceCacheResources = * Scene - > SurfaceCacheResources ;
2014-06-05 16:38:54 -04:00
SetSRVParameter ( RHICmdList , ShaderRHI , IrradianceCacheNormal , SurfaceCacheResources . Level [ DepthLevel ] - > Normal . SRV ) ;
SetSRVParameter ( RHICmdList , ShaderRHI , ScatterDrawParameters , SurfaceCacheResources . Level [ DepthLevel ] - > ScatterDrawParameters . SRV ) ;
SetSRVParameter ( RHICmdList , ShaderRHI , SavedStartIndex , SurfaceCacheResources . Level [ DepthLevel ] - > SavedStartIndex . SRV ) ;
SetSRVParameter ( RHICmdList , ShaderRHI , IrradianceCachePositionRadius , SurfaceCacheResources . Level [ DepthLevel ] - > PositionAndRadius . SRV ) ;
2014-06-03 15:53:13 -04:00
2014-06-05 16:38:54 -04:00
OccluderRadius . SetBuffer ( RHICmdList , ShaderRHI , SurfaceCacheResources . Level [ DepthLevel ] - > OccluderRadius ) ;
2014-12-01 12:44:34 -05:00
RecordConeVisibility . SetBuffer ( RHICmdList , ShaderRHI , GTemporaryIrradianceCacheResources . ConeVisibility ) ;
2014-12-16 20:00:22 -05:00
RecordConeData . SetBuffer ( RHICmdList , ShaderRHI , GTemporaryIrradianceCacheResources . ConeData ) ;
2014-11-21 21:37:13 -05:00
DebugBuffer . SetBuffer ( RHICmdList , ShaderRHI , GDebugBuffer . DebugData ) ;
2014-06-03 15:53:13 -04:00
2014-06-05 16:38:54 -04:00
SetShaderValue ( RHICmdList , ShaderRHI , ViewDimensionsParameter , View . ViewRect ) ;
2014-06-03 15:53:13 -04:00
2014-06-04 17:01:43 -04:00
FAOSampleData2 AOSampleData ;
2014-06-03 15:53:13 -04:00
2014-06-04 17:01:43 -04:00
TArray < FVector , TInlineAllocator < 9 > > SampleDirections ;
GetSpacedVectors ( SampleDirections ) ;
for ( int32 SampleIndex = 0 ; SampleIndex < NumConeSampleDirections ; SampleIndex + + )
2014-06-03 15:53:13 -04:00
{
2014-06-04 17:01:43 -04:00
AOSampleData . SampleDirections [ SampleIndex ] = FVector4 ( SampleDirections [ SampleIndex ] ) ;
}
2014-06-03 15:53:13 -04:00
2014-06-05 16:38:54 -04:00
SetUniformBufferParameterImmediate ( RHICmdList , ShaderRHI , GetUniformBufferParameter < FAOSampleData2 > ( ) , AOSampleData ) ;
2014-06-03 15:53:13 -04:00
FVector2D ThreadToCulledTileValue ( DownsampleFactorValue / ( float ) ( GAODownsampleFactor * GDistanceFieldAOTileSizeX ) , DownsampleFactorValue / ( float ) ( GAODownsampleFactor * GDistanceFieldAOTileSizeY ) ) ;
2014-06-05 16:38:54 -04:00
SetShaderValue ( RHICmdList , ShaderRHI , ThreadToCulledTile , ThreadToCulledTileValue ) ;
2014-06-03 15:53:13 -04:00
FTileIntersectionResources * TileIntersectionResources = ( ( FSceneViewState * ) View . State ) - > AOTileIntersectionResources ;
2014-06-05 16:38:54 -04:00
SetSRVParameter ( RHICmdList , ShaderRHI , TileHeadDataUnpacked , TileIntersectionResources - > TileHeadDataUnpacked . SRV ) ;
SetSRVParameter ( RHICmdList , ShaderRHI , TileHeadData , TileIntersectionResources - > TileHeadData . SRV ) ;
SetSRVParameter ( RHICmdList , ShaderRHI , TileArrayData , TileIntersectionResources - > TileArrayData . SRV ) ;
SetSRVParameter ( RHICmdList , ShaderRHI , IrradianceCacheTileCoordinate , SurfaceCacheResources . Level [ DepthLevel ] - > TileCoordinate . SRV ) ;
2014-06-03 15:53:13 -04:00
2014-06-05 16:38:54 -04:00
SetShaderValue ( RHICmdList , ShaderRHI , TileListGroupSize , TileListGroupSizeValue ) ;
2014-06-03 15:53:13 -04:00
2014-06-06 14:14:50 -04:00
SetShaderValue ( RHICmdList , ShaderRHI , TanConeHalfAngle , FMath : : Tan ( GAOConeHalfAngle ) ) ;
2014-06-03 15:53:13 -04:00
FVector UnoccludedVector ( 0 ) ;
for ( int32 SampleIndex = 0 ; SampleIndex < NumConeSampleDirections ; SampleIndex + + )
{
2014-06-04 17:01:43 -04:00
UnoccludedVector + = SampleDirections [ SampleIndex ] ;
2014-06-03 15:53:13 -04:00
}
float BentNormalNormalizeFactorValue = 1.0f / ( UnoccludedVector / NumConeSampleDirections ) . Size ( ) ;
2014-06-05 16:38:54 -04:00
SetShaderValue ( RHICmdList , ShaderRHI , BentNormalNormalizeFactor , BentNormalNormalizeFactorValue ) ;
2014-06-03 15:53:13 -04:00
const int32 NumTexelsOneDimX = GDistanceFieldVolumeTextureAtlas . GetSizeX ( ) ;
const int32 NumTexelsOneDimY = GDistanceFieldVolumeTextureAtlas . GetSizeY ( ) ;
const int32 NumTexelsOneDimZ = GDistanceFieldVolumeTextureAtlas . GetSizeZ ( ) ;
const FVector InvTextureDim ( 1.0f / NumTexelsOneDimX , 1.0f / NumTexelsOneDimY , 1.0f / NumTexelsOneDimZ ) ;
2014-06-05 16:38:54 -04:00
SetShaderValue ( RHICmdList , ShaderRHI , DistanceFieldAtlasTexelSize , InvTextureDim ) ;
2014-06-03 15:53:13 -04:00
SetTextureParameter (
2014-06-05 16:38:54 -04:00
RHICmdList ,
2014-06-03 15:53:13 -04:00
ShaderRHI ,
DistanceFieldNormalTexture ,
DistanceFieldNormalSampler ,
TStaticSamplerState < SF_Point , AM_Clamp , AM_Clamp , AM_Clamp > : : GetRHI ( ) ,
DistanceFieldNormal . ShaderResourceTexture
) ;
SetTextureParameter (
2014-06-05 16:38:54 -04:00
RHICmdList ,
2014-06-03 15:53:13 -04:00
ShaderRHI ,
IrradianceCacheSplatTexture ,
IrradianceCacheSplatSampler ,
TStaticSamplerState < SF_Point , AM_Clamp , AM_Clamp , AM_Clamp > : : GetRHI ( ) ,
DistanceFieldAOIrradianceCacheSplat . ShaderResourceTexture
) ;
2014-06-05 16:38:54 -04:00
SetShaderValue ( RHICmdList , ShaderRHI , RecordRadiusScale , GAORecordRadiusScale ) ;
2014-06-03 15:53:13 -04:00
}
2014-06-10 07:29:49 -04:00
void UnsetParameters ( FRHICommandList & RHICmdList )
2014-06-03 15:53:13 -04:00
{
2014-06-05 16:38:54 -04:00
OccluderRadius . UnsetUAV ( RHICmdList , GetComputeShader ( ) ) ;
2014-12-01 12:44:34 -05:00
RecordConeVisibility . UnsetUAV ( RHICmdList , GetComputeShader ( ) ) ;
2014-12-16 20:00:22 -05:00
RecordConeData . UnsetUAV ( RHICmdList , GetComputeShader ( ) ) ;
2014-11-21 21:37:13 -05:00
DebugBuffer . UnsetUAV ( RHICmdList , GetComputeShader ( ) ) ;
2014-06-03 15:53:13 -04:00
}
2015-04-01 07:20:55 -04:00
virtual bool Serialize ( FArchive & Ar ) override
2014-06-03 15:53:13 -04:00
{
bool bShaderHasOutdatedParameters = FGlobalShader : : Serialize ( Ar ) ;
Ar < < DeferredParameters ;
Ar < < ObjectParameters ;
Ar < < AOParameters ;
Ar < < AOLevelParameters ;
Ar < < IrradianceCachePositionRadius ;
Ar < < IrradianceCacheNormal ;
Ar < < OccluderRadius ;
2014-12-01 12:44:34 -05:00
Ar < < RecordConeVisibility ;
2014-12-16 20:00:22 -05:00
Ar < < RecordConeData ;
2014-11-21 21:37:13 -05:00
Ar < < DebugBuffer ;
2014-06-03 15:53:13 -04:00
Ar < < IrradianceCacheTileCoordinate ;
Ar < < ScatterDrawParameters ;
Ar < < SavedStartIndex ;
Ar < < ViewDimensionsParameter ;
Ar < < ThreadToCulledTile ;
Ar < < TileHeadDataUnpacked ;
Ar < < TileHeadData ;
Ar < < TileArrayData ;
Ar < < TileListGroupSize ;
2014-06-06 14:14:50 -04:00
Ar < < TanConeHalfAngle ;
2014-06-03 15:53:13 -04:00
Ar < < BentNormalNormalizeFactor ;
Ar < < DistanceFieldAtlasTexelSize ;
Ar < < DistanceFieldNormalTexture ;
Ar < < DistanceFieldNormalSampler ;
Ar < < IrradianceCacheSplatTexture ;
Ar < < IrradianceCacheSplatSampler ;
Ar < < RecordRadiusScale ;
return bShaderHasOutdatedParameters ;
}
private :
FDeferredPixelShaderParameters DeferredParameters ;
2014-11-21 22:32:16 -05:00
FDistanceFieldCulledObjectBufferParameters ObjectParameters ;
2014-06-03 15:53:13 -04:00
FAOParameters AOParameters ;
FAOLevelParameters AOLevelParameters ;
FShaderResourceParameter IrradianceCacheNormal ;
FShaderResourceParameter IrradianceCachePositionRadius ;
FRWShaderParameter OccluderRadius ;
2014-12-01 12:44:34 -05:00
FRWShaderParameter RecordConeVisibility ;
2014-12-16 20:00:22 -05:00
FRWShaderParameter RecordConeData ;
2014-11-21 21:37:13 -05:00
FRWShaderParameter DebugBuffer ;
2014-06-03 15:53:13 -04:00
FShaderResourceParameter ScatterDrawParameters ;
FShaderResourceParameter SavedStartIndex ;
FShaderResourceParameter IrradianceCacheTileCoordinate ;
FShaderParameter ViewDimensionsParameter ;
FShaderParameter ThreadToCulledTile ;
FShaderResourceParameter TileHeadDataUnpacked ;
FShaderResourceParameter TileHeadData ;
FShaderResourceParameter TileArrayData ;
FShaderParameter TileListGroupSize ;
2014-06-06 14:14:50 -04:00
FShaderParameter TanConeHalfAngle ;
2014-06-03 15:53:13 -04:00
FShaderParameter BentNormalNormalizeFactor ;
FShaderParameter DistanceFieldAtlasTexelSize ;
FShaderResourceParameter DistanceFieldNormalTexture ;
FShaderResourceParameter DistanceFieldNormalSampler ;
FShaderResourceParameter IrradianceCacheSplatTexture ;
FShaderResourceParameter IrradianceCacheSplatSampler ;
FShaderParameter RecordRadiusScale ;
} ;
2015-01-29 14:46:20 -05:00
IMPLEMENT_SHADER_TYPE ( template < > , TConeTraceOcclusionCS < true > , TEXT ( " DistanceFieldSurfaceCacheLightingCompute " ) , TEXT ( " ConeTraceOcclusionCS " ) , SF_Compute ) ;
IMPLEMENT_SHADER_TYPE ( template < > , TConeTraceOcclusionCS < false > , TEXT ( " DistanceFieldSurfaceCacheLightingCompute " ) , TEXT ( " ConeTraceOcclusionCS " ) , SF_Compute ) ;
2014-06-03 15:53:13 -04:00
2014-12-16 20:00:22 -05:00
class FCombineConesCS : public FGlobalShader
2014-12-01 12:44:34 -05:00
{
2014-12-16 20:00:22 -05:00
DECLARE_SHADER_TYPE ( FCombineConesCS , Global )
2014-12-01 12:44:34 -05:00
public :
static bool ShouldCache ( EShaderPlatform Platform )
{
return IsFeatureLevelSupported ( Platform , ERHIFeatureLevel : : SM5 ) & & DoesPlatformSupportDistanceFieldAO ( Platform ) ;
}
static void ModifyCompilationEnvironment ( EShaderPlatform Platform , FShaderCompilerEnvironment & OutEnvironment )
{
FGlobalShader : : ModifyCompilationEnvironment ( Platform , OutEnvironment ) ;
OutEnvironment . SetDefine ( TEXT ( " NUM_CONE_DIRECTIONS " ) , NumConeSampleDirections ) ;
// To reduce shader compile time of compute shaders with shared memory, doesn't have an impact on generated code with current compiler (June 2010 DX SDK)
OutEnvironment . CompilerFlags . Add ( CFLAG_StandardOptimization ) ;
}
2014-12-16 20:00:22 -05:00
FCombineConesCS ( const ShaderMetaType : : CompiledShaderInitializerType & Initializer )
2014-12-01 12:44:34 -05:00
: FGlobalShader ( Initializer )
{
AOParameters . Bind ( Initializer . ParameterMap ) ;
IrradianceCacheBentNormal . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceCacheBentNormal " ) ) ;
IrradianceCacheNormal . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceCacheNormal " ) ) ;
RecordConeVisibility . Bind ( Initializer . ParameterMap , TEXT ( " RecordConeVisibility " ) ) ;
ScatterDrawParameters . Bind ( Initializer . ParameterMap , TEXT ( " ScatterDrawParameters " ) ) ;
SavedStartIndex . Bind ( Initializer . ParameterMap , TEXT ( " SavedStartIndex " ) ) ;
BentNormalNormalizeFactor . Bind ( Initializer . ParameterMap , TEXT ( " BentNormalNormalizeFactor " ) ) ;
}
2014-12-16 20:00:22 -05:00
FCombineConesCS ( )
2014-12-01 12:44:34 -05:00
{
}
void SetParameters (
FRHICommandList & RHICmdList ,
const FSceneView & View ,
int32 DepthLevel ,
2014-12-16 20:00:22 -05:00
const FDistanceFieldAOParameters & Parameters ,
const FLightSceneProxy * DirectionalLight ,
const FMatrix & WorldToShadowMatrixValue ,
FLightTileIntersectionResources * TileIntersectionResources ,
FVPLResources * VPLResources )
2014-12-01 12:44:34 -05:00
{
FComputeShaderRHIParamRef ShaderRHI = GetComputeShader ( ) ;
FGlobalShader : : SetParameters ( RHICmdList , ShaderRHI , View ) ;
2014-12-16 20:00:22 -05:00
2014-12-01 12:44:34 -05:00
AOParameters . Set ( RHICmdList , ShaderRHI , Parameters ) ;
const FScene * Scene = ( const FScene * ) View . Family - > Scene ;
FSurfaceCacheResources & SurfaceCacheResources = * Scene - > SurfaceCacheResources ;
SetSRVParameter ( RHICmdList , ShaderRHI , IrradianceCacheNormal , SurfaceCacheResources . Level [ DepthLevel ] - > Normal . SRV ) ;
SetSRVParameter ( RHICmdList , ShaderRHI , ScatterDrawParameters , SurfaceCacheResources . Level [ DepthLevel ] - > ScatterDrawParameters . SRV ) ;
SetSRVParameter ( RHICmdList , ShaderRHI , SavedStartIndex , SurfaceCacheResources . Level [ DepthLevel ] - > SavedStartIndex . SRV ) ;
SetSRVParameter ( RHICmdList , ShaderRHI , RecordConeVisibility , GTemporaryIrradianceCacheResources . ConeVisibility . SRV ) ;
IrradianceCacheBentNormal . SetBuffer ( RHICmdList , ShaderRHI , SurfaceCacheResources . Level [ DepthLevel ] - > BentNormal ) ;
2014-12-16 20:00:22 -05:00
2014-12-01 12:44:34 -05:00
FAOSampleData2 AOSampleData ;
TArray < FVector , TInlineAllocator < 9 > > SampleDirections ;
GetSpacedVectors ( SampleDirections ) ;
for ( int32 SampleIndex = 0 ; SampleIndex < NumConeSampleDirections ; SampleIndex + + )
{
AOSampleData . SampleDirections [ SampleIndex ] = FVector4 ( SampleDirections [ SampleIndex ] ) ;
}
SetUniformBufferParameterImmediate ( RHICmdList , ShaderRHI , GetUniformBufferParameter < FAOSampleData2 > ( ) , AOSampleData ) ;
FVector UnoccludedVector ( 0 ) ;
for ( int32 SampleIndex = 0 ; SampleIndex < NumConeSampleDirections ; SampleIndex + + )
{
UnoccludedVector + = SampleDirections [ SampleIndex ] ;
}
float BentNormalNormalizeFactorValue = 1.0f / ( UnoccludedVector / NumConeSampleDirections ) . Size ( ) ;
SetShaderValue ( RHICmdList , ShaderRHI , BentNormalNormalizeFactor , BentNormalNormalizeFactorValue ) ;
}
void UnsetParameters ( FRHICommandList & RHICmdList )
{
IrradianceCacheBentNormal . UnsetUAV ( RHICmdList , GetComputeShader ( ) ) ;
}
2015-04-01 07:20:55 -04:00
virtual bool Serialize ( FArchive & Ar ) override
2014-12-01 12:44:34 -05:00
{
bool bShaderHasOutdatedParameters = FGlobalShader : : Serialize ( Ar ) ;
Ar < < AOParameters ;
Ar < < IrradianceCacheBentNormal ;
Ar < < IrradianceCacheNormal ;
Ar < < RecordConeVisibility ;
Ar < < ScatterDrawParameters ;
Ar < < SavedStartIndex ;
Ar < < BentNormalNormalizeFactor ;
return bShaderHasOutdatedParameters ;
}
private :
FAOParameters AOParameters ;
FRWShaderParameter IrradianceCacheBentNormal ;
FShaderResourceParameter IrradianceCacheNormal ;
FShaderResourceParameter RecordConeVisibility ;
FShaderResourceParameter ScatterDrawParameters ;
FShaderResourceParameter SavedStartIndex ;
FShaderParameter BentNormalNormalizeFactor ;
} ;
2014-12-16 20:00:22 -05:00
IMPLEMENT_SHADER_TYPE ( , FCombineConesCS , TEXT ( " DistanceFieldSurfaceCacheLightingCompute " ) , TEXT ( " CombineConesCS " ) , SF_Compute ) ;
2014-12-01 12:44:34 -05:00
2014-09-26 17:07:59 -04:00
class FWriteDownsampledDepthPS : public FGlobalShader
{
DECLARE_SHADER_TYPE ( FWriteDownsampledDepthPS , Global ) ;
public :
static bool ShouldCache ( EShaderPlatform Platform )
{
return IsFeatureLevelSupported ( Platform , ERHIFeatureLevel : : SM5 ) & & DoesPlatformSupportDistanceFieldAO ( Platform ) ;
}
static void ModifyCompilationEnvironment ( EShaderPlatform Platform , FShaderCompilerEnvironment & OutEnvironment )
{
OutEnvironment . SetDefine ( TEXT ( " DOWNSAMPLE_FACTOR " ) , GAODownsampleFactor ) ;
}
/** Default constructor. */
FWriteDownsampledDepthPS ( ) { }
/** Initialization constructor. */
FWriteDownsampledDepthPS ( const ShaderMetaType : : CompiledShaderInitializerType & Initializer )
: FGlobalShader ( Initializer )
{
DeferredParameters . Bind ( Initializer . ParameterMap ) ;
DistanceFieldNormalTexture . Bind ( Initializer . ParameterMap , TEXT ( " DistanceFieldNormalTexture " ) ) ;
DistanceFieldNormalSampler . Bind ( Initializer . ParameterMap , TEXT ( " DistanceFieldNormalSampler " ) ) ;
}
void SetParameters ( FRHICommandList & RHICmdList , const FSceneView & View , FSceneRenderTargetItem & DistanceFieldNormal )
{
const FPixelShaderRHIParamRef ShaderRHI = GetPixelShader ( ) ;
FGlobalShader : : SetParameters ( RHICmdList , ShaderRHI , View ) ;
DeferredParameters . Set ( RHICmdList , ShaderRHI , View ) ;
SetTextureParameter ( RHICmdList , ShaderRHI , DistanceFieldNormalTexture , DistanceFieldNormalSampler , TStaticSamplerState < SF_Point > : : GetRHI ( ) , DistanceFieldNormal . ShaderResourceTexture ) ;
}
// FShader interface.
2015-04-01 07:20:55 -04:00
virtual bool Serialize ( FArchive & Ar ) override
2014-09-26 17:07:59 -04:00
{
bool bShaderHasOutdatedParameters = FGlobalShader : : Serialize ( Ar ) ;
Ar < < DeferredParameters ;
Ar < < DistanceFieldNormalTexture ;
Ar < < DistanceFieldNormalSampler ;
return bShaderHasOutdatedParameters ;
}
private :
FDeferredPixelShaderParameters DeferredParameters ;
FShaderResourceParameter DistanceFieldNormalTexture ;
FShaderResourceParameter DistanceFieldNormalSampler ;
} ;
IMPLEMENT_SHADER_TYPE ( , FWriteDownsampledDepthPS , TEXT ( " DistanceFieldSurfaceCacheLighting " ) , TEXT ( " WriteDownsampledDepthPS " ) , SF_Pixel ) ;
2014-06-03 15:53:13 -04:00
/** */
2014-11-21 21:37:13 -05:00
template < bool bFinalInterpolationPass , bool bSupportIrradiance >
2014-06-03 15:53:13 -04:00
class TIrradianceCacheSplatVS : public FGlobalShader
{
DECLARE_SHADER_TYPE ( TIrradianceCacheSplatVS , Global ) ;
public :
static bool ShouldCache ( EShaderPlatform Platform )
{
2014-06-26 15:53:01 -04:00
return IsFeatureLevelSupported ( Platform , ERHIFeatureLevel : : SM5 ) & & DoesPlatformSupportDistanceFieldAO ( Platform ) ;
2014-06-03 15:53:13 -04:00
}
static void ModifyCompilationEnvironment ( EShaderPlatform Platform , FShaderCompilerEnvironment & OutEnvironment )
{
FGlobalShader : : ModifyCompilationEnvironment ( Platform , OutEnvironment ) ;
OutEnvironment . SetDefine ( TEXT ( " FINAL_INTERPOLATION_PASS " ) , ( uint32 ) bFinalInterpolationPass ) ;
2014-11-21 21:37:13 -05:00
OutEnvironment . SetDefine ( TEXT ( " SUPPORT_IRRADIANCE " ) , bSupportIrradiance ? TEXT ( " 1 " ) : TEXT ( " 0 " ) ) ;
2014-06-03 15:53:13 -04:00
}
TIrradianceCacheSplatVS ( const ShaderMetaType : : CompiledShaderInitializerType & Initializer ) :
FGlobalShader ( Initializer )
{
IrradianceCachePositionRadius . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceCachePositionRadius " ) ) ;
IrradianceCacheOccluderRadius . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceCacheOccluderRadius " ) ) ;
IrradianceCacheNormal . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceCacheNormal " ) ) ;
IrradianceCacheBentNormal . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceCacheBentNormal " ) ) ;
2014-11-21 21:37:13 -05:00
IrradianceCacheIrradiance . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceCacheIrradiance " ) ) ;
2014-06-03 15:53:13 -04:00
InterpolationRadiusScale . Bind ( Initializer . ParameterMap , TEXT ( " InterpolationRadiusScale " ) ) ;
NormalizedOffsetToPixelCenter . Bind ( Initializer . ParameterMap , TEXT ( " NormalizedOffsetToPixelCenter " ) ) ;
HackExpand . Bind ( Initializer . ParameterMap , TEXT ( " HackExpand " ) ) ;
2015-03-02 13:22:05 -05:00
InterpolationBoundingDirection . Bind ( Initializer . ParameterMap , TEXT ( " InterpolationBoundingDirection " ) ) ;
2014-12-16 20:00:22 -05:00
AOParameters . Bind ( Initializer . ParameterMap ) ;
2014-06-03 15:53:13 -04:00
}
TIrradianceCacheSplatVS ( ) { }
2014-12-16 20:00:22 -05:00
void SetParameters ( FRHICommandList & RHICmdList , const FSceneView & View , const FDistanceFieldAOParameters & Parameters , int32 DepthLevel , int32 CurrentLevelDownsampleFactorValue , FVector2D NormalizedOffsetToPixelCenterValue )
2014-06-03 15:53:13 -04:00
{
const FVertexShaderRHIParamRef ShaderRHI = GetVertexShader ( ) ;
2014-06-05 16:38:54 -04:00
FGlobalShader : : SetParameters ( RHICmdList , ShaderRHI , View ) ;
2014-06-03 15:53:13 -04:00
const FScene * Scene = ( const FScene * ) View . Family - > Scene ;
FSurfaceCacheResources & SurfaceCacheResources = * Scene - > SurfaceCacheResources ;
2014-06-05 16:38:54 -04:00
SetSRVParameter ( RHICmdList , ShaderRHI , IrradianceCachePositionRadius , SurfaceCacheResources . Level [ DepthLevel ] - > PositionAndRadius . SRV ) ;
SetSRVParameter ( RHICmdList , ShaderRHI , IrradianceCacheOccluderRadius , SurfaceCacheResources . Level [ DepthLevel ] - > OccluderRadius . SRV ) ;
SetSRVParameter ( RHICmdList , ShaderRHI , IrradianceCacheNormal , SurfaceCacheResources . Level [ DepthLevel ] - > Normal . SRV ) ;
SetSRVParameter ( RHICmdList , ShaderRHI , IrradianceCacheBentNormal , SurfaceCacheResources . Level [ DepthLevel ] - > BentNormal . SRV ) ;
2014-11-21 21:37:13 -05:00
SetSRVParameter ( RHICmdList , ShaderRHI , IrradianceCacheIrradiance , SurfaceCacheResources . Level [ DepthLevel ] - > Irradiance . SRV ) ;
2014-06-03 15:53:13 -04:00
2014-06-05 16:38:54 -04:00
SetShaderValue ( RHICmdList , ShaderRHI , InterpolationRadiusScale , ( bFinalInterpolationPass ? GAOInterpolationRadiusScale : 1.0f ) ) ;
SetShaderValue ( RHICmdList , ShaderRHI , NormalizedOffsetToPixelCenter , NormalizedOffsetToPixelCenterValue ) ;
2014-06-03 15:53:13 -04:00
2014-09-26 19:53:37 -04:00
const FIntPoint AOViewRectSize = FIntPoint : : DivideAndRoundUp ( View . ViewRect . Size ( ) , CurrentLevelDownsampleFactorValue ) ;
2014-06-03 15:53:13 -04:00
const FVector2D HackExpandValue ( .5f / AOViewRectSize . X , .5f / AOViewRectSize . Y ) ;
2014-06-05 16:38:54 -04:00
SetShaderValue ( RHICmdList , ShaderRHI , HackExpand , HackExpandValue ) ;
2014-12-16 20:00:22 -05:00
2015-03-02 13:22:05 -05:00
// Must push the bounding geometry toward the camera with depth testing, to be in front of any potential receivers
SetShaderValue ( RHICmdList , ShaderRHI , InterpolationBoundingDirection , GAOInterpolationDepthTesting ? - 1.0f : 1.0f ) ;
2014-12-16 20:00:22 -05:00
AOParameters . Set ( RHICmdList , ShaderRHI , Parameters ) ;
2014-06-03 15:53:13 -04:00
}
2015-04-01 07:20:55 -04:00
virtual bool Serialize ( FArchive & Ar ) override
2014-06-03 15:53:13 -04:00
{
bool bShaderHasOutdatedParameters = FGlobalShader : : Serialize ( Ar ) ;
Ar < < IrradianceCachePositionRadius ;
Ar < < IrradianceCacheOccluderRadius ;
Ar < < IrradianceCacheNormal ;
Ar < < IrradianceCacheBentNormal ;
2014-11-21 21:37:13 -05:00
Ar < < IrradianceCacheIrradiance ;
2014-06-03 15:53:13 -04:00
Ar < < InterpolationRadiusScale ;
Ar < < NormalizedOffsetToPixelCenter ;
Ar < < HackExpand ;
2015-03-02 13:22:05 -05:00
Ar < < InterpolationBoundingDirection ;
2014-12-16 20:00:22 -05:00
Ar < < AOParameters ;
2014-06-03 15:53:13 -04:00
return bShaderHasOutdatedParameters ;
}
private :
FShaderResourceParameter IrradianceCachePositionRadius ;
FShaderResourceParameter IrradianceCacheOccluderRadius ;
FShaderResourceParameter IrradianceCacheNormal ;
FShaderResourceParameter IrradianceCacheBentNormal ;
2014-11-21 21:37:13 -05:00
FShaderResourceParameter IrradianceCacheIrradiance ;
2014-06-03 15:53:13 -04:00
FShaderParameter InterpolationRadiusScale ;
FShaderParameter NormalizedOffsetToPixelCenter ;
FShaderParameter HackExpand ;
2015-03-02 13:22:05 -05:00
FShaderParameter InterpolationBoundingDirection ;
2014-12-16 20:00:22 -05:00
FAOParameters AOParameters ;
2014-06-03 15:53:13 -04:00
} ;
2014-11-21 21:37:13 -05:00
// typedef required to get around macro expansion failure due to commas in template argument list
# define IMPLEMENT_SPLAT_VS_TYPE(bFinalInterpolationPass, bSupportIrradiance) \
typedef TIrradianceCacheSplatVS < bFinalInterpolationPass , bSupportIrradiance > TIrradianceCacheSplatVS # # bFinalInterpolationPass # # bSupportIrradiance ; \
IMPLEMENT_SHADER_TYPE ( template < > , TIrradianceCacheSplatVS # # bFinalInterpolationPass # # bSupportIrradiance , TEXT ( " DistanceFieldSurfaceCacheLighting " ) , TEXT ( " IrradianceCacheSplatVS " ) , SF_Vertex ) ;
2014-06-03 15:53:13 -04:00
2014-11-21 21:37:13 -05:00
IMPLEMENT_SPLAT_VS_TYPE ( true , true )
IMPLEMENT_SPLAT_VS_TYPE ( false , true )
IMPLEMENT_SPLAT_VS_TYPE ( true , false )
IMPLEMENT_SPLAT_VS_TYPE ( false , false )
template < bool bFinalInterpolationPass , bool bSupportIrradiance >
2014-06-03 15:53:13 -04:00
class TIrradianceCacheSplatPS : public FGlobalShader
{
DECLARE_SHADER_TYPE ( TIrradianceCacheSplatPS , Global ) ;
public :
static bool ShouldCache ( EShaderPlatform Platform )
{
2014-06-26 15:53:01 -04:00
return IsFeatureLevelSupported ( Platform , ERHIFeatureLevel : : SM5 ) & & DoesPlatformSupportDistanceFieldAO ( Platform ) ;
2014-06-03 15:53:13 -04:00
}
static void ModifyCompilationEnvironment ( EShaderPlatform Platform , FShaderCompilerEnvironment & OutEnvironment )
{
FGlobalShader : : ModifyCompilationEnvironment ( Platform , OutEnvironment ) ;
OutEnvironment . SetDefine ( TEXT ( " DOWNSAMPLE_FACTOR " ) , GAODownsampleFactor ) ;
OutEnvironment . SetDefine ( TEXT ( " FINAL_INTERPOLATION_PASS " ) , ( uint32 ) bFinalInterpolationPass ) ;
2014-11-21 21:37:13 -05:00
OutEnvironment . SetDefine ( TEXT ( " SUPPORT_IRRADIANCE " ) , bSupportIrradiance ? TEXT ( " 1 " ) : TEXT ( " 0 " ) ) ;
2014-06-03 15:53:13 -04:00
}
/** Default constructor. */
TIrradianceCacheSplatPS ( ) { }
/** Initialization constructor. */
TIrradianceCacheSplatPS ( const ShaderMetaType : : CompiledShaderInitializerType & Initializer )
: FGlobalShader ( Initializer )
{
AOParameters . Bind ( Initializer . ParameterMap ) ;
DeferredParameters . Bind ( Initializer . ParameterMap ) ;
AOLevelParameters . Bind ( Initializer . ParameterMap ) ;
DistanceFieldNormalTexture . Bind ( Initializer . ParameterMap , TEXT ( " DistanceFieldNormalTexture " ) ) ;
DistanceFieldNormalSampler . Bind ( Initializer . ParameterMap , TEXT ( " DistanceFieldNormalSampler " ) ) ;
InterpolationAngleNormalization . Bind ( Initializer . ParameterMap , TEXT ( " InterpolationAngleNormalization " ) ) ;
InvMinCosPointBehindPlane . Bind ( Initializer . ParameterMap , TEXT ( " InvMinCosPointBehindPlane " ) ) ;
}
2014-08-28 13:54:31 -04:00
void SetParameters ( FRHICommandList & RHICmdList , const FSceneView & View , FSceneRenderTargetItem & DistanceFieldNormal , int32 DestLevelDownsampleFactor , const FDistanceFieldAOParameters & Parameters )
2014-06-03 15:53:13 -04:00
{
const FPixelShaderRHIParamRef ShaderRHI = GetPixelShader ( ) ;
2014-06-05 16:38:54 -04:00
FGlobalShader : : SetParameters ( RHICmdList , ShaderRHI , View ) ;
2014-08-28 13:54:31 -04:00
AOParameters . Set ( RHICmdList , ShaderRHI , Parameters ) ;
2014-06-05 16:38:54 -04:00
DeferredParameters . Set ( RHICmdList , ShaderRHI , View ) ;
AOLevelParameters . Set ( RHICmdList , ShaderRHI , View , DestLevelDownsampleFactor ) ;
2014-06-03 15:53:13 -04:00
SetTextureParameter (
2014-06-05 16:38:54 -04:00
RHICmdList ,
2014-06-03 15:53:13 -04:00
ShaderRHI ,
DistanceFieldNormalTexture ,
DistanceFieldNormalSampler ,
TStaticSamplerState < SF_Point , AM_Clamp , AM_Clamp , AM_Clamp > : : GetRHI ( ) ,
DistanceFieldNormal . ShaderResourceTexture
) ;
const float EffectiveMaxAngle = bFinalInterpolationPass ? GAOInterpolationMaxAngle * GAOInterpolationAngleScale : GAOInterpolationMaxAngle ;
const float InterpolationAngleNormalizationValue = 1.0f / FMath : : Sqrt ( 1.0f - FMath : : Cos ( EffectiveMaxAngle * PI / 180.0f ) ) ;
2014-06-05 16:38:54 -04:00
SetShaderValue ( RHICmdList , ShaderRHI , InterpolationAngleNormalization , InterpolationAngleNormalizationValue ) ;
2014-06-03 15:53:13 -04:00
const float MinCosPointBehindPlaneValue = FMath : : Cos ( ( GAOMinPointBehindPlaneAngle + 90.0f ) * PI / 180.0f ) ;
2014-06-05 16:38:54 -04:00
SetShaderValue ( RHICmdList , ShaderRHI , InvMinCosPointBehindPlane , 1.0f / MinCosPointBehindPlaneValue ) ;
2014-06-03 15:53:13 -04:00
}
// FShader interface.
2015-04-01 07:20:55 -04:00
virtual bool Serialize ( FArchive & Ar ) override
2014-06-03 15:53:13 -04:00
{
bool bShaderHasOutdatedParameters = FGlobalShader : : Serialize ( Ar ) ;
Ar < < AOParameters ;
Ar < < AOLevelParameters ;
Ar < < DeferredParameters ;
Ar < < DistanceFieldNormalTexture ;
Ar < < DistanceFieldNormalSampler ;
Ar < < InterpolationAngleNormalization ;
Ar < < InvMinCosPointBehindPlane ;
return bShaderHasOutdatedParameters ;
}
private :
FAOParameters AOParameters ;
FAOLevelParameters AOLevelParameters ;
FDeferredPixelShaderParameters DeferredParameters ;
FShaderResourceParameter DistanceFieldNormalTexture ;
FShaderResourceParameter DistanceFieldNormalSampler ;
FShaderParameter InterpolationAngleNormalization ;
FShaderParameter InvMinCosPointBehindPlane ;
} ;
2014-11-21 21:37:13 -05:00
// typedef required to get around macro expansion failure due to commas in template argument list
# define IMPLEMENT_SPLAT_PS_TYPE(bFinalInterpolationPass, bSupportIrradiance) \
typedef TIrradianceCacheSplatPS < bFinalInterpolationPass , bSupportIrradiance > TIrradianceCacheSplatPS # # bFinalInterpolationPass # # bSupportIrradiance ; \
IMPLEMENT_SHADER_TYPE ( template < > , TIrradianceCacheSplatPS # # bFinalInterpolationPass # # bSupportIrradiance , TEXT ( " DistanceFieldSurfaceCacheLighting " ) , TEXT ( " IrradianceCacheSplatPS " ) , SF_Pixel ) ;
2014-06-03 15:53:13 -04:00
2014-11-21 21:37:13 -05:00
IMPLEMENT_SPLAT_PS_TYPE ( true , true )
IMPLEMENT_SPLAT_PS_TYPE ( false , true )
IMPLEMENT_SPLAT_PS_TYPE ( true , false )
IMPLEMENT_SPLAT_PS_TYPE ( false , false )
2014-09-26 17:07:59 -04:00
2014-11-21 21:37:13 -05:00
template < bool bSupportIrradiance >
class TDistanceFieldAOCombinePS : public FGlobalShader
2014-06-03 15:53:13 -04:00
{
2014-11-21 21:37:13 -05:00
DECLARE_SHADER_TYPE ( TDistanceFieldAOCombinePS , Global ) ;
2014-06-03 15:53:13 -04:00
public :
static bool ShouldCache ( EShaderPlatform Platform )
{
2014-06-26 15:53:01 -04:00
return IsFeatureLevelSupported ( Platform , ERHIFeatureLevel : : SM5 ) & & DoesPlatformSupportDistanceFieldAO ( Platform ) ;
2014-06-03 15:53:13 -04:00
}
static void ModifyCompilationEnvironment ( EShaderPlatform Platform , FShaderCompilerEnvironment & OutEnvironment )
{
OutEnvironment . SetDefine ( TEXT ( " DOWNSAMPLE_FACTOR " ) , GAODownsampleFactor ) ;
2014-11-21 21:37:13 -05:00
OutEnvironment . SetDefine ( TEXT ( " SUPPORT_IRRADIANCE " ) , bSupportIrradiance ? TEXT ( " 1 " ) : TEXT ( " 0 " ) ) ;
2014-06-03 15:53:13 -04:00
}
/** Default constructor. */
2014-11-21 21:37:13 -05:00
TDistanceFieldAOCombinePS ( ) { }
2014-06-03 15:53:13 -04:00
/** Initialization constructor. */
2014-11-21 21:37:13 -05:00
TDistanceFieldAOCombinePS ( const ShaderMetaType : : CompiledShaderInitializerType & Initializer )
2014-06-03 15:53:13 -04:00
: FGlobalShader ( Initializer )
{
DeferredParameters . Bind ( Initializer . ParameterMap ) ;
AOParameters . Bind ( Initializer . ParameterMap ) ;
AOLevelParameters . Bind ( Initializer . ParameterMap ) ;
2014-11-21 21:37:13 -05:00
BentNormalAOTexture . Bind ( Initializer . ParameterMap , TEXT ( " BentNormalAOTexture " ) ) ;
BentNormalAOSampler . Bind ( Initializer . ParameterMap , TEXT ( " BentNormalAOSampler " ) ) ;
IrradianceTexture . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceTexture " ) ) ;
IrradianceSampler . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceSampler " ) ) ;
2014-08-28 16:10:11 -04:00
DistanceFieldNormalTexture . Bind ( Initializer . ParameterMap , TEXT ( " DistanceFieldNormalTexture " ) ) ;
DistanceFieldNormalSampler . Bind ( Initializer . ParameterMap , TEXT ( " DistanceFieldNormalSampler " ) ) ;
2014-11-21 21:37:13 -05:00
DebugBuffer . Bind ( Initializer . ParameterMap , TEXT ( " DebugBuffer " ) ) ;
2015-01-29 14:46:20 -05:00
DistanceFadeScale . Bind ( Initializer . ParameterMap , TEXT ( " DistanceFadeScale " ) ) ;
2015-02-19 16:20:47 -05:00
SelfOcclusionReplacement . Bind ( Initializer . ParameterMap , TEXT ( " SelfOcclusionReplacement " ) ) ;
2014-06-03 15:53:13 -04:00
}
2014-12-01 12:44:34 -05:00
void SetParameters (
FRHICommandList & RHICmdList ,
const FSceneView & View ,
FSceneRenderTargetItem & InBentNormalTexture ,
IPooledRenderTarget * InIrradianceTexture ,
FSceneRenderTargetItem & DistanceFieldNormal ,
const FDistanceFieldAOParameters & Parameters )
2014-06-03 15:53:13 -04:00
{
const FPixelShaderRHIParamRef ShaderRHI = GetPixelShader ( ) ;
2014-06-05 16:38:54 -04:00
FGlobalShader : : SetParameters ( RHICmdList , ShaderRHI , View ) ;
DeferredParameters . Set ( RHICmdList , ShaderRHI , View ) ;
2014-08-28 13:54:31 -04:00
AOParameters . Set ( RHICmdList , ShaderRHI , Parameters ) ;
2014-06-05 16:38:54 -04:00
AOLevelParameters . Set ( RHICmdList , ShaderRHI , View , GAODownsampleFactor ) ;
2014-06-03 15:53:13 -04:00
2014-11-21 21:37:13 -05:00
SetTextureParameter ( RHICmdList , ShaderRHI , BentNormalAOTexture , BentNormalAOSampler , TStaticSamplerState < SF_Point > : : GetRHI ( ) , InBentNormalTexture . ShaderResourceTexture ) ;
if ( IrradianceTexture . IsBound ( ) )
{
SetTextureParameter ( RHICmdList , ShaderRHI , IrradianceTexture , IrradianceSampler , TStaticSamplerState < SF_Point > : : GetRHI ( ) , InIrradianceTexture - > GetRenderTargetItem ( ) . ShaderResourceTexture ) ;
}
2014-08-28 16:10:11 -04:00
SetTextureParameter (
RHICmdList ,
ShaderRHI ,
DistanceFieldNormalTexture ,
DistanceFieldNormalSampler ,
TStaticSamplerState < SF_Point , AM_Clamp , AM_Clamp , AM_Clamp > : : GetRHI ( ) ,
DistanceFieldNormal . ShaderResourceTexture
) ;
2014-11-21 21:37:13 -05:00
SetSRVParameter ( RHICmdList , ShaderRHI , DebugBuffer , GDebugBuffer . DebugData . SRV ) ;
2015-01-29 14:46:20 -05:00
const float DistanceFadeScaleValue = 1.0f / ( ( 1.0f - GAOViewFadeDistanceScale ) * GAOMaxViewDistance ) ;
SetShaderValue ( RHICmdList , ShaderRHI , DistanceFadeScale , DistanceFadeScaleValue ) ;
2015-02-19 16:20:47 -05:00
extern float GVPLSelfOcclusionReplacement ;
SetShaderValue ( RHICmdList , ShaderRHI , SelfOcclusionReplacement , GVPLSelfOcclusionReplacement ) ;
2014-06-03 15:53:13 -04:00
}
2014-12-01 12:44:34 -05:00
2014-06-03 15:53:13 -04:00
// FShader interface.
2015-04-01 07:20:55 -04:00
virtual bool Serialize ( FArchive & Ar ) override
2014-06-03 15:53:13 -04:00
{
bool bShaderHasOutdatedParameters = FGlobalShader : : Serialize ( Ar ) ;
Ar < < DeferredParameters ;
Ar < < AOParameters ;
Ar < < AOLevelParameters ;
2014-11-21 21:37:13 -05:00
Ar < < BentNormalAOTexture ;
Ar < < BentNormalAOSampler ;
Ar < < IrradianceTexture ;
Ar < < IrradianceSampler ;
2014-08-28 16:10:11 -04:00
Ar < < DistanceFieldNormalTexture ;
Ar < < DistanceFieldNormalSampler ;
2014-11-21 21:37:13 -05:00
Ar < < DebugBuffer ;
2015-01-29 14:46:20 -05:00
Ar < < DistanceFadeScale ;
2015-02-19 16:20:47 -05:00
Ar < < SelfOcclusionReplacement ;
2014-06-03 15:53:13 -04:00
return bShaderHasOutdatedParameters ;
}
private :
FDeferredPixelShaderParameters DeferredParameters ;
FAOParameters AOParameters ;
FAOLevelParameters AOLevelParameters ;
2014-11-21 21:37:13 -05:00
FShaderResourceParameter BentNormalAOTexture ;
FShaderResourceParameter BentNormalAOSampler ;
FShaderResourceParameter IrradianceTexture ;
FShaderResourceParameter IrradianceSampler ;
2014-08-28 16:10:11 -04:00
FShaderResourceParameter DistanceFieldNormalTexture ;
FShaderResourceParameter DistanceFieldNormalSampler ;
2014-11-21 21:37:13 -05:00
FShaderResourceParameter DebugBuffer ;
2015-01-29 14:46:20 -05:00
FShaderParameter DistanceFadeScale ;
2015-02-19 16:20:47 -05:00
FShaderParameter SelfOcclusionReplacement ;
2014-06-03 15:53:13 -04:00
} ;
2014-11-21 21:37:13 -05:00
IMPLEMENT_SHADER_TYPE ( template < > , TDistanceFieldAOCombinePS < true > , TEXT ( " DistanceFieldSurfaceCacheLighting " ) , TEXT ( " AOCombinePS " ) , SF_Pixel ) ;
IMPLEMENT_SHADER_TYPE ( template < > , TDistanceFieldAOCombinePS < false > , TEXT ( " DistanceFieldSurfaceCacheLighting " ) , TEXT ( " AOCombinePS " ) , SF_Pixel ) ;
2014-06-03 15:53:13 -04:00
2015-04-03 18:56:44 -04:00
template < bool bSupportIrradiance , bool bHighQuality >
2014-11-21 21:37:13 -05:00
class TFillGapsPS : public FGlobalShader
2014-06-03 15:53:13 -04:00
{
2014-11-21 21:37:13 -05:00
DECLARE_SHADER_TYPE ( TFillGapsPS , Global ) ;
2014-06-03 15:53:13 -04:00
public :
static bool ShouldCache ( EShaderPlatform Platform )
{
2014-06-26 15:53:01 -04:00
return IsFeatureLevelSupported ( Platform , ERHIFeatureLevel : : SM5 ) & & DoesPlatformSupportDistanceFieldAO ( Platform ) ;
2014-06-03 15:53:13 -04:00
}
static void ModifyCompilationEnvironment ( EShaderPlatform Platform , FShaderCompilerEnvironment & OutEnvironment )
{
OutEnvironment . SetDefine ( TEXT ( " DOWNSAMPLE_FACTOR " ) , GAODownsampleFactor ) ;
2014-11-21 21:37:13 -05:00
OutEnvironment . SetDefine ( TEXT ( " SUPPORT_IRRADIANCE " ) , bSupportIrradiance ? TEXT ( " 1 " ) : TEXT ( " 0 " ) ) ;
2015-04-03 18:56:44 -04:00
OutEnvironment . SetDefine ( TEXT ( " HIGH_QUALITY_FILL_GAPS " ) , bHighQuality ? TEXT ( " 1 " ) : TEXT ( " 0 " ) ) ;
2014-06-03 15:53:13 -04:00
}
/** Default constructor. */
2014-11-21 21:37:13 -05:00
TFillGapsPS ( ) { }
2014-06-03 15:53:13 -04:00
/** Initialization constructor. */
2014-11-21 21:37:13 -05:00
TFillGapsPS ( const ShaderMetaType : : CompiledShaderInitializerType & Initializer )
2014-06-03 15:53:13 -04:00
: FGlobalShader ( Initializer )
{
BentNormalAOTexture . Bind ( Initializer . ParameterMap , TEXT ( " BentNormalAOTexture " ) ) ;
BentNormalAOSampler . Bind ( Initializer . ParameterMap , TEXT ( " BentNormalAOSampler " ) ) ;
2014-11-21 21:37:13 -05:00
IrradianceTexture . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceTexture " ) ) ;
IrradianceSampler . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceSampler " ) ) ;
2014-06-03 15:53:13 -04:00
BentNormalAOTexelSize . Bind ( Initializer . ParameterMap , TEXT ( " BentNormalAOTexelSize " ) ) ;
2015-04-03 18:56:44 -04:00
MinDownsampleFactorToBaseLevel . Bind ( Initializer . ParameterMap , TEXT ( " MinDownsampleFactorToBaseLevel " ) ) ;
2014-06-03 15:53:13 -04:00
}
2014-11-21 21:37:13 -05:00
void SetParameters ( FRHICommandList & RHICmdList , const FSceneView & View , FSceneRenderTargetItem & DistanceFieldAOBentNormal2 , IPooledRenderTarget * DistanceFieldIrradiance2 )
2014-06-03 15:53:13 -04:00
{
const FPixelShaderRHIParamRef ShaderRHI = GetPixelShader ( ) ;
2014-06-05 16:38:54 -04:00
FGlobalShader : : SetParameters ( RHICmdList , ShaderRHI , View ) ;
2014-06-03 15:53:13 -04:00
SetTextureParameter (
2014-06-05 16:38:54 -04:00
RHICmdList ,
2014-06-03 15:53:13 -04:00
ShaderRHI ,
BentNormalAOTexture ,
BentNormalAOSampler ,
TStaticSamplerState < SF_Bilinear , AM_Clamp , AM_Clamp , AM_Clamp > : : GetRHI ( ) ,
DistanceFieldAOBentNormal2 . ShaderResourceTexture
) ;
2014-11-21 21:37:13 -05:00
if ( IrradianceTexture . IsBound ( ) )
{
SetTextureParameter (
RHICmdList ,
ShaderRHI ,
IrradianceTexture ,
IrradianceSampler ,
TStaticSamplerState < SF_Bilinear , AM_Clamp , AM_Clamp , AM_Clamp > : : GetRHI ( ) ,
DistanceFieldIrradiance2 - > GetRenderTargetItem ( ) . ShaderResourceTexture
) ;
}
2014-06-03 15:53:13 -04:00
const FIntPoint DownsampledBufferSize ( GSceneRenderTargets . GetBufferSizeXY ( ) / FIntPoint ( GAODownsampleFactor , GAODownsampleFactor ) ) ;
const FVector2D BaseLevelTexelSizeValue ( 1.0f / DownsampledBufferSize . X , 1.0f / DownsampledBufferSize . Y ) ;
2014-06-05 16:38:54 -04:00
SetShaderValue ( RHICmdList , ShaderRHI , BentNormalAOTexelSize , BaseLevelTexelSizeValue ) ;
2015-04-03 18:56:44 -04:00
const float MinDownsampleFactor = 1 < < ( GAOMinLevel * GAOPowerOfTwoBetweenLevels ) ;
SetShaderValue ( RHICmdList , ShaderRHI , MinDownsampleFactorToBaseLevel , MinDownsampleFactor ) ;
2014-06-03 15:53:13 -04:00
}
// FShader interface.
2015-04-01 07:20:55 -04:00
virtual bool Serialize ( FArchive & Ar ) override
2014-06-03 15:53:13 -04:00
{
bool bShaderHasOutdatedParameters = FGlobalShader : : Serialize ( Ar ) ;
Ar < < BentNormalAOTexture ;
Ar < < BentNormalAOSampler ;
2014-11-21 21:37:13 -05:00
Ar < < IrradianceTexture ;
Ar < < IrradianceSampler ;
2014-06-03 15:53:13 -04:00
Ar < < BentNormalAOTexelSize ;
2015-04-03 18:56:44 -04:00
Ar < < MinDownsampleFactorToBaseLevel ;
2014-06-03 15:53:13 -04:00
return bShaderHasOutdatedParameters ;
}
private :
FShaderResourceParameter BentNormalAOTexture ;
FShaderResourceParameter BentNormalAOSampler ;
2014-11-21 21:37:13 -05:00
FShaderResourceParameter IrradianceTexture ;
FShaderResourceParameter IrradianceSampler ;
2014-06-03 15:53:13 -04:00
FShaderParameter BentNormalAOTexelSize ;
2015-04-03 18:56:44 -04:00
FShaderParameter MinDownsampleFactorToBaseLevel ;
2014-06-03 15:53:13 -04:00
} ;
2015-04-03 18:56:44 -04:00
# define IMPLEMENT_FILLGAPS_PS_TYPE(bSupportIrradiance,bHighQuality) \
typedef TFillGapsPS < bSupportIrradiance , bHighQuality > TFillGapsPS # # bSupportIrradiance # # bHighQuality ; \
IMPLEMENT_SHADER_TYPE ( template < > , TFillGapsPS # # bSupportIrradiance # # bHighQuality , TEXT ( " DistanceFieldLightingPost " ) , TEXT ( " FillGapsPS " ) , SF_Pixel ) ;
IMPLEMENT_FILLGAPS_PS_TYPE ( true , true ) ;
IMPLEMENT_FILLGAPS_PS_TYPE ( true , false ) ;
IMPLEMENT_FILLGAPS_PS_TYPE ( false , true ) ;
IMPLEMENT_FILLGAPS_PS_TYPE ( false , false ) ;
2014-06-03 15:53:13 -04:00
2014-11-21 21:37:13 -05:00
template < bool bSupportIrradiance >
class TUpdateHistoryPS : public FGlobalShader
2014-06-03 15:53:13 -04:00
{
2014-11-21 21:37:13 -05:00
DECLARE_SHADER_TYPE ( TUpdateHistoryPS , Global ) ;
2014-06-03 15:53:13 -04:00
public :
static bool ShouldCache ( EShaderPlatform Platform )
{
2014-06-26 15:53:01 -04:00
return IsFeatureLevelSupported ( Platform , ERHIFeatureLevel : : SM5 ) & & DoesPlatformSupportDistanceFieldAO ( Platform ) ;
2014-06-03 15:53:13 -04:00
}
static void ModifyCompilationEnvironment ( EShaderPlatform Platform , FShaderCompilerEnvironment & OutEnvironment )
{
OutEnvironment . SetDefine ( TEXT ( " DOWNSAMPLE_FACTOR " ) , GAODownsampleFactor ) ;
2014-11-21 21:37:13 -05:00
OutEnvironment . SetDefine ( TEXT ( " SUPPORT_IRRADIANCE " ) , bSupportIrradiance ? TEXT ( " 1 " ) : TEXT ( " 0 " ) ) ;
2014-06-03 15:53:13 -04:00
}
/** Default constructor. */
2014-11-21 21:37:13 -05:00
TUpdateHistoryPS ( ) { }
2014-06-03 15:53:13 -04:00
/** Initialization constructor. */
2014-11-21 21:37:13 -05:00
TUpdateHistoryPS ( const ShaderMetaType : : CompiledShaderInitializerType & Initializer )
2014-06-03 15:53:13 -04:00
: FGlobalShader ( Initializer )
{
DeferredParameters . Bind ( Initializer . ParameterMap ) ;
BentNormalAOTexture . Bind ( Initializer . ParameterMap , TEXT ( " BentNormalAOTexture " ) ) ;
BentNormalAOSampler . Bind ( Initializer . ParameterMap , TEXT ( " BentNormalAOSampler " ) ) ;
2014-11-21 21:37:13 -05:00
BentNormalHistoryTexture . Bind ( Initializer . ParameterMap , TEXT ( " BentNormalHistoryTexture " ) ) ;
BentNormalHistorySampler . Bind ( Initializer . ParameterMap , TEXT ( " BentNormalHistorySampler " ) ) ;
IrradianceTexture . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceTexture " ) ) ;
IrradianceSampler . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceSampler " ) ) ;
IrradianceHistoryTexture . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceHistoryTexture " ) ) ;
IrradianceHistorySampler . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceHistorySampler " ) ) ;
2014-06-03 15:53:13 -04:00
CameraMotion . Bind ( Initializer . ParameterMap ) ;
HistoryWeight . Bind ( Initializer . ParameterMap , TEXT ( " HistoryWeight " ) ) ;
2015-03-30 17:48:16 -04:00
HistoryDistanceThreshold . Bind ( Initializer . ParameterMap , TEXT ( " HistoryDistanceThreshold " ) ) ;
2015-04-03 18:56:44 -04:00
UseHistoryFilter . Bind ( Initializer . ParameterMap , TEXT ( " UseHistoryFilter " ) ) ;
2015-02-19 16:09:15 -05:00
VelocityTexture . Bind ( Initializer . ParameterMap , TEXT ( " VelocityTexture " ) ) ;
VelocityTextureSampler . Bind ( Initializer . ParameterMap , TEXT ( " VelocityTextureSampler " ) ) ;
2014-06-03 15:53:13 -04:00
}
2014-11-21 21:37:13 -05:00
void SetParameters (
FRHICommandList & RHICmdList ,
const FSceneView & View ,
FSceneRenderTargetItem & BentNormalHistoryTextureValue ,
TRefCountPtr < IPooledRenderTarget > * IrradianceHistoryRT ,
FSceneRenderTargetItem & DistanceFieldAOBentNormal ,
2015-02-19 16:09:15 -05:00
IPooledRenderTarget * DistanceFieldIrradiance ,
FSceneRenderTargetItem & VelocityTextureValue )
2014-06-03 15:53:13 -04:00
{
const FPixelShaderRHIParamRef ShaderRHI = GetPixelShader ( ) ;
2014-06-05 16:38:54 -04:00
FGlobalShader : : SetParameters ( RHICmdList , ShaderRHI , View ) ;
DeferredParameters . Set ( RHICmdList , ShaderRHI , View ) ;
2014-06-03 15:53:13 -04:00
SetTextureParameter (
2014-06-05 16:38:54 -04:00
RHICmdList ,
2014-06-03 15:53:13 -04:00
ShaderRHI ,
BentNormalAOTexture ,
BentNormalAOSampler ,
TStaticSamplerState < SF_Bilinear , AM_Clamp , AM_Clamp , AM_Clamp > : : GetRHI ( ) ,
DistanceFieldAOBentNormal . ShaderResourceTexture
) ;
SetTextureParameter (
2014-06-05 16:38:54 -04:00
RHICmdList ,
2014-06-03 15:53:13 -04:00
ShaderRHI ,
2014-11-21 21:37:13 -05:00
BentNormalHistoryTexture ,
BentNormalHistorySampler ,
2014-06-03 15:53:13 -04:00
TStaticSamplerState < SF_Bilinear , AM_Clamp , AM_Clamp , AM_Clamp > : : GetRHI ( ) ,
2014-11-21 21:37:13 -05:00
BentNormalHistoryTextureValue . ShaderResourceTexture
2014-06-03 15:53:13 -04:00
) ;
2014-11-21 21:37:13 -05:00
if ( IrradianceTexture . IsBound ( ) )
{
SetTextureParameter (
RHICmdList ,
ShaderRHI ,
IrradianceTexture ,
IrradianceSampler ,
TStaticSamplerState < SF_Bilinear , AM_Clamp , AM_Clamp , AM_Clamp > : : GetRHI ( ) ,
DistanceFieldIrradiance - > GetRenderTargetItem ( ) . ShaderResourceTexture
) ;
}
if ( IrradianceHistoryTexture . IsBound ( ) )
{
SetTextureParameter (
RHICmdList ,
ShaderRHI ,
IrradianceHistoryTexture ,
IrradianceHistorySampler ,
TStaticSamplerState < SF_Bilinear , AM_Clamp , AM_Clamp , AM_Clamp > : : GetRHI ( ) ,
( * IrradianceHistoryRT ) - > GetRenderTargetItem ( ) . ShaderResourceTexture
) ;
}
2014-06-05 16:38:54 -04:00
CameraMotion . Set ( RHICmdList , View , ShaderRHI ) ;
2014-06-03 15:53:13 -04:00
2014-06-05 16:38:54 -04:00
SetShaderValue ( RHICmdList , ShaderRHI , HistoryWeight , GAOHistoryWeight ) ;
2015-03-30 17:48:16 -04:00
SetShaderValue ( RHICmdList , ShaderRHI , HistoryDistanceThreshold , GAOHistoryDistanceThreshold ) ;
2015-04-03 18:56:44 -04:00
SetShaderValue ( RHICmdList , ShaderRHI , UseHistoryFilter , ( GAOHistoryStabilityPass ? 1.0f : 0.0f ) ) ;
2015-02-19 16:09:15 -05:00
SetTextureParameter (
RHICmdList ,
ShaderRHI ,
VelocityTexture ,
VelocityTextureSampler ,
TStaticSamplerState < SF_Bilinear , AM_Clamp , AM_Clamp , AM_Clamp > : : GetRHI ( ) ,
VelocityTextureValue . ShaderResourceTexture
) ;
2014-06-03 15:53:13 -04:00
}
// FShader interface.
virtual bool Serialize ( FArchive & Ar )
{
bool bShaderHasOutdatedParameters = FGlobalShader : : Serialize ( Ar ) ;
Ar < < DeferredParameters ;
Ar < < BentNormalAOTexture ;
Ar < < BentNormalAOSampler ;
2014-11-21 21:37:13 -05:00
Ar < < BentNormalHistoryTexture ;
Ar < < BentNormalHistorySampler ;
Ar < < IrradianceTexture ;
Ar < < IrradianceSampler ;
Ar < < IrradianceHistoryTexture ;
Ar < < IrradianceHistorySampler ;
2014-06-03 15:53:13 -04:00
Ar < < CameraMotion ;
Ar < < HistoryWeight ;
2015-03-30 17:48:16 -04:00
Ar < < HistoryDistanceThreshold ;
2015-04-03 18:56:44 -04:00
Ar < < UseHistoryFilter ;
2015-02-19 16:09:15 -05:00
Ar < < VelocityTexture ;
Ar < < VelocityTextureSampler ;
2014-06-03 15:53:13 -04:00
return bShaderHasOutdatedParameters ;
}
private :
FDeferredPixelShaderParameters DeferredParameters ;
FShaderResourceParameter BentNormalAOTexture ;
FShaderResourceParameter BentNormalAOSampler ;
2014-11-21 21:37:13 -05:00
FShaderResourceParameter BentNormalHistoryTexture ;
FShaderResourceParameter BentNormalHistorySampler ;
FShaderResourceParameter IrradianceTexture ;
FShaderResourceParameter IrradianceSampler ;
FShaderResourceParameter IrradianceHistoryTexture ;
FShaderResourceParameter IrradianceHistorySampler ;
2014-06-03 15:53:13 -04:00
FCameraMotionParameters CameraMotion ;
FShaderParameter HistoryWeight ;
2015-03-30 17:48:16 -04:00
FShaderParameter HistoryDistanceThreshold ;
2015-04-03 18:56:44 -04:00
FShaderParameter UseHistoryFilter ;
2015-02-19 16:09:15 -05:00
FShaderResourceParameter VelocityTexture ;
FShaderResourceParameter VelocityTextureSampler ;
2014-06-03 15:53:13 -04:00
} ;
2015-04-03 18:56:44 -04:00
IMPLEMENT_SHADER_TYPE ( template < > , TUpdateHistoryPS < true > , TEXT ( " DistanceFieldLightingPost " ) , TEXT ( " UpdateHistoryPS " ) , SF_Pixel ) ;
IMPLEMENT_SHADER_TYPE ( template < > , TUpdateHistoryPS < false > , TEXT ( " DistanceFieldLightingPost " ) , TEXT ( " UpdateHistoryPS " ) , SF_Pixel ) ;
2014-06-03 15:53:13 -04:00
2015-02-19 16:24:46 -05:00
template < bool bSupportIrradiance >
class TFilterHistoryPS : public FGlobalShader
{
DECLARE_SHADER_TYPE ( TFilterHistoryPS , Global ) ;
public :
static bool ShouldCache ( EShaderPlatform Platform )
{
return IsFeatureLevelSupported ( Platform , ERHIFeatureLevel : : SM5 ) & & DoesPlatformSupportDistanceFieldAO ( Platform ) ;
}
static void ModifyCompilationEnvironment ( EShaderPlatform Platform , FShaderCompilerEnvironment & OutEnvironment )
{
OutEnvironment . SetDefine ( TEXT ( " DOWNSAMPLE_FACTOR " ) , GAODownsampleFactor ) ;
OutEnvironment . SetDefine ( TEXT ( " SUPPORT_IRRADIANCE " ) , bSupportIrradiance ? TEXT ( " 1 " ) : TEXT ( " 0 " ) ) ;
}
/** Default constructor. */
TFilterHistoryPS ( ) { }
/** Initialization constructor. */
TFilterHistoryPS ( const ShaderMetaType : : CompiledShaderInitializerType & Initializer )
: FGlobalShader ( Initializer )
{
BentNormalAOTexture . Bind ( Initializer . ParameterMap , TEXT ( " BentNormalAOTexture " ) ) ;
BentNormalAOSampler . Bind ( Initializer . ParameterMap , TEXT ( " BentNormalAOSampler " ) ) ;
IrradianceTexture . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceTexture " ) ) ;
IrradianceSampler . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceSampler " ) ) ;
HistoryWeight . Bind ( Initializer . ParameterMap , TEXT ( " HistoryWeight " ) ) ;
BentNormalAOTexelSize . Bind ( Initializer . ParameterMap , TEXT ( " BentNormalAOTexelSize " ) ) ;
}
void SetParameters (
FRHICommandList & RHICmdList ,
const FSceneView & View ,
FSceneRenderTargetItem & BentNormalHistoryTextureValue ,
IPooledRenderTarget * IrradianceHistoryRT )
{
const FPixelShaderRHIParamRef ShaderRHI = GetPixelShader ( ) ;
FGlobalShader : : SetParameters ( RHICmdList , ShaderRHI , View ) ;
SetTextureParameter (
RHICmdList ,
ShaderRHI ,
BentNormalAOTexture ,
BentNormalAOSampler ,
TStaticSamplerState < SF_Bilinear , AM_Clamp , AM_Clamp , AM_Clamp > : : GetRHI ( ) ,
BentNormalHistoryTextureValue . ShaderResourceTexture
) ;
if ( IrradianceTexture . IsBound ( ) )
{
SetTextureParameter (
RHICmdList ,
ShaderRHI ,
IrradianceTexture ,
IrradianceSampler ,
TStaticSamplerState < SF_Bilinear , AM_Clamp , AM_Clamp , AM_Clamp > : : GetRHI ( ) ,
IrradianceHistoryRT - > GetRenderTargetItem ( ) . ShaderResourceTexture
) ;
}
SetShaderValue ( RHICmdList , ShaderRHI , HistoryWeight , GAOHistoryWeight ) ;
const FIntPoint DownsampledBufferSize ( GSceneRenderTargets . GetBufferSizeXY ( ) / FIntPoint ( GAODownsampleFactor , GAODownsampleFactor ) ) ;
const FVector2D BaseLevelTexelSizeValue ( 1.0f / DownsampledBufferSize . X , 1.0f / DownsampledBufferSize . Y ) ;
SetShaderValue ( RHICmdList , ShaderRHI , BentNormalAOTexelSize , BaseLevelTexelSizeValue ) ;
}
// FShader interface.
virtual bool Serialize ( FArchive & Ar )
{
bool bShaderHasOutdatedParameters = FGlobalShader : : Serialize ( Ar ) ;
Ar < < BentNormalAOTexture ;
Ar < < BentNormalAOSampler ;
Ar < < IrradianceTexture ;
Ar < < IrradianceSampler ;
Ar < < HistoryWeight ;
Ar < < BentNormalAOTexelSize ;
return bShaderHasOutdatedParameters ;
}
private :
FShaderResourceParameter BentNormalAOTexture ;
FShaderResourceParameter BentNormalAOSampler ;
FShaderResourceParameter IrradianceTexture ;
FShaderResourceParameter IrradianceSampler ;
FShaderParameter HistoryWeight ;
FShaderParameter BentNormalAOTexelSize ;
} ;
2015-04-03 18:56:44 -04:00
IMPLEMENT_SHADER_TYPE ( template < > , TFilterHistoryPS < true > , TEXT ( " DistanceFieldLightingPost " ) , TEXT ( " FilterHistoryPS " ) , SF_Pixel ) ;
IMPLEMENT_SHADER_TYPE ( template < > , TFilterHistoryPS < false > , TEXT ( " DistanceFieldLightingPost " ) , TEXT ( " FilterHistoryPS " ) , SF_Pixel ) ;
2015-02-19 16:24:46 -05:00
2014-11-21 21:37:13 -05:00
void AllocateOrReuseAORenderTarget ( TRefCountPtr < IPooledRenderTarget > & Target , const TCHAR * Name , bool bWithAlpha )
2014-06-03 15:53:13 -04:00
{
if ( ! Target )
{
2014-09-26 17:07:59 -04:00
FIntPoint BufferSize = GetBufferSizeForAO ( ) ;
2014-06-03 15:53:13 -04:00
2014-11-21 21:37:13 -05:00
FPooledRenderTargetDesc Desc ( FPooledRenderTargetDesc : : Create2DDesc ( BufferSize , bWithAlpha ? PF_FloatRGBA : PF_FloatRGB , TexCreate_None , TexCreate_RenderTargetable | TexCreate_UAV , false ) ) ;
2014-06-03 15:53:13 -04:00
GRenderTargetPool . FindFreeElement ( Desc , Target , Name ) ;
}
}
void UpdateHistory (
2014-07-08 10:43:52 -04:00
FRHICommandList & RHICmdList ,
2014-12-16 20:00:22 -05:00
const FViewInfo & View ,
2014-11-21 21:37:13 -05:00
const TCHAR * BentNormalHistoryRTName ,
const TCHAR * IrradianceHistoryRTName ,
2015-02-19 16:09:15 -05:00
FSceneRenderTargetItem & VelocityTexture ,
2014-06-03 15:53:13 -04:00
/** Contains last frame's history, if non-NULL. This will be updated with the new frame's history. */
2014-11-21 21:37:13 -05:00
TRefCountPtr < IPooledRenderTarget > * BentNormalHistoryState ,
TRefCountPtr < IPooledRenderTarget > * IrradianceHistoryState ,
2014-06-03 15:53:13 -04:00
/** Source */
2014-11-21 21:37:13 -05:00
TRefCountPtr < IPooledRenderTarget > & BentNormalSource ,
TRefCountPtr < IPooledRenderTarget > & IrradianceSource ,
2014-06-03 15:53:13 -04:00
/** Output of Temporal Reprojection for the next step in the pipeline. */
2014-11-21 21:37:13 -05:00
TRefCountPtr < IPooledRenderTarget > & BentNormalHistoryOutput ,
TRefCountPtr < IPooledRenderTarget > & IrradianceHistoryOutput )
2014-06-03 15:53:13 -04:00
{
2014-11-21 21:37:13 -05:00
if ( BentNormalHistoryState )
2014-06-03 15:53:13 -04:00
{
2014-12-16 20:00:22 -05:00
const bool bUseDistanceFieldGI = IsDistanceFieldGIAllowed ( View ) ;
2014-11-21 21:37:13 -05:00
if ( * BentNormalHistoryState
& & ! View . bCameraCut
& & ! View . bPrevTransformsReset
2014-12-16 20:00:22 -05:00
& & ( ! bUseDistanceFieldGI | | ( IrradianceHistoryState & & * IrradianceHistoryState ) ) )
2014-06-03 15:53:13 -04:00
{
// Reuse a render target from the pool with a consistent name, for vis purposes
2014-11-21 21:37:13 -05:00
TRefCountPtr < IPooledRenderTarget > NewBentNormalHistory ;
AllocateOrReuseAORenderTarget ( NewBentNormalHistory , BentNormalHistoryRTName , true ) ;
TRefCountPtr < IPooledRenderTarget > NewIrradianceHistory ;
2014-12-16 20:00:22 -05:00
if ( bUseDistanceFieldGI )
2014-11-21 21:37:13 -05:00
{
AllocateOrReuseAORenderTarget ( NewIrradianceHistory , IrradianceHistoryRTName , false ) ;
}
2014-06-03 15:53:13 -04:00
2015-02-19 16:24:46 -05:00
SCOPED_DRAW_EVENT ( RHICmdList , UpdateHistory ) ;
2014-11-21 21:37:13 -05:00
2015-02-19 16:24:46 -05:00
{
2014-11-21 21:37:13 -05:00
FTextureRHIParamRef RenderTargets [ 2 ] =
{
NewBentNormalHistory - > GetRenderTargetItem ( ) . TargetableTexture ,
2014-12-16 20:00:22 -05:00
bUseDistanceFieldGI ? NewIrradianceHistory - > GetRenderTargetItem ( ) . TargetableTexture : NULL ,
2014-11-21 21:37:13 -05:00
} ;
2014-12-16 20:00:22 -05:00
SetRenderTargets ( RHICmdList , ARRAY_COUNT ( RenderTargets ) - ( bUseDistanceFieldGI ? 0 : 1 ) , RenderTargets , FTextureRHIParamRef ( ) , 0 , NULL ) ;
2014-06-03 15:53:13 -04:00
2014-07-10 21:07:13 -04:00
RHICmdList . SetViewport ( 0 , 0 , 0.0f , View . ViewRect . Width ( ) / GAODownsampleFactor , View . ViewRect . Height ( ) / GAODownsampleFactor , 1.0f ) ;
2014-06-12 07:13:34 -04:00
RHICmdList . SetRasterizerState ( TStaticRasterizerState < FM_Solid , CM_None > : : GetRHI ( ) ) ;
RHICmdList . SetDepthStencilState ( TStaticDepthStencilState < false , CF_Always > : : GetRHI ( ) ) ;
RHICmdList . SetBlendState ( TStaticBlendState < > : : GetRHI ( ) ) ;
2014-06-03 15:53:13 -04:00
2014-08-28 06:22:54 -04:00
TShaderMapRef < FPostProcessVS > VertexShader ( View . ShaderMap ) ;
2014-06-03 15:53:13 -04:00
2014-12-16 20:00:22 -05:00
if ( bUseDistanceFieldGI )
2014-11-21 21:37:13 -05:00
{
TShaderMapRef < TUpdateHistoryPS < true > > PixelShader ( View . ShaderMap ) ;
2014-06-03 15:53:13 -04:00
2014-11-21 21:37:13 -05:00
static FGlobalBoundShaderState BoundShaderState ;
SetGlobalBoundShaderState ( RHICmdList , View . GetFeatureLevel ( ) , BoundShaderState , GFilterVertexDeclaration . VertexDeclarationRHI , * VertexShader , * PixelShader ) ;
2015-02-19 16:09:15 -05:00
PixelShader - > SetParameters ( RHICmdList , View , ( * BentNormalHistoryState ) - > GetRenderTargetItem ( ) , IrradianceHistoryState , BentNormalSource - > GetRenderTargetItem ( ) , IrradianceSource , VelocityTexture ) ;
2014-11-21 21:37:13 -05:00
}
else
{
TShaderMapRef < TUpdateHistoryPS < false > > PixelShader ( View . ShaderMap ) ;
static FGlobalBoundShaderState BoundShaderState ;
SetGlobalBoundShaderState ( RHICmdList , View . GetFeatureLevel ( ) , BoundShaderState , GFilterVertexDeclaration . VertexDeclarationRHI , * VertexShader , * PixelShader ) ;
2015-02-19 16:09:15 -05:00
PixelShader - > SetParameters ( RHICmdList , View , ( * BentNormalHistoryState ) - > GetRenderTargetItem ( ) , IrradianceHistoryState , BentNormalSource - > GetRenderTargetItem ( ) , IrradianceSource , VelocityTexture ) ;
2014-11-21 21:37:13 -05:00
}
VertexShader - > SetParameters ( RHICmdList , View ) ;
2014-06-03 15:53:13 -04:00
DrawRectangle (
2014-06-12 07:13:34 -04:00
RHICmdList ,
2014-06-03 15:53:13 -04:00
0 , 0 ,
View . ViewRect . Width ( ) / GAODownsampleFactor , View . ViewRect . Height ( ) / GAODownsampleFactor ,
2014-07-10 21:07:13 -04:00
View . ViewRect . Min . X / GAODownsampleFactor , View . ViewRect . Min . Y / GAODownsampleFactor ,
2014-06-03 15:53:13 -04:00
View . ViewRect . Width ( ) / GAODownsampleFactor , View . ViewRect . Height ( ) / GAODownsampleFactor ,
FIntPoint ( View . ViewRect . Width ( ) / GAODownsampleFactor , View . ViewRect . Height ( ) / GAODownsampleFactor ) ,
GSceneRenderTargets . GetBufferSizeXY ( ) / FIntPoint ( GAODownsampleFactor , GAODownsampleFactor ) ,
* VertexShader ) ;
2015-04-03 18:56:44 -04:00
RHICmdList . CopyToResolveTarget ( NewBentNormalHistory - > GetRenderTargetItem ( ) . TargetableTexture , NewBentNormalHistory - > GetRenderTargetItem ( ) . ShaderResourceTexture , false , FResolveParams ( ) ) ;
if ( bUseDistanceFieldGI )
{
RHICmdList . CopyToResolveTarget ( NewIrradianceHistory - > GetRenderTargetItem ( ) . TargetableTexture , NewIrradianceHistory - > GetRenderTargetItem ( ) . ShaderResourceTexture , false , FResolveParams ( ) ) ;
}
2014-06-03 15:53:13 -04:00
}
2015-04-03 18:56:44 -04:00
if ( GAOHistoryStabilityPass )
{
const FPooledRenderTargetDesc & HistoryDesc = ( * BentNormalHistoryState ) - > GetDesc ( ) ;
// Reallocate history if buffer sizes have changed
if ( HistoryDesc . Extent ! = GSceneRenderTargets . GetBufferSizeXY ( ) / FIntPoint ( GAODownsampleFactor , GAODownsampleFactor ) )
{
GRenderTargetPool . FreeUnusedResource ( * BentNormalHistoryState ) ;
* BentNormalHistoryState = NULL ;
// Update the view state's render target reference with the new history
AllocateOrReuseAORenderTarget ( * BentNormalHistoryState , BentNormalHistoryRTName , true ) ;
if ( bUseDistanceFieldGI )
{
GRenderTargetPool . FreeUnusedResource ( * IrradianceHistoryState ) ;
* IrradianceHistoryState = NULL ;
AllocateOrReuseAORenderTarget ( * IrradianceHistoryState , IrradianceHistoryRTName , false ) ;
}
}
{
FTextureRHIParamRef RenderTargets [ 2 ] =
{
( * BentNormalHistoryState ) - > GetRenderTargetItem ( ) . TargetableTexture ,
bUseDistanceFieldGI ? ( * IrradianceHistoryState ) - > GetRenderTargetItem ( ) . TargetableTexture : NULL ,
} ;
SetRenderTargets ( RHICmdList , ARRAY_COUNT ( RenderTargets ) - ( bUseDistanceFieldGI ? 0 : 1 ) , RenderTargets , FTextureRHIParamRef ( ) , 0 , NULL ) ;
RHICmdList . SetViewport ( 0 , 0 , 0.0f , View . ViewRect . Width ( ) / GAODownsampleFactor , View . ViewRect . Height ( ) / GAODownsampleFactor , 1.0f ) ;
RHICmdList . SetRasterizerState ( TStaticRasterizerState < FM_Solid , CM_None > : : GetRHI ( ) ) ;
RHICmdList . SetDepthStencilState ( TStaticDepthStencilState < false , CF_Always > : : GetRHI ( ) ) ;
RHICmdList . SetBlendState ( TStaticBlendState < > : : GetRHI ( ) ) ;
TShaderMapRef < FPostProcessVS > VertexShader ( View . ShaderMap ) ;
if ( bUseDistanceFieldGI )
{
TShaderMapRef < TFilterHistoryPS < true > > PixelShader ( View . ShaderMap ) ;
static FGlobalBoundShaderState BoundShaderState ;
SetGlobalBoundShaderState ( RHICmdList , View . GetFeatureLevel ( ) , BoundShaderState , GFilterVertexDeclaration . VertexDeclarationRHI , * VertexShader , * PixelShader ) ;
PixelShader - > SetParameters ( RHICmdList , View , NewBentNormalHistory - > GetRenderTargetItem ( ) , NewIrradianceHistory ) ;
}
else
{
TShaderMapRef < TFilterHistoryPS < false > > PixelShader ( View . ShaderMap ) ;
static FGlobalBoundShaderState BoundShaderState ;
SetGlobalBoundShaderState ( RHICmdList , View . GetFeatureLevel ( ) , BoundShaderState , GFilterVertexDeclaration . VertexDeclarationRHI , * VertexShader , * PixelShader ) ;
PixelShader - > SetParameters ( RHICmdList , View , NewBentNormalHistory - > GetRenderTargetItem ( ) , NewIrradianceHistory ) ;
}
VertexShader - > SetParameters ( RHICmdList , View ) ;
DrawRectangle (
RHICmdList ,
0 , 0 ,
View . ViewRect . Width ( ) / GAODownsampleFactor , View . ViewRect . Height ( ) / GAODownsampleFactor ,
0 , 0 ,
View . ViewRect . Width ( ) / GAODownsampleFactor , View . ViewRect . Height ( ) / GAODownsampleFactor ,
FIntPoint ( View . ViewRect . Width ( ) / GAODownsampleFactor , View . ViewRect . Height ( ) / GAODownsampleFactor ) ,
GSceneRenderTargets . GetBufferSizeXY ( ) / FIntPoint ( GAODownsampleFactor , GAODownsampleFactor ) ,
* VertexShader ) ;
RHICmdList . CopyToResolveTarget ( ( * BentNormalHistoryState ) - > GetRenderTargetItem ( ) . TargetableTexture , ( * BentNormalHistoryState ) - > GetRenderTargetItem ( ) . ShaderResourceTexture , false , FResolveParams ( ) ) ;
if ( bUseDistanceFieldGI )
{
RHICmdList . CopyToResolveTarget ( ( * IrradianceHistoryState ) - > GetRenderTargetItem ( ) . TargetableTexture , ( * IrradianceHistoryState ) - > GetRenderTargetItem ( ) . ShaderResourceTexture , false , FResolveParams ( ) ) ;
}
}
BentNormalHistoryOutput = * BentNormalHistoryState ;
IrradianceHistoryOutput = * IrradianceHistoryState ;
}
else
2015-02-19 16:24:46 -05:00
{
// Update the view state's render target reference with the new history
2015-04-03 18:56:44 -04:00
* BentNormalHistoryState = NewBentNormalHistory ;
BentNormalHistoryOutput = NewBentNormalHistory ;
2015-02-19 16:24:46 -05:00
2015-04-03 18:56:44 -04:00
* IrradianceHistoryState = NewIrradianceHistory ;
IrradianceHistoryOutput = NewIrradianceHistory ;
2015-02-19 16:24:46 -05:00
}
2014-06-03 15:53:13 -04:00
}
else
{
// Use the current frame's mask for next frame's history
2014-11-21 21:37:13 -05:00
* BentNormalHistoryState = BentNormalSource ;
BentNormalHistoryOutput = BentNormalSource ;
BentNormalSource = NULL ;
* IrradianceHistoryState = IrradianceSource ;
IrradianceHistoryOutput = IrradianceSource ;
IrradianceSource = NULL ;
2014-06-03 15:53:13 -04:00
}
}
else
{
// Temporal reprojection is disabled or there is no view state - pass through
2014-11-21 21:37:13 -05:00
BentNormalHistoryOutput = BentNormalSource ;
IrradianceHistoryOutput = IrradianceSource ;
2014-06-03 15:53:13 -04:00
}
}
2014-08-28 16:10:11 -04:00
void PostProcessBentNormalAO (
FRHICommandList & RHICmdList ,
const FDistanceFieldAOParameters & Parameters ,
2014-12-16 20:00:22 -05:00
const FViewInfo & View ,
2015-02-19 16:09:15 -05:00
FSceneRenderTargetItem & VelocityTexture ,
2014-11-21 21:37:13 -05:00
FSceneRenderTargetItem & BentNormalInterpolation ,
IPooledRenderTarget * IrradianceInterpolation ,
2014-08-28 16:10:11 -04:00
FSceneRenderTargetItem & DistanceFieldNormal ,
2014-11-21 21:37:13 -05:00
TRefCountPtr < IPooledRenderTarget > & BentNormalOutput ,
TRefCountPtr < IPooledRenderTarget > & IrradianceOutput )
2014-06-03 15:53:13 -04:00
{
2014-12-16 20:00:22 -05:00
const bool bUseDistanceFieldGI = IsDistanceFieldGIAllowed ( View ) ;
2014-06-03 15:53:13 -04:00
TRefCountPtr < IPooledRenderTarget > DistanceFieldAOBentNormal ;
2014-11-21 21:37:13 -05:00
TRefCountPtr < IPooledRenderTarget > DistanceFieldIrradiance ;
AllocateOrReuseAORenderTarget ( DistanceFieldAOBentNormal , TEXT ( " DistanceFieldBentNormalAO " ) , true ) ;
2014-12-16 20:00:22 -05:00
if ( bUseDistanceFieldGI )
2014-11-21 21:37:13 -05:00
{
AllocateOrReuseAORenderTarget ( DistanceFieldIrradiance , TEXT ( " DistanceFieldIrradiance " ) , false ) ;
}
2014-06-03 15:53:13 -04:00
TRefCountPtr < IPooledRenderTarget > DistanceFieldAOBentNormal2 ;
2014-11-21 21:37:13 -05:00
TRefCountPtr < IPooledRenderTarget > DistanceFieldIrradiance2 ;
2014-06-03 15:53:13 -04:00
if ( GAOFillGaps )
{
2014-11-21 21:37:13 -05:00
AllocateOrReuseAORenderTarget ( DistanceFieldAOBentNormal2 , TEXT ( " DistanceFieldBentNormalAO2 " ) , true ) ;
2014-12-16 20:00:22 -05:00
if ( bUseDistanceFieldGI )
2014-11-21 21:37:13 -05:00
{
AllocateOrReuseAORenderTarget ( DistanceFieldIrradiance2 , TEXT ( " DistanceFieldIrradiance2 " ) , false ) ;
}
2014-06-03 15:53:13 -04:00
}
{
2014-10-20 10:43:43 -04:00
SCOPED_DRAW_EVENT ( RHICmdList , AOCombine ) ;
2014-06-03 15:53:13 -04:00
2015-04-03 18:56:44 -04:00
TRefCountPtr < IPooledRenderTarget > EffectiveDiffuseIrradianceTarget ;
2014-11-21 21:37:13 -05:00
2014-12-16 20:00:22 -05:00
if ( bUseDistanceFieldGI )
2014-11-21 21:37:13 -05:00
{
2015-04-03 18:56:44 -04:00
EffectiveDiffuseIrradianceTarget = GAOFillGaps ? DistanceFieldIrradiance2 : DistanceFieldIrradiance ;
2014-11-21 21:37:13 -05:00
}
FTextureRHIParamRef RenderTargets [ 2 ] =
{
GAOFillGaps ? DistanceFieldAOBentNormal2 - > GetRenderTargetItem ( ) . TargetableTexture : DistanceFieldAOBentNormal - > GetRenderTargetItem ( ) . TargetableTexture ,
2015-04-03 18:56:44 -04:00
EffectiveDiffuseIrradianceTarget ? EffectiveDiffuseIrradianceTarget - > GetRenderTargetItem ( ) . TargetableTexture : NULL ,
2014-11-21 21:37:13 -05:00
} ;
2014-12-16 20:00:22 -05:00
SetRenderTargets ( RHICmdList , ARRAY_COUNT ( RenderTargets ) - ( bUseDistanceFieldGI ? 0 : 1 ) , RenderTargets , FTextureRHIParamRef ( ) , 0 , NULL ) ;
2014-06-03 15:53:13 -04:00
{
2014-07-10 21:07:13 -04:00
RHICmdList . SetViewport ( 0 , 0 , 0.0f , View . ViewRect . Width ( ) / GAODownsampleFactor , View . ViewRect . Height ( ) / GAODownsampleFactor , 1.0f ) ;
2014-06-12 07:13:34 -04:00
RHICmdList . SetRasterizerState ( TStaticRasterizerState < FM_Solid , CM_None > : : GetRHI ( ) ) ;
RHICmdList . SetDepthStencilState ( TStaticDepthStencilState < false , CF_Always > : : GetRHI ( ) ) ;
RHICmdList . SetBlendState ( TStaticBlendState < > : : GetRHI ( ) ) ;
2014-06-03 15:53:13 -04:00
2014-08-28 06:22:54 -04:00
TShaderMapRef < FPostProcessVS > VertexShader ( View . ShaderMap ) ;
2014-06-03 15:53:13 -04:00
2014-12-16 20:00:22 -05:00
if ( bUseDistanceFieldGI )
2014-11-21 21:37:13 -05:00
{
TShaderMapRef < TDistanceFieldAOCombinePS < true > > PixelShader ( View . ShaderMap ) ;
static FGlobalBoundShaderState BoundShaderState ;
SetGlobalBoundShaderState ( RHICmdList , View . GetFeatureLevel ( ) , BoundShaderState , GFilterVertexDeclaration . VertexDeclarationRHI , * VertexShader , * PixelShader ) ;
PixelShader - > SetParameters ( RHICmdList , View , BentNormalInterpolation , IrradianceInterpolation , DistanceFieldNormal , Parameters ) ;
}
else
{
TShaderMapRef < TDistanceFieldAOCombinePS < false > > PixelShader ( View . ShaderMap ) ;
static FGlobalBoundShaderState BoundShaderState ;
SetGlobalBoundShaderState ( RHICmdList , View . GetFeatureLevel ( ) , BoundShaderState , GFilterVertexDeclaration . VertexDeclarationRHI , * VertexShader , * PixelShader ) ;
PixelShader - > SetParameters ( RHICmdList , View , BentNormalInterpolation , IrradianceInterpolation , DistanceFieldNormal , Parameters ) ;
}
2014-06-03 15:53:13 -04:00
DrawRectangle (
2014-06-12 07:13:34 -04:00
RHICmdList ,
2014-06-03 15:53:13 -04:00
0 , 0 ,
View . ViewRect . Width ( ) / GAODownsampleFactor , View . ViewRect . Height ( ) / GAODownsampleFactor ,
2014-07-10 21:07:13 -04:00
0 , 0 ,
2014-06-03 15:53:13 -04:00
View . ViewRect . Width ( ) / GAODownsampleFactor , View . ViewRect . Height ( ) / GAODownsampleFactor ,
FIntPoint ( View . ViewRect . Width ( ) / GAODownsampleFactor , View . ViewRect . Height ( ) / GAODownsampleFactor ) ,
2014-09-26 17:07:59 -04:00
GetBufferSizeForAO ( ) ,
2014-06-03 15:53:13 -04:00
* VertexShader ) ;
}
2015-04-03 18:56:44 -04:00
RHICmdList . CopyToResolveTarget ( DistanceFieldAOBentNormal2 - > GetRenderTargetItem ( ) . TargetableTexture , DistanceFieldAOBentNormal2 - > GetRenderTargetItem ( ) . ShaderResourceTexture , false , FResolveParams ( ) ) ;
if ( bUseDistanceFieldGI )
{
RHICmdList . CopyToResolveTarget ( EffectiveDiffuseIrradianceTarget - > GetRenderTargetItem ( ) . TargetableTexture , EffectiveDiffuseIrradianceTarget - > GetRenderTargetItem ( ) . ShaderResourceTexture , false , FResolveParams ( ) ) ;
}
2014-06-03 15:53:13 -04:00
}
if ( GAOFillGaps )
{
2014-10-20 10:43:43 -04:00
SCOPED_DRAW_EVENT ( RHICmdList , FillGaps ) ;
2014-11-21 21:37:13 -05:00
FTextureRHIParamRef RenderTargets [ 2 ] =
{
DistanceFieldAOBentNormal - > GetRenderTargetItem ( ) . TargetableTexture ,
2014-12-16 20:00:22 -05:00
bUseDistanceFieldGI ? DistanceFieldIrradiance - > GetRenderTargetItem ( ) . TargetableTexture : NULL ,
2014-11-21 21:37:13 -05:00
} ;
2014-12-16 20:00:22 -05:00
SetRenderTargets ( RHICmdList , ARRAY_COUNT ( RenderTargets ) - ( bUseDistanceFieldGI ? 0 : 1 ) , RenderTargets , FTextureRHIParamRef ( ) , 0 , NULL ) ;
2014-06-03 15:53:13 -04:00
{
2014-07-10 21:07:13 -04:00
RHICmdList . SetViewport ( 0 , 0 , 0.0f , View . ViewRect . Width ( ) / GAODownsampleFactor , View . ViewRect . Height ( ) / GAODownsampleFactor , 1.0f ) ;
2014-06-12 07:13:34 -04:00
RHICmdList . SetRasterizerState ( TStaticRasterizerState < FM_Solid , CM_None > : : GetRHI ( ) ) ;
RHICmdList . SetDepthStencilState ( TStaticDepthStencilState < false , CF_Always > : : GetRHI ( ) ) ;
RHICmdList . SetBlendState ( TStaticBlendState < > : : GetRHI ( ) ) ;
2014-06-03 15:53:13 -04:00
2014-08-28 06:22:54 -04:00
TShaderMapRef < FPostProcessVS > VertexShader ( View . ShaderMap ) ;
2014-06-03 15:53:13 -04:00
2015-04-03 18:56:44 -04:00
if ( GAOFillGapsHighQuality )
2014-11-21 21:37:13 -05:00
{
2015-04-03 18:56:44 -04:00
if ( bUseDistanceFieldGI )
{
TShaderMapRef < TFillGapsPS < true , true > > PixelShader ( View . ShaderMap ) ;
2014-11-21 21:37:13 -05:00
2015-04-03 18:56:44 -04:00
static FGlobalBoundShaderState BoundShaderState ;
SetGlobalBoundShaderState ( RHICmdList , View . GetFeatureLevel ( ) , BoundShaderState , GFilterVertexDeclaration . VertexDeclarationRHI , * VertexShader , * PixelShader ) ;
PixelShader - > SetParameters ( RHICmdList , View , DistanceFieldAOBentNormal2 - > GetRenderTargetItem ( ) , DistanceFieldIrradiance2 ) ;
}
else
{
TShaderMapRef < TFillGapsPS < false , true > > PixelShader ( View . ShaderMap ) ;
static FGlobalBoundShaderState BoundShaderState ;
SetGlobalBoundShaderState ( RHICmdList , View . GetFeatureLevel ( ) , BoundShaderState , GFilterVertexDeclaration . VertexDeclarationRHI , * VertexShader , * PixelShader ) ;
PixelShader - > SetParameters ( RHICmdList , View , DistanceFieldAOBentNormal2 - > GetRenderTargetItem ( ) , DistanceFieldIrradiance2 ) ;
}
2014-11-21 21:37:13 -05:00
}
else
{
2015-04-03 18:56:44 -04:00
if ( bUseDistanceFieldGI )
{
TShaderMapRef < TFillGapsPS < true , false > > PixelShader ( View . ShaderMap ) ;
2014-11-21 21:37:13 -05:00
2015-04-03 18:56:44 -04:00
static FGlobalBoundShaderState BoundShaderState ;
SetGlobalBoundShaderState ( RHICmdList , View . GetFeatureLevel ( ) , BoundShaderState , GFilterVertexDeclaration . VertexDeclarationRHI , * VertexShader , * PixelShader ) ;
PixelShader - > SetParameters ( RHICmdList , View , DistanceFieldAOBentNormal2 - > GetRenderTargetItem ( ) , DistanceFieldIrradiance2 ) ;
}
else
{
TShaderMapRef < TFillGapsPS < false , false > > PixelShader ( View . ShaderMap ) ;
static FGlobalBoundShaderState BoundShaderState ;
SetGlobalBoundShaderState ( RHICmdList , View . GetFeatureLevel ( ) , BoundShaderState , GFilterVertexDeclaration . VertexDeclarationRHI , * VertexShader , * PixelShader ) ;
PixelShader - > SetParameters ( RHICmdList , View , DistanceFieldAOBentNormal2 - > GetRenderTargetItem ( ) , DistanceFieldIrradiance2 ) ;
}
2014-11-21 21:37:13 -05:00
}
2014-06-03 15:53:13 -04:00
2014-06-05 16:38:54 -04:00
VertexShader - > SetParameters ( RHICmdList , View ) ;
2014-06-03 15:53:13 -04:00
DrawRectangle (
2014-06-12 07:13:34 -04:00
RHICmdList ,
2014-06-03 15:53:13 -04:00
0 , 0 ,
View . ViewRect . Width ( ) / GAODownsampleFactor , View . ViewRect . Height ( ) / GAODownsampleFactor ,
2014-07-10 21:07:13 -04:00
0 , 0 ,
2014-06-03 15:53:13 -04:00
View . ViewRect . Width ( ) / GAODownsampleFactor , View . ViewRect . Height ( ) / GAODownsampleFactor ,
FIntPoint ( View . ViewRect . Width ( ) / GAODownsampleFactor , View . ViewRect . Height ( ) / GAODownsampleFactor ) ,
GSceneRenderTargets . GetBufferSizeXY ( ) / FIntPoint ( GAODownsampleFactor , GAODownsampleFactor ) ,
* VertexShader ) ;
}
2015-04-03 18:56:44 -04:00
RHICmdList . CopyToResolveTarget ( DistanceFieldAOBentNormal - > GetRenderTargetItem ( ) . TargetableTexture , DistanceFieldAOBentNormal - > GetRenderTargetItem ( ) . ShaderResourceTexture , false , FResolveParams ( ) ) ;
if ( bUseDistanceFieldGI )
{
RHICmdList . CopyToResolveTarget ( DistanceFieldIrradiance - > GetRenderTargetItem ( ) . TargetableTexture , DistanceFieldIrradiance - > GetRenderTargetItem ( ) . ShaderResourceTexture , false , FResolveParams ( ) ) ;
}
2014-06-03 15:53:13 -04:00
}
2014-12-16 20:00:22 -05:00
FSceneViewState * ViewState = ( FSceneViewState * ) View . State ;
2014-11-21 21:37:13 -05:00
TRefCountPtr < IPooledRenderTarget > * BentNormalHistoryState = ViewState ? & ViewState - > DistanceFieldAOHistoryRT : NULL ;
TRefCountPtr < IPooledRenderTarget > * IrradianceHistoryState = ViewState ? & ViewState - > DistanceFieldIrradianceHistoryRT : NULL ;
BentNormalOutput = DistanceFieldAOBentNormal ;
IrradianceOutput = DistanceFieldIrradiance ;
2014-06-03 15:53:13 -04:00
if ( GAOUseHistory )
{
UpdateHistory (
2014-06-12 07:13:34 -04:00
RHICmdList ,
2014-06-03 15:53:13 -04:00
View ,
TEXT ( " DistanceFieldAOHistory " ) ,
2014-11-21 21:37:13 -05:00
TEXT ( " DistanceFieldIrradianceHistory " ) ,
2015-02-19 16:09:15 -05:00
VelocityTexture ,
2014-11-21 21:37:13 -05:00
BentNormalHistoryState ,
IrradianceHistoryState ,
2014-06-03 15:53:13 -04:00
DistanceFieldAOBentNormal ,
2014-11-21 21:37:13 -05:00
DistanceFieldIrradiance ,
BentNormalOutput ,
IrradianceOutput ) ;
2014-06-03 15:53:13 -04:00
}
}
2015-02-06 23:31:19 -05:00
enum EAOUpsampleType
{
AOUpsample_OutputBentNormal ,
AOUpsample_OutputAO ,
AOUpsample_OutputBentNormalAndIrradiance ,
AOUpsample_OutputIrradiance
} ;
template < EAOUpsampleType UpsampleType >
2014-09-18 16:44:19 -04:00
class TDistanceFieldAOUpsamplePS : public FGlobalShader
2014-06-03 15:53:13 -04:00
{
2014-09-18 16:44:19 -04:00
DECLARE_SHADER_TYPE ( TDistanceFieldAOUpsamplePS , Global ) ;
2014-06-03 15:53:13 -04:00
public :
static bool ShouldCache ( EShaderPlatform Platform )
{
2014-06-26 15:53:01 -04:00
return IsFeatureLevelSupported ( Platform , ERHIFeatureLevel : : SM5 ) & & DoesPlatformSupportDistanceFieldAO ( Platform ) ;
2014-06-03 15:53:13 -04:00
}
static void ModifyCompilationEnvironment ( EShaderPlatform Platform , FShaderCompilerEnvironment & OutEnvironment )
{
OutEnvironment . SetDefine ( TEXT ( " DOWNSAMPLE_FACTOR " ) , GAODownsampleFactor ) ;
2015-02-06 23:31:19 -05:00
OutEnvironment . SetDefine ( TEXT ( " OUTPUT_BENT_NORMAL " ) , ( UpsampleType = = AOUpsample_OutputBentNormal | | UpsampleType = = AOUpsample_OutputBentNormalAndIrradiance ) ? TEXT ( " 1 " ) : TEXT ( " 0 " ) ) ;
OutEnvironment . SetDefine ( TEXT ( " SUPPORT_IRRADIANCE " ) , ( UpsampleType = = AOUpsample_OutputIrradiance | | UpsampleType = = AOUpsample_OutputBentNormalAndIrradiance ) ? TEXT ( " 1 " ) : TEXT ( " 0 " ) ) ;
OutEnvironment . SetDefine ( TEXT ( " OUTPUT_AO " ) , ( UpsampleType = = AOUpsample_OutputAO ) ? TEXT ( " 1 " ) : TEXT ( " 0 " ) ) ;
2014-06-03 15:53:13 -04:00
}
/** Default constructor. */
2014-09-18 16:44:19 -04:00
TDistanceFieldAOUpsamplePS ( ) { }
2014-06-03 15:53:13 -04:00
/** Initialization constructor. */
2014-09-18 16:44:19 -04:00
TDistanceFieldAOUpsamplePS ( const ShaderMetaType : : CompiledShaderInitializerType & Initializer )
2014-06-03 15:53:13 -04:00
: FGlobalShader ( Initializer )
{
DeferredParameters . Bind ( Initializer . ParameterMap ) ;
BentNormalAOTexture . Bind ( Initializer . ParameterMap , TEXT ( " BentNormalAOTexture " ) ) ;
BentNormalAOSampler . Bind ( Initializer . ParameterMap , TEXT ( " BentNormalAOSampler " ) ) ;
2014-11-21 21:37:13 -05:00
IrradianceTexture . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceTexture " ) ) ;
IrradianceSampler . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceSampler " ) ) ;
2014-06-03 15:53:13 -04:00
}
2014-11-21 21:37:13 -05:00
void SetParameters ( FRHICommandList & RHICmdList , const FSceneView & View , TRefCountPtr < IPooledRenderTarget > & DistanceFieldAOBentNormal , IPooledRenderTarget * DistanceFieldIrradiance )
2014-06-03 15:53:13 -04:00
{
const FPixelShaderRHIParamRef ShaderRHI = GetPixelShader ( ) ;
2014-06-05 16:38:54 -04:00
FGlobalShader : : SetParameters ( RHICmdList , ShaderRHI , View ) ;
DeferredParameters . Set ( RHICmdList , ShaderRHI , View ) ;
2014-06-03 15:53:13 -04:00
2014-06-05 16:38:54 -04:00
SetTextureParameter ( RHICmdList , ShaderRHI , BentNormalAOTexture , BentNormalAOSampler , TStaticSamplerState < SF_Bilinear > : : GetRHI ( ) , DistanceFieldAOBentNormal - > GetRenderTargetItem ( ) . ShaderResourceTexture ) ;
2014-11-21 21:37:13 -05:00
if ( IrradianceTexture . IsBound ( ) )
{
SetTextureParameter ( RHICmdList , ShaderRHI , IrradianceTexture , IrradianceSampler , TStaticSamplerState < SF_Bilinear > : : GetRHI ( ) , DistanceFieldIrradiance - > GetRenderTargetItem ( ) . ShaderResourceTexture ) ;
}
2014-06-03 15:53:13 -04:00
}
// FShader interface.
2015-04-01 07:20:55 -04:00
virtual bool Serialize ( FArchive & Ar ) override
2014-06-03 15:53:13 -04:00
{
bool bShaderHasOutdatedParameters = FGlobalShader : : Serialize ( Ar ) ;
Ar < < DeferredParameters ;
Ar < < BentNormalAOTexture ;
Ar < < BentNormalAOSampler ;
2014-11-21 21:37:13 -05:00
Ar < < IrradianceTexture ;
Ar < < IrradianceSampler ;
2014-06-03 15:53:13 -04:00
return bShaderHasOutdatedParameters ;
}
private :
FDeferredPixelShaderParameters DeferredParameters ;
FShaderResourceParameter BentNormalAOTexture ;
FShaderResourceParameter BentNormalAOSampler ;
2014-11-21 21:37:13 -05:00
FShaderResourceParameter IrradianceTexture ;
FShaderResourceParameter IrradianceSampler ;
2014-06-03 15:53:13 -04:00
} ;
2015-02-06 23:31:19 -05:00
# define IMPLEMENT_UPSAMPLE_PS_TYPE(UpsampleType) \
typedef TDistanceFieldAOUpsamplePS < UpsampleType > TDistanceFieldAOUpsamplePS # # UpsampleType ; \
2015-04-03 18:56:44 -04:00
IMPLEMENT_SHADER_TYPE ( template < > , TDistanceFieldAOUpsamplePS # # UpsampleType , TEXT ( " DistanceFieldLightingPost " ) , TEXT ( " AOUpsamplePS " ) , SF_Pixel ) ;
2014-06-03 15:53:13 -04:00
2015-02-06 23:31:19 -05:00
IMPLEMENT_UPSAMPLE_PS_TYPE ( AOUpsample_OutputBentNormal )
IMPLEMENT_UPSAMPLE_PS_TYPE ( AOUpsample_OutputAO )
IMPLEMENT_UPSAMPLE_PS_TYPE ( AOUpsample_OutputBentNormalAndIrradiance )
IMPLEMENT_UPSAMPLE_PS_TYPE ( AOUpsample_OutputIrradiance )
2014-11-21 21:37:13 -05:00
2014-12-16 20:00:22 -05:00
void UpsampleBentNormalAO (
FRHICommandList & RHICmdList ,
const TArray < FViewInfo > & Views ,
TRefCountPtr < IPooledRenderTarget > & DistanceFieldAOBentNormal ,
2015-02-06 23:31:19 -05:00
TRefCountPtr < IPooledRenderTarget > & DistanceFieldIrradiance ,
bool bVisualizeAmbientOcclusion ,
bool bVisualizeGlobalIllumination )
2014-06-03 15:53:13 -04:00
{
for ( int32 ViewIndex = 0 ; ViewIndex < Views . Num ( ) ; ViewIndex + + )
{
const FViewInfo & View = Views [ ViewIndex ] ;
2014-12-16 20:00:22 -05:00
const bool bUseDistanceFieldGI = IsDistanceFieldGIAllowed ( View ) ;
2014-06-03 15:53:13 -04:00
2014-10-20 10:43:43 -04:00
SCOPED_DRAW_EVENT ( RHICmdList , UpsampleAO ) ;
2014-06-03 15:53:13 -04:00
2014-06-12 07:13:34 -04:00
RHICmdList . SetViewport ( View . ViewRect . Min . X , View . ViewRect . Min . Y , 0.0f , View . ViewRect . Max . X , View . ViewRect . Max . Y , 1.0f ) ;
RHICmdList . SetRasterizerState ( TStaticRasterizerState < FM_Solid , CM_None > : : GetRHI ( ) ) ;
RHICmdList . SetDepthStencilState ( TStaticDepthStencilState < false , CF_Always > : : GetRHI ( ) ) ;
RHICmdList . SetBlendState ( TStaticBlendState < > : : GetRHI ( ) ) ;
2014-06-03 15:53:13 -04:00
2014-08-28 06:22:54 -04:00
TShaderMapRef < FPostProcessVS > VertexShader ( View . ShaderMap ) ;
2014-06-03 15:53:13 -04:00
2015-02-06 23:31:19 -05:00
if ( bVisualizeAmbientOcclusion )
2014-09-18 16:44:19 -04:00
{
2015-02-06 23:31:19 -05:00
TShaderMapRef < TDistanceFieldAOUpsamplePS < AOUpsample_OutputAO > > PixelShader ( View . ShaderMap ) ;
static FGlobalBoundShaderState BoundShaderState ;
SetGlobalBoundShaderState ( RHICmdList , View . GetFeatureLevel ( ) , BoundShaderState , GFilterVertexDeclaration . VertexDeclarationRHI , * VertexShader , * PixelShader ) ;
PixelShader - > SetParameters ( RHICmdList , View , DistanceFieldAOBentNormal , DistanceFieldIrradiance ) ;
}
else if ( bVisualizeGlobalIllumination & & bUseDistanceFieldGI )
{
TShaderMapRef < TDistanceFieldAOUpsamplePS < AOUpsample_OutputIrradiance > > PixelShader ( View . ShaderMap ) ;
static FGlobalBoundShaderState BoundShaderState ;
SetGlobalBoundShaderState ( RHICmdList , View . GetFeatureLevel ( ) , BoundShaderState , GFilterVertexDeclaration . VertexDeclarationRHI , * VertexShader , * PixelShader ) ;
PixelShader - > SetParameters ( RHICmdList , View , DistanceFieldAOBentNormal , DistanceFieldIrradiance ) ;
2014-09-18 16:44:19 -04:00
}
else
{
2014-12-16 20:00:22 -05:00
if ( bUseDistanceFieldGI )
{
2015-02-06 23:31:19 -05:00
TShaderMapRef < TDistanceFieldAOUpsamplePS < AOUpsample_OutputBentNormalAndIrradiance > > PixelShader ( View . ShaderMap ) ;
2014-12-16 20:00:22 -05:00
static FGlobalBoundShaderState BoundShaderState ;
SetGlobalBoundShaderState ( RHICmdList , View . GetFeatureLevel ( ) , BoundShaderState , GFilterVertexDeclaration . VertexDeclarationRHI , * VertexShader , * PixelShader ) ;
PixelShader - > SetParameters ( RHICmdList , View , DistanceFieldAOBentNormal , DistanceFieldIrradiance ) ;
}
else
{
2015-02-06 23:31:19 -05:00
TShaderMapRef < TDistanceFieldAOUpsamplePS < AOUpsample_OutputBentNormal > > PixelShader ( View . ShaderMap ) ;
2014-12-16 20:00:22 -05:00
static FGlobalBoundShaderState BoundShaderState ;
SetGlobalBoundShaderState ( RHICmdList , View . GetFeatureLevel ( ) , BoundShaderState , GFilterVertexDeclaration . VertexDeclarationRHI , * VertexShader , * PixelShader ) ;
PixelShader - > SetParameters ( RHICmdList , View , DistanceFieldAOBentNormal , DistanceFieldIrradiance ) ;
}
2014-09-18 16:44:19 -04:00
}
2014-06-03 15:53:13 -04:00
DrawRectangle (
2014-06-12 07:13:34 -04:00
RHICmdList ,
2014-06-03 15:53:13 -04:00
0 , 0 ,
View . ViewRect . Width ( ) , View . ViewRect . Height ( ) ,
View . ViewRect . Min . X / GAODownsampleFactor , View . ViewRect . Min . Y / GAODownsampleFactor ,
View . ViewRect . Width ( ) / GAODownsampleFactor , View . ViewRect . Height ( ) / GAODownsampleFactor ,
FIntPoint ( View . ViewRect . Width ( ) , View . ViewRect . Height ( ) ) ,
2014-09-26 17:07:59 -04:00
GetBufferSizeForAO ( ) ,
2014-06-03 15:53:13 -04:00
* VertexShader ) ;
}
}
/** Generates a pseudo-random position inside the unit sphere, uniformly distributed over the volume of the sphere. */
FVector GetUnitPosition2 ( FRandomStream & RandomStream )
{
FVector Result ;
// Use rejection sampling to generate a valid sample
do
{
Result . X = RandomStream . GetFraction ( ) * 2 - 1 ;
Result . Y = RandomStream . GetFraction ( ) * 2 - 1 ;
Result . Z = RandomStream . GetFraction ( ) * 2 - 1 ;
} while ( Result . SizeSquared ( ) > 1.f ) ;
return Result ;
}
/** Generates a pseudo-random unit vector, uniformly distributed over all directions. */
FVector GetUnitVector2 ( FRandomStream & RandomStream )
{
2014-11-26 10:01:12 -05:00
return GetUnitPosition2 ( RandomStream ) . GetUnsafeNormal ( ) ;
2014-06-03 15:53:13 -04:00
}
void GenerateBestSpacedVectors ( )
{
2014-06-04 17:01:43 -04:00
static bool bGenerated = false ;
bool bApplyRepulsion = false ;
if ( bApplyRepulsion & & ! bGenerated )
{
bGenerated = true ;
FVector OriginalSpacedVectors9 [ ARRAY_COUNT ( SpacedVectors9 ) ] ;
for ( int32 i = 0 ; i < ARRAY_COUNT ( OriginalSpacedVectors9 ) ; i + + )
{
OriginalSpacedVectors9 [ i ] = SpacedVectors9 [ i ] ;
}
float CosHalfAngle = 1 - 1.0f / ( float ) ARRAY_COUNT ( OriginalSpacedVectors9 ) ;
// Used to prevent self-shadowing on a plane
float AngleBias = .03f ;
float MinAngle = FMath : : Acos ( CosHalfAngle ) + AngleBias ;
float MinZ = FMath : : Sin ( MinAngle ) ;
// Relaxation iterations by repulsion
for ( int32 Iteration = 0 ; Iteration < 10000 ; Iteration + + )
{
for ( int32 i = 0 ; i < ARRAY_COUNT ( OriginalSpacedVectors9 ) ; i + + )
{
FVector Force ( 0.0f , 0.0f , 0.0f ) ;
for ( int32 j = 0 ; j < ARRAY_COUNT ( OriginalSpacedVectors9 ) ; j + + )
{
if ( i ! = j )
{
FVector Distance = OriginalSpacedVectors9 [ i ] - OriginalSpacedVectors9 [ j ] ;
float Dot = OriginalSpacedVectors9 [ i ] | OriginalSpacedVectors9 [ j ] ;
if ( Dot > 0 )
{
// Repulsion force
2014-11-26 10:01:12 -05:00
Force + = .001f * Distance . GetSafeNormal ( ) * Dot * Dot * Dot * Dot ;
2014-06-04 17:01:43 -04:00
}
}
}
FVector NewPosition = OriginalSpacedVectors9 [ i ] + Force ;
NewPosition . Z = FMath : : Max ( NewPosition . Z , MinZ ) ;
2014-11-26 10:01:12 -05:00
NewPosition = NewPosition . GetSafeNormal ( ) ;
2014-06-04 17:01:43 -04:00
OriginalSpacedVectors9 [ i ] = NewPosition ;
}
}
for ( int32 i = 0 ; i < ARRAY_COUNT ( OriginalSpacedVectors9 ) ; i + + )
{
2015-01-29 14:46:20 -05:00
UE_LOG ( LogDistanceField , Log , TEXT ( " FVector(%f, %f, %f), " ) , OriginalSpacedVectors9 [ i ] . X , OriginalSpacedVectors9 [ i ] . Y , OriginalSpacedVectors9 [ i ] . Z ) ;
2014-06-04 17:01:43 -04:00
}
int32 temp = 0 ;
}
bool bBruteForceGenerateConeDirections = false ;
if ( bBruteForceGenerateConeDirections )
2014-06-03 15:53:13 -04:00
{
FVector BestSpacedVectors9 [ 9 ] ;
float BestCoverage = 0 ;
// Each cone covers an area of ConeSolidAngle = HemisphereSolidAngle / NumCones
// HemisphereSolidAngle = 2 * PI
// ConeSolidAngle = 2 * PI * (1 - cos(ConeHalfAngle))
// cos(ConeHalfAngle) = 1 - 1 / NumCones
float CosHalfAngle = 1 - 1.0f / ( float ) ARRAY_COUNT ( BestSpacedVectors9 ) ;
// Prevent self-intersection in sample set
float MinAngle = FMath : : Acos ( CosHalfAngle ) ;
float MinZ = FMath : : Sin ( MinAngle ) ;
2014-06-04 17:01:43 -04:00
FRandomStream RandomStream ( 123567 ) ;
2014-06-03 15:53:13 -04:00
// Super slow random brute force search
for ( int i = 0 ; i < 1000000 ; i + + )
{
FVector CandidateSpacedVectors [ ARRAY_COUNT ( BestSpacedVectors9 ) ] ;
for ( int j = 0 ; j < ARRAY_COUNT ( CandidateSpacedVectors ) ; j + + )
{
FVector NewSample ;
// Reject invalid directions until we get a valid one
do
{
NewSample = GetUnitVector2 ( RandomStream ) ;
}
while ( NewSample . Z < = MinZ ) ;
CandidateSpacedVectors [ j ] = NewSample ;
}
float Coverage = 0 ;
int NumSamples = 10000 ;
// Determine total cone coverage with monte carlo estimation
for ( int sample = 0 ; sample < NumSamples ; sample + + )
{
FVector NewSample ;
do
{
NewSample = GetUnitVector2 ( RandomStream ) ;
}
while ( NewSample . Z < = 0 ) ;
bool bIntersects = false ;
for ( int j = 0 ; j < ARRAY_COUNT ( CandidateSpacedVectors ) ; j + + )
{
if ( FVector : : DotProduct ( CandidateSpacedVectors [ j ] , NewSample ) > CosHalfAngle )
{
bIntersects = true ;
break ;
}
}
Coverage + = bIntersects ? 1 / ( float ) NumSamples : 0 ;
}
if ( Coverage > BestCoverage )
{
BestCoverage = Coverage ;
for ( int j = 0 ; j < ARRAY_COUNT ( CandidateSpacedVectors ) ; j + + )
{
BestSpacedVectors9 [ j ] = CandidateSpacedVectors [ j ] ;
}
}
}
int32 temp = 0 ;
}
}
2015-04-03 18:56:44 -04:00
FIntPoint BuildTileObjectLists ( FRHICommandListImmediate & RHICmdList , FScene * Scene , TArray < FViewInfo > & Views , FSceneRenderTargetItem & DistanceFieldNormal , const FDistanceFieldAOParameters & Parameters )
2014-06-03 15:53:13 -04:00
{
2014-10-20 10:43:43 -04:00
SCOPED_DRAW_EVENT ( RHICmdList , BuildTileList ) ;
2014-06-12 07:13:34 -04:00
SetRenderTarget ( RHICmdList , NULL , NULL ) ;
2014-06-03 15:53:13 -04:00
FIntPoint TileListGroupSize ;
if ( GAOScatterTileCulling )
{
for ( int32 ViewIndex = 0 ; ViewIndex < Views . Num ( ) ; ViewIndex + + )
{
const FViewInfo & View = Views [ ViewIndex ] ;
uint32 GroupSizeX = FMath : : DivideAndRoundUp ( View . ViewRect . Size ( ) . X / GAODownsampleFactor , GDistanceFieldAOTileSizeX ) ;
uint32 GroupSizeY = FMath : : DivideAndRoundUp ( View . ViewRect . Size ( ) . Y / GAODownsampleFactor , GDistanceFieldAOTileSizeY ) ;
TileListGroupSize = FIntPoint ( GroupSizeX , GroupSizeY ) ;
FTileIntersectionResources * & TileIntersectionResources = ( ( FSceneViewState * ) View . State ) - > AOTileIntersectionResources ;
if ( ! TileIntersectionResources | | TileIntersectionResources - > TileDimensions ! = TileListGroupSize )
{
if ( TileIntersectionResources )
{
TileIntersectionResources - > ReleaseResource ( ) ;
}
else
{
TileIntersectionResources = new FTileIntersectionResources ( ) ;
}
TileIntersectionResources - > TileDimensions = TileListGroupSize ;
TileIntersectionResources - > InitResource ( ) ;
}
{
2014-10-20 10:43:43 -04:00
SCOPED_DRAW_EVENT ( RHICmdList , BuildTileCones ) ;
2014-08-28 06:22:54 -04:00
TShaderMapRef < FBuildTileConesCS > ComputeShader ( View . ShaderMap ) ;
2014-06-03 15:53:13 -04:00
2014-06-12 07:13:34 -04:00
RHICmdList . SetComputeShader ( ComputeShader - > GetComputeShader ( ) ) ;
2015-04-03 18:56:44 -04:00
ComputeShader - > SetParameters ( RHICmdList , View , DistanceFieldNormal , Scene , FVector2D ( GroupSizeX , GroupSizeY ) , Parameters ) ;
2014-06-05 16:38:54 -04:00
DispatchComputeShader ( RHICmdList , * ComputeShader , GroupSizeX , GroupSizeY , 1 ) ;
2014-06-03 15:53:13 -04:00
2014-06-05 16:38:54 -04:00
ComputeShader - > UnsetParameters ( RHICmdList ) ;
2014-06-03 15:53:13 -04:00
}
{
2015-01-29 14:46:20 -05:00
SCOPED_DRAW_EVENT ( RHICmdList , CullObjectsToTiles ) ;
2014-06-03 15:53:13 -04:00
2014-08-28 06:22:54 -04:00
TShaderMapRef < FObjectCullVS > VertexShader ( View . ShaderMap ) ;
TShaderMapRef < FObjectCullPS > PixelShader ( View . ShaderMap ) ;
2014-06-03 15:53:13 -04:00
TArray < FUnorderedAccessViewRHIParamRef > UAVs ;
PixelShader - > GetUAVs ( Views [ 0 ] , UAVs ) ;
2014-12-16 20:00:22 -05:00
RHICmdList . SetRenderTargets ( 0 , ( const FRHIRenderTargetView * ) NULL , NULL , UAVs . Num ( ) , UAVs . GetData ( ) ) ;
2014-06-03 15:53:13 -04:00
2014-06-12 07:13:34 -04:00
RHICmdList . SetViewport ( 0 , 0 , 0.0f , GroupSizeX , GroupSizeY , 1.0f ) ;
2014-06-03 15:53:13 -04:00
// Render backfaces since camera may intersect
2014-06-12 07:13:34 -04:00
RHICmdList . SetRasterizerState ( View . bReverseCulling ? TStaticRasterizerState < FM_Solid , CM_CW > : : GetRHI ( ) : TStaticRasterizerState < FM_Solid , CM_CCW > : : GetRHI ( ) ) ;
RHICmdList . SetDepthStencilState ( TStaticDepthStencilState < false , CF_Always > : : GetRHI ( ) ) ;
RHICmdList . SetBlendState ( TStaticBlendState < > : : GetRHI ( ) ) ;
2014-06-03 15:53:13 -04:00
static FGlobalBoundShaderState BoundShaderState ;
2014-06-27 11:07:13 -04:00
2014-08-19 10:41:34 -04:00
SetGlobalBoundShaderState ( RHICmdList , View . GetFeatureLevel ( ) , BoundShaderState , GetVertexDeclarationFVector4 ( ) , * VertexShader , * PixelShader ) ;
2014-06-03 15:53:13 -04:00
2014-11-21 22:32:16 -05:00
VertexShader - > SetParameters ( RHICmdList , View , Parameters ) ;
2014-08-28 13:54:31 -04:00
PixelShader - > SetParameters ( RHICmdList , View , FVector2D ( GroupSizeX , GroupSizeY ) , Parameters ) ;
2014-06-03 15:53:13 -04:00
2014-06-12 07:13:34 -04:00
RHICmdList . SetStreamSource ( 0 , StencilingGeometry : : GLowPolyStencilSphereVertexBuffer . VertexBufferRHI , sizeof ( FVector4 ) , 0 ) ;
2014-06-03 15:53:13 -04:00
2014-11-21 22:32:16 -05:00
RHICmdList . DrawIndexedPrimitiveIndirect (
PT_TriangleList ,
2014-06-03 15:53:13 -04:00
StencilingGeometry : : GLowPolyStencilSphereIndexBuffer . IndexBufferRHI ,
2014-11-21 22:32:16 -05:00
GAOCulledObjectBuffers . Buffers . ObjectIndirectArguments . Buffer ,
0 ) ;
2014-06-03 15:53:13 -04:00
}
}
}
else
{
for ( int32 ViewIndex = 0 ; ViewIndex < Views . Num ( ) ; ViewIndex + + )
{
const FViewInfo & View = Views [ ViewIndex ] ;
uint32 GroupSizeX = ( View . ViewRect . Size ( ) . X / GAODownsampleFactor + GDistanceFieldAOTileSizeX - 1 ) / GDistanceFieldAOTileSizeX ;
uint32 GroupSizeY = ( View . ViewRect . Size ( ) . Y / GAODownsampleFactor + GDistanceFieldAOTileSizeY - 1 ) / GDistanceFieldAOTileSizeY ;
TileListGroupSize = FIntPoint ( GroupSizeX , GroupSizeY ) ;
FTileIntersectionResources * & TileIntersectionResources = ( ( FSceneViewState * ) View . State ) - > AOTileIntersectionResources ;
if ( ! TileIntersectionResources | | TileIntersectionResources - > TileDimensions ! = TileListGroupSize )
{
if ( TileIntersectionResources )
{
TileIntersectionResources - > ReleaseResource ( ) ;
}
else
{
TileIntersectionResources = new FTileIntersectionResources ( ) ;
}
TileIntersectionResources - > TileDimensions = TileListGroupSize ;
TileIntersectionResources - > InitResource ( ) ;
}
// Indicates the clear value for each channel of the UAV format
2014-07-09 11:02:23 -04:00
uint32 ClearValues [ 4 ] = { 0 } ;
2014-06-12 07:13:34 -04:00
RHICmdList . ClearUAV ( TileIntersectionResources - > TileArrayNextAllocation . UAV , ClearValues ) ;
RHICmdList . ClearUAV ( TileIntersectionResources - > TileHeadData . UAV , ClearValues ) ;
2014-06-03 15:53:13 -04:00
2014-08-28 06:22:54 -04:00
TShaderMapRef < FDistanceFieldBuildTileListCS > ComputeShader ( View . ShaderMap ) ;
2014-06-03 15:53:13 -04:00
2014-06-12 07:13:34 -04:00
RHICmdList . SetComputeShader ( ComputeShader - > GetComputeShader ( ) ) ;
2014-11-21 22:32:16 -05:00
ComputeShader - > SetParameters ( RHICmdList , View , Scene , FVector2D ( GroupSizeX , GroupSizeY ) , Parameters ) ;
2014-06-05 16:38:54 -04:00
DispatchComputeShader ( RHICmdList , * ComputeShader , GroupSizeX , GroupSizeY , 1 ) ;
2014-06-03 15:53:13 -04:00
2014-06-05 16:38:54 -04:00
ComputeShader - > UnsetParameters ( RHICmdList ) ;
2014-06-03 15:53:13 -04:00
}
}
return TileListGroupSize ;
}
2015-04-03 18:56:44 -04:00
void SetupDepthStencil (
FRHICommandListImmediate & RHICmdList ,
const FViewInfo & View ,
FSceneRenderTargetItem & SplatDepthStencilBuffer ,
FSceneRenderTargetItem & DistanceFieldNormal ,
int32 DepthLevel ,
int32 DestLevelDownsampleFactor )
2014-09-26 17:07:59 -04:00
{
2014-10-20 10:43:43 -04:00
SCOPED_DRAW_EVENT ( RHICmdList , SetupDepthStencil ) ;
2014-09-26 17:07:59 -04:00
2015-04-03 18:56:44 -04:00
SetRenderTarget ( RHICmdList , NULL , SplatDepthStencilBuffer . TargetableTexture ) ;
RHICmdList . Clear ( false , FLinearColor ( 0 , 0 , 0 , 0 ) , true , 0 , true , 0 , FIntRect ( ) ) ;
2014-09-26 17:07:59 -04:00
{
RHICmdList . SetViewport ( 0 , 0 , 0.0f , View . ViewRect . Width ( ) / GAODownsampleFactor , View . ViewRect . Height ( ) / GAODownsampleFactor , 1.0f ) ;
RHICmdList . SetRasterizerState ( TStaticRasterizerState < FM_Solid , CM_None > : : GetRHI ( ) ) ;
// Depth writes on
RHICmdList . SetDepthStencilState ( TStaticDepthStencilState < true , CF_Always > : : GetRHI ( ) ) ;
// Color writes off
RHICmdList . SetBlendState ( TStaticBlendState < CW_NONE > : : GetRHI ( ) ) ;
TShaderMapRef < FPostProcessVS > VertexShader ( View . ShaderMap ) ;
TShaderMapRef < FWriteDownsampledDepthPS > PixelShader ( View . ShaderMap ) ;
static FGlobalBoundShaderState BoundShaderState ;
SetGlobalBoundShaderState ( RHICmdList , View . GetFeatureLevel ( ) , BoundShaderState , GFilterVertexDeclaration . VertexDeclarationRHI , * VertexShader , * PixelShader ) ;
PixelShader - > SetParameters ( RHICmdList , View , DistanceFieldNormal ) ;
// Draw a quad writing depth out to the depth stencil view
DrawRectangle (
RHICmdList ,
0 , 0 ,
View . ViewRect . Width ( ) / GAODownsampleFactor , View . ViewRect . Height ( ) / GAODownsampleFactor ,
0 , 0 ,
View . ViewRect . Width ( ) / GAODownsampleFactor , View . ViewRect . Height ( ) / GAODownsampleFactor ,
FIntPoint ( View . ViewRect . Width ( ) / GAODownsampleFactor , View . ViewRect . Height ( ) / GAODownsampleFactor ) ,
GetBufferSizeForAO ( ) ,
* VertexShader ) ;
}
if ( GAOInterpolationStencilTesting )
{
RHICmdList . SetViewport ( 0 , 0 , 0.0f , View . ViewRect . Width ( ) / GAODownsampleFactor , View . ViewRect . Height ( ) / GAODownsampleFactor , 1.0f ) ;
RHICmdList . SetRasterizerState ( TStaticRasterizerState < FM_Solid , CM_None > : : GetRHI ( ) ) ;
RHICmdList . SetBlendState ( TStaticBlendState < CW_NONE > : : GetRHI ( ) ) ;
// Depth tests on, write 1 to stencil if depth test passed
RHICmdList . SetDepthStencilState ( TStaticDepthStencilState <
2015-04-01 10:53:07 -04:00
false , CF_DepthNearOrEqual ,
2014-09-26 17:07:59 -04:00
true , CF_Always , SO_Keep , SO_Keep , SO_Replace ,
false , CF_Always , SO_Keep , SO_Keep , SO_Keep ,
0xff , 0xff
> : : GetRHI ( ) , 1 ) ;
TShaderMapRef < TOneColorVS < true > > VertexShader ( View . ShaderMap ) ;
TShaderMapRef < FOneColorPS > PixelShader ( View . ShaderMap ) ;
static FGlobalBoundShaderState BoundShaderState ;
SetGlobalBoundShaderState ( RHICmdList , View . GetFeatureLevel ( ) , BoundShaderState , GetVertexDeclarationFVector4 ( ) , * VertexShader , * PixelShader ) ;
SetShaderValue ( RHICmdList , PixelShader - > GetPixelShader ( ) , PixelShader - > ColorParameter , FLinearColor : : Black ) ;
2014-12-01 12:44:34 -05:00
FVector ViewSpaceMaxDistance ( 0.0f , 0.0f , GetMaxAOViewDistance ( ) ) ;
2014-09-26 17:07:59 -04:00
FVector4 ClipSpaceMaxDistance = View . ViewMatrices . ProjMatrix . TransformPosition ( ViewSpaceMaxDistance ) ;
float ClipSpaceZ = ClipSpaceMaxDistance . Z / ClipSpaceMaxDistance . W ;
// Place the quad's depth at the max AO view distance
// Any pixels that pass the depth test should not receive AO and therefore write a 1 to stencil
FVector4 ClearQuadVertices [ 4 ] =
{
FVector4 ( - 1.0f , 1.0f , ClipSpaceZ , 1.0f ) ,
FVector4 ( 1.0f , 1.0f , ClipSpaceZ , 1.0f ) ,
FVector4 ( - 1.0f , - 1.0f , ClipSpaceZ , 1.0f ) ,
FVector4 ( 1.0f , - 1.0f , ClipSpaceZ , 1.0f )
} ;
DrawPrimitiveUP ( RHICmdList , PT_TriangleStrip , 2 , ClearQuadVertices , sizeof ( ClearQuadVertices [ 0 ] ) ) ;
}
2015-04-03 18:56:44 -04:00
RHICmdList . CopyToResolveTarget ( SplatDepthStencilBuffer . TargetableTexture , SplatDepthStencilBuffer . ShaderResourceTexture , false , FResolveParams ( ) ) ;
2014-09-26 17:07:59 -04:00
}
2014-08-28 13:54:31 -04:00
void RenderIrradianceCacheInterpolation (
FRHICommandListImmediate & RHICmdList ,
2014-12-16 20:00:22 -05:00
const FViewInfo & View ,
2014-11-21 21:37:13 -05:00
IPooledRenderTarget * BentNormalInterpolationTarget ,
IPooledRenderTarget * IrradianceInterpolationTarget ,
2014-08-28 13:54:31 -04:00
FSceneRenderTargetItem & DistanceFieldNormal ,
int32 DepthLevel ,
int32 DestLevelDownsampleFactor ,
const FDistanceFieldAOParameters & Parameters ,
bool bFinalInterpolation )
2014-06-03 15:53:13 -04:00
{
check ( ! ( bFinalInterpolation & & DepthLevel ! = 0 ) ) ;
2014-12-16 20:00:22 -05:00
const bool bUseDistanceFieldGI = IsDistanceFieldGIAllowed ( View ) ;
2014-06-03 15:53:13 -04:00
2014-09-26 17:07:59 -04:00
{
TRefCountPtr < IPooledRenderTarget > SplatDepthStencilBuffer ;
if ( bFinalInterpolation & & ( GAOInterpolationDepthTesting | | GAOInterpolationStencilTesting ) )
{
2014-11-21 21:37:13 -05:00
FPooledRenderTargetDesc Desc ( FPooledRenderTargetDesc : : Create2DDesc ( BentNormalInterpolationTarget - > GetDesc ( ) . Extent , PF_DepthStencil , TexCreate_None , TexCreate_DepthStencilTargetable , false ) ) ;
2014-09-26 17:07:59 -04:00
GRenderTargetPool . FindFreeElement ( Desc , SplatDepthStencilBuffer , TEXT ( " DistanceFieldAOSplatDepthBuffer " ) ) ;
2015-04-03 18:56:44 -04:00
SetupDepthStencil ( RHICmdList , View , SplatDepthStencilBuffer - > GetRenderTargetItem ( ) , DistanceFieldNormal , DepthLevel , DestLevelDownsampleFactor ) ;
2014-09-26 17:07:59 -04:00
GRenderTargetPool . VisualizeTexture . SetCheckPoint ( RHICmdList , SplatDepthStencilBuffer ) ;
}
2014-10-20 10:43:43 -04:00
SCOPED_DRAW_EVENT ( RHICmdList , IrradianceCacheSplat ) ;
2014-09-26 17:07:59 -04:00
2015-04-03 18:56:44 -04:00
const bool bBindIrradiance = bUseDistanceFieldGI & & bFinalInterpolation ;
FTextureRHIParamRef DepthBuffer = SplatDepthStencilBuffer ? SplatDepthStencilBuffer - > GetRenderTargetItem ( ) . TargetableTexture : NULL ;
// PS4 fast clear which is only triggered through SetRenderTargetsAndClear adds 3ms of GPU idle time currently
static bool bUseSetAndClear = false ;
if ( bUseSetAndClear )
{
FRHIRenderTargetView RenderTargets [ MaxSimultaneousRenderTargets ] ;
RenderTargets [ 0 ] = FRHIRenderTargetView ( BentNormalInterpolationTarget - > GetRenderTargetItem ( ) . TargetableTexture ) ;
RenderTargets [ 1 ] = FRHIRenderTargetView ( bBindIrradiance ? IrradianceInterpolationTarget - > GetRenderTargetItem ( ) . TargetableTexture : NULL ) ;
const int32 MRTCount = bBindIrradiance ? 2 : 1 ;
FRHIDepthRenderTargetView DepthView ( DepthBuffer ) ;
FRHISetRenderTargetsInfo Info ( MRTCount , RenderTargets , DepthView ) ;
Info . bClearColor = true ;
Info . ClearColors [ 0 ] = FLinearColor ( 0 , 0 , 0 , 0 ) ;
Info . ClearColors [ 1 ] = FLinearColor ( 0 , 0 , 0 , 0 ) ;
// set the render target
RHICmdList . SetRenderTargetsAndClear ( Info ) ;
}
else
{
2015-04-13 12:42:09 -04:00
FTextureRHIParamRef RenderTargets [ 2 ] =
{
BentNormalInterpolationTarget - > GetRenderTargetItem ( ) . TargetableTexture ,
bBindIrradiance ? IrradianceInterpolationTarget - > GetRenderTargetItem ( ) . TargetableTexture : NULL
} ;
2015-04-03 18:56:44 -04:00
SetRenderTargets ( RHICmdList , ARRAY_COUNT ( RenderTargets ) - ( bBindIrradiance ? 0 : 1 ) , RenderTargets , DepthBuffer , 0 , NULL ) ;
FLinearColor ClearColors [ 2 ] = { FLinearColor ( 0 , 0 , 0 , 0 ) , FLinearColor ( 0 , 0 , 0 , 0 ) } ;
RHICmdList . ClearMRT ( true , ARRAY_COUNT ( ClearColors ) - ( bBindIrradiance ? 0 : 1 ) , ClearColors , false , 0 , false , 0 , FIntRect ( ) ) ;
}
2014-09-26 17:07:59 -04:00
static int32 NumInterpolationSections = 8 ;
if ( GCircleVertexBuffer . NumSections ! = NumInterpolationSections )
{
GCircleVertexBuffer . NumSections = NumInterpolationSections ;
GCircleVertexBuffer . UpdateRHI ( ) ;
}
2014-06-03 15:53:13 -04:00
{
const FScene * Scene = ( const FScene * ) View . Family - > Scene ;
FSurfaceCacheResources & SurfaceCacheResources = * Scene - > SurfaceCacheResources ;
2014-09-26 19:53:37 -04:00
const uint32 DownsampledViewSizeX = FMath : : DivideAndRoundUp ( View . ViewRect . Width ( ) , DestLevelDownsampleFactor ) ;
const uint32 DownsampledViewSizeY = FMath : : DivideAndRoundUp ( View . ViewRect . Height ( ) , DestLevelDownsampleFactor ) ;
2014-06-03 15:53:13 -04:00
2014-07-10 21:07:13 -04:00
RHICmdList . SetViewport ( 0 , 0 , 0.0f , DownsampledViewSizeX , DownsampledViewSizeY , 1.0f ) ;
2014-06-12 07:13:34 -04:00
RHICmdList . SetRasterizerState ( TStaticRasterizerState < FM_Solid , CM_None > : : GetRHI ( ) ) ;
2014-09-26 17:07:59 -04:00
if ( bFinalInterpolation & & ( GAOInterpolationDepthTesting | | GAOInterpolationStencilTesting ) )
{
if ( GAOInterpolationDepthTesting )
{
if ( GAOInterpolationStencilTesting )
{
// Depth tests enabled, pass stencil test if stencil is zero
RHICmdList . SetDepthStencilState ( TStaticDepthStencilState <
2015-04-01 10:53:07 -04:00
false , CF_DepthNearOrEqual ,
2014-09-26 17:07:59 -04:00
true , CF_Equal , SO_Keep , SO_Keep , SO_Keep ,
false , CF_Always , SO_Keep , SO_Keep , SO_Keep ,
0xff , 0xff
> : : GetRHI ( ) ) ;
}
else
{
// Depth tests enabled
2015-04-01 10:53:07 -04:00
RHICmdList . SetDepthStencilState ( TStaticDepthStencilState < false , CF_DepthNearOrEqual > : : GetRHI ( ) ) ;
2014-09-26 17:07:59 -04:00
}
}
else if ( GAOInterpolationStencilTesting )
{
// Pass stencil test if stencil is zero
RHICmdList . SetDepthStencilState ( TStaticDepthStencilState <
false , CF_Always ,
true , CF_Equal , SO_Keep , SO_Keep , SO_Keep ,
false , CF_Always , SO_Keep , SO_Keep , SO_Keep ,
0xff , 0xff
> : : GetRHI ( ) ) ;
}
}
else
{
RHICmdList . SetDepthStencilState ( TStaticDepthStencilState < false , CF_Always > : : GetRHI ( ) ) ;
}
2014-11-21 21:37:13 -05:00
RHICmdList . SetBlendState ( TStaticBlendState < CW_RGBA , BO_Add , BF_One , BF_One , BO_Add , BF_One , BF_One , CW_RGBA , BO_Add , BF_One , BF_One , BO_Add , BF_One , BF_One > : : GetRHI ( ) ) ;
2014-06-03 15:53:13 -04:00
const FIntPoint BufferSize = GSceneRenderTargets . GetBufferSizeXY ( ) ;
const float InvBufferSizeX = 1.0f / BufferSize . X ;
const float InvBufferSizeY = 1.0f / BufferSize . Y ;
const FVector2D ScreenPositionScale (
View . ViewRect . Width ( ) * InvBufferSizeX / + 2.0f ,
View . ViewRect . Height ( ) * InvBufferSizeY / ( - 2.0f * GProjectionSignY ) ) ;
const FVector2D ScreenPositionBias (
2014-11-13 14:04:52 -05:00
( View . ViewRect . Width ( ) / 2.0f ) * InvBufferSizeX ,
( View . ViewRect . Height ( ) / 2.0f ) * InvBufferSizeY ) ;
2014-06-03 15:53:13 -04:00
FVector2D OffsetToLowResCorner = ( FVector2D ( .5f , .5f ) / FVector2D ( DownsampledViewSizeX , DownsampledViewSizeY ) - FVector2D ( .5f , .5f ) ) * FVector2D ( 2 , - 2 ) ;
FVector2D OffsetToTopResPixel = ( FVector2D ( .5f , .5f ) / BufferSize - ScreenPositionBias ) / ScreenPositionScale ;
FVector2D NormalizedOffsetToPixelCenter = OffsetToLowResCorner - OffsetToTopResPixel ;
2014-06-12 07:13:34 -04:00
RHICmdList . SetStreamSource ( 0 , GCircleVertexBuffer . VertexBufferRHI , sizeof ( FScreenVertex ) , 0 ) ;
2014-06-03 15:53:13 -04:00
if ( bFinalInterpolation )
{
2014-09-26 17:07:59 -04:00
for ( int32 SplatSourceDepthLevel = GAOMaxLevel ; SplatSourceDepthLevel > = FMath : : Max ( DepthLevel , GAOMinLevel ) ; SplatSourceDepthLevel - - )
2014-06-03 15:53:13 -04:00
{
2014-12-16 20:00:22 -05:00
if ( bUseDistanceFieldGI )
2014-11-21 21:37:13 -05:00
{
TShaderMapRef < TIrradianceCacheSplatVS < true , true > > VertexShader ( View . ShaderMap ) ;
TShaderMapRef < TIrradianceCacheSplatPS < true , true > > PixelShader ( View . ShaderMap ) ;
2014-06-03 15:53:13 -04:00
2014-11-21 21:37:13 -05:00
static FGlobalBoundShaderState BoundShaderState ;
SetGlobalBoundShaderState ( RHICmdList , View . GetFeatureLevel ( ) , BoundShaderState , GScreenVertexDeclaration . VertexDeclarationRHI , * VertexShader , * PixelShader ) ;
2014-12-16 20:00:22 -05:00
VertexShader - > SetParameters ( RHICmdList , View , Parameters , SplatSourceDepthLevel , DestLevelDownsampleFactor , NormalizedOffsetToPixelCenter ) ;
2014-11-21 21:37:13 -05:00
PixelShader - > SetParameters ( RHICmdList , View , DistanceFieldNormal , DestLevelDownsampleFactor , Parameters ) ;
}
else
{
TShaderMapRef < TIrradianceCacheSplatVS < true , false > > VertexShader ( View . ShaderMap ) ;
TShaderMapRef < TIrradianceCacheSplatPS < true , false > > PixelShader ( View . ShaderMap ) ;
static FGlobalBoundShaderState BoundShaderState ;
SetGlobalBoundShaderState ( RHICmdList , View . GetFeatureLevel ( ) , BoundShaderState , GScreenVertexDeclaration . VertexDeclarationRHI , * VertexShader , * PixelShader ) ;
2014-12-16 20:00:22 -05:00
VertexShader - > SetParameters ( RHICmdList , View , Parameters , SplatSourceDepthLevel , DestLevelDownsampleFactor , NormalizedOffsetToPixelCenter ) ;
2014-11-21 21:37:13 -05:00
PixelShader - > SetParameters ( RHICmdList , View , DistanceFieldNormal , DestLevelDownsampleFactor , Parameters ) ;
}
2014-06-03 15:53:13 -04:00
2014-06-12 07:13:34 -04:00
RHICmdList . DrawPrimitiveIndirect ( PT_TriangleList , SurfaceCacheResources . Level [ SplatSourceDepthLevel ] - > ScatterDrawParameters . Buffer , 0 ) ;
2014-06-03 15:53:13 -04:00
}
}
else
{
2014-09-26 17:07:59 -04:00
for ( int32 SplatSourceDepthLevel = GAOMaxLevel ; SplatSourceDepthLevel > = FMath : : Max ( DepthLevel , GAOMinLevel ) ; SplatSourceDepthLevel - - )
2014-06-03 15:53:13 -04:00
{
2014-12-16 20:00:22 -05:00
if ( bUseDistanceFieldGI )
2014-11-21 21:37:13 -05:00
{
TShaderMapRef < TIrradianceCacheSplatVS < false , true > > VertexShader ( View . ShaderMap ) ;
TShaderMapRef < TIrradianceCacheSplatPS < false , true > > PixelShader ( View . ShaderMap ) ;
2014-06-03 15:53:13 -04:00
2014-11-21 21:37:13 -05:00
static FGlobalBoundShaderState BoundShaderState ;
SetGlobalBoundShaderState ( RHICmdList , View . GetFeatureLevel ( ) , BoundShaderState , GScreenVertexDeclaration . VertexDeclarationRHI , * VertexShader , * PixelShader ) ;
2014-12-16 20:00:22 -05:00
VertexShader - > SetParameters ( RHICmdList , View , Parameters , SplatSourceDepthLevel , DestLevelDownsampleFactor , NormalizedOffsetToPixelCenter ) ;
2014-11-21 21:37:13 -05:00
PixelShader - > SetParameters ( RHICmdList , View , DistanceFieldNormal , DestLevelDownsampleFactor , Parameters ) ;
}
else
{
TShaderMapRef < TIrradianceCacheSplatVS < false , false > > VertexShader ( View . ShaderMap ) ;
TShaderMapRef < TIrradianceCacheSplatPS < false , false > > PixelShader ( View . ShaderMap ) ;
static FGlobalBoundShaderState BoundShaderState ;
SetGlobalBoundShaderState ( RHICmdList , View . GetFeatureLevel ( ) , BoundShaderState , GScreenVertexDeclaration . VertexDeclarationRHI , * VertexShader , * PixelShader ) ;
2014-12-16 20:00:22 -05:00
VertexShader - > SetParameters ( RHICmdList , View , Parameters , SplatSourceDepthLevel , DestLevelDownsampleFactor , NormalizedOffsetToPixelCenter ) ;
2014-11-21 21:37:13 -05:00
PixelShader - > SetParameters ( RHICmdList , View , DistanceFieldNormal , DestLevelDownsampleFactor , Parameters ) ;
}
2014-06-03 15:53:13 -04:00
2014-06-12 07:13:34 -04:00
RHICmdList . DrawPrimitiveIndirect ( PT_TriangleList , SurfaceCacheResources . Level [ SplatSourceDepthLevel ] - > ScatterDrawParameters . Buffer , 0 ) ;
2014-06-03 15:53:13 -04:00
}
}
}
2015-04-03 18:56:44 -04:00
RHICmdList . CopyToResolveTarget ( BentNormalInterpolationTarget - > GetRenderTargetItem ( ) . TargetableTexture , BentNormalInterpolationTarget - > GetRenderTargetItem ( ) . ShaderResourceTexture , false , FResolveParams ( ) ) ;
if ( bFinalInterpolation & & bUseDistanceFieldGI & & ( GAOInterpolationDepthTesting | | GAOInterpolationStencilTesting ) )
{
RHICmdList . CopyToResolveTarget ( IrradianceInterpolationTarget - > GetRenderTargetItem ( ) . TargetableTexture , IrradianceInterpolationTarget - > GetRenderTargetItem ( ) . ShaderResourceTexture , false , FResolveParams ( ) ) ;
}
2014-06-03 15:53:13 -04:00
}
}
2015-01-29 14:46:20 -05:00
void ListDistanceFieldLightingMemory ( const FViewInfo & View )
{
const FScene * Scene = ( const FScene * ) View . Family - > Scene ;
UE_LOG ( LogTemp , Log , TEXT ( " Shared GPU memory (excluding render targets) " ) ) ;
if ( Scene - > DistanceFieldSceneData . NumObjectsInBuffer > 0 )
{
UE_LOG ( LogTemp , Log , TEXT ( " Scene Object data %.3fMb " ) , Scene - > DistanceFieldSceneData . ObjectBuffers - > GetSizeBytes ( ) / 1024.0f / 1024.0f ) ;
}
UE_LOG ( LogTemp , Log , TEXT ( " %s " ) , * GDistanceFieldVolumeTextureAtlas . GetSizeString ( ) ) ;
extern FString GetObjectBufferMemoryString ( ) ;
UE_LOG ( LogTemp , Log , TEXT ( " %s " ) , * GetObjectBufferMemoryString ( ) ) ;
UE_LOG ( LogTemp , Log , TEXT ( " " ) ) ;
UE_LOG ( LogTemp , Log , TEXT ( " Distance Field AO " ) ) ;
if ( Scene - > SurfaceCacheResources )
{
UE_LOG ( LogTemp , Log , TEXT ( " Surface cache %.3fMb " ) , Scene - > SurfaceCacheResources - > GetSizeBytes ( ) / 1024.0f / 1024.0f ) ;
}
UE_LOG ( LogTemp , Log , TEXT ( " Temporary cache %.3fMb " ) , GTemporaryIrradianceCacheResources . GetSizeBytes ( ) / 1024.0f / 1024.0f ) ;
UE_LOG ( LogTemp , Log , TEXT ( " Culled objects %.3fMb " ) , GAOCulledObjectBuffers . Buffers . GetSizeBytes ( ) / 1024.0f / 1024.0f ) ;
FTileIntersectionResources * TileIntersectionResources = ( ( FSceneViewState * ) View . State ) - > AOTileIntersectionResources ;
if ( TileIntersectionResources )
{
UE_LOG ( LogTemp , Log , TEXT ( " Tile Culled objects %.3fMb " ) , TileIntersectionResources - > GetSizeBytes ( ) / 1024.0f / 1024.0f ) ;
}
UE_LOG ( LogTemp , Log , TEXT ( " " ) ) ;
UE_LOG ( LogTemp , Log , TEXT ( " Distance Field GI " ) ) ;
if ( Scene - > DistanceFieldSceneData . SurfelBuffers )
{
UE_LOG ( LogTemp , Log , TEXT ( " Scene surfel data %.3fMb " ) , Scene - > DistanceFieldSceneData . SurfelBuffers - > GetSizeBytes ( ) / 1024.0f / 1024.0f ) ;
}
if ( Scene - > DistanceFieldSceneData . InstancedSurfelBuffers )
{
UE_LOG ( LogTemp , Log , TEXT ( " Instanced scene surfel data %.3fMb " ) , Scene - > DistanceFieldSceneData . InstancedSurfelBuffers - > GetSizeBytes ( ) / 1024.0f / 1024.0f ) ;
}
extern void ListDistanceFieldGIMemory ( const FViewInfo & View ) ;
ListDistanceFieldGIMemory ( View ) ;
}
2014-11-21 22:32:16 -05:00
bool SupportsDistanceFieldAO ( ERHIFeatureLevel : : Type FeatureLevel , EShaderPlatform ShaderPlatform )
2014-06-03 15:53:13 -04:00
{
2014-11-21 22:32:16 -05:00
return GDistanceFieldAO
& & FeatureLevel > = ERHIFeatureLevel : : SM5
& & DoesPlatformSupportDistanceFieldAO ( ShaderPlatform ) ;
}
2014-06-03 15:53:13 -04:00
2015-02-19 16:15:13 -05:00
bool ShouldRenderDynamicSkyLight ( const FScene * Scene , const FSceneViewFamily & ViewFamily )
{
return Scene - > SkyLight
& & Scene - > SkyLight - > ProcessedTexture
& & ! Scene - > SkyLight - > bWantsStaticShadowing
& & ! Scene - > SkyLight - > bHasStaticLighting
& & ViewFamily . EngineShowFlags . SkyLighting
& & Scene - > GetFeatureLevel ( ) > = ERHIFeatureLevel : : SM4
& & ! IsSimpleDynamicLightingEnabled ( )
& & ! ViewFamily . EngineShowFlags . VisualizeLightCulling ;
}
2014-11-21 22:32:16 -05:00
bool FDeferredShadingSceneRenderer : : ShouldPrepareForDistanceFieldAO ( ) const
{
return SupportsDistanceFieldAO ( Scene - > GetFeatureLevel ( ) , Scene - > GetShaderPlatform ( ) )
2015-02-19 16:15:13 -05:00
& & ( ( ShouldRenderDynamicSkyLight ( Scene , ViewFamily ) & & Scene - > SkyLight - > bCastShadows & & ViewFamily . EngineShowFlags . DistanceFieldAO )
2014-11-21 22:32:16 -05:00
| | ViewFamily . EngineShowFlags . VisualizeMeshDistanceFields
2014-12-16 20:00:22 -05:00
| | ViewFamily . EngineShowFlags . VisualizeDistanceFieldAO
| | ViewFamily . EngineShowFlags . VisualizeDistanceFieldGI ) ;
2014-06-03 15:53:13 -04:00
}
2015-01-29 14:46:20 -05:00
FRWBuffer * GDebugBuffer2 = NULL ;
IMPLEMENT_SHADER_TYPE ( , FTrackGPUProgressCS , TEXT ( " DistanceFieldGlobalIllumination " ) , TEXT ( " TrackGPUProgressCS " ) , SF_Compute ) ;
void TrackGPUProgress ( FRHICommandListImmediate & RHICmdList , uint32 DebugId )
{
/*
TShaderMapRef < FTrackGPUProgressCS > ComputeShader ( GetGlobalShaderMap ( ERHIFeatureLevel : : SM5 ) ) ;
RHICmdList . SetComputeShader ( ComputeShader - > GetComputeShader ( ) ) ;
ComputeShader - > SetParameters ( RHICmdList , DebugId ) ;
DispatchComputeShader ( RHICmdList , * ComputeShader , 1 , 1 , 1 ) ;
ComputeShader - > UnsetParameters ( RHICmdList ) ;
{
FRenderQueryRHIRef Query = RHICmdList . CreateRenderQuery ( RQT_AbsoluteTime ) ;
uint64 Temp = 0 ;
RHICmdList . EndRenderQuery ( Query ) ;
RHICmdList . GetRenderQueryResult ( Query , Temp , true ) ;
uint32 * Ptr = ( uint32 * ) RHICmdList . LockVertexBuffer ( GDebugBuffer2 - > Buffer , 0 , 4 , RLM_ReadOnly ) ;
UE_LOG ( LogDistanceField , Warning , TEXT ( " DebugId %u, " ) , * Ptr ) ;
RHICmdList . UnlockVertexBuffer ( GDebugBuffer2 - > Buffer ) ;
} */
}
2014-11-21 21:37:13 -05:00
bool FDeferredShadingSceneRenderer : : RenderDistanceFieldAOSurfaceCache (
FRHICommandListImmediate & RHICmdList ,
const FDistanceFieldAOParameters & Parameters ,
2015-02-19 16:09:15 -05:00
const TRefCountPtr < IPooledRenderTarget > & VelocityTexture ,
2014-11-21 21:37:13 -05:00
TRefCountPtr < IPooledRenderTarget > & OutDynamicBentNormalAO ,
2015-02-06 23:31:19 -05:00
TRefCountPtr < IPooledRenderTarget > & OutDynamicIrradiance ,
bool bVisualizeAmbientOcclusion ,
bool bVisualizeGlobalIllumination )
2014-06-03 15:53:13 -04:00
{
//@todo - support multiple views
const FViewInfo & View = Views [ 0 ] ;
2014-11-21 22:32:16 -05:00
if ( SupportsDistanceFieldAO ( View . GetFeatureLevel ( ) , View . GetShaderPlatform ( ) )
2014-06-03 15:53:13 -04:00
& & Views . Num ( ) = = 1
// ViewState is used to cache tile intersection resources which have to be sized based on the view
2014-11-24 17:38:29 -05:00
& & View . State
& & View . IsPerspectiveProjection ( ) )
2014-06-03 15:53:13 -04:00
{
QUICK_SCOPE_CYCLE_COUNTER ( STAT_RenderDistanceFieldAOSurfaceCache ) ;
2015-02-19 16:26:32 -05:00
SCOPED_DRAW_EVENT ( RHICmdList , DistanceFieldLighting ) ;
2014-06-03 15:53:13 -04:00
2014-11-21 22:32:16 -05:00
if ( GDistanceFieldVolumeTextureAtlas . VolumeTextureRHI & & Scene - > DistanceFieldSceneData . NumObjectsInBuffer )
2014-06-03 15:53:13 -04:00
{
2014-11-21 22:32:16 -05:00
check ( ! Scene - > DistanceFieldSceneData . HasPendingOperations ( ) ) ;
2014-12-16 20:00:22 -05:00
const bool bUseDistanceFieldGI = IsDistanceFieldGIAllowed ( View ) ;
2014-11-21 22:32:16 -05:00
2015-01-29 14:46:20 -05:00
if ( ! GDebugBuffer2 )
{
GDebugBuffer2 = new FRWBuffer ( ) ;
GDebugBuffer2 - > Initialize ( 4 , 1 , PF_R32_UINT ) ;
}
2014-06-03 15:53:13 -04:00
GenerateBestSpacedVectors ( ) ;
// Create surface cache state that will persist across frames if needed
if ( ! Scene - > SurfaceCacheResources )
{
Scene - > SurfaceCacheResources = new FSurfaceCacheResources ( ) ;
}
2015-01-29 14:46:20 -05:00
if ( bListMemoryNextFrame )
{
bListMemoryNextFrame = false ;
ListDistanceFieldLightingMemory ( View ) ;
}
2014-06-03 15:53:13 -04:00
FSurfaceCacheResources & SurfaceCacheResources = * Scene - > SurfaceCacheResources ;
2014-12-16 20:00:22 -05:00
2014-09-26 17:07:59 -04:00
FIntPoint DownsampledViewRect = FIntPoint : : DivideAndRoundDown ( View . ViewRect . Size ( ) , GAODownsampleFactor ) ;
2014-12-01 12:44:34 -05:00
// Needed because samples are kept across frames
2014-11-21 21:37:13 -05:00
int32 SlackAmount = 4 ;
2014-12-01 12:44:34 -05:00
int32 MaxSurfaceCacheSamples = DownsampledViewRect . X * DownsampledViewRect . Y / ( 1 < < ( 2 * GAOMinLevel * GAOPowerOfTwoBetweenLevels ) ) ;
SurfaceCacheResources . AllocateFor ( GAOMinLevel , GAOMaxLevel , SlackAmount * MaxSurfaceCacheSamples ) ;
GTemporaryIrradianceCacheResources . AllocateFor ( MaxSurfaceCacheSamples ) ;
2014-09-26 17:07:59 -04:00
uint32 ClearValues [ 4 ] = { 0 } ;
2014-06-03 15:53:13 -04:00
2014-12-16 20:00:22 -05:00
if ( ! SurfaceCacheResources . bClearedResources
| | ! GAOReuseAcrossFrames
// Drop records that will have uninitialized Irradiance if switching from AO only to AO + GI
2014-12-17 01:20:20 -05:00
| | ( bUseDistanceFieldGI & & ! SurfaceCacheResources . bHasIrradiance ) )
2014-06-03 15:53:13 -04:00
{
// Reset the number of active cache records to 0
2014-09-26 17:07:59 -04:00
for ( int32 DepthLevel = GAOMaxLevel ; DepthLevel > = GAOMinLevel ; DepthLevel - - )
2014-06-03 15:53:13 -04:00
{
2014-06-12 07:13:34 -04:00
RHICmdList . ClearUAV ( SurfaceCacheResources . Level [ DepthLevel ] - > ScatterDrawParameters . UAV , ClearValues ) ;
2014-06-03 15:53:13 -04:00
}
2014-10-03 18:02:05 -04:00
RHICmdList . ClearUAV ( SurfaceCacheResources . TempResources - > ScatterDrawParameters . UAV , ClearValues ) ;
2014-06-03 15:53:13 -04:00
SurfaceCacheResources . bClearedResources = true ;
}
2014-12-16 20:00:22 -05:00
SurfaceCacheResources . bHasIrradiance = bUseDistanceFieldGI ;
2014-11-21 22:32:16 -05:00
QUICK_SCOPE_CYCLE_COUNTER ( STAT_AOIssueGPUWork ) ;
2014-06-03 15:53:13 -04:00
{
2014-11-21 22:32:16 -05:00
SCOPED_DRAW_EVENT ( RHICmdList , ObjectFrustumCulling ) ;
2014-06-03 15:53:13 -04:00
2014-11-21 22:32:16 -05:00
if ( GAOCulledObjectBuffers . Buffers . MaxObjects < Scene - > DistanceFieldSceneData . NumObjectsInBuffer
| | GAOCulledObjectBuffers . Buffers . MaxObjects > 3 * Scene - > DistanceFieldSceneData . NumObjectsInBuffer )
2014-06-03 15:53:13 -04:00
{
2014-11-21 22:32:16 -05:00
GAOCulledObjectBuffers . Buffers . MaxObjects = Scene - > DistanceFieldSceneData . NumObjectsInBuffer * 5 / 4 ;
GAOCulledObjectBuffers . Buffers . Release ( ) ;
GAOCulledObjectBuffers . Buffers . Initialize ( ) ;
2014-06-03 15:53:13 -04:00
}
{
2014-12-16 20:00:22 -05:00
RHICmdList . ClearUAV ( GAOCulledObjectBuffers . Buffers . ObjectIndirectArguments . UAV , ClearValues ) ;
2014-11-21 22:32:16 -05:00
TShaderMapRef < FCullObjectsForViewCS > ComputeShader ( GetGlobalShaderMap ( Scene - > GetFeatureLevel ( ) ) ) ;
RHICmdList . SetComputeShader ( ComputeShader - > GetComputeShader ( ) ) ;
ComputeShader - > SetParameters ( RHICmdList , Scene , View , Parameters ) ;
2014-06-03 15:53:13 -04:00
2014-11-21 22:32:16 -05:00
DispatchComputeShader ( RHICmdList , * ComputeShader , FMath : : DivideAndRoundUp < uint32 > ( Scene - > DistanceFieldSceneData . NumObjectsInBuffer , UpdateObjectsGroupSize ) , 1 , 1 ) ;
ComputeShader - > UnsetParameters ( RHICmdList ) ;
2014-06-03 15:53:13 -04:00
}
2014-11-21 22:32:16 -05:00
}
2015-04-03 18:56:44 -04:00
2014-11-21 22:32:16 -05:00
TRefCountPtr < IPooledRenderTarget > DistanceFieldNormal ;
{
const FIntPoint BufferSize = GetBufferSizeForAO ( ) ;
FPooledRenderTargetDesc Desc ( FPooledRenderTargetDesc : : Create2DDesc ( BufferSize , PF_FloatRGBA , TexCreate_None , TexCreate_RenderTargetable | TexCreate_UAV , false ) ) ;
GRenderTargetPool . FindFreeElement ( Desc , DistanceFieldNormal , TEXT ( " DistanceFieldNormal " ) ) ;
}
// Compute the distance field normal, this is used for surface caching instead of the GBuffer normal because it matches the occluding geometry
ComputeDistanceFieldNormal ( RHICmdList , Views , DistanceFieldNormal - > GetRenderTargetItem ( ) , Parameters ) ;
2015-04-03 18:56:44 -04:00
// Intersect objects with screen tiles, build lists
FIntPoint TileListGroupSize = BuildTileObjectLists ( RHICmdList , Scene , Views , DistanceFieldNormal - > GetRenderTargetItem ( ) , Parameters ) ;
2014-11-21 22:32:16 -05:00
GRenderTargetPool . VisualizeTexture . SetCheckPoint ( RHICmdList , DistanceFieldNormal ) ;
if ( GAOReuseAcrossFrames )
{
SCOPED_DRAW_EVENT ( RHICmdList , TrimRecords ) ;
// Copy and trim last frame's surface cache samples
2014-09-26 17:07:59 -04:00
for ( int32 DepthLevel = GAOMaxLevel ; DepthLevel > = GAOMinLevel ; DepthLevel - - )
2014-06-03 15:53:13 -04:00
{
2015-01-29 14:46:20 -05:00
if ( GAOTrimOldRecordsFraction > 0 )
2014-06-03 15:53:13 -04:00
{
{
2014-11-21 22:32:16 -05:00
TShaderMapRef < FSetupCopyIndirectArgumentsCS > ComputeShader ( View . ShaderMap ) ;
2014-06-03 15:53:13 -04:00
2014-06-12 07:13:34 -04:00
RHICmdList . SetComputeShader ( ComputeShader - > GetComputeShader ( ) ) ;
2014-06-05 16:38:54 -04:00
ComputeShader - > SetParameters ( RHICmdList , View , DepthLevel ) ;
DispatchComputeShader ( RHICmdList , * ComputeShader , 1 , 1 , 1 ) ;
2014-06-03 15:53:13 -04:00
2014-06-05 16:38:54 -04:00
ComputeShader - > UnsetParameters ( RHICmdList ) ;
2014-06-03 15:53:13 -04:00
}
2014-12-16 20:00:22 -05:00
if ( bUseDistanceFieldGI )
2014-06-03 15:53:13 -04:00
{
2014-11-21 22:32:16 -05:00
TShaderMapRef < TCopyIrradianceCacheSamplesCS < true > > ComputeShader ( View . ShaderMap ) ;
2014-06-03 15:53:13 -04:00
2014-06-12 07:13:34 -04:00
RHICmdList . SetComputeShader ( ComputeShader - > GetComputeShader ( ) ) ;
2014-11-21 22:32:16 -05:00
ComputeShader - > SetParameters ( RHICmdList , View , DepthLevel ) ;
2014-11-21 21:37:13 -05:00
DispatchIndirectComputeShader ( RHICmdList , * ComputeShader , SurfaceCacheResources . DispatchParameters . Buffer , 0 ) ;
ComputeShader - > UnsetParameters ( RHICmdList ) ;
}
else
{
2014-11-21 22:32:16 -05:00
TShaderMapRef < TCopyIrradianceCacheSamplesCS < false > > ComputeShader ( View . ShaderMap ) ;
2014-11-21 21:37:13 -05:00
RHICmdList . SetComputeShader ( ComputeShader - > GetComputeShader ( ) ) ;
2014-11-21 22:32:16 -05:00
ComputeShader - > SetParameters ( RHICmdList , View , DepthLevel ) ;
2014-06-05 16:38:54 -04:00
DispatchIndirectComputeShader ( RHICmdList , * ComputeShader , SurfaceCacheResources . DispatchParameters . Buffer , 0 ) ;
2014-06-03 15:53:13 -04:00
2014-06-05 16:38:54 -04:00
ComputeShader - > UnsetParameters ( RHICmdList ) ;
2014-06-03 15:53:13 -04:00
}
2014-11-21 22:32:16 -05:00
Swap ( SurfaceCacheResources . Level [ DepthLevel ] , SurfaceCacheResources . TempResources ) ;
2014-06-03 15:53:13 -04:00
}
}
}
2014-11-21 22:32:16 -05:00
2014-12-16 20:00:22 -05:00
if ( bUseDistanceFieldGI )
{
2015-01-29 14:46:20 -05:00
extern void UpdateVPLs (
2014-12-16 20:00:22 -05:00
FRHICommandListImmediate & RHICmdList ,
const FViewInfo & View ,
const FScene * Scene ,
const FDistanceFieldAOParameters & Parameters ) ;
2015-01-29 14:46:20 -05:00
UpdateVPLs ( RHICmdList , View , Scene , Parameters ) ;
2014-12-16 20:00:22 -05:00
}
2014-11-21 22:32:16 -05:00
// Start from the highest depth, which will consider the fewest potential shading points
// Each level potentially prevents the next higher resolution level from doing expensive shading work
// This is the core of the surface cache algorithm
for ( int32 DepthLevel = GAOMaxLevel ; DepthLevel > = GAOMinLevel ; DepthLevel - - )
{
int32 DestLevelDownsampleFactor = GAODownsampleFactor * ( 1 < < ( DepthLevel * GAOPowerOfTwoBetweenLevels ) ) ;
SCOPED_DRAW_EVENTF ( RHICmdList , Level , TEXT ( " Level_%d " ) , DepthLevel ) ;
TRefCountPtr < IPooledRenderTarget > DistanceFieldAOBentNormalSplat ;
{
FIntPoint AOBufferSize = FIntPoint : : DivideAndRoundUp ( GSceneRenderTargets . GetBufferSizeXY ( ) , DestLevelDownsampleFactor ) ;
FPooledRenderTargetDesc Desc ( FPooledRenderTargetDesc : : Create2DDesc ( AOBufferSize , PF_FloatRGBA , TexCreate_None , TexCreate_RenderTargetable | TexCreate_UAV , false ) ) ;
GRenderTargetPool . FindFreeElement ( Desc , DistanceFieldAOBentNormalSplat , TEXT ( " DistanceFieldAOBentNormalSplat " ) ) ;
}
// Splat / interpolate the surface cache records onto the buffer sized for the current depth level
2014-12-16 20:00:22 -05:00
RenderIrradianceCacheInterpolation ( RHICmdList , View , DistanceFieldAOBentNormalSplat , NULL , DistanceFieldNormal - > GetRenderTargetItem ( ) , DepthLevel , DestLevelDownsampleFactor , Parameters , false ) ;
2014-11-21 22:32:16 -05:00
{
2014-12-16 20:00:22 -05:00
SCOPED_DRAW_EVENT ( RHICmdList , PopulateAndConeTrace ) ;
2014-11-21 22:32:16 -05:00
SetRenderTarget ( RHICmdList , NULL , NULL ) ;
// Save off the current record count before adding any more
{
TShaderMapRef < FSaveStartIndexCS > ComputeShader ( View . ShaderMap ) ;
RHICmdList . SetComputeShader ( ComputeShader - > GetComputeShader ( ) ) ;
ComputeShader - > SetParameters ( RHICmdList , View , DepthLevel ) ;
DispatchComputeShader ( RHICmdList , * ComputeShader , 1 , 1 , 1 ) ;
ComputeShader - > UnsetParameters ( RHICmdList ) ;
}
// Create new records which haven't been shaded yet for shading points which don't have a valid interpolation from existing records
for ( int32 ViewIndex = 0 ; ViewIndex < Views . Num ( ) ; ViewIndex + + )
{
2015-03-06 15:13:38 -05:00
const FViewInfo & ViewInfo = Views [ ViewIndex ] ;
2014-11-21 22:32:16 -05:00
2015-03-06 15:13:38 -05:00
FIntPoint DownsampledViewSize = FIntPoint : : DivideAndRoundUp ( ViewInfo . ViewRect . Size ( ) , DestLevelDownsampleFactor ) ;
2014-11-21 22:32:16 -05:00
uint32 GroupSizeX = FMath : : DivideAndRoundUp ( DownsampledViewSize . X , GDistanceFieldAOTileSizeX ) ;
uint32 GroupSizeY = FMath : : DivideAndRoundUp ( DownsampledViewSize . Y , GDistanceFieldAOTileSizeY ) ;
2015-03-06 15:13:38 -05:00
TShaderMapRef < FPopulateCacheCS > ComputeShader ( ViewInfo . ShaderMap ) ;
2014-11-21 22:32:16 -05:00
RHICmdList . SetComputeShader ( ComputeShader - > GetComputeShader ( ) ) ;
2015-03-06 15:13:38 -05:00
ComputeShader - > SetParameters ( RHICmdList , ViewInfo , DistanceFieldAOBentNormalSplat - > GetRenderTargetItem ( ) , DistanceFieldNormal - > GetRenderTargetItem ( ) , DestLevelDownsampleFactor , DepthLevel , TileListGroupSize , Parameters ) ;
2014-11-21 22:32:16 -05:00
DispatchComputeShader ( RHICmdList , * ComputeShader , GroupSizeX , GroupSizeY , 1 ) ;
ComputeShader - > UnsetParameters ( RHICmdList ) ;
}
{
2014-12-01 12:44:34 -05:00
TShaderMapRef < TSetupFinalGatherIndirectArgumentsCS < true > > ComputeShader ( View . ShaderMap ) ;
2014-11-21 22:32:16 -05:00
RHICmdList . SetComputeShader ( ComputeShader - > GetComputeShader ( ) ) ;
ComputeShader - > SetParameters ( RHICmdList , View , DepthLevel ) ;
DispatchComputeShader ( RHICmdList , * ComputeShader , 1 , 1 , 1 ) ;
ComputeShader - > UnsetParameters ( RHICmdList ) ;
}
// Compute lighting for the new surface cache records by cone-stepping through the object distance fields
2014-12-16 20:00:22 -05:00
if ( bUseDistanceFieldGI )
2014-11-21 22:32:16 -05:00
{
2015-01-29 14:46:20 -05:00
TShaderMapRef < TConeTraceOcclusionCS < true > > ComputeShader ( View . ShaderMap ) ;
2014-11-21 22:32:16 -05:00
RHICmdList . SetComputeShader ( ComputeShader - > GetComputeShader ( ) ) ;
ComputeShader - > SetParameters ( RHICmdList , View , DistanceFieldAOBentNormalSplat - > GetRenderTargetItem ( ) , DistanceFieldNormal - > GetRenderTargetItem ( ) , DestLevelDownsampleFactor , DepthLevel , TileListGroupSize , Parameters ) ;
DispatchIndirectComputeShader ( RHICmdList , * ComputeShader , SurfaceCacheResources . DispatchParameters . Buffer , 0 ) ;
ComputeShader - > UnsetParameters ( RHICmdList ) ;
}
else
{
2015-01-29 14:46:20 -05:00
TShaderMapRef < TConeTraceOcclusionCS < false > > ComputeShader ( View . ShaderMap ) ;
2014-11-21 22:32:16 -05:00
RHICmdList . SetComputeShader ( ComputeShader - > GetComputeShader ( ) ) ;
ComputeShader - > SetParameters ( RHICmdList , View , DistanceFieldAOBentNormalSplat - > GetRenderTargetItem ( ) , DistanceFieldNormal - > GetRenderTargetItem ( ) , DestLevelDownsampleFactor , DepthLevel , TileListGroupSize , Parameters ) ;
DispatchIndirectComputeShader ( RHICmdList , * ComputeShader , SurfaceCacheResources . DispatchParameters . Buffer , 0 ) ;
ComputeShader - > UnsetParameters ( RHICmdList ) ;
}
}
2014-12-01 12:44:34 -05:00
2015-02-19 16:27:54 -05:00
if ( bUseDistanceFieldGI )
{
extern void ComputeIrradianceForSamples (
int32 DepthLevel ,
FRHICommandListImmediate & RHICmdList ,
const FViewInfo & View ,
const FScene * Scene ,
const FDistanceFieldAOParameters & Parameters ,
FTemporaryIrradianceCacheResources * TemporaryIrradianceCacheResources ) ;
ComputeIrradianceForSamples ( DepthLevel , RHICmdList , View , Scene , Parameters , & GTemporaryIrradianceCacheResources ) ;
}
// Compute heightfield occlusion after heightfield GI, otherwise it self-shadows incorrectly
2015-02-06 23:31:19 -05:00
View . HeightfieldLightingViewInfo . ComputeOcclusionForSamples ( View , RHICmdList , GTemporaryIrradianceCacheResources , DepthLevel , Parameters ) ;
2014-12-01 12:44:34 -05:00
{
TShaderMapRef < TSetupFinalGatherIndirectArgumentsCS < false > > ComputeShader ( View . ShaderMap ) ;
RHICmdList . SetComputeShader ( ComputeShader - > GetComputeShader ( ) ) ;
ComputeShader - > SetParameters ( RHICmdList , View , DepthLevel ) ;
DispatchComputeShader ( RHICmdList , * ComputeShader , 1 , 1 , 1 ) ;
ComputeShader - > UnsetParameters ( RHICmdList ) ;
}
2015-02-19 16:27:54 -05:00
// Compute and store the final bent normal now that all occlusion sources have been computed (distance fields, heightfields)
2014-12-01 12:44:34 -05:00
{
2015-02-06 23:31:19 -05:00
TShaderMapRef < FCombineConesCS > ComputeShader ( View . ShaderMap ) ;
2014-12-01 12:44:34 -05:00
2015-02-06 23:31:19 -05:00
RHICmdList . SetComputeShader ( ComputeShader - > GetComputeShader ( ) ) ;
ComputeShader - > SetParameters ( RHICmdList , View , DepthLevel , Parameters , NULL , FMatrix : : Identity , NULL , NULL ) ;
DispatchIndirectComputeShader ( RHICmdList , * ComputeShader , SurfaceCacheResources . DispatchParameters . Buffer , 0 ) ;
2014-12-01 12:44:34 -05:00
2015-02-06 23:31:19 -05:00
ComputeShader - > UnsetParameters ( RHICmdList ) ;
2014-12-01 12:44:34 -05:00
}
2014-11-21 22:32:16 -05:00
}
TRefCountPtr < IPooledRenderTarget > BentNormalAccumulation ;
TRefCountPtr < IPooledRenderTarget > IrradianceAccumulation ;
{
FIntPoint BufferSize = GetBufferSizeForAO ( ) ;
FPooledRenderTargetDesc Desc ( FPooledRenderTargetDesc : : Create2DDesc ( BufferSize , PF_FloatRGBA , TexCreate_None , TexCreate_RenderTargetable | TexCreate_UAV , false ) ) ;
GRenderTargetPool . FindFreeElement ( Desc , BentNormalAccumulation , TEXT ( " BentNormalAccumulation " ) ) ;
2014-12-16 20:00:22 -05:00
if ( bUseDistanceFieldGI )
2014-11-21 22:32:16 -05:00
{
GRenderTargetPool . FindFreeElement ( Desc , IrradianceAccumulation , TEXT ( " IrradianceAccumulation " ) ) ;
}
}
// Splat the surface cache records onto the opaque pixels, using less strict weighting so the lighting is smoothed in world space
{
SCOPED_DRAW_EVENT ( RHICmdList , FinalIrradianceCacheSplat ) ;
2014-12-16 20:00:22 -05:00
RenderIrradianceCacheInterpolation ( RHICmdList , View , BentNormalAccumulation , IrradianceAccumulation , DistanceFieldNormal - > GetRenderTargetItem ( ) , 0 , GAODownsampleFactor , Parameters , true ) ;
2014-11-21 22:32:16 -05:00
}
GRenderTargetPool . VisualizeTexture . SetCheckPoint ( RHICmdList , BentNormalAccumulation ) ;
// Post process the AO to cover over artifacts
TRefCountPtr < IPooledRenderTarget > BentNormalOutput ;
TRefCountPtr < IPooledRenderTarget > IrradianceOutput ;
2015-02-19 16:09:15 -05:00
PostProcessBentNormalAO (
RHICmdList ,
Parameters ,
View ,
VelocityTexture - > GetRenderTargetItem ( ) ,
BentNormalAccumulation - > GetRenderTargetItem ( ) ,
IrradianceAccumulation ,
DistanceFieldNormal - > GetRenderTargetItem ( ) ,
BentNormalOutput ,
IrradianceOutput ) ;
2014-11-21 22:32:16 -05:00
GRenderTargetPool . VisualizeTexture . SetCheckPoint ( RHICmdList , BentNormalOutput ) ;
2015-02-06 23:31:19 -05:00
if ( bVisualizeAmbientOcclusion | | bVisualizeGlobalIllumination )
2014-11-21 22:32:16 -05:00
{
GSceneRenderTargets . BeginRenderingSceneColor ( RHICmdList ) ;
}
else
{
FPooledRenderTargetDesc Desc = GSceneRenderTargets . GetSceneColor ( ) - > GetDesc ( ) ;
// Make sure we get a signed format
Desc . Format = PF_FloatRGBA ;
GRenderTargetPool . FindFreeElement ( Desc , OutDynamicBentNormalAO , TEXT ( " DynamicBentNormalAO " ) ) ;
2014-12-16 20:00:22 -05:00
if ( bUseDistanceFieldGI )
2014-11-21 22:32:16 -05:00
{
Desc . Format = PF_FloatRGB ;
GRenderTargetPool . FindFreeElement ( Desc , OutDynamicIrradiance , TEXT ( " DynamicIrradiance " ) ) ;
}
FTextureRHIParamRef RenderTargets [ 2 ] =
{
OutDynamicBentNormalAO - > GetRenderTargetItem ( ) . TargetableTexture ,
2014-12-16 20:00:22 -05:00
bUseDistanceFieldGI ? OutDynamicIrradiance - > GetRenderTargetItem ( ) . TargetableTexture : NULL
2014-11-21 22:32:16 -05:00
} ;
2014-12-16 20:00:22 -05:00
SetRenderTargets ( RHICmdList , ARRAY_COUNT ( RenderTargets ) - ( bUseDistanceFieldGI ? 0 : 1 ) , RenderTargets , FTextureRHIParamRef ( ) , 0 , NULL ) ;
2014-11-21 22:32:16 -05:00
}
// Upsample to full resolution, write to output
2015-02-06 23:31:19 -05:00
UpsampleBentNormalAO ( RHICmdList , Views , BentNormalOutput , IrradianceOutput , bVisualizeAmbientOcclusion , bVisualizeGlobalIllumination ) ;
2014-11-21 22:32:16 -05:00
2015-04-03 18:56:44 -04:00
if ( ! bVisualizeAmbientOcclusion & & ! bVisualizeGlobalIllumination )
{
RHICmdList . CopyToResolveTarget ( OutDynamicBentNormalAO - > GetRenderTargetItem ( ) . TargetableTexture , OutDynamicBentNormalAO - > GetRenderTargetItem ( ) . ShaderResourceTexture , false , FResolveParams ( ) ) ;
if ( bUseDistanceFieldGI )
{
RHICmdList . CopyToResolveTarget ( OutDynamicIrradiance - > GetRenderTargetItem ( ) . TargetableTexture , OutDynamicIrradiance - > GetRenderTargetItem ( ) . ShaderResourceTexture , false , FResolveParams ( ) ) ;
}
}
2014-11-21 22:32:16 -05:00
return true ;
2014-06-03 15:53:13 -04:00
}
}
return false ;
}
2014-11-21 21:37:13 -05:00
template < bool bApplyShadowing , bool bSupportIrradiance >
2014-06-06 14:14:50 -04:00
class TDynamicSkyLightDiffusePS : public FGlobalShader
2014-06-03 15:53:13 -04:00
{
2014-06-06 14:14:50 -04:00
DECLARE_SHADER_TYPE ( TDynamicSkyLightDiffusePS , Global ) ;
2014-06-03 15:53:13 -04:00
public :
static bool ShouldCache ( EShaderPlatform Platform )
{
2014-06-26 15:53:01 -04:00
return IsFeatureLevelSupported ( Platform , ERHIFeatureLevel : : SM4 ) ;
2014-06-03 15:53:13 -04:00
}
static void ModifyCompilationEnvironment ( EShaderPlatform Platform , FShaderCompilerEnvironment & OutEnvironment )
{
FGlobalShader : : ModifyCompilationEnvironment ( Platform , OutEnvironment ) ;
OutEnvironment . SetDefine ( TEXT ( " DOWNSAMPLE_FACTOR " ) , GAODownsampleFactor ) ;
2014-06-06 14:14:50 -04:00
OutEnvironment . SetDefine ( TEXT ( " APPLY_SHADOWING " ) , ( uint32 ) ( bApplyShadowing ? 1 : 0 ) ) ;
2014-11-21 21:37:13 -05:00
OutEnvironment . SetDefine ( TEXT ( " SUPPORT_IRRADIANCE " ) , bSupportIrradiance ? TEXT ( " 1 " ) : TEXT ( " 0 " ) ) ;
2014-06-03 15:53:13 -04:00
}
/** Default constructor. */
2014-06-06 14:14:50 -04:00
TDynamicSkyLightDiffusePS ( ) { }
2014-06-03 15:53:13 -04:00
/** Initialization constructor. */
2014-06-06 14:14:50 -04:00
TDynamicSkyLightDiffusePS ( const ShaderMetaType : : CompiledShaderInitializerType & Initializer )
2014-06-03 15:53:13 -04:00
: FGlobalShader ( Initializer )
{
DeferredParameters . Bind ( Initializer . ParameterMap ) ;
2015-01-19 15:48:04 -05:00
PreIntegratedGF . Bind ( Initializer . ParameterMap , TEXT ( " PreIntegratedGF " ) ) ;
PreIntegratedGFSampler . Bind ( Initializer . ParameterMap , TEXT ( " PreIntegratedGFSampler " ) ) ;
2014-08-28 13:54:31 -04:00
DynamicBentNormalAOTexture . Bind ( Initializer . ParameterMap , TEXT ( " BentNormalAOTexture " ) ) ;
DynamicBentNormalAOSampler . Bind ( Initializer . ParameterMap , TEXT ( " BentNormalAOSampler " ) ) ;
2014-11-21 21:37:13 -05:00
DynamicIrradianceTexture . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceTexture " ) ) ;
DynamicIrradianceSampler . Bind ( Initializer . ParameterMap , TEXT ( " IrradianceSampler " ) ) ;
2014-08-28 13:54:31 -04:00
ContrastAndNormalizeMulAdd . Bind ( Initializer . ParameterMap , TEXT ( " ContrastAndNormalizeMulAdd " ) ) ;
2014-10-01 18:51:00 -04:00
OcclusionTintAndMinOcclusion . Bind ( Initializer . ParameterMap , TEXT ( " OcclusionTintAndMinOcclusion " ) ) ;
2014-06-03 15:53:13 -04:00
}
2014-11-21 21:37:13 -05:00
void SetParameters ( FRHICommandList & RHICmdList , const FSceneView & View , FTextureRHIParamRef DynamicBentNormalAO , IPooledRenderTarget * DynamicIrradiance , const FDistanceFieldAOParameters & Parameters , const FSkyLightSceneProxy * SkyLight )
2014-06-03 15:53:13 -04:00
{
const FPixelShaderRHIParamRef ShaderRHI = GetPixelShader ( ) ;
2014-06-05 16:38:54 -04:00
FGlobalShader : : SetParameters ( RHICmdList , ShaderRHI , View ) ;
DeferredParameters . Set ( RHICmdList , ShaderRHI , View ) ;
2014-06-03 15:53:13 -04:00
2015-01-19 15:48:04 -05:00
SetTextureParameter ( RHICmdList , ShaderRHI , PreIntegratedGF , PreIntegratedGFSampler , TStaticSamplerState < SF_Bilinear , AM_Clamp , AM_Clamp , AM_Clamp > : : GetRHI ( ) , GSystemTextures . PreintegratedGF - > GetRenderTargetItem ( ) . ShaderResourceTexture ) ;
2014-08-28 13:54:31 -04:00
SetTextureParameter ( RHICmdList , ShaderRHI , DynamicBentNormalAOTexture , DynamicBentNormalAOSampler , TStaticSamplerState < SF_Point > : : GetRHI ( ) , DynamicBentNormalAO ) ;
2014-06-03 15:53:13 -04:00
2014-11-21 21:37:13 -05:00
if ( DynamicIrradianceTexture . IsBound ( ) )
{
SetTextureParameter ( RHICmdList , ShaderRHI , DynamicIrradianceTexture , DynamicIrradianceSampler , TStaticSamplerState < SF_Point > : : GetRHI ( ) , DynamicIrradiance - > GetRenderTargetItem ( ) . ShaderResourceTexture ) ;
}
2014-08-28 13:54:31 -04:00
// Scale and bias to remap the contrast curve to [0,1]
const float Min = 1 / ( 1 + FMath : : Exp ( - Parameters . Contrast * ( 0 * 10 - 5 ) ) ) ;
const float Max = 1 / ( 1 + FMath : : Exp ( - Parameters . Contrast * ( 1 * 10 - 5 ) ) ) ;
const float Mul = 1.0f / ( Max - Min ) ;
const float Add = - Min / ( Max - Min ) ;
SetShaderValue ( RHICmdList , ShaderRHI , ContrastAndNormalizeMulAdd , FVector ( Parameters . Contrast , Mul , Add ) ) ;
2014-10-01 18:51:00 -04:00
FVector4 OcclusionTintAndMinOcclusionValue = FVector4 ( SkyLight - > OcclusionTint ) ;
OcclusionTintAndMinOcclusionValue . W = SkyLight - > MinOcclusion ;
SetShaderValue ( RHICmdList , ShaderRHI , OcclusionTintAndMinOcclusion , OcclusionTintAndMinOcclusionValue ) ;
2014-06-03 15:53:13 -04:00
}
// FShader interface.
2015-04-01 07:20:55 -04:00
virtual bool Serialize ( FArchive & Ar ) override
2014-06-03 15:53:13 -04:00
{
bool bShaderHasOutdatedParameters = FGlobalShader : : Serialize ( Ar ) ;
Ar < < DeferredParameters ;
2015-01-19 15:48:04 -05:00
Ar < < PreIntegratedGF < < PreIntegratedGFSampler ;
2014-08-28 13:54:31 -04:00
Ar < < DynamicBentNormalAOTexture ;
Ar < < DynamicBentNormalAOSampler ;
2014-11-21 21:37:13 -05:00
Ar < < DynamicIrradianceTexture ;
Ar < < DynamicIrradianceSampler ;
2014-08-28 13:54:31 -04:00
Ar < < ContrastAndNormalizeMulAdd ;
2014-10-01 18:51:00 -04:00
Ar < < OcclusionTintAndMinOcclusion ;
2014-06-03 15:53:13 -04:00
return bShaderHasOutdatedParameters ;
}
private :
FDeferredPixelShaderParameters DeferredParameters ;
2015-01-19 15:48:04 -05:00
FShaderResourceParameter PreIntegratedGF ;
FShaderResourceParameter PreIntegratedGFSampler ;
2014-08-28 13:54:31 -04:00
FShaderResourceParameter DynamicBentNormalAOTexture ;
FShaderResourceParameter DynamicBentNormalAOSampler ;
2014-11-21 21:37:13 -05:00
FShaderResourceParameter DynamicIrradianceTexture ;
FShaderResourceParameter DynamicIrradianceSampler ;
2014-08-28 13:54:31 -04:00
FShaderParameter ContrastAndNormalizeMulAdd ;
2014-10-01 18:51:00 -04:00
FShaderParameter OcclusionTintAndMinOcclusion ;
2014-06-03 15:53:13 -04:00
} ;
2014-11-21 21:37:13 -05:00
# define IMPLEMENT_SKYLIGHT_PS_TYPE(bApplyShadowing, bSupportIrradiance) \
typedef TDynamicSkyLightDiffusePS < bApplyShadowing , bSupportIrradiance > TDynamicSkyLightDiffusePS # # bApplyShadowing # # bSupportIrradiance ; \
IMPLEMENT_SHADER_TYPE ( template < > , TDynamicSkyLightDiffusePS # # bApplyShadowing # # bSupportIrradiance , TEXT ( " SkyLighting " ) , TEXT ( " SkyLightDiffusePS " ) , SF_Pixel ) ;
IMPLEMENT_SKYLIGHT_PS_TYPE ( true , true )
IMPLEMENT_SKYLIGHT_PS_TYPE ( false , true )
IMPLEMENT_SKYLIGHT_PS_TYPE ( true , false )
IMPLEMENT_SKYLIGHT_PS_TYPE ( false , false )
2014-06-03 15:53:13 -04:00
2015-02-06 23:31:19 -05:00
bool FDeferredShadingSceneRenderer : : ShouldRenderDistanceFieldAO ( ) const
{
return Scene - > SkyLight - > bCastShadows
& & ViewFamily . EngineShowFlags . DistanceFieldAO
& & ! ViewFamily . EngineShowFlags . VisualizeDistanceFieldAO
& & ! ViewFamily . EngineShowFlags . VisualizeDistanceFieldGI
& & ! ViewFamily . EngineShowFlags . VisualizeMeshDistanceFields ;
}
2015-02-19 16:09:15 -05:00
void FDeferredShadingSceneRenderer : : RenderDynamicSkyLighting ( FRHICommandListImmediate & RHICmdList , const TRefCountPtr < IPooledRenderTarget > & VelocityTexture , TRefCountPtr < IPooledRenderTarget > & DynamicBentNormalAO )
2014-11-21 22:32:16 -05:00
{
2015-02-19 16:15:13 -05:00
if ( ShouldRenderDynamicSkyLight ( Scene , ViewFamily ) )
2014-06-03 15:53:13 -04:00
{
2014-10-20 10:43:43 -04:00
SCOPED_DRAW_EVENT ( RHICmdList , SkyLightDiffuse ) ;
2014-06-03 15:53:13 -04:00
bool bApplyShadowing = false ;
2014-08-28 13:54:31 -04:00
FDistanceFieldAOParameters Parameters ( Scene - > SkyLight - > OcclusionMaxDistance , Scene - > SkyLight - > Contrast ) ;
2014-11-21 21:37:13 -05:00
TRefCountPtr < IPooledRenderTarget > DynamicIrradiance ;
2014-06-03 15:53:13 -04:00
2015-02-06 23:31:19 -05:00
if ( ShouldRenderDistanceFieldAO ( ) )
2014-06-03 15:53:13 -04:00
{
2015-02-19 16:09:15 -05:00
bApplyShadowing = RenderDistanceFieldAOSurfaceCache ( RHICmdList , Parameters , VelocityTexture , DynamicBentNormalAO , DynamicIrradiance , false , false ) ;
2014-06-03 15:53:13 -04:00
}
2014-06-27 11:07:13 -04:00
GSceneRenderTargets . BeginRenderingSceneColor ( RHICmdList ) ;
2014-06-03 15:53:13 -04:00
for ( int32 ViewIndex = 0 ; ViewIndex < Views . Num ( ) ; ViewIndex + + )
{
const FViewInfo & View = Views [ ViewIndex ] ;
2014-06-12 07:13:34 -04:00
RHICmdList . SetViewport ( View . ViewRect . Min . X , View . ViewRect . Min . Y , 0.0f , View . ViewRect . Max . X , View . ViewRect . Max . Y , 1.0f ) ;
2014-11-21 21:37:13 -05:00
RHICmdList . SetRasterizerState ( TStaticRasterizerState < FM_Solid , CM_None > : : GetRHI ( ) ) ;
RHICmdList . SetDepthStencilState ( TStaticDepthStencilState < false , CF_Always > : : GetRHI ( ) ) ;
if ( GAOOverwriteSceneColor )
{
RHICmdList . SetBlendState ( TStaticBlendState < > : : GetRHI ( ) ) ;
}
else
{
RHICmdList . SetBlendState ( TStaticBlendState < CW_RGB , BO_Add , BF_One , BF_One > : : GetRHI ( ) ) ;
}
2014-06-03 15:53:13 -04:00
2014-12-16 20:00:22 -05:00
const bool bUseDistanceFieldGI = IsDistanceFieldGIAllowed ( View ) ;
2014-08-28 06:22:54 -04:00
TShaderMapRef < FPostProcessVS > VertexShader ( View . ShaderMap ) ;
2014-06-03 15:53:13 -04:00
2014-06-06 14:14:50 -04:00
if ( bApplyShadowing )
{
2014-12-16 20:00:22 -05:00
if ( bUseDistanceFieldGI )
2014-11-21 21:37:13 -05:00
{
TShaderMapRef < TDynamicSkyLightDiffusePS < true , true > > PixelShader ( View . ShaderMap ) ;
2014-06-03 15:53:13 -04:00
2014-11-21 21:37:13 -05:00
static FGlobalBoundShaderState BoundShaderState ;
SetGlobalBoundShaderState ( RHICmdList , View . GetFeatureLevel ( ) , BoundShaderState , GFilterVertexDeclaration . VertexDeclarationRHI , * VertexShader , * PixelShader ) ;
PixelShader - > SetParameters ( RHICmdList , View , DynamicBentNormalAO - > GetRenderTargetItem ( ) . ShaderResourceTexture , DynamicIrradiance , Parameters , Scene - > SkyLight ) ;
}
else
{
TShaderMapRef < TDynamicSkyLightDiffusePS < true , false > > PixelShader ( View . ShaderMap ) ;
static FGlobalBoundShaderState BoundShaderState ;
SetGlobalBoundShaderState ( RHICmdList , View . GetFeatureLevel ( ) , BoundShaderState , GFilterVertexDeclaration . VertexDeclarationRHI , * VertexShader , * PixelShader ) ;
PixelShader - > SetParameters ( RHICmdList , View , DynamicBentNormalAO - > GetRenderTargetItem ( ) . ShaderResourceTexture , DynamicIrradiance , Parameters , Scene - > SkyLight ) ;
}
2014-06-06 14:14:50 -04:00
}
else
{
2014-12-16 20:00:22 -05:00
if ( bUseDistanceFieldGI )
2014-11-21 21:37:13 -05:00
{
TShaderMapRef < TDynamicSkyLightDiffusePS < false , true > > PixelShader ( View . ShaderMap ) ;
2014-06-06 14:14:50 -04:00
2014-11-21 21:37:13 -05:00
static FGlobalBoundShaderState BoundShaderState ;
SetGlobalBoundShaderState ( RHICmdList , View . GetFeatureLevel ( ) , BoundShaderState , GFilterVertexDeclaration . VertexDeclarationRHI , * VertexShader , * PixelShader ) ;
PixelShader - > SetParameters ( RHICmdList , View , GWhiteTexture - > TextureRHI , NULL , Parameters , Scene - > SkyLight ) ;
}
else
{
TShaderMapRef < TDynamicSkyLightDiffusePS < false , false > > PixelShader ( View . ShaderMap ) ;
static FGlobalBoundShaderState BoundShaderState ;
SetGlobalBoundShaderState ( RHICmdList , View . GetFeatureLevel ( ) , BoundShaderState , GFilterVertexDeclaration . VertexDeclarationRHI , * VertexShader , * PixelShader ) ;
PixelShader - > SetParameters ( RHICmdList , View , GWhiteTexture - > TextureRHI , NULL , Parameters , Scene - > SkyLight ) ;
}
2014-06-06 14:14:50 -04:00
}
2014-06-10 07:29:49 -04:00
2014-06-03 15:53:13 -04:00
DrawRectangle (
2014-06-12 07:13:34 -04:00
RHICmdList ,
2014-06-03 15:53:13 -04:00
0 , 0 ,
View . ViewRect . Width ( ) , View . ViewRect . Height ( ) ,
View . ViewRect . Min . X , View . ViewRect . Min . Y ,
View . ViewRect . Width ( ) , View . ViewRect . Height ( ) ,
FIntPoint ( View . ViewRect . Width ( ) , View . ViewRect . Height ( ) ) ,
GSceneRenderTargets . GetBufferSizeXY ( ) ,
* VertexShader ) ;
}
}
2014-06-06 14:14:50 -04:00
}
2014-11-21 22:32:16 -05:00
class FVisualizeMeshDistanceFieldCS : public FGlobalShader
{
DECLARE_SHADER_TYPE ( FVisualizeMeshDistanceFieldCS , Global ) ;
public :
static bool ShouldCache ( EShaderPlatform Platform )
{
return IsFeatureLevelSupported ( Platform , ERHIFeatureLevel : : SM5 ) & & DoesPlatformSupportDistanceFieldAO ( Platform ) ;
}
static void ModifyCompilationEnvironment ( EShaderPlatform Platform , FShaderCompilerEnvironment & OutEnvironment )
{
OutEnvironment . SetDefine ( TEXT ( " DOWNSAMPLE_FACTOR " ) , GAODownsampleFactor ) ;
OutEnvironment . SetDefine ( TEXT ( " THREADGROUP_SIZEX " ) , GDistanceFieldAOTileSizeX ) ;
OutEnvironment . SetDefine ( TEXT ( " THREADGROUP_SIZEY " ) , GDistanceFieldAOTileSizeY ) ;
}
/** Default constructor. */
FVisualizeMeshDistanceFieldCS ( ) { }
/** Initialization constructor. */
FVisualizeMeshDistanceFieldCS ( const ShaderMetaType : : CompiledShaderInitializerType & Initializer )
: FGlobalShader ( Initializer )
{
VisualizeMeshDistanceFields . Bind ( Initializer . ParameterMap , TEXT ( " VisualizeMeshDistanceFields " ) ) ;
NumGroups . Bind ( Initializer . ParameterMap , TEXT ( " NumGroups " ) ) ;
ObjectParameters . Bind ( Initializer . ParameterMap ) ;
DeferredParameters . Bind ( Initializer . ParameterMap ) ;
AOParameters . Bind ( Initializer . ParameterMap ) ;
}
void SetParameters (
FRHICommandList & RHICmdList ,
const FSceneView & View ,
FSceneRenderTargetItem & VisualizeMeshDistanceFieldsValue ,
FVector2D NumGroupsValue ,
const FDistanceFieldAOParameters & Parameters )
{
const FComputeShaderRHIParamRef ShaderRHI = GetComputeShader ( ) ;
FGlobalShader : : SetParameters ( RHICmdList , ShaderRHI , View ) ;
VisualizeMeshDistanceFields . SetTexture ( RHICmdList , ShaderRHI , VisualizeMeshDistanceFieldsValue . ShaderResourceTexture , VisualizeMeshDistanceFieldsValue . UAV ) ;
ObjectParameters . Set ( RHICmdList , ShaderRHI , GAOCulledObjectBuffers . Buffers ) ;
AOParameters . Set ( RHICmdList , ShaderRHI , Parameters ) ;
DeferredParameters . Set ( RHICmdList , ShaderRHI , View ) ;
SetShaderValue ( RHICmdList , ShaderRHI , NumGroups , NumGroupsValue ) ;
}
void UnsetParameters ( FRHICommandList & RHICmdList )
{
VisualizeMeshDistanceFields . UnsetUAV ( RHICmdList , GetComputeShader ( ) ) ;
}
// FShader interface.
2015-04-01 07:20:55 -04:00
virtual bool Serialize ( FArchive & Ar ) override
2014-11-21 22:32:16 -05:00
{
bool bShaderHasOutdatedParameters = FGlobalShader : : Serialize ( Ar ) ;
Ar < < VisualizeMeshDistanceFields ;
Ar < < NumGroups ;
Ar < < ObjectParameters ;
Ar < < DeferredParameters ;
Ar < < AOParameters ;
return bShaderHasOutdatedParameters ;
}
private :
FRWShaderParameter VisualizeMeshDistanceFields ;
FShaderParameter NumGroups ;
FDistanceFieldCulledObjectBufferParameters ObjectParameters ;
FDeferredPixelShaderParameters DeferredParameters ;
FAOParameters AOParameters ;
} ;
IMPLEMENT_SHADER_TYPE ( , FVisualizeMeshDistanceFieldCS , TEXT ( " DistanceFieldSurfaceCacheLighting " ) , TEXT ( " VisualizeMeshDistanceFieldCS " ) , SF_Compute ) ;
class FVisualizeDistanceFieldUpsamplePS : public FGlobalShader
{
DECLARE_SHADER_TYPE ( FVisualizeDistanceFieldUpsamplePS , Global ) ;
public :
static bool ShouldCache ( EShaderPlatform Platform )
{
return IsFeatureLevelSupported ( Platform , ERHIFeatureLevel : : SM5 ) & & DoesPlatformSupportDistanceFieldAO ( Platform ) ;
}
static void ModifyCompilationEnvironment ( EShaderPlatform Platform , FShaderCompilerEnvironment & OutEnvironment )
{
OutEnvironment . SetDefine ( TEXT ( " DOWNSAMPLE_FACTOR " ) , GAODownsampleFactor ) ;
}
/** Default constructor. */
FVisualizeDistanceFieldUpsamplePS ( ) { }
/** Initialization constructor. */
FVisualizeDistanceFieldUpsamplePS ( const ShaderMetaType : : CompiledShaderInitializerType & Initializer )
: FGlobalShader ( Initializer )
{
DeferredParameters . Bind ( Initializer . ParameterMap ) ;
VisualizeDistanceFieldTexture . Bind ( Initializer . ParameterMap , TEXT ( " VisualizeDistanceFieldTexture " ) ) ;
VisualizeDistanceFieldSampler . Bind ( Initializer . ParameterMap , TEXT ( " VisualizeDistanceFieldSampler " ) ) ;
}
void SetParameters ( FRHICommandList & RHICmdList , const FSceneView & View , TRefCountPtr < IPooledRenderTarget > & VisualizeDistanceField )
{
const FPixelShaderRHIParamRef ShaderRHI = GetPixelShader ( ) ;
FGlobalShader : : SetParameters ( RHICmdList , ShaderRHI , View ) ;
DeferredParameters . Set ( RHICmdList , ShaderRHI , View ) ;
SetTextureParameter ( RHICmdList , ShaderRHI , VisualizeDistanceFieldTexture , VisualizeDistanceFieldSampler , TStaticSamplerState < SF_Bilinear > : : GetRHI ( ) , VisualizeDistanceField - > GetRenderTargetItem ( ) . ShaderResourceTexture ) ;
}
// FShader interface.
2015-04-01 07:20:55 -04:00
virtual bool Serialize ( FArchive & Ar ) override
2014-11-21 22:32:16 -05:00
{
bool bShaderHasOutdatedParameters = FGlobalShader : : Serialize ( Ar ) ;
Ar < < DeferredParameters ;
Ar < < VisualizeDistanceFieldTexture ;
Ar < < VisualizeDistanceFieldSampler ;
return bShaderHasOutdatedParameters ;
}
private :
FDeferredPixelShaderParameters DeferredParameters ;
FShaderResourceParameter VisualizeDistanceFieldTexture ;
FShaderResourceParameter VisualizeDistanceFieldSampler ;
} ;
IMPLEMENT_SHADER_TYPE ( , FVisualizeDistanceFieldUpsamplePS , TEXT ( " DistanceFieldSurfaceCacheLighting " ) , TEXT ( " VisualizeDistanceFieldUpsamplePS " ) , SF_Pixel ) ;
void FDeferredShadingSceneRenderer : : RenderMeshDistanceFieldVisualization ( FRHICommandListImmediate & RHICmdList , const FDistanceFieldAOParameters & Parameters )
{
//@todo - support multiple views
const FViewInfo & View = Views [ 0 ] ;
if ( GDistanceFieldAO
& & FeatureLevel > = ERHIFeatureLevel : : SM5
& & DoesPlatformSupportDistanceFieldAO ( View . GetShaderPlatform ( ) )
& & Views . Num ( ) = = 1 )
{
QUICK_SCOPE_CYCLE_COUNTER ( STAT_RenderMeshDistanceFieldVis ) ;
SCOPED_DRAW_EVENT ( RHICmdList , VisualizeMeshDistanceFields ) ;
if ( GDistanceFieldVolumeTextureAtlas . VolumeTextureRHI & & Scene - > DistanceFieldSceneData . NumObjectsInBuffer > 0 )
{
check ( ! Scene - > DistanceFieldSceneData . HasPendingOperations ( ) ) ;
QUICK_SCOPE_CYCLE_COUNTER ( STAT_AOIssueGPUWork ) ;
{
if ( GAOCulledObjectBuffers . Buffers . MaxObjects < Scene - > DistanceFieldSceneData . NumObjectsInBuffer )
{
GAOCulledObjectBuffers . Buffers . MaxObjects = Scene - > DistanceFieldSceneData . NumObjectsInBuffer * 5 / 4 ;
GAOCulledObjectBuffers . Buffers . Release ( ) ;
GAOCulledObjectBuffers . Buffers . Initialize ( ) ;
}
{
2015-01-07 20:41:06 -05:00
uint32 ClearValues [ 4 ] = { 0 } ;
RHICmdList . ClearUAV ( GAOCulledObjectBuffers . Buffers . ObjectIndirectArguments . UAV , ClearValues ) ;
2014-11-21 22:32:16 -05:00
TShaderMapRef < FCullObjectsForViewCS > ComputeShader ( GetGlobalShaderMap ( Scene - > GetFeatureLevel ( ) ) ) ;
RHICmdList . SetComputeShader ( ComputeShader - > GetComputeShader ( ) ) ;
ComputeShader - > SetParameters ( RHICmdList , Scene , View , Parameters ) ;
DispatchComputeShader ( RHICmdList , * ComputeShader , FMath : : DivideAndRoundUp < uint32 > ( Scene - > DistanceFieldSceneData . NumObjectsInBuffer , UpdateObjectsGroupSize ) , 1 , 1 ) ;
ComputeShader - > UnsetParameters ( RHICmdList ) ;
}
}
TRefCountPtr < IPooledRenderTarget > VisualizeResultRT ;
{
const FIntPoint BufferSize = GetBufferSizeForAO ( ) ;
FPooledRenderTargetDesc Desc ( FPooledRenderTargetDesc : : Create2DDesc ( BufferSize , PF_FloatRGBA , TexCreate_None , TexCreate_RenderTargetable | TexCreate_UAV , false ) ) ;
GRenderTargetPool . FindFreeElement ( Desc , VisualizeResultRT , TEXT ( " VisualizeDistanceField " ) ) ;
}
{
SetRenderTarget ( RHICmdList , NULL , NULL ) ;
for ( int32 ViewIndex = 0 ; ViewIndex < Views . Num ( ) ; ViewIndex + + )
{
2015-03-06 15:13:38 -05:00
const FViewInfo & ViewInfo = Views [ ViewIndex ] ;
2014-11-21 22:32:16 -05:00
2015-03-06 15:13:38 -05:00
uint32 GroupSizeX = FMath : : DivideAndRoundUp ( ViewInfo . ViewRect . Size ( ) . X / GAODownsampleFactor , GDistanceFieldAOTileSizeX ) ;
uint32 GroupSizeY = FMath : : DivideAndRoundUp ( ViewInfo . ViewRect . Size ( ) . Y / GAODownsampleFactor , GDistanceFieldAOTileSizeY ) ;
2014-11-21 22:32:16 -05:00
{
SCOPED_DRAW_EVENT ( RHICmdList , VisualizeMeshDistanceFieldCS ) ;
2015-03-06 15:13:38 -05:00
TShaderMapRef < FVisualizeMeshDistanceFieldCS > ComputeShader ( ViewInfo . ShaderMap ) ;
2014-11-21 22:32:16 -05:00
RHICmdList . SetComputeShader ( ComputeShader - > GetComputeShader ( ) ) ;
2015-03-06 15:13:38 -05:00
ComputeShader - > SetParameters ( RHICmdList , ViewInfo , VisualizeResultRT - > GetRenderTargetItem ( ) , FVector2D ( GroupSizeX , GroupSizeY ) , Parameters ) ;
2014-11-21 22:32:16 -05:00
DispatchComputeShader ( RHICmdList , * ComputeShader , GroupSizeX , GroupSizeY , 1 ) ;
ComputeShader - > UnsetParameters ( RHICmdList ) ;
}
}
}
{
GSceneRenderTargets . BeginRenderingSceneColor ( RHICmdList ) ;
for ( int32 ViewIndex = 0 ; ViewIndex < Views . Num ( ) ; ViewIndex + + )
{
2015-03-06 15:13:38 -05:00
const FViewInfo & ViewInfo = Views [ ViewIndex ] ;
2014-11-21 22:32:16 -05:00
SCOPED_DRAW_EVENT ( RHICmdList , UpsampleAO ) ;
2015-03-06 15:13:38 -05:00
RHICmdList . SetViewport ( ViewInfo . ViewRect . Min . X , ViewInfo . ViewRect . Min . Y , 0.0f , ViewInfo . ViewRect . Max . X , ViewInfo . ViewRect . Max . Y , 1.0f ) ;
2014-11-21 22:32:16 -05:00
RHICmdList . SetRasterizerState ( TStaticRasterizerState < FM_Solid , CM_None > : : GetRHI ( ) ) ;
RHICmdList . SetDepthStencilState ( TStaticDepthStencilState < false , CF_Always > : : GetRHI ( ) ) ;
RHICmdList . SetBlendState ( TStaticBlendState < > : : GetRHI ( ) ) ;
2015-03-06 15:13:38 -05:00
TShaderMapRef < FPostProcessVS > VertexShader ( ViewInfo . ShaderMap ) ;
TShaderMapRef < FVisualizeDistanceFieldUpsamplePS > PixelShader ( ViewInfo . ShaderMap ) ;
2014-11-21 22:32:16 -05:00
static FGlobalBoundShaderState BoundShaderState ;
2015-03-06 15:13:38 -05:00
SetGlobalBoundShaderState ( RHICmdList , ViewInfo . GetFeatureLevel ( ) , BoundShaderState , GFilterVertexDeclaration . VertexDeclarationRHI , * VertexShader , * PixelShader ) ;
2014-11-21 22:32:16 -05:00
2015-03-06 15:13:38 -05:00
PixelShader - > SetParameters ( RHICmdList , ViewInfo , VisualizeResultRT ) ;
2014-11-21 22:32:16 -05:00
DrawRectangle (
RHICmdList ,
0 , 0 ,
2015-03-06 15:13:38 -05:00
ViewInfo . ViewRect . Width ( ) , ViewInfo . ViewRect . Height ( ) ,
ViewInfo . ViewRect . Min . X / GAODownsampleFactor , ViewInfo . ViewRect . Min . Y / GAODownsampleFactor ,
ViewInfo . ViewRect . Width ( ) / GAODownsampleFactor , ViewInfo . ViewRect . Height ( ) / GAODownsampleFactor ,
FIntPoint ( ViewInfo . ViewRect . Width ( ) , ViewInfo . ViewRect . Height ( ) ) ,
2014-11-21 22:32:16 -05:00
GetBufferSizeForAO ( ) ,
* VertexShader ) ;
}
}
}
}
}