Files
UnrealEngineUWP/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessUpscale.cpp

366 lines
12 KiB
C++
Raw Normal View History

// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
/*=============================================================================
PostProcessUpscale.cpp: Post processing Upscale implementation.
=============================================================================*/
#include "RendererPrivate.h"
#include "ScenePrivate.h"
#include "SceneFilterRendering.h"
#include "PostProcessUpscale.h"
#include "PostProcessing.h"
#include "PostProcessHistogram.h"
#include "PostProcessEyeAdaptation.h"
#include "SceneUtils.h"
static TAutoConsoleVariable<float> CVarUpscaleSoftness(
TEXT("r.Upscale.Softness"),
0.3f,
TEXT("To scale up with higher quality losing some sharpness\n")
TEXT(" 0..1 (0.3 is good for ScreenPercentage 90"),
ECVF_Scalability | ECVF_RenderThreadSafe);
Copying //UE4/Orion-Staging to //UE4/Main (originated from //Orion/Dev-General @ 2831630) #lockdown Nick.Penwarden ========================== MAJOR FEATURES + CHANGES ========================== Change 2831624 on 2016/01/17 by Marcus.Wassmer Merge disable of FCachedReadPlatformData on PS4. Reduces memory spikes. 2830986 #rb none #test none #codereview Michael.Noland,James.Golding Change 2831402 on 2016/01/17 by Marcus.Wassmer HLOD priority and streamout changes. Give texture pool an extra 200MB which we can afford thanks to James/Michael #rb Chris.Gagnon #test run agora, notice nice textures. #lockdown Andrew.Grant Change 2831398 on 2016/01/17 by Marcus.Wassmer Fix 3 logic bugs with Relocate #rb chris.gagnon #test run game, look for corruption. #lockdown Andrew.Grant Change 2831372 on 2016/01/16 by Marcus.Wassmer Update param.sfo's and lockdown version in prep for good PS4 playtest build. #rb none #test build from last night... #lockdown Andrew.Grant Change 2831274 on 2016/01/16 by Graeme.Thornton Disable platform file cache wrapper on PS4 #codereview James.Golding #rb none #tests ran cooked ps4 build, timed loading (no real change), measured memory used for file handles (small) Change 2831237 on 2016/01/16 by Sammy.James Fix PS4 compile error #codereview Andrew.Grant #rb none #tests none Change 2831219 on 2016/01/16 by Matt.Kuhlenschmidt Fix possible invalid access to shared movie player resource across threads causing startup crash. #codereview marcus.wassmer #rb none, #tests initial load Change 2831218 on 2016/01/16 by Marcus.Wassmer Fix bad warning case. #codereview Martin.Mittring #rb none #test none Change 2831201 on 2016/01/16 by Andrew.Grant Added extra info about referencer to missing asset reference message #rb none #tests cooked, ran editor Change 2831183 on 2016/01/16 by David.Nikdel #OSS #PS4 #Purchasing #StoreV2 - Force failure if we have no receipts after a "successful" checkout. - Report consumed entitlements as well as unconsumed but leave ValidationInfo empty so we can tell the difference at the application level - Convert productIds to skuIds at checkout time - Added PS4 Implementation of IOnlineStoreV2 - Bugfix: set bSuccessfullyStartedUp=false when InitNPGameSettings() fails - Adjusted FOnlineStoreOffer to use FText::AsCurrencyBase #RB: Paul.Moore #TESTS: login, purchase redemption, store MTX purchasing on PS4 & PC Change 2831129 on 2016/01/16 by David.Nikdel #MCP - Added a ctor to make converting from FOnlineError to FMcpQueryResult easier (for stuff that was already using FMcpQueryResult). #RB: none #TESTS: frontend Change 2830986 on 2016/01/15 by Michael.Noland PS4: Disabling FCachedReadPlatformFile on PS4 to significantly reduce high watermark memory consumption during blocking loads #rb marcus.wassmer #tests Ran Paragon PS4 down a bad path that currently does a blocking map and hero load #lockdown andrew.grant Change 2830943 on 2016/01/15 by Max.Chen Sequencer: Fix bug introduced with preroll. It was also causing a crash in particle track instance. #tests Master sequence trailer plays without crashing #rb none Change 2830912 on 2016/01/15 by Michael.Noland Rendering: Exposed GRHIDeviceId (only filled in on D3D11 and D3D12 RHI's under the same circumstances as GRHIAdapterName, etc..., 0 otherwise) #rb mieszko.zielinski #tests Tested printing the value out #codereview martin.mittring Change 2830910 on 2016/01/15 by Michael.Noland Rendering: Improved GPU driver detection logic to handle more cases #codereview martin.mittring #rb mieszko.zielinski #tests Tested on my machine which was previous reporting Unknown for the values as some entries contained the key in the Settings subfolder Change 2830776 on 2016/01/15 by Martin.Mittring from Dev-Rendering added ensure to track down multiple issues like OR-11771 CRASH: User Crashed when pressing the Play button OR-12430 CRASH: OT2 user crashed with FRHIResource::AddRef() #rb:Gil.Gribb #code_review:Gil.Gribb,Mark.Satterthwaite,Marcus.Wassmer
2016-01-20 11:32:08 -05:00
static TAutoConsoleVariable<float> CVarUpscalePaniniD(
TEXT("r.Upscale.Panini.D"),
0,
TEXT("Allow and configure to apply a panini distortion to the rendered image. Values between 0 and 1 allow to fade the effect (lerp).\n")
TEXT("Implementation from research paper \"Pannini: A New Projection for Rendering Wide Angle Perspective Images\"\n")
TEXT(" 0: off (default)\n")
TEXT(">0: enabled (requires an extra post processing pass if upsampling wasn't used - see r.ScreenPercentage)\n")
TEXT(" 1: Panini cylindrical stereographic projection"),
ECVF_RenderThreadSafe);
static TAutoConsoleVariable<float> CVarUpscalePaniniS(
TEXT("r.Upscale.Panini.S"),
0,
TEXT("Panini projection's hard vertical compression factor.\n")
TEXT(" 0: no vertical compression factor (default)\n")
TEXT(" 1: Hard vertical compression"),
ECVF_RenderThreadSafe);
static TAutoConsoleVariable<float> CVarUpscalePaniniScreenFit(
TEXT("r.Upscale.Panini.ScreenFit"),
1.0f,
TEXT("Panini projection screen fit effect factor (lerp).\n")
TEXT(" 0: fit vertically\n")
TEXT(" 1: fit horizontally (default)"),
ECVF_RenderThreadSafe);
const FRCPassPostProcessUpscale::PaniniParams FRCPassPostProcessUpscale::PaniniParams::Default;
Copying //UE4/Orion-Staging to //UE4/Main (originated from //Orion/Dev-General @ 2831630) #lockdown Nick.Penwarden ========================== MAJOR FEATURES + CHANGES ========================== Change 2831624 on 2016/01/17 by Marcus.Wassmer Merge disable of FCachedReadPlatformData on PS4. Reduces memory spikes. 2830986 #rb none #test none #codereview Michael.Noland,James.Golding Change 2831402 on 2016/01/17 by Marcus.Wassmer HLOD priority and streamout changes. Give texture pool an extra 200MB which we can afford thanks to James/Michael #rb Chris.Gagnon #test run agora, notice nice textures. #lockdown Andrew.Grant Change 2831398 on 2016/01/17 by Marcus.Wassmer Fix 3 logic bugs with Relocate #rb chris.gagnon #test run game, look for corruption. #lockdown Andrew.Grant Change 2831372 on 2016/01/16 by Marcus.Wassmer Update param.sfo's and lockdown version in prep for good PS4 playtest build. #rb none #test build from last night... #lockdown Andrew.Grant Change 2831274 on 2016/01/16 by Graeme.Thornton Disable platform file cache wrapper on PS4 #codereview James.Golding #rb none #tests ran cooked ps4 build, timed loading (no real change), measured memory used for file handles (small) Change 2831237 on 2016/01/16 by Sammy.James Fix PS4 compile error #codereview Andrew.Grant #rb none #tests none Change 2831219 on 2016/01/16 by Matt.Kuhlenschmidt Fix possible invalid access to shared movie player resource across threads causing startup crash. #codereview marcus.wassmer #rb none, #tests initial load Change 2831218 on 2016/01/16 by Marcus.Wassmer Fix bad warning case. #codereview Martin.Mittring #rb none #test none Change 2831201 on 2016/01/16 by Andrew.Grant Added extra info about referencer to missing asset reference message #rb none #tests cooked, ran editor Change 2831183 on 2016/01/16 by David.Nikdel #OSS #PS4 #Purchasing #StoreV2 - Force failure if we have no receipts after a "successful" checkout. - Report consumed entitlements as well as unconsumed but leave ValidationInfo empty so we can tell the difference at the application level - Convert productIds to skuIds at checkout time - Added PS4 Implementation of IOnlineStoreV2 - Bugfix: set bSuccessfullyStartedUp=false when InitNPGameSettings() fails - Adjusted FOnlineStoreOffer to use FText::AsCurrencyBase #RB: Paul.Moore #TESTS: login, purchase redemption, store MTX purchasing on PS4 & PC Change 2831129 on 2016/01/16 by David.Nikdel #MCP - Added a ctor to make converting from FOnlineError to FMcpQueryResult easier (for stuff that was already using FMcpQueryResult). #RB: none #TESTS: frontend Change 2830986 on 2016/01/15 by Michael.Noland PS4: Disabling FCachedReadPlatformFile on PS4 to significantly reduce high watermark memory consumption during blocking loads #rb marcus.wassmer #tests Ran Paragon PS4 down a bad path that currently does a blocking map and hero load #lockdown andrew.grant Change 2830943 on 2016/01/15 by Max.Chen Sequencer: Fix bug introduced with preroll. It was also causing a crash in particle track instance. #tests Master sequence trailer plays without crashing #rb none Change 2830912 on 2016/01/15 by Michael.Noland Rendering: Exposed GRHIDeviceId (only filled in on D3D11 and D3D12 RHI's under the same circumstances as GRHIAdapterName, etc..., 0 otherwise) #rb mieszko.zielinski #tests Tested printing the value out #codereview martin.mittring Change 2830910 on 2016/01/15 by Michael.Noland Rendering: Improved GPU driver detection logic to handle more cases #codereview martin.mittring #rb mieszko.zielinski #tests Tested on my machine which was previous reporting Unknown for the values as some entries contained the key in the Settings subfolder Change 2830776 on 2016/01/15 by Martin.Mittring from Dev-Rendering added ensure to track down multiple issues like OR-11771 CRASH: User Crashed when pressing the Play button OR-12430 CRASH: OT2 user crashed with FRHIResource::AddRef() #rb:Gil.Gribb #code_review:Gil.Gribb,Mark.Satterthwaite,Marcus.Wassmer
2016-01-20 11:32:08 -05:00
FRCPassPostProcessUpscale::PaniniParams::PaniniParams(const FViewInfo& View)
{
*this = PaniniParams();
if (View.IsPerspectiveProjection() && !GEngine->StereoRenderingDevice.IsValid())
{
D = FMath::Max(CVarUpscalePaniniD.GetValueOnRenderThread(), 0.0f);
S = CVarUpscalePaniniS.GetValueOnRenderThread();
ScreenFit = FMath::Max(CVarUpscalePaniniScreenFit.GetValueOnRenderThread(), 0.0f);
}
}
static FVector2D PaniniProjection(FVector2D OM, float d, float s)
{
float PaniniDirectionXZInvLength = 1.0f / FMath::Sqrt(1.0f + OM.X * OM.X);
float SinPhi = OM.X * PaniniDirectionXZInvLength;
float TanTheta = OM.Y * PaniniDirectionXZInvLength;
float CosPhi = FMath::Sqrt(1.0f - SinPhi * SinPhi);
float S = (d + 1.0f) / (d + CosPhi);
return S * FVector2D(SinPhi, FMath::Lerp(TanTheta, TanTheta / CosPhi, s));
}
/** Encapsulates the upscale vertex shader. */
class FPostProcessUpscaleVS : public FPostProcessVS
{
DECLARE_SHADER_TYPE(FPostProcessUpscaleVS,Global);
/** Default constructor. */
FPostProcessUpscaleVS() {}
public:
FShaderParameter PaniniParameters;
/** Initialization constructor. */
FPostProcessUpscaleVS(const ShaderMetaType::CompiledShaderInitializerType& Initializer)
: FPostProcessVS(Initializer)
{
PaniniParameters.Bind(Initializer.ParameterMap,TEXT("PaniniParams"));
}
static bool ShouldCache(EShaderPlatform Platform)
{
return true;
}
static void ModifyCompilationEnvironment(EShaderPlatform Platform, FShaderCompilerEnvironment& OutEnvironment)
{
FPostProcessVS::ModifyCompilationEnvironment(Platform,OutEnvironment);
OutEnvironment.SetDefine(TEXT("TESS_RECT_X"), FTesselatedScreenRectangleIndexBuffer::Width);
OutEnvironment.SetDefine(TEXT("TESS_RECT_Y"), FTesselatedScreenRectangleIndexBuffer::Height);
}
void SetParameters(const FRenderingCompositePassContext& Context, const FRCPassPostProcessUpscale::PaniniParams& InPaniniConfig)
{
const FVertexShaderRHIParamRef ShaderRHI = GetVertexShader();
FGlobalShader::SetParameters(Context.RHICmdList, ShaderRHI, Context.View);
{
const FVector2D FOVPerAxis = Context.View.ViewMatrices.GetHalfFieldOfViewPerAxis();
const FVector2D ScreenPosToPaniniFactor = FVector2D(FMath::Tan(FOVPerAxis.X), FMath::Tan(FOVPerAxis.Y));
const FVector2D PaniniDirection = FVector2D(1.0f, 0.0f) * ScreenPosToPaniniFactor;
const FVector2D PaniniPosition = PaniniProjection(PaniniDirection, InPaniniConfig.D, InPaniniConfig.S);
const float WidthFit = ScreenPosToPaniniFactor.X / PaniniPosition.X;
const float OutScreenPosScale = FMath::Lerp(1.0f, WidthFit, InPaniniConfig.ScreenFit);
FVector Value(InPaniniConfig.D, InPaniniConfig.S, OutScreenPosScale);
SetShaderValue(Context.RHICmdList, ShaderRHI, PaniniParameters, Value);
}
}
virtual bool Serialize(FArchive& Ar) override
{
bool bShaderHasOutdatedParameters = FPostProcessVS::Serialize(Ar);
Ar << PaniniParameters;
return bShaderHasOutdatedParameters;
}
};
IMPLEMENT_SHADER_TYPE(,FPostProcessUpscaleVS,TEXT("PostProcessUpscale"),TEXT("MainVS"),SF_Vertex);
/** Encapsulates the post processing upscale pixel shader. */
template <uint32 Method>
class FPostProcessUpscalePS : public FGlobalShader
{
DECLARE_SHADER_TYPE(FPostProcessUpscalePS, Global);
static bool ShouldCache(EShaderPlatform Platform)
{
Copying //UE4/Dev-Mobile to Dev-Main (//UE4/Dev-Main) #lockdown Ben.Marsh Change 2718980 on 2015/10/07 by Dmitriy.Dyomin UWorld::CreateWorld: remove commandlet-specific behavior (Contributed by slonopotamus) Change 2719155 on 2015/10/07 by Allan.Bentham HQ ES2 Reflections, selects the nearest 3 reflection captures to the primitive and reflects around the captures themselves (parallax correction). Change 2724572 on 2015/10/12 by Jack.Porter Fix for landscape disappearing when using r.forcelod Change 2726062 on 2015/10/13 by Jack.Porter Merged CL2726057 from 4.10 Fixed issues with landscape mirror tool on landscapes substantially above and below the zero line Fixed problem where landscape grass was not invalidated after using the mirror tool Change 2726133 on 2015/10/13 by Jack.Porter Fix for Device Profiles editor missing specific Android device profiles Fix for Device Profiles editor creating blank device profiles for Android cook variant "platforms" Change 2736210 on 2015/10/21 by Dmitriy.Dyomin Mobile Rendering: ReceiveDecals flag support for all meshes (previously only for skeletal meshes) Change 2736463 on 2015/10/21 by Jack.Porter Merge of 4.10 CL 2736461 Fixed Landscape disappearing when Layer Debug visualization selected outside Landscape edit mode Change 2742855 on 2015/10/27 by Dmitriy.Dyomin Fixed: World origin offset handling for UInterpToMovementComponent https://udn.unrealengine.com/questions/266512/uinterptomovementcomponent-doesnt-update-with-worl.html Change 2745055 on 2015/10/28 by Allan.Bentham Update reflection captures (via update captures button) now works when mobile preview is active. Change 2755668 on 2015/11/05 by Allan.Bentham Use distance from shadow view to object instead of view space Z. Change 2762186 on 2015/11/11 by Jack.Porter The user can now specify the relative priority for each Android texture format in Project Settings. This will affect the format selected for Launch on Device and by the device for projects packaged using the Android_Multi target Change 2765902 on 2015/11/13 by Gareth.Martin Landscape per-component layer whitelisting basic functionality Change 2769487 on 2015/11/17 by Jack.Porter Support reflection viewmode on ES2 Preview Change 2769576 on 2015/11/17 by Gareth.Martin Improved landscape per-component layer whitelisting functionality - added shortcut keys (plus/minus + click) to whitelist/un-whitelist a layer from the paint tool - automatically added components' painted layers to the component whitelists when enabling whitelist restriction Change 2771223 on 2015/11/18 by Gareth.Martin Improved landscape per-component layer whitelisting functionality - Removing a layer from the whitelist will now delete its data from the component Change 2777862 on 2015/11/23 by Gareth.Martin Improved landscape per-component layer whitelisting functionality - on the shared verts on component edges/corners painting must now pass the whitelist of all components sharing the vert or it won't paint, rather than causing a disconnect Better handling of erasing 100%-painted areas of blended landscape weightmap - It will now pick the first other painted layer on that component to fill the erased value with, so 100% areas of blended layers are now erasable. - todo: erasing can still cause disconnects on shared edge verts Change 2780470 on 2015/11/25 by Dmitriy.Dyomin Use hardware instancing when device supports it Change 2780679 on 2015/11/25 by Jack.Porter Landscape layer usage viewmode Change 2781878 on 2015/11/26 by Gareth.Martin Better handling of erasing 100%-painted areas of blended landscape weightmap - It will now pick the *most painted* other painted layer on that component to fill the erased value with, and correctly takes shared edge/corner verts into account Various fixes to TMap/TSet/TFixedSizeArrayView - all reviewed by Core Change 2782214 on 2015/11/27 by Allan.Bentham Prevent editor's ES2 emulation shaders degamma-ing the alpha channel when reading material textures. Merging using Ronin-To-UE4-Dev-Mobile Change 2782536 on 2015/11/30 by Jack.Porter When updating reflection captures in ES2 mode, first wait for any shader compilation initiated by the feature level switch to complete Change 2792617 on 2015/12/07 by Jack.Porter Added a Project Setting to edit the r.DiscardUnusedQuality console variable Change 2792618 on 2015/12/07 by Gareth.Martin Baking landscape material world-position-offset into collision Change 2794270 on 2015/12/08 by Dmitriy.Dyomin DynamicMeshBuilder uses 16bit index buffer on ES2 platforms Change 2794556 on 2015/12/08 by Allan.Bentham Fix incorrect mip/roughness selection for HQ reflections. Fixed couple of merge issues. Change 2794568 on 2015/12/08 by Gareth.Martin Fix black spot / hole if all layers on a component use height blending and add to <= 0 [CL 2796640 by Nick Penwarden in Main branch]
2015-12-09 15:04:15 -05:00
// Always allow point and bilinear upscale. (Provides upscaling for ES2 emulation)
if (Method == 0 || Method == 1)
{
return true;
}
return IsFeatureLevelSupported(Platform, ERHIFeatureLevel::SM4);
}
static void ModifyCompilationEnvironment(EShaderPlatform Platform, FShaderCompilerEnvironment& OutEnvironment)
{
FGlobalShader::ModifyCompilationEnvironment(Platform,OutEnvironment);
OutEnvironment.SetDefine(TEXT("METHOD"), Method);
}
/** Default constructor. */
FPostProcessUpscalePS() {}
public:
FPostProcessPassParameters PostprocessParameter;
FDeferredPixelShaderParameters DeferredParameters;
FShaderParameter UpscaleSoftness;
/** Initialization constructor. */
FPostProcessUpscalePS(const ShaderMetaType::CompiledShaderInitializerType& Initializer)
: FGlobalShader(Initializer)
{
PostprocessParameter.Bind(Initializer.ParameterMap);
DeferredParameters.Bind(Initializer.ParameterMap);
UpscaleSoftness.Bind(Initializer.ParameterMap,TEXT("UpscaleSoftness"));
}
void SetPS(const FRenderingCompositePassContext& Context)
{
const FPixelShaderRHIParamRef ShaderRHI = GetPixelShader();
FGlobalShader::SetParameters(Context.RHICmdList, ShaderRHI, Context.View);
FSamplerStateRHIParamRef FilterTable[2];
FilterTable[0] = TStaticSamplerState<SF_Bilinear,AM_Clamp,AM_Clamp,AM_Clamp>::GetRHI();
FilterTable[1] = TStaticSamplerState<SF_Point,AM_Clamp,AM_Clamp,AM_Clamp>::GetRHI();
PostprocessParameter.SetPS(ShaderRHI, Context, 0, eFC_0000, FilterTable);
DeferredParameters.Set(Context.RHICmdList, ShaderRHI, Context.View);
{
float UpscaleSoftnessValue = FMath::Clamp(CVarUpscaleSoftness.GetValueOnRenderThread(), 0.0f, 1.0f);
SetShaderValue(Context.RHICmdList, ShaderRHI, UpscaleSoftness, UpscaleSoftnessValue);
}
}
// FShader interface.
virtual bool Serialize(FArchive& Ar) override
{
bool bShaderHasOutdatedParameters = FGlobalShader::Serialize(Ar);
Ar << PostprocessParameter << DeferredParameters << UpscaleSoftness;
return bShaderHasOutdatedParameters;
}
static const TCHAR* GetSourceFilename()
{
return TEXT("PostProcessUpscale");
}
static const TCHAR* GetFunctionName()
{
return TEXT("MainPS");
}
};
// #define avoids a lot of code duplication
#define VARIATION1(A) typedef FPostProcessUpscalePS<A> FPostProcessUpscalePS##A; \
IMPLEMENT_SHADER_TYPE2(FPostProcessUpscalePS##A, SF_Pixel);
VARIATION1(0)
VARIATION1(1)
VARIATION1(2)
VARIATION1(3)
#undef VARIATION1
FRCPassPostProcessUpscale::FRCPassPostProcessUpscale(uint32 InUpscaleQuality, const PaniniParams& InPaniniConfig)
: UpscaleQuality(InUpscaleQuality)
{
PaniniConfig.D = FMath::Max(InPaniniConfig.D, 0.0f);
PaniniConfig.S = InPaniniConfig.S;
PaniniConfig.ScreenFit = FMath::Max(InPaniniConfig.ScreenFit, 0.0f);
}
template <uint32 Method, uint32 bTesselatedQuad>
FShader* FRCPassPostProcessUpscale::SetShader(const FRenderingCompositePassContext& Context, const PaniniParams& PaniniConfig)
{
if(bTesselatedQuad)
{
check(PaniniConfig.D > 0.0f);
TShaderMapRef<FPostProcessUpscaleVS> VertexShader(Context.GetShaderMap());
TShaderMapRef<FPostProcessUpscalePS<Method> > PixelShader(Context.GetShaderMap());
static FGlobalBoundShaderState BoundShaderState;
SetGlobalBoundShaderState(Context.RHICmdList, Context.GetFeatureLevel(), BoundShaderState, GFilterVertexDeclaration.VertexDeclarationRHI, *VertexShader, *PixelShader);
PixelShader->SetPS(Context);
VertexShader->SetParameters(Context, PaniniConfig);
return *VertexShader;
}
else
{
check(PaniniConfig.D == 0.0f);
TShaderMapRef<FPostProcessVS> VertexShader(Context.GetShaderMap());
TShaderMapRef<FPostProcessUpscalePS<Method> > PixelShader(Context.GetShaderMap());
static FGlobalBoundShaderState BoundShaderState;
SetGlobalBoundShaderState(Context.RHICmdList, Context.GetFeatureLevel(), BoundShaderState, GFilterVertexDeclaration.VertexDeclarationRHI, *VertexShader, *PixelShader);
PixelShader->SetPS(Context);
VertexShader->SetParameters(Context);
return *VertexShader;
}
}
void FRCPassPostProcessUpscale::Process(FRenderingCompositePassContext& Context)
{
SCOPED_DRAW_EVENT(Context.RHICmdList, PostProcessUpscale);
const FPooledRenderTargetDesc* InputDesc = GetInputDesc(ePId_Input0);
if(!InputDesc)
{
// input is not hooked up correctly
return;
}
const FSceneView& View = Context.View;
const FSceneViewFamily& ViewFamily = *(View.Family);
FIntRect SrcRect = View.ViewRect;
// no upscale if separate ren target is used.
FIntRect DestRect = (ViewFamily.bUseSeparateRenderTarget) ? View.ViewRect : View.UnscaledViewRect; // Simple upscaling, ES2 post process does not currently have a specific upscaling pass.
FIntPoint SrcSize = InputDesc->Extent;
const FSceneRenderTargetItem& DestRenderTarget = PassOutputs[0].RequestSurface(Context);
if (!DestRenderTarget.TargetableTexture)
{
return;
}
// Set the view family's render target/viewport.
SetRenderTarget(Context.RHICmdList, DestRenderTarget.TargetableTexture, FTextureRHIRef());
bool bTessellatedQuad = PaniniConfig.D >= 0.01f;
// with distortion (bTessellatedQuad) we need to clear the background
FIntRect ExcludeRect = bTessellatedQuad ? FIntRect() : DestRect;
Context.SetViewportAndCallRHI(DestRect);
if (View.StereoPass == eSSP_FULL || View.StereoPass == eSSP_LEFT_EYE)
{
Context.RHICmdList.Clear(true, FLinearColor::Black, false, 1.0f, false, 0, ExcludeRect);
}
// set the state
Context.RHICmdList.SetBlendState(TStaticBlendState<>::GetRHI());
Context.RHICmdList.SetRasterizerState(TStaticRasterizerState<>::GetRHI());
Context.RHICmdList.SetDepthStencilState(TStaticDepthStencilState<false, CF_Always>::GetRHI());
FShader* VertexShader = 0;
if(bTessellatedQuad)
{
switch (UpscaleQuality)
{
case 0: VertexShader = SetShader<0, 1>(Context, PaniniConfig); break;
case 1: VertexShader = SetShader<1, 1>(Context, PaniniConfig); break;
case 2: VertexShader = SetShader<2, 1>(Context, PaniniConfig); break;
case 3: VertexShader = SetShader<3, 1>(Context, PaniniConfig); break;
default:
checkNoEntry();
break;
}
}
else
{
switch (UpscaleQuality)
{
case 0: VertexShader = SetShader<0, 0>(Context, PaniniParams::Default); break;
case 1: VertexShader = SetShader<1, 0>(Context, PaniniParams::Default); break;
case 2: VertexShader = SetShader<2, 0>(Context, PaniniParams::Default); break;
case 3: VertexShader = SetShader<3, 0>(Context, PaniniParams::Default); break;
default:
checkNoEntry();
break;
}
}
// Draw a quad, a triangle or a tessellated quad
DrawRectangle(
Context.RHICmdList,
0, 0,
DestRect.Width(), DestRect.Height(),
SrcRect.Min.X, SrcRect.Min.Y,
SrcRect.Width(), SrcRect.Height(),
DestRect.Size(),
SrcSize,
VertexShader,
bTessellatedQuad ? EDRF_UseTesselatedIndexBuffer: EDRF_UseTriangleOptimization);
Context.RHICmdList.CopyToResolveTarget(DestRenderTarget.TargetableTexture, DestRenderTarget.ShaderResourceTexture, false, FResolveParams());
}
FPooledRenderTargetDesc FRCPassPostProcessUpscale::ComputeOutputDesc(EPassOutputId InPassOutputId) const
{
FPooledRenderTargetDesc Ret = GetInput(ePId_Input0)->GetOutput()->RenderTargetDesc;
Ret.Reset();
Ret.DebugName = TEXT("Upscale");
return Ret;
}