You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#lockdown Nick.Penwarden #rb none ========================== MAJOR FEATURES + CHANGES ========================== Change 3055495 on 2016/07/19 by Marc.Olano Allow Noise material node on mobile No reason to exclude mobile, except for Fast Gradient Noise, which uses 3D textures. Allow this node on ES2 for all of the other noise functions. #jira UE-33345 Change 3055602 on 2016/07/19 by Luke.Thatcher Fix crash bug in D3D11 RHI when selecting adapters. - Array of adapter descriptors will get out of sync with the adapter index if any adapter is skipped (e.g. the Microsoft Basic Render Device). #jira UE-33236 Change 3055890 on 2016/07/19 by Daniel.Wright Improved the assert in LoadModuleChecked so we won't have to check the log to see which module it was Change 3055891 on 2016/07/19 by Daniel.Wright Fixed Global Distance Field not dirtying previous object position on UpdateTransform - left behind a phantom shadow on teleports * This will effectively double partial distiance field update costs until clipping of the update regions is implemented Change 3055892 on 2016/07/19 by Daniel.Wright Higher poly light source shapes drawn into reflection captures Change 3055893 on 2016/07/19 by Daniel.Wright More info to 'Incompatible surface format' GNM assert Change 3055904 on 2016/07/19 by Daniel.Wright Reflection environment normalization improvements * Indirect specular from reflection captures is now mixed with indirect diffuse from lightmaps based on roughness, such that a mirror surface will have no mixing. Reflection captures now match other reflection methods like SSR and planar reflections much more closely. * When a stationary skylight is present, Reflection captures are now normalized as if the initial skylight will always be present, giving consistent results with static skylight reflections. The skylight and reflection captures with sky removed used to be normalized separately, compacting the relative brightness between the sky and scene. * Added r.ReflectionEnvironmentLightmapMixing for debugging lightmap mixing issues. This toggle was previously not possible due to prenormalizing the capture data. * The standard deferred reflection path (r.DoTiledReflections 0) can no longer match the results of the compute path or base pass reflections, as it would require MRT to accumulate the average brightness * Removed unused r.DiffuseFromCaptures * Cost of reflection environment on PS4 increased from 1.52ms -> 1.75ms with this change, but decreased back to 1.58ms by reducing tile size to 8x8 Change 3055905 on 2016/07/19 by Daniel.Wright Workaround for RTDF shadows not working on PS4 - manual clear of ObjectIndirectArguments instead of RHICmdList.ClearUAV Change 3059486 on 2016/07/21 by Nick.Penwarden Testing #uecritical Change 3060558 on 2016/07/21 by Daniel.Wright Fixed skylight with specified cubemap being black Change 3061999 on 2016/07/22 by Marcus.Wassmer Disable old AMD driver hacks for DX11. QA has already tested with them off and given thumbs up. Change 3062241 on 2016/07/22 by Daniel.Wright Fixed bug in RHISupportsSeparateMSAAAndResolveTextures that was preventing MSAA for any non-Vulkan platforms Change 3062244 on 2016/07/22 by Daniel.Wright Discard old prenormalized reflection environment data on load Change 3062283 on 2016/07/22 by Daniel.Wright MSAA support for the forward renderer * AntiAliasing method is chosen in Rendering project settings, DefaultSettings category * Deferred passes like shadow projection, fogging and decals are only computed per-pixel and can introduce aliasing * Added Rendering project setting VertexFoggingForOpaque, which makes height fog cheaper and work properly with MSAA * The AntiAliasing method in PostProcessSettings has been removed, this may affect existing content * Added r.MSAACount which defaults to 4 * Integrated wide custom resolve filter from Oculus renderer, controlled by r.WideCustomResolve * GBuffer targets are no longer allocated when using the forward renderer * Decal blend modes that write to the GBuffer fall back to SceneColor emissive only Change 3062666 on 2016/07/23 by Uriel.Doyon Added legend to streaming accuracy viewmodes Added a new helper class FRenderTargetTemp to be reused in different canvas rendering. Exposed the pass through pixel shader so that it can be reused. #review-3058986 @marcus.wassmer Change 3063023 on 2016/07/25 by Luke.Thatcher Fix "RecompileShaders Changed" when using Cook On The Fly. #jira UE-33573 Change 3063078 on 2016/07/25 by Ben.Woodhouse Add -emitdrawevents command line option to emit draw events by default. This is useful when capturing with Renderdoc Change 3063315 on 2016/07/25 by Ben.Woodhouse Fix div 0 in motion blur. This caused artifacts in some fairly common cases #jira UE-32331 Change 3063897 on 2016/07/25 by Uriel.Doyon Fixed missing qualifier on interpolants Change 3064559 on 2016/07/26 by Ben.Woodhouse Fix for cooker crash with BC6H textures (XB1, but may affect other platforms). Also fixes corruption issue with texture slices not being a multiple of 4 pixels (expanding as necessary), courtesy of Stu McKenna at the Coalition Tested fix on xbox, PC and PS4, using QAGame #jira UE-28592 Change 3064896 on 2016/07/26 by Ben.Woodhouse Fix compile errors on PS4 (the variable "sample" was conflicting with a keyword, causing compile errors). Also making encoding consistent on new shaders (ansi rather than UTF16) Change 3064913 on 2016/07/26 by Ben.Marsh Fix spelling of "Editor, Tools, Monolithics & DDC" node in Dev-Rendering build settings. Change 3065326 on 2016/07/26 by Uriel.Doyon Fixed UnbuiltInstanceBoundsList not being reset correctly, creating broken rendered primitives. #jira UE-32585 Change 3065541 on 2016/07/26 by Daniel.Wright Materials with a GBuffer SceneTexture lookup will fail to compile with forward shading Change 3065543 on 2016/07/26 by Daniel.Wright Restored DetailMode changes causing a FGlobalComponentRecreateRenderStateContext - accidental removal from cl 2969413 Change 3065545 on 2016/07/26 by Daniel.Wright Added material property bNormalCurvatureToRoughness, which can slightly reduce aliasing. Tweakable impact with r.NormalCurvatureToRoughnessScale. Fixed reflection capture feedback with base pass reflections Change 3066783 on 2016/07/27 by Daniel.Wright Moved PreShadowCacheDepthZ out of FSceneRenderTargets and into FScene, which fixes issues with cached preshadows and multiple scenes, including HighResScreenShot Disabled GMinScreenRadiusForShadowCaster on per-object shadows, which fixes popping when trying to increase shadow resolution from the defaults (r.Shadow.TexelsPerPixel 3) Change 3066794 on 2016/07/27 by Daniel.Wright Fixed crash rendering planar reflections due to NULL PostProcessSettings Change 3067412 on 2016/07/27 by Daniel.Wright Fix for OpenGL4 with uint interpolator Change 3068470 on 2016/07/28 by Daniel.Wright Fixed crash rendering translucency with translucent shadows which were determined to be invisible Change 3069046 on 2016/07/28 by Daniel.Wright Handle null Family in SetupAntiAliasingMethod Change 3069059 on 2016/07/28 by Daniel.Wright Added r.ReflectionEnvironmentBeginMixingRoughness (.1) and r.ReflectionEnvironmentEndMixingRoughness (.3), which can be used to tweak the lightmap mixing heuristc, or revert to previous behavior (mixing even on a mirror surface) Change 3069391 on 2016/07/28 by Daniel.Wright Fixed AverageBrightness being applied to reflections in gamma space in the mobile base pass, causing ES2 reflections to be overbright Change 3070369 on 2016/07/29 by Daniel.Wright r.ReflectionEnvironmentBeginMixingRoughness and r.ReflectionEnvironmentEndMixingRoughness set to 0 can be used to achieve old non-roughness based lightmap mixing Change 3070370 on 2016/07/29 by Daniel.Wright Bumped reflection capture DDC version to get rid of legacy prenormalized data Change 3070680 on 2016/07/29 by Marcus.Wassmer Fix slate ensure that is most likely a timing issue exposed by rendering. #ue-33902 Change 3070811 on 2016/07/29 by Marcus.Wassmer Fix ProjectLauncher errors when loading old versions #ue-33939 Change 3070971 on 2016/07/29 by Uriel.Doyon Updated ListTextures outputs to fix cooked VS non cooked differences and also to put enphasis on disk VS memory Change 3071452 on 2016/07/31 by Uriel.Doyon Updated the legend description for the (texture streaming) primitive distance accuracy view mode [CL 3072803 by Marcus Wassmer in Main branch]
538 lines
19 KiB
C++
538 lines
19 KiB
C++
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
|
|
|
|
/*=============================================================================
|
|
ScreenSpaceReflections.cpp: Post processing Screen Space Reflections implementation.
|
|
=============================================================================*/
|
|
|
|
#include "RendererPrivate.h"
|
|
#include "ScenePrivate.h"
|
|
#include "SceneFilterRendering.h"
|
|
#include "PostProcessing.h"
|
|
#include "ScreenSpaceReflections.h"
|
|
#include "PostProcessTemporalAA.h"
|
|
#include "PostProcessAmbientOcclusion.h"
|
|
#include "PostProcessHierarchical.h"
|
|
#include "SceneUtils.h"
|
|
|
|
static TAutoConsoleVariable<int32> CVarSSRQuality(
|
|
TEXT("r.SSR.Quality"),
|
|
3,
|
|
TEXT("Whether to use screen space reflections and at what quality setting.\n")
|
|
TEXT("(limits the setting in the post process settings which has a different scale)\n")
|
|
TEXT("(costs performance, adds more visual realism but the technique has limits)\n")
|
|
TEXT(" 0: off (default)\n")
|
|
TEXT(" 1: low (no glossy)\n")
|
|
TEXT(" 2: medium (no glossy)\n")
|
|
TEXT(" 3: high (glossy/using roughness, few samples)\n")
|
|
TEXT(" 4: very high (likely too slow for real-time)"),
|
|
ECVF_Scalability | ECVF_RenderThreadSafe);
|
|
|
|
static TAutoConsoleVariable<int32> CVarSSRTemporal(
|
|
TEXT("r.SSR.Temporal"),
|
|
0,
|
|
TEXT("Defines if we use the temporal smoothing for the screen space reflection\n")
|
|
TEXT(" 0 is off (for debugging), 1 is on (default)"),
|
|
ECVF_RenderThreadSafe);
|
|
|
|
static TAutoConsoleVariable<int32> CVarSSRStencil(
|
|
TEXT("r.SSR.Stencil"),
|
|
0,
|
|
TEXT("Defines if we use the stencil prepass for the screen space reflection\n")
|
|
TEXT(" 0 is off (default), 1 is on"),
|
|
ECVF_RenderThreadSafe);
|
|
|
|
static TAutoConsoleVariable<int32> CVarSSRCone(
|
|
TEXT("r.SSR.Cone"),
|
|
0,
|
|
TEXT("Defines if we use cone traced screen space reflection\n")
|
|
TEXT(" 0 is off (default), 1 is on"),
|
|
ECVF_RenderThreadSafe);
|
|
|
|
DECLARE_FLOAT_COUNTER_STAT(TEXT("ScreenSpace Reflections"), Stat_GPU_ScreenSpaceReflections, STATGROUP_GPU);
|
|
|
|
bool ShouldRenderScreenSpaceReflections(const FViewInfo& View)
|
|
{
|
|
if(!View.Family->EngineShowFlags.ScreenSpaceReflections)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if(!View.State)
|
|
{
|
|
// not view state (e.g. thumbnail rendering?), no HZB (no screen space reflections or occlusion culling)
|
|
return false;
|
|
}
|
|
|
|
int SSRQuality = CVarSSRQuality.GetValueOnRenderThread();
|
|
|
|
if(SSRQuality <= 0)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if(View.FinalPostProcessSettings.ScreenSpaceReflectionIntensity < 1.0f)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
static float ComputeRoughnessMaskScale(const FRenderingCompositePassContext& Context, uint32 SSRQuality)
|
|
{
|
|
float MaxRoughness = FMath::Clamp(Context.View.FinalPostProcessSettings.ScreenSpaceReflectionMaxRoughness, 0.01f, 1.0f);
|
|
|
|
// f(x) = x * Scale + Bias
|
|
// f(MaxRoughness) = 0
|
|
// f(MaxRoughness/2) = 1
|
|
|
|
float RoughnessMaskScale = -2.0f / MaxRoughness;
|
|
return RoughnessMaskScale * (SSRQuality < 3 ? 2.0f : 1.0f);
|
|
}
|
|
|
|
FLinearColor ComputeSSRParams(const FRenderingCompositePassContext& Context, uint32 SSRQuality, bool bEnableDiscard)
|
|
{
|
|
float RoughnessMaskScale = ComputeRoughnessMaskScale(Context, SSRQuality);
|
|
|
|
float FrameRandom = 0;
|
|
|
|
if(Context.ViewState)
|
|
{
|
|
bool bTemporalAAIsOn = Context.View.AntiAliasingMethod == AAM_TemporalAA;
|
|
|
|
if(bTemporalAAIsOn)
|
|
{
|
|
// usually this number is in the 0..7 range but it depends on the TemporalAA quality
|
|
FrameRandom = Context.ViewState->GetCurrentTemporalAASampleIndex() * 1551;
|
|
}
|
|
else
|
|
{
|
|
// 8 aligns with the temporal smoothing, larger number will do more flickering (power of two for best performance)
|
|
FrameRandom = Context.ViewState->GetFrameIndexMod8() * 1551;
|
|
}
|
|
}
|
|
|
|
return FLinearColor(
|
|
FMath::Clamp(Context.View.FinalPostProcessSettings.ScreenSpaceReflectionIntensity * 0.01f, 0.0f, 1.0f),
|
|
RoughnessMaskScale,
|
|
(float)bEnableDiscard, // TODO
|
|
FrameRandom);
|
|
}
|
|
|
|
/**
|
|
* Encapsulates the post processing screen space reflections pixel shader stencil pass.
|
|
*/
|
|
class FPostProcessScreenSpaceReflectionsStencilPS : public FGlobalShader
|
|
{
|
|
DECLARE_SHADER_TYPE(FPostProcessScreenSpaceReflectionsStencilPS, Global);
|
|
|
|
static bool ShouldCache(EShaderPlatform Platform)
|
|
{
|
|
return IsFeatureLevelSupported(Platform, ERHIFeatureLevel::SM4);
|
|
}
|
|
|
|
static void ModifyCompilationEnvironment(EShaderPlatform Platform, FShaderCompilerEnvironment& OutEnvironment)
|
|
{
|
|
FGlobalShader::ModifyCompilationEnvironment(Platform, OutEnvironment);
|
|
OutEnvironment.SetDefine( TEXT("PREV_FRAME_COLOR"), uint32(0) );
|
|
OutEnvironment.SetDefine( TEXT("SSR_QUALITY"), uint32(0) );
|
|
}
|
|
|
|
/** Default constructor. */
|
|
FPostProcessScreenSpaceReflectionsStencilPS() {}
|
|
|
|
public:
|
|
FPostProcessPassParameters PostprocessParameter;
|
|
FDeferredPixelShaderParameters DeferredParameters;
|
|
FShaderParameter SSRParams;
|
|
|
|
/** Initialization constructor. */
|
|
FPostProcessScreenSpaceReflectionsStencilPS(const ShaderMetaType::CompiledShaderInitializerType& Initializer)
|
|
: FGlobalShader(Initializer)
|
|
{
|
|
PostprocessParameter.Bind(Initializer.ParameterMap);
|
|
DeferredParameters.Bind(Initializer.ParameterMap);
|
|
SSRParams.Bind(Initializer.ParameterMap, TEXT("SSRParams"));
|
|
}
|
|
|
|
void SetParameters(const FRenderingCompositePassContext& Context, uint32 SSRQuality, bool EnableDiscard)
|
|
{
|
|
const FFinalPostProcessSettings& Settings = Context.View.FinalPostProcessSettings;
|
|
const FPixelShaderRHIParamRef ShaderRHI = GetPixelShader();
|
|
|
|
FGlobalShader::SetParameters(Context.RHICmdList, ShaderRHI, Context.View);
|
|
|
|
PostprocessParameter.SetPS(ShaderRHI, Context, TStaticSamplerState<SF_Point, AM_Clamp, AM_Clamp, AM_Clamp>::GetRHI());
|
|
DeferredParameters.Set(Context.RHICmdList, ShaderRHI, Context.View);
|
|
|
|
{
|
|
FLinearColor Value = ComputeSSRParams(Context, SSRQuality, EnableDiscard);
|
|
|
|
SetShaderValue(Context.RHICmdList, ShaderRHI, SSRParams, Value);
|
|
}
|
|
}
|
|
|
|
// FShader interface.
|
|
virtual bool Serialize(FArchive& Ar) override
|
|
{
|
|
bool bShaderHasOutdatedParameters = FGlobalShader::Serialize(Ar);
|
|
Ar << PostprocessParameter << DeferredParameters << SSRParams;
|
|
return bShaderHasOutdatedParameters;
|
|
}
|
|
};
|
|
|
|
IMPLEMENT_SHADER_TYPE(,FPostProcessScreenSpaceReflectionsStencilPS,TEXT("ScreenSpaceReflections"),TEXT("ScreenSpaceReflectionsStencilPS"),SF_Pixel);
|
|
static const uint32 SSRConeQuality = 5;
|
|
|
|
/**
|
|
* Encapsulates the post processing screen space reflections pixel shader.
|
|
* @param SSRQuality 0:Visualize Mask
|
|
*/
|
|
template<uint32 PrevFrame, uint32 SSRQuality >
|
|
class FPostProcessScreenSpaceReflectionsPS : public FGlobalShader
|
|
{
|
|
DECLARE_SHADER_TYPE(FPostProcessScreenSpaceReflectionsPS, Global);
|
|
|
|
static bool ShouldCache(EShaderPlatform Platform)
|
|
{
|
|
return IsFeatureLevelSupported(Platform, ERHIFeatureLevel::SM4);
|
|
}
|
|
|
|
static void ModifyCompilationEnvironment(EShaderPlatform Platform, FShaderCompilerEnvironment& OutEnvironment)
|
|
{
|
|
FGlobalShader::ModifyCompilationEnvironment(Platform, OutEnvironment);
|
|
OutEnvironment.SetDefine( TEXT("PREV_FRAME_COLOR"), PrevFrame );
|
|
OutEnvironment.SetDefine( TEXT("SSR_QUALITY"), SSRQuality );
|
|
OutEnvironment.SetDefine( TEXT("SSR_CONE_QUALITY"), SSRConeQuality );
|
|
}
|
|
|
|
/** Default constructor. */
|
|
FPostProcessScreenSpaceReflectionsPS() {}
|
|
|
|
public:
|
|
FPostProcessPassParameters PostprocessParameter;
|
|
FDeferredPixelShaderParameters DeferredParameters;
|
|
FShaderParameter SSRParams;
|
|
FShaderParameter HZBUvFactorAndInvFactor;
|
|
|
|
/** Initialization constructor. */
|
|
FPostProcessScreenSpaceReflectionsPS(const ShaderMetaType::CompiledShaderInitializerType& Initializer)
|
|
: FGlobalShader(Initializer)
|
|
{
|
|
PostprocessParameter.Bind(Initializer.ParameterMap);
|
|
DeferredParameters.Bind(Initializer.ParameterMap);
|
|
SSRParams.Bind(Initializer.ParameterMap, TEXT("SSRParams"));
|
|
HZBUvFactorAndInvFactor.Bind(Initializer.ParameterMap, TEXT("HZBUvFactorAndInvFactor"));
|
|
}
|
|
|
|
void SetParameters(const FRenderingCompositePassContext& Context)
|
|
{
|
|
const FFinalPostProcessSettings& Settings = Context.View.FinalPostProcessSettings;
|
|
const FPixelShaderRHIParamRef ShaderRHI = GetPixelShader();
|
|
|
|
FGlobalShader::SetParameters(Context.RHICmdList, ShaderRHI, Context.View);
|
|
|
|
PostprocessParameter.SetPS(ShaderRHI, Context, TStaticSamplerState<SF_Point, AM_Clamp, AM_Clamp, AM_Clamp>::GetRHI());
|
|
DeferredParameters.Set(Context.RHICmdList, ShaderRHI, Context.View);
|
|
|
|
{
|
|
FLinearColor Value = ComputeSSRParams(Context, SSRQuality, false);
|
|
|
|
SetShaderValue(Context.RHICmdList, ShaderRHI, SSRParams, Value);
|
|
}
|
|
|
|
{
|
|
const FVector2D HZBUvFactor(
|
|
float(Context.View.ViewRect.Width()) / float(2 * Context.View.HZBMipmap0Size.X),
|
|
float(Context.View.ViewRect.Height()) / float(2 * Context.View.HZBMipmap0Size.Y)
|
|
);
|
|
const FVector4 HZBUvFactorAndInvFactorValue(
|
|
HZBUvFactor.X,
|
|
HZBUvFactor.Y,
|
|
1.0f / HZBUvFactor.X,
|
|
1.0f / HZBUvFactor.Y
|
|
);
|
|
|
|
SetShaderValue(Context.RHICmdList, ShaderRHI, HZBUvFactorAndInvFactor, HZBUvFactorAndInvFactorValue);
|
|
}
|
|
}
|
|
|
|
// FShader interface.
|
|
virtual bool Serialize(FArchive& Ar) override
|
|
{
|
|
bool bShaderHasOutdatedParameters = FGlobalShader::Serialize(Ar);
|
|
Ar << PostprocessParameter << DeferredParameters << SSRParams << HZBUvFactorAndInvFactor;
|
|
return bShaderHasOutdatedParameters;
|
|
}
|
|
};
|
|
|
|
// Typedef is necessary because the C preprocessor thinks the comma in the template parameter list is a comma in the macro parameter list.
|
|
#define IMPLEMENT_REFLECTION_PIXELSHADER_TYPE(A, B) \
|
|
typedef FPostProcessScreenSpaceReflectionsPS<A,B> FPostProcessScreenSpaceReflectionsPS##A##B; \
|
|
IMPLEMENT_SHADER_TYPE(template<>,FPostProcessScreenSpaceReflectionsPS##A##B,TEXT("ScreenSpaceReflections"),TEXT("ScreenSpaceReflectionsPS"),SF_Pixel)
|
|
|
|
IMPLEMENT_REFLECTION_PIXELSHADER_TYPE(0,0);
|
|
IMPLEMENT_REFLECTION_PIXELSHADER_TYPE(0,1);
|
|
IMPLEMENT_REFLECTION_PIXELSHADER_TYPE(1,1);
|
|
IMPLEMENT_REFLECTION_PIXELSHADER_TYPE(0,2);
|
|
IMPLEMENT_REFLECTION_PIXELSHADER_TYPE(1,2);
|
|
IMPLEMENT_REFLECTION_PIXELSHADER_TYPE(0,3);
|
|
IMPLEMENT_REFLECTION_PIXELSHADER_TYPE(1,3);
|
|
IMPLEMENT_REFLECTION_PIXELSHADER_TYPE(0,4);
|
|
IMPLEMENT_REFLECTION_PIXELSHADER_TYPE(1,4);
|
|
IMPLEMENT_REFLECTION_PIXELSHADER_TYPE(0,5); // SSRConeQuality
|
|
IMPLEMENT_REFLECTION_PIXELSHADER_TYPE(1,5); // SSRConeQuality
|
|
|
|
// --------------------------------------------------------
|
|
|
|
|
|
// @param Quality usually in 0..100 range, default is 50
|
|
// @return see CVarSSRQuality, never 0
|
|
static int32 ComputeSSRQuality(float Quality)
|
|
{
|
|
int32 Ret;
|
|
|
|
if(Quality >= 60.0f)
|
|
{
|
|
Ret = (Quality >= 80.0f) ? 4 : 3;
|
|
}
|
|
else
|
|
{
|
|
Ret = (Quality >= 40.0f) ? 2 : 1;
|
|
}
|
|
|
|
int SSRQualityCVar = FMath::Max(0, CVarSSRQuality.GetValueOnRenderThread());
|
|
|
|
return FMath::Min(Ret, SSRQualityCVar);
|
|
}
|
|
|
|
void FRCPassPostProcessScreenSpaceReflections::Process(FRenderingCompositePassContext& Context)
|
|
{
|
|
auto& RHICmdList = Context.RHICmdList;
|
|
FSceneRenderTargets& SceneContext = FSceneRenderTargets::Get(RHICmdList);
|
|
|
|
const FSceneView& View = Context.View;
|
|
const auto FeatureLevel = Context.GetFeatureLevel();
|
|
|
|
int32 SSRQuality = ComputeSSRQuality(View.FinalPostProcessSettings.ScreenSpaceReflectionQuality);
|
|
uint32 iPreFrame = bPrevFrame ? 1 : 0;
|
|
|
|
SSRQuality = FMath::Clamp(SSRQuality, 1, 4);
|
|
|
|
const bool VisualizeSSR = View.Family->EngineShowFlags.VisualizeSSR;
|
|
const bool SSRStencilPrePass = CVarSSRStencil.GetValueOnRenderThread() != 0 && !VisualizeSSR;
|
|
|
|
FRenderingCompositeOutputRef* Input2 = GetInput(ePId_Input2);
|
|
|
|
const bool SSRConeTracing = Input2 && Input2->GetOutput();
|
|
|
|
if (VisualizeSSR)
|
|
{
|
|
iPreFrame = 0;
|
|
SSRQuality = 0;
|
|
}
|
|
else if (SSRConeTracing)
|
|
{
|
|
SSRQuality = SSRConeQuality;
|
|
}
|
|
|
|
const FSceneRenderTargetItem& DestRenderTarget = PassOutputs[0].RequestSurface(Context);
|
|
|
|
SCOPED_GPU_STAT(RHICmdList, Stat_GPU_ScreenSpaceReflections);
|
|
|
|
if (SSRStencilPrePass)
|
|
{ // ScreenSpaceReflectionsStencil draw event
|
|
SCOPED_DRAW_EVENTF(Context.RHICmdList, ScreenSpaceReflectionsStencil, TEXT("ScreenSpaceReflectionsStencil %dx%d"), View.ViewRect.Width(), View.ViewRect.Height());
|
|
|
|
TShaderMapRef< FPostProcessVS > VertexShader(Context.GetShaderMap());
|
|
TShaderMapRef< FPostProcessScreenSpaceReflectionsStencilPS > PixelShader(Context.GetShaderMap());
|
|
|
|
// bind the dest render target and the depth stencil render target
|
|
SetRenderTarget(RHICmdList, DestRenderTarget.TargetableTexture, SceneContext.GetSceneDepthSurface(), ESimpleRenderTargetMode::EUninitializedColorAndDepth, FExclusiveDepthStencil::DepthRead_StencilWrite);
|
|
Context.SetViewportAndCallRHI(View.ViewRect);
|
|
|
|
// Clear stencil to 0
|
|
RHICmdList.Clear(false, FLinearColor::White, false, (float)ERHIZBuffer::FarPlane, true, 0, View.ViewRect);
|
|
|
|
// bind shader
|
|
static FGlobalBoundShaderState BoundShaderState;
|
|
SetGlobalBoundShaderState(Context.RHICmdList, FeatureLevel, BoundShaderState, GFilterVertexDeclaration.VertexDeclarationRHI, *VertexShader, *PixelShader);
|
|
VertexShader->SetParameters(Context);
|
|
PixelShader->SetParameters(Context, SSRQuality, true);
|
|
|
|
// Clobers the stencil to pixel that should not compute SSR
|
|
RHICmdList.SetDepthStencilState(TStaticDepthStencilState<false, CF_Always, true, CF_Always, SO_Replace, SO_Replace, SO_Replace>::GetRHI(), 0x80);
|
|
|
|
// Set rasterizer state to solid
|
|
RHICmdList.SetRasterizerState(TStaticRasterizerState<>::GetRHI());
|
|
|
|
// disable blend mode
|
|
RHICmdList.SetBlendState(TStaticBlendState<>::GetRHI());
|
|
|
|
DrawPostProcessPass(
|
|
Context.RHICmdList,
|
|
0, 0,
|
|
View.ViewRect.Width(), View.ViewRect.Height(),
|
|
View.ViewRect.Min.X, View.ViewRect.Min.Y,
|
|
View.ViewRect.Width(), View.ViewRect.Height(),
|
|
View.ViewRect.Size(),
|
|
SceneContext.GetBufferSizeXY(),
|
|
*VertexShader,
|
|
View.StereoPass,
|
|
Context.HasHmdMesh(),
|
|
EDRF_UseTriangleOptimization);
|
|
|
|
} // ScreenSpaceReflectionsStencil draw event
|
|
|
|
{ // ScreenSpaceReflections draw event
|
|
SCOPED_DRAW_EVENTF(Context.RHICmdList, ScreenSpaceReflections, TEXT("ScreenSpaceReflections %dx%d"), View.ViewRect.Width(), View.ViewRect.Height());
|
|
|
|
if (SSRStencilPrePass)
|
|
{
|
|
// set up the stencil test to match 0, meaning FPostProcessScreenSpaceReflectionsStencilPS has been discarded
|
|
RHICmdList.SetDepthStencilState(TStaticDepthStencilState<false, CF_Always, true, CF_Equal, SO_Keep, SO_Keep, SO_Keep>::GetRHI(), 0);
|
|
}
|
|
else
|
|
{
|
|
// bind only the dest render target
|
|
SetRenderTarget(RHICmdList, DestRenderTarget.TargetableTexture, FTextureRHIRef());
|
|
Context.SetViewportAndCallRHI(View.ViewRect);
|
|
|
|
RHICmdList.SetDepthStencilState(TStaticDepthStencilState<false, CF_Always>::GetRHI());
|
|
}
|
|
|
|
// clear DestRenderTarget only outside of the view's rectangle
|
|
RHICmdList.Clear(true, FLinearColor::Black, false, (float)ERHIZBuffer::FarPlane, false, 0, View.ViewRect);
|
|
|
|
// set the state
|
|
RHICmdList.SetBlendState(TStaticBlendState<>::GetRHI());
|
|
RHICmdList.SetRasterizerState(TStaticRasterizerState<>::GetRHI());
|
|
|
|
TShaderMapRef< FPostProcessVS > VertexShader(Context.GetShaderMap());
|
|
|
|
#define CASE(A, B) \
|
|
case (A + 2 * (B + 3 * 0 )): \
|
|
{ \
|
|
TShaderMapRef< FPostProcessScreenSpaceReflectionsPS<A, B> > PixelShader(Context.GetShaderMap()); \
|
|
static FGlobalBoundShaderState BoundShaderState; \
|
|
SetGlobalBoundShaderState(RHICmdList, FeatureLevel, BoundShaderState, GFilterVertexDeclaration.VertexDeclarationRHI, *VertexShader, *PixelShader); \
|
|
VertexShader->SetParameters(Context); \
|
|
PixelShader->SetParameters(Context); \
|
|
}; \
|
|
break
|
|
|
|
switch (iPreFrame + 2 * (SSRQuality + 3 * 0))
|
|
{
|
|
CASE(0,0);
|
|
CASE(0,1); CASE(1,1);
|
|
CASE(0,2); CASE(1,2);
|
|
CASE(0,3); CASE(1,3);
|
|
CASE(0,4); CASE(1,4);
|
|
CASE(0,5); CASE(1,5); //SSRConeQuality
|
|
default:
|
|
check(!"Missing case in FRCPassPostProcessScreenSpaceReflections");
|
|
}
|
|
#undef CASE
|
|
|
|
DrawPostProcessPass(
|
|
RHICmdList,
|
|
0, 0,
|
|
View.ViewRect.Width(), View.ViewRect.Height(),
|
|
View.ViewRect.Min.X, View.ViewRect.Min.Y,
|
|
View.ViewRect.Width(), View.ViewRect.Height(),
|
|
View.ViewRect.Size(),
|
|
FSceneRenderTargets::Get(Context.RHICmdList).GetBufferSizeXY(),
|
|
*VertexShader,
|
|
View.StereoPass,
|
|
Context.HasHmdMesh(),
|
|
EDRF_UseTriangleOptimization);
|
|
|
|
RHICmdList.CopyToResolveTarget(DestRenderTarget.TargetableTexture, DestRenderTarget.ShaderResourceTexture, false, FResolveParams());
|
|
} // ScreenSpaceReflections
|
|
}
|
|
|
|
FPooledRenderTargetDesc FRCPassPostProcessScreenSpaceReflections::ComputeOutputDesc(EPassOutputId InPassOutputId) const
|
|
{
|
|
FPooledRenderTargetDesc Ret(FPooledRenderTargetDesc::Create2DDesc(FSceneRenderTargets::Get_FrameConstantsOnly().GetBufferSizeXY(), PF_FloatRGBA, FClearValueBinding::None, TexCreate_None, TexCreate_RenderTargetable, false));
|
|
|
|
Ret.DebugName = TEXT("ScreenSpaceReflections");
|
|
Ret.AutoWritable = false;
|
|
return Ret;
|
|
}
|
|
|
|
void RenderScreenSpaceReflections(FRHICommandListImmediate& RHICmdList, FViewInfo& View, TRefCountPtr<IPooledRenderTarget>& SSROutput)
|
|
{
|
|
FRenderingCompositePassContext CompositeContext(RHICmdList, View);
|
|
FPostprocessContext Context(RHICmdList, CompositeContext.Graph, View );
|
|
|
|
FSceneViewState* ViewState = (FSceneViewState*)Context.View.State;
|
|
|
|
FRenderingCompositePass* SceneColorInput = Context.Graph.RegisterPass( new FRCPassPostProcessInput( FSceneRenderTargets::Get(RHICmdList).GetSceneColor() ) );
|
|
FRenderingCompositePass* HZBInput = Context.Graph.RegisterPass( new FRCPassPostProcessInput( View.HZB ) );
|
|
FRenderingCompositePass* HCBInput = nullptr;
|
|
|
|
bool bPrevFrame = 0;
|
|
if( ViewState && ViewState->TemporalAAHistoryRT && !Context.View.bCameraCut )
|
|
{
|
|
SceneColorInput = Context.Graph.RegisterPass( new FRCPassPostProcessInput( ViewState->TemporalAAHistoryRT ) );
|
|
bPrevFrame = 1;
|
|
}
|
|
|
|
if (CVarSSRCone.GetValueOnRenderThread())
|
|
{
|
|
HCBInput = Context.Graph.RegisterPass( new FRCPassPostProcessBuildHCB() );
|
|
HCBInput->SetInput( ePId_Input0, SceneColorInput );
|
|
}
|
|
|
|
{
|
|
FRenderingCompositePass* TracePass = Context.Graph.RegisterPass( new FRCPassPostProcessScreenSpaceReflections( bPrevFrame ) );
|
|
TracePass->SetInput( ePId_Input0, SceneColorInput );
|
|
TracePass->SetInput( ePId_Input1, HZBInput );
|
|
TracePass->SetInput( ePId_Input2, HCBInput );
|
|
|
|
Context.FinalOutput = FRenderingCompositeOutputRef( TracePass );
|
|
}
|
|
|
|
const bool bTemporalFilter = View.AntiAliasingMethod != AAM_TemporalAA || CVarSSRTemporal.GetValueOnRenderThread() != 0;
|
|
|
|
if( ViewState && bTemporalFilter )
|
|
{
|
|
{
|
|
FRenderingCompositeOutputRef HistoryInput;
|
|
if( ViewState && ViewState->SSRHistoryRT && !Context.View.bCameraCut )
|
|
{
|
|
HistoryInput = Context.Graph.RegisterPass( new FRCPassPostProcessInput( ViewState->SSRHistoryRT ) );
|
|
}
|
|
else
|
|
{
|
|
// No history, use black
|
|
HistoryInput = Context.Graph.RegisterPass(new FRCPassPostProcessInput(GSystemTextures.BlackDummy));
|
|
}
|
|
|
|
FRenderingCompositePass* TemporalAAPass = Context.Graph.RegisterPass( new FRCPassPostProcessSSRTemporalAA );
|
|
TemporalAAPass->SetInput( ePId_Input0, Context.FinalOutput );
|
|
TemporalAAPass->SetInput( ePId_Input1, HistoryInput );
|
|
//TemporalAAPass->SetInput( ePId_Input2, VelocityInput );
|
|
|
|
Context.FinalOutput = FRenderingCompositeOutputRef( TemporalAAPass );
|
|
}
|
|
|
|
if( ViewState )
|
|
{
|
|
FRenderingCompositePass* HistoryOutput = Context.Graph.RegisterPass( new FRCPassPostProcessOutput( &ViewState->SSRHistoryRT ) );
|
|
HistoryOutput->SetInput( ePId_Input0, Context.FinalOutput );
|
|
|
|
Context.FinalOutput = FRenderingCompositeOutputRef( HistoryOutput );
|
|
}
|
|
}
|
|
|
|
{
|
|
FRenderingCompositePass* ReflectionOutput = Context.Graph.RegisterPass( new FRCPassPostProcessOutput( &SSROutput ) );
|
|
ReflectionOutput->SetInput( ePId_Input0, Context.FinalOutput );
|
|
|
|
Context.FinalOutput = FRenderingCompositeOutputRef( ReflectionOutput );
|
|
}
|
|
|
|
CompositeContext.Process(Context.FinalOutput.GetPass(), TEXT("ReflectionEnvironments"));
|
|
}
|