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 ========================== MAJOR FEATURES + CHANGES ========================== Change 2854295 on 2016/02/03 by Gareth.Martin@gareth.martin Added support for Landscape grass to use the landscape's light/shadow maps (original github pull request #1798 by Frugality) Change 2875167 on 2016/02/21 by Rolando.Caloca@Home_DM DM - glslang Change 2875650 on 2016/02/22 by Rolando.Caloca@rolando.caloca_T3903_DM DM - Common RHI changes Change 2876429 on 2016/02/22 by Rolando.Caloca@rolando.caloca_T3903_DM DM - Initial rhi check-in. Tappy & SunTemple working on PC. #codereview Jack.Porter, Chris.Babcock, Josh.Adams Change 2876665 on 2016/02/22 by Rolando.Caloca@rolando.caloca_T3903_DM DM - Split Immediate command list off RHI Change 2881242 on 2016/02/25 by Jack.Porter@Jack.Porter_UE4_Stream changes to exclude LPV shaders from Vulkan (reapplied with edit instead of integrate records) Change 2881356 on 2016/02/25 by Jack.Porter@Jack.Porter_UE4_Stream Static shadowing + dynamic-object CSM Change 2881359 on 2016/02/25 by Jack.Porter@Jack.Porter_UE4_Stream Mobile GPU particles Change 2881360 on 2016/02/25 by Jack.Porter@Jack.Porter_UE4_Stream Planar reflections very WIP Change 2881363 on 2016/02/25 by Jack.Porter@Jack.Porter_UE4_Stream Separate Translucency very WIP Change 2881365 on 2016/02/25 by Jack.Porter@Jack.Porter_UE4_Stream ProtoStar engine changes Change 2881371 on 2016/02/25 by Jack.Porter@Jack.Porter_UE4_Stream HACK for Max Texture Samplers hardcoded to 8 on ES2 Should be cleaned up better with UE-24419. Change 2884295 on 2016/02/26 by Rolando.Caloca@rolando.caloca_T3903_DM DM - Integrate pipeline cache Change 2887043 on 2016/02/29 by Rolando.Caloca@Home_DM DM - Initial CCT support Change 2887572 on 2016/03/01 by Rolando.Caloca@rolando.caloca_T3903_DM DM - Empty bound shader states cache - Only used currently on Vulkan Change 2889114 on 2016/03/01 by Rolando.Caloca@Home_DM DM - Added GRHINeedsExtraDeletionLatency from 4.11 Change 2889115 on 2016/03/01 by Rolando.Caloca@Home_DM DM - Remove batched elements quads (was not been used at least since UE3!) Change 2895373 on 2016/03/04 by Rolando.Caloca@rolando.caloca_T3903_DM DM - Fence mgr (disabled) Change 2898926 on 2016/03/08 by Rolando.Caloca@rolando.caloca_T3903_DM DM - Resource management (disabled) Change 2899937 on 2016/03/08 by Rolando.Caloca@rolando.caloca_T3903_DM DM - Expand number of stencil op bits Change 2901132 on 2016/03/09 by Rolando.Caloca@rolando.caloca_T3903_DM DM - Add support for more MaxSimultaneousRenderTargets Change 2903074 on 2016/03/10 by Rolando.Caloca@rolando.caloca_T3903_DM DM - Support for 3d staging textures Change 2903211 on 2016/03/10 by Jack.Porter@Jack.Porter_UE4_Stream Vulkan RHI stub for new SharedResourceView RHI call Change 2904014 on 2016/03/10 by Rolando.Caloca@rolando.caloca_T3903_DM DM - SM4 preq Change 2905389 on 2016/03/11 by Jack.Porter@Jack.Porter_UE4_Stream Android Vulkan support initial checkin Change 2908458 on 2016/03/14 by Allan.Bentham@Dev-Mobile Reinstate vertex fog, fixes UE-28166 Change 2910294 on 2016/03/15 by Rolando.Caloca@rolando.caloca_T3903_DM DM - Use fence manager Change 2910801 on 2016/03/15 by Rolando.Caloca@rolando.caloca_T3903_DM DM - Descriptor pool [CL 2912606 by Peter Sauerbrei in Main branch]
475 lines
16 KiB
C++
475 lines
16 KiB
C++
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
|
|
|
|
/*=============================================================================
|
|
PostProcessDOF.cpp: Post process Depth of Field implementation.
|
|
=============================================================================*/
|
|
|
|
#include "RendererPrivate.h"
|
|
#include "ScenePrivate.h"
|
|
#include "SceneFilterRendering.h"
|
|
#include "PostProcessBokehDOF.h"
|
|
#include "PostProcessDOF.h"
|
|
#include "PostProcessing.h"
|
|
#include "SceneUtils.h"
|
|
|
|
|
|
/** Encapsulates the DOF setup pixel shader. */
|
|
// @param FarBlur 0:off, 1:on
|
|
// @param NearBlur 0:off, 1:on, 2:on with Vignette
|
|
template <uint32 FarBlur, uint32 NearBlur>
|
|
class FPostProcessDOFSetupPS : public FGlobalShader
|
|
{
|
|
DECLARE_SHADER_TYPE(FPostProcessDOFSetupPS, Global);
|
|
|
|
static bool ShouldCache(EShaderPlatform Platform)
|
|
{
|
|
return IsFeatureLevelSupported(Platform, ERHIFeatureLevel::ES3_1);
|
|
}
|
|
|
|
static void ModifyCompilationEnvironment(EShaderPlatform Platform, FShaderCompilerEnvironment& OutEnvironment)
|
|
{
|
|
FGlobalShader::ModifyCompilationEnvironment(Platform,OutEnvironment);
|
|
OutEnvironment.SetDefine(TEXT("FORWARD_SHADING"), IsFeatureLevelSupported(Platform, ERHIFeatureLevel::SM4) ? 0u : 1u);
|
|
OutEnvironment.SetDefine(TEXT("NEAR_BLUR"), (uint32)(NearBlur >= 1));
|
|
OutEnvironment.SetDefine(TEXT("DOF_VIGNETTE"), (uint32)(NearBlur == 2));
|
|
OutEnvironment.SetDefine(TEXT("MRT_COUNT"), FarBlur + (NearBlur > 0));
|
|
}
|
|
|
|
/** Default constructor. */
|
|
FPostProcessDOFSetupPS() {}
|
|
|
|
public:
|
|
FPostProcessPassParameters PostprocessParameter;
|
|
FDeferredPixelShaderParameters DeferredParameters;
|
|
FShaderParameter DepthOfFieldParams;
|
|
|
|
/** Initialization constructor. */
|
|
FPostProcessDOFSetupPS(const ShaderMetaType::CompiledShaderInitializerType& Initializer)
|
|
: FGlobalShader(Initializer)
|
|
{
|
|
PostprocessParameter.Bind(Initializer.ParameterMap);
|
|
DeferredParameters.Bind(Initializer.ParameterMap);
|
|
DepthOfFieldParams.Bind(Initializer.ParameterMap,TEXT("DepthOfFieldParams"));
|
|
}
|
|
|
|
// FShader interface.
|
|
virtual bool Serialize(FArchive& Ar) override
|
|
{
|
|
bool bShaderHasOutdatedParameters = FGlobalShader::Serialize(Ar);
|
|
Ar << PostprocessParameter << DeferredParameters << DepthOfFieldParams;
|
|
return bShaderHasOutdatedParameters;
|
|
}
|
|
|
|
void SetParameters(const FRenderingCompositePassContext& Context)
|
|
{
|
|
const FPixelShaderRHIParamRef ShaderRHI = GetPixelShader();
|
|
|
|
FGlobalShader::SetParameters(Context.RHICmdList, ShaderRHI, Context.View);
|
|
|
|
if (Context.GetFeatureLevel() < ERHIFeatureLevel::SM4)
|
|
{
|
|
// Trying bilin here to attempt to alleviate some issues with 1/4 res input...
|
|
PostprocessParameter.SetPS(ShaderRHI, Context, TStaticSamplerState<SF_Bilinear, AM_Border, AM_Border, AM_Clamp>::GetRHI());
|
|
}
|
|
else
|
|
{
|
|
PostprocessParameter.SetPS(ShaderRHI, Context, TStaticSamplerState<SF_Point, AM_Border, AM_Border, AM_Clamp>::GetRHI());
|
|
}
|
|
|
|
DeferredParameters.Set(Context.RHICmdList, ShaderRHI, Context.View);
|
|
|
|
{
|
|
FVector4 DepthOfFieldParamValues[2];
|
|
|
|
FRCPassPostProcessBokehDOF::ComputeDepthOfFieldParams(Context, DepthOfFieldParamValues);
|
|
|
|
SetShaderValueArray(Context.RHICmdList, ShaderRHI, DepthOfFieldParams, DepthOfFieldParamValues, 2);
|
|
}
|
|
}
|
|
|
|
static const TCHAR* GetSourceFilename()
|
|
{
|
|
return TEXT("PostProcessDOF");
|
|
}
|
|
|
|
static const TCHAR* GetFunctionName()
|
|
{
|
|
return TEXT("SetupPS");
|
|
}
|
|
};
|
|
|
|
// #define avoids a lot of code duplication
|
|
#define VARIATION1(A, B) typedef FPostProcessDOFSetupPS<A, B> FPostProcessDOFSetupPS##A##B; \
|
|
IMPLEMENT_SHADER_TYPE2(FPostProcessDOFSetupPS##A##B, SF_Pixel);
|
|
|
|
VARIATION1(0, 1) VARIATION1(0, 2)
|
|
VARIATION1(1, 0) VARIATION1(1, 1) VARIATION1(1, 2)
|
|
|
|
#undef VARIATION1
|
|
|
|
// @param FarBlur 0:off, 1:on
|
|
// @param NearBlur 0:off, 1:on, 2:on with Vignette
|
|
template <uint32 FarBlur, uint32 NearBlur>
|
|
static FShader* SetDOFShaderTempl(const FRenderingCompositePassContext& Context)
|
|
{
|
|
TShaderMapRef<FPostProcessVS> VertexShader(Context.GetShaderMap());
|
|
TShaderMapRef<FPostProcessDOFSetupPS<FarBlur, NearBlur> > PixelShader(Context.GetShaderMap());
|
|
|
|
static FGlobalBoundShaderState BoundShaderState;
|
|
|
|
SetGlobalBoundShaderState(Context.RHICmdList, Context.GetFeatureLevel(), BoundShaderState, GFilterVertexDeclaration.VertexDeclarationRHI, *VertexShader, *PixelShader);
|
|
|
|
VertexShader->SetParameters(Context);
|
|
PixelShader->SetParameters(Context);
|
|
|
|
return *VertexShader;
|
|
}
|
|
|
|
|
|
void FRCPassPostProcessDOFSetup::Process(FRenderingCompositePassContext& Context)
|
|
{
|
|
SCOPED_DRAW_EVENT(Context.RHICmdList, DOFSetup);
|
|
|
|
const FPooledRenderTargetDesc* InputDesc = GetInputDesc(ePId_Input0);
|
|
|
|
if(!InputDesc)
|
|
{
|
|
// input is not hooked up correctly
|
|
return;
|
|
}
|
|
|
|
uint32 NumRenderTargets = (bNearBlur && bFarBlur) ? 2 : 1;
|
|
|
|
const FSceneView& View = Context.View;
|
|
const FSceneViewFamily& ViewFamily = *(View.Family);
|
|
|
|
const auto FeatureLevel = Context.GetFeatureLevel();
|
|
auto ShaderMap = Context.GetShaderMap();
|
|
|
|
FIntPoint SrcSize = InputDesc->Extent;
|
|
FIntPoint DestSize = PassOutputs[0].RenderTargetDesc.Extent;
|
|
|
|
// e.g. 4 means the input texture is 4x smaller than the buffer size
|
|
uint32 ScaleFactor = FSceneRenderTargets::Get(Context.RHICmdList).GetBufferSizeXY().X / SrcSize.X;
|
|
|
|
FIntRect SrcRect = View.ViewRect / ScaleFactor;
|
|
FIntRect DestRect = SrcRect / 2;
|
|
|
|
const FSceneRenderTargetItem& DestRenderTarget0 = PassOutputs[0].RequestSurface(Context);
|
|
const FSceneRenderTargetItem& DestRenderTarget1 = (NumRenderTargets == 2) ? PassOutputs[1].RequestSurface(Context) : FSceneRenderTargetItem();
|
|
|
|
// Set the view family's render target/viewport.
|
|
FTextureRHIParamRef RenderTargets[2] =
|
|
{
|
|
DestRenderTarget0.TargetableTexture,
|
|
DestRenderTarget1.TargetableTexture
|
|
};
|
|
//@todo Ronin find a way to use the same codepath for all platforms.
|
|
const EShaderPlatform ShaderPlatform = GShaderPlatformForFeatureLevel[Context.GetFeatureLevel()];
|
|
if (IsVulkanMobilePlatform(ShaderPlatform))
|
|
{
|
|
SetRenderTargets(Context.RHICmdList, NumRenderTargets, RenderTargets, FTextureRHIParamRef(), ESimpleRenderTargetMode::EClearColorAndDepth, FExclusiveDepthStencil());
|
|
}
|
|
else
|
|
{
|
|
SetRenderTargets(Context.RHICmdList, NumRenderTargets, RenderTargets, FTextureRHIParamRef(), 0, NULL);
|
|
}
|
|
|
|
FLinearColor ClearColors[2] =
|
|
{
|
|
FLinearColor(0, 0, 0, 0),
|
|
FLinearColor(0, 0, 0, 0)
|
|
};
|
|
// is optimized away if possible (RT size=view size, )
|
|
Context.RHICmdList.ClearMRT(true, NumRenderTargets, ClearColors, false, 1.0f, false, 0, DestRect);
|
|
|
|
Context.SetViewportAndCallRHI(DestRect.Min.X, DestRect.Min.Y, 0.0f, DestRect.Max.X + 1, DestRect.Max.Y + 1, 1.0f );
|
|
|
|
// set the state
|
|
Context.RHICmdList.SetBlendState(TStaticBlendState<>::GetRHI());
|
|
Context.RHICmdList.SetRasterizerState(TStaticRasterizerState<>::GetRHI());
|
|
Context.RHICmdList.SetDepthStencilState(TStaticDepthStencilState<false, CF_Always>::GetRHI());
|
|
|
|
const float DOFVignetteSize = FMath::Max(0.0f, View.FinalPostProcessSettings.DepthOfFieldVignetteSize);
|
|
|
|
// todo: test is conservative, with bad content we would waste a bit of performance
|
|
const bool bDOFVignette = bNearBlur && DOFVignetteSize < 200.0f;
|
|
|
|
// 0:off, 1:on, 2:on with Vignette
|
|
uint32 NearBlur = 0;
|
|
{
|
|
if(bNearBlur)
|
|
{
|
|
NearBlur = (DOFVignetteSize < 200.0f) ? 2 : 1;
|
|
}
|
|
}
|
|
|
|
FShader* VertexShader = 0;
|
|
|
|
if(bFarBlur)
|
|
{
|
|
switch(NearBlur)
|
|
{
|
|
case 0: VertexShader = SetDOFShaderTempl<1, 0>(Context);break;
|
|
case 1: VertexShader = SetDOFShaderTempl<1, 1>(Context);break;
|
|
case 2: VertexShader = SetDOFShaderTempl<1, 2>(Context);break;
|
|
default: check(!"Invalid NearBlur input");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
switch(NearBlur)
|
|
{
|
|
case 0: check(!"Internal error: In this case we should not run the pass");break;
|
|
case 1: VertexShader = SetDOFShaderTempl<0, 1>(Context);break;
|
|
case 2: VertexShader = SetDOFShaderTempl<0, 2>(Context);break;
|
|
default: check(!"Invalid NearBlur input");
|
|
}
|
|
}
|
|
|
|
DrawPostProcessPass(
|
|
Context.RHICmdList,
|
|
0, 0,
|
|
DestRect.Width() + 1, DestRect.Height() + 1,
|
|
SrcRect.Min.X, SrcRect.Min.Y,
|
|
SrcRect.Width() + 1, SrcRect.Height() + 1,
|
|
DestRect.Size() + FIntPoint(1, 1),
|
|
SrcSize,
|
|
VertexShader,
|
|
View.StereoPass,
|
|
Context.HasHmdMesh(),
|
|
EDRF_UseTriangleOptimization);
|
|
|
|
Context.RHICmdList.CopyToResolveTarget(DestRenderTarget0.TargetableTexture, DestRenderTarget0.ShaderResourceTexture, false, FResolveParams());
|
|
Context.RHICmdList.CopyToResolveTarget(DestRenderTarget1.TargetableTexture, DestRenderTarget1.ShaderResourceTexture, false, FResolveParams());
|
|
}
|
|
|
|
FPooledRenderTargetDesc FRCPassPostProcessDOFSetup::ComputeOutputDesc(EPassOutputId InPassOutputId) const
|
|
{
|
|
FPooledRenderTargetDesc Ret = GetInput(ePId_Input0)->GetOutput()->RenderTargetDesc;
|
|
|
|
// Ret.Extent = FIntPoint::DivideAndRoundUp(ret.Extent, 2);
|
|
Ret.Extent /= 2;
|
|
Ret.Extent.X = FMath::Max(1, Ret.Extent.X);
|
|
Ret.Extent.Y = FMath::Max(1, Ret.Extent.Y);
|
|
|
|
Ret.Reset();
|
|
Ret.TargetableFlags &= ~(uint32)TexCreate_UAV;
|
|
Ret.TargetableFlags |= TexCreate_RenderTargetable;
|
|
Ret.AutoWritable = false;
|
|
Ret.DebugName = (InPassOutputId == ePId_Output0) ? TEXT("DOFSetup0") : TEXT("DOFSetup1");
|
|
|
|
// more precision for additive blending and we need the alpha channel
|
|
Ret.Format = PF_FloatRGBA;
|
|
|
|
Ret.ClearValue = FClearValueBinding(FLinearColor(0,0,0,0));
|
|
|
|
return Ret;
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Encapsulates the DOF setup pixel shader. */
|
|
// @param FarBlur 0:off, 1:on
|
|
// @param NearBlur 0:off, 1:on
|
|
template <uint32 FarBlur, uint32 NearBlur>
|
|
class FPostProcessDOFRecombinePS : public FGlobalShader
|
|
{
|
|
DECLARE_SHADER_TYPE(FPostProcessDOFRecombinePS, Global);
|
|
|
|
static bool ShouldCache(EShaderPlatform Platform)
|
|
{
|
|
return IsFeatureLevelSupported(Platform, ERHIFeatureLevel::ES3_1);
|
|
}
|
|
|
|
static void ModifyCompilationEnvironment(EShaderPlatform Platform, FShaderCompilerEnvironment& OutEnvironment)
|
|
{
|
|
FGlobalShader::ModifyCompilationEnvironment(Platform,OutEnvironment);
|
|
OutEnvironment.SetDefine(TEXT("FAR_BLUR"), FarBlur);
|
|
OutEnvironment.SetDefine(TEXT("NEAR_BLUR"), NearBlur);
|
|
OutEnvironment.SetDefine(TEXT("FORWARD_SHADING"), IsFeatureLevelSupported(Platform, ERHIFeatureLevel::SM4) ? 0u : 1u);
|
|
}
|
|
|
|
/** Default constructor. */
|
|
FPostProcessDOFRecombinePS() {}
|
|
|
|
public:
|
|
FPostProcessPassParameters PostprocessParameter;
|
|
FDeferredPixelShaderParameters DeferredParameters;
|
|
FShaderParameter DepthOfFieldUVLimit;
|
|
|
|
/** Initialization constructor. */
|
|
FPostProcessDOFRecombinePS(const ShaderMetaType::CompiledShaderInitializerType& Initializer)
|
|
: FGlobalShader(Initializer)
|
|
{
|
|
PostprocessParameter.Bind(Initializer.ParameterMap);
|
|
DeferredParameters.Bind(Initializer.ParameterMap);
|
|
DepthOfFieldUVLimit.Bind(Initializer.ParameterMap,TEXT("DepthOfFieldUVLimit"));
|
|
}
|
|
|
|
// FShader interface.
|
|
virtual bool Serialize(FArchive& Ar) override
|
|
{
|
|
bool bShaderHasOutdatedParameters = FGlobalShader::Serialize(Ar);
|
|
Ar << PostprocessParameter << DeferredParameters << DepthOfFieldUVLimit;
|
|
return bShaderHasOutdatedParameters;
|
|
}
|
|
|
|
void SetParameters(const FRenderingCompositePassContext& Context)
|
|
{
|
|
FSceneRenderTargets& SceneContext = FSceneRenderTargets::Get(Context.RHICmdList);
|
|
const FPixelShaderRHIParamRef ShaderRHI = GetPixelShader();
|
|
|
|
FGlobalShader::SetParameters(Context.RHICmdList, ShaderRHI, Context.View);
|
|
|
|
DeferredParameters.Set(Context.RHICmdList, ShaderRHI, Context.View);
|
|
PostprocessParameter.SetPS(ShaderRHI, Context, TStaticSamplerState<SF_Bilinear,AM_Clamp,AM_Clamp,AM_Clamp>::GetRHI(), eFC_0001);
|
|
|
|
// Compute out of bounds UVs in the source texture.
|
|
FVector4 Bounds;
|
|
Bounds.X = (((float)((Context.View.ViewRect.Min.X + 1) & (~1))) + 3.0f) / ((float)(SceneContext.GetBufferSizeXY().X));
|
|
Bounds.Y = (((float)((Context.View.ViewRect.Min.Y + 1) & (~1))) + 3.0f) / ((float)(SceneContext.GetBufferSizeXY().Y));
|
|
Bounds.Z = (((float)(Context.View.ViewRect.Max.X & (~1))) - 3.0f) / ((float)(SceneContext.GetBufferSizeXY().X));
|
|
Bounds.W = (((float)(Context.View.ViewRect.Max.Y & (~1))) - 3.0f) / ((float)(SceneContext.GetBufferSizeXY().Y));
|
|
|
|
SetShaderValue(Context.RHICmdList, ShaderRHI, DepthOfFieldUVLimit, Bounds);
|
|
}
|
|
|
|
static const TCHAR* GetSourceFilename()
|
|
{
|
|
return TEXT("PostProcessDOF");
|
|
}
|
|
|
|
static const TCHAR* GetFunctionName()
|
|
{
|
|
return TEXT("MainRecombinePS");
|
|
}
|
|
};
|
|
|
|
// #define avoids a lot of code duplication
|
|
#define VARIATION1(A, B) typedef FPostProcessDOFRecombinePS<A, B> FPostProcessDOFRecombinePS##A##B; \
|
|
IMPLEMENT_SHADER_TYPE2(FPostProcessDOFRecombinePS##A##B, SF_Pixel);
|
|
|
|
VARIATION1(0, 1) VARIATION1(1, 0) VARIATION1(1, 1)
|
|
|
|
#undef VARIATION1
|
|
|
|
// @param FarBlur 0:off, 1:on
|
|
// @param NearBlur 0:off, 1:on, 2:on with Vignette
|
|
template <uint32 FarBlur, uint32 NearBlur>
|
|
static FShader* SetDOFRecombineShaderTempl(const FRenderingCompositePassContext& Context)
|
|
{
|
|
TShaderMapRef<FPostProcessVS> VertexShader(Context.GetShaderMap());
|
|
TShaderMapRef<FPostProcessDOFRecombinePS<FarBlur, NearBlur> > PixelShader(Context.GetShaderMap());
|
|
|
|
static FGlobalBoundShaderState BoundShaderState;
|
|
|
|
SetGlobalBoundShaderState(Context.RHICmdList, Context.GetFeatureLevel(), BoundShaderState, GFilterVertexDeclaration.VertexDeclarationRHI, *VertexShader, *PixelShader);
|
|
|
|
VertexShader->SetParameters(Context);
|
|
PixelShader->SetParameters(Context);
|
|
|
|
return *VertexShader;
|
|
}
|
|
|
|
void FRCPassPostProcessDOFRecombine::Process(FRenderingCompositePassContext& Context)
|
|
{
|
|
SCOPED_DRAW_EVENT(Context.RHICmdList, DOFRecombine);
|
|
|
|
// Get the Far or Near RTDesc
|
|
const FPooledRenderTargetDesc* InputDesc = GetInputDesc(ePId_Input1);
|
|
|
|
if(!InputDesc)
|
|
{
|
|
InputDesc = GetInputDesc(ePId_Input2);
|
|
}
|
|
|
|
check(InputDesc);
|
|
|
|
const FSceneView& View = Context.View;
|
|
|
|
const auto FeatureLevel = Context.GetFeatureLevel();
|
|
auto ShaderMap = Context.GetShaderMap();
|
|
|
|
FIntPoint TexSize = InputDesc->Extent;
|
|
|
|
// usually 1, 2, 4 or 8
|
|
uint32 ScaleToFullRes = FSceneRenderTargets::Get(Context.RHICmdList).GetBufferSizeXY().X / TexSize.X;
|
|
|
|
FIntRect HalfResViewRect = View.ViewRect / ScaleToFullRes;
|
|
|
|
const FSceneRenderTargetItem& DestRenderTarget = PassOutputs[0].RequestSurface(Context);
|
|
|
|
// Set the view family's render target/viewport.
|
|
|
|
//@todo Ronin find a way to use the same codepath for all platforms.
|
|
const EShaderPlatform ShaderPlatform = GShaderPlatformForFeatureLevel[Context.GetFeatureLevel()];
|
|
if (IsVulkanMobilePlatform(ShaderPlatform))
|
|
{
|
|
SetRenderTarget(Context.RHICmdList, DestRenderTarget.TargetableTexture, FTextureRHIRef(), ESimpleRenderTargetMode::EClearColorAndDepth);
|
|
}
|
|
else
|
|
{
|
|
SetRenderTarget(Context.RHICmdList, DestRenderTarget.TargetableTexture, FTextureRHIRef());
|
|
// is optimized away if possible (RT size=view size, )
|
|
Context.RHICmdList.Clear(true, FLinearColor::Black, false, 1.0f, false, 0, View.ViewRect);
|
|
}
|
|
|
|
Context.SetViewportAndCallRHI(View.ViewRect);
|
|
|
|
// set the state
|
|
Context.RHICmdList.SetBlendState(TStaticBlendState<>::GetRHI());
|
|
Context.RHICmdList.SetRasterizerState(TStaticRasterizerState<>::GetRHI());
|
|
Context.RHICmdList.SetDepthStencilState(TStaticDepthStencilState<false, CF_Always>::GetRHI());
|
|
|
|
bool bFarBlur = GetInputDesc(ePId_Input1) != 0;
|
|
bool bNearBlur = GetInputDesc(ePId_Input2) != 0;
|
|
|
|
FShader* VertexShader = 0;
|
|
|
|
if(bFarBlur)
|
|
{
|
|
if(bNearBlur)
|
|
{
|
|
VertexShader = SetDOFRecombineShaderTempl<1, 1>(Context);
|
|
}
|
|
else
|
|
{
|
|
VertexShader = SetDOFRecombineShaderTempl<1, 0>(Context);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
VertexShader = SetDOFRecombineShaderTempl<0, 1>(Context);
|
|
}
|
|
|
|
DrawPostProcessPass(
|
|
Context.RHICmdList,
|
|
0, 0,
|
|
View.ViewRect.Width(), View.ViewRect.Height(),
|
|
HalfResViewRect.Min.X, HalfResViewRect.Min.Y,
|
|
HalfResViewRect.Width(), HalfResViewRect.Height(),
|
|
View.ViewRect.Size(),
|
|
TexSize,
|
|
VertexShader,
|
|
View.StereoPass,
|
|
Context.HasHmdMesh(),
|
|
EDRF_UseTriangleOptimization);
|
|
|
|
|
|
Context.RHICmdList.CopyToResolveTarget(DestRenderTarget.TargetableTexture, DestRenderTarget.ShaderResourceTexture, false, FResolveParams());
|
|
}
|
|
|
|
FPooledRenderTargetDesc FRCPassPostProcessDOFRecombine::ComputeOutputDesc(EPassOutputId InPassOutputId) const
|
|
{
|
|
FPooledRenderTargetDesc Ret = GetInput(ePId_Input0)->GetOutput()->RenderTargetDesc;
|
|
|
|
Ret.Reset();
|
|
Ret.AutoWritable = false;
|
|
Ret.DebugName = TEXT("DOFRecombine");
|
|
|
|
Ret.ClearValue = FClearValueBinding(FLinearColor::Black);
|
|
|
|
return Ret;
|
|
} |