Files
UnrealEngineUWP/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessSelectionOutline.cpp
Jack Porter 1fdfd523ae Copying //UE4/Dev-Mobile to //UE4/Dev-Main (Source: //UE4/Dev-Mobile @ 3228013)
#lockdown Nick.Penwarden
#rb None

==========================
MAJOR FEATURES + CHANGES
==========================

Change 3156770 on 2016/10/10 by Allan.Bentham

	Fix VULKAN_ENABLE_API_DUMP build on android.

Change 3157838 on 2016/10/11 by Allan.Bentham

	Fix Vulkan API tracing on android.

Change 3170713 on 2016/10/21 by Steve.Cano

	Adding the "Optional Mobile Features BP Library" plugin to explose Blueprint functions for Sound Volume, Battery level, system temperature (only available on android), and Headphones being plugged in

	#jira UE-30896
	#android
	#ios
	#ue4

Change 3171064 on 2016/10/21 by Steve.Cano

	Plugins to provide a common interface and Android implemenation for providing access to GPS / Location data from Blueprints

	#ue4
	#android
	#jira UE-35917

Change 3171065 on 2016/10/21 by Steve.Cano

	IOS implementation of LocationServices plugin to provide access to location data in Blueprints

	#ue4
	#ios
	#jira UE-35917

Change 3181802 on 2016/11/01 by Steve.Cano

	Fix an issue introduced in CL 3170713 - Adding new config section to RequiredSections list so that we can generate projects successfully.

	#jira UE-30896
	#ios

Change 3181807 on 2016/11/01 by Steve.Cano

	Make sure to clear out references to our eglSurface when we destroy it, else we will try to set our context with an invalid surface.

	#jira UE-35004
	#android
	#ue4

Change 3184827 on 2016/11/03 by Allan.Bentham

	Do not HDR32 encode for views without view family.
	TranslucentAlphaOnly blend mode now works with encoding.
	#jira UE-37951

Change 3186684 on 2016/11/04 by Jack.Porter

	Merging //UE4/Dev-Main to Dev-Mobile (//UE4/Dev-Mobile)

Change 3188693 on 2016/11/07 by Chris.Babcock

	Corrections to memory stats for Android
	#jira WEX-3760
	#ue4
	#android

Change 3191538 on 2016/11/09 by Allan.Bentham

	Mobile tonemapper can use CVarTonemapperOverride

Change 3192575 on 2016/11/09 by Chris.Babcock

	Support placing UE4Game files in ExternalFilesDir for automatic cleanup on uninstall for distribution packages
	#jira UEPLAT-1422
	#ue4
	#android

Change 3196231 on 2016/11/13 by Jack.Porter

	Merging //UE4/Dev-Main to Dev-Mobile (//UE4/Dev-Mobile)

Change 3196538 on 2016/11/14 by Jack.Porter

	Fix issue where lighting would not build for the first editor session of projects defaulting to MobileHDR=false as HardwareTargetingModule didn't set cvars
	#jira UE-38507

Change 3198068 on 2016/11/15 by Dmitriy.Dyomin

	Fixed android console command sender to work with ADB version 1.0.36
	#jira UE-35171

Change 3200230 on 2016/11/16 by Jack.Porter

	Remove mosaic resolution limitation on ES3 devices
	#jira WEX-3119

Change 3201251 on 2016/11/16 by Chris.Babcock

	Fix Android compile error

Change 3203542 on 2016/11/18 by Jack.Porter

	Merging //UE4/Dev-Main to Dev-Mobile (//UE4/Dev-Mobile)

Change 3205598 on 2016/11/21 by Dmitriy.Dyomin

	Fixed: Missing selection outline in editor ES2 preview
	#jira UE-6458

Change 3205622 on 2016/11/21 by Dmitriy.Dyomin

	Fix ES2 build error from CL# 3205598

Change 3207232 on 2016/11/22 by Dmitriy.Dyomin

	ES2 GLSL generated shader simplifications

Change 3208608 on 2016/11/23 by Dmitriy.Dyomin

	Fixed: Landscape Grasstype warning causes log spam when landscape is streamed in or out
	#jira UE-38694

Change 3209135 on 2016/11/23 by Alicia.Cano

	Packaging for iOS fails due to several invalid object type errors
	#jira UE-38431
	#ios

Change 3209822 on 2016/11/24 by Jack.Porter

	IWYU changes for LocationServicesBPLibrary

Change 3209824 on 2016/11/24 by Jack.Porter

	Merging //UE4/Dev-Main to Dev-Mobile (//UE4/Dev-Mobile)

Change 3210264 on 2016/11/25 by Jack.Porter

	Fix unicode compile issue on Korean windows

Change 3210268 on 2016/11/25 by Jack.Porter

	IWYU and unicode fixes to Dev-Mobile

Change 3211800 on 2016/11/28 by Allan.Bentham

	Create and set PrimitiveSceneProxy->PrimitiveSceneInfo before SetTransform render thread command is enqueued. Avoids race condition with FPrimitiveSceneInfo's constructor which can occur on out-of-order CPUs.

Change 3212621 on 2016/11/28 by Jack.Porter

	More IWYU fixes.

Change 3213080 on 2016/11/29 by Allan.Bentham

	enable UseSingleSampleShadowFromStationaryLights on mobile.

	PR #2990: Fixes single sample shadows for mobile. (Contributed by kallehamalainen)

Change 3213164 on 2016/11/29 by Jack.Porter

	Win32 IWYU fix

Change 3213932 on 2016/11/29 by Chris.Babcock

	Fix handling of ETC2 filtering by Google Play Store (if only ETC2, require ES3.0+ but don't use texture filtering in manifest)
	#jira UE-39120
	#ue4
	#android

Change 3214563 on 2016/11/29 by Dmitriy.Dyomin

	Disable dynamic buffer discarding on Adreno330 (was casuing 10ms stalls on slate buffers update)

Change 3214571 on 2016/11/29 by Dmitriy.Dyomin

	Custom stencil on Mobile
	#jira UEMOB-183

Change 3214641 on 2016/11/30 by Dmitriy.Dyomin

	Disable distance culling when rendering image for world composition
	#jira UE-37754

Change 3214656 on 2016/11/30 by Jack.Porter

	Merging //UE4/Dev-Main to Dev-Mobile (//UE4/Dev-Mobile)

Change 3218479 on 2016/12/01 by Jack.Porter

	Fix for Vulkan build error when using AutoSDK

Change 3218596 on 2016/12/02 by Dmitriy.Dyomin

	Fixed: Android split screen multiplayer does not function or render correctly
	#jira UE-35204

Change 3218874 on 2016/12/02 by Allan.Bentham

	Fix CSM shadow bug when ES3.1 + mobileHDR == false.
	Fix inverted culling when rendering shadow depths with mobilehdr == false
	#jira UE-39111

Change 3220911 on 2016/12/04 by Jack.Porter

	Fixed landscape duplicated GUID detection and crash when one of the landscapes is in a hidden streaming level

Change 3220935 on 2016/12/04 by Jack.Porter

	Merging //UE4/Dev-Main to Dev-Mobile (//UE4/Dev-Mobile)

Change 3222831 on 2016/12/05 by Dmitriy.Dyomin

	Added support for MGD and Andreno profilers
	#jira UEMOB-184

Change 3222843 on 2016/12/05 by Jack.Porter

	Fixed bug caused by CL 3196538 causing r.MobileHDR to toggle and crash when opening render settings
	#jira UE-38507

Change 3222934 on 2016/12/06 by Jack.Porter

	Android graphics debugger text changes

Change 3223042 on 2016/12/06 by Dmitriy.Dyomin

	Fixed: missing GPU particles in LDR mode on device
	#jira UE-39363

Change 3223043 on 2016/12/06 by Jack.Porter

	Fixed logspam warnings from TcpMessaging launching on Android
	#jira UE-37895

Change 3223046 on 2016/12/06 by Allan.Bentham

	Move ES3.1 preview mode out of experimental.
	Add per device quality level preview to ES3.1 preview sub menu when project settings allow.

	#jira UEMOB-178

Change 3223113 on 2016/12/06 by Allan.Bentham

	changed MOBILE_EMULATION define for METAL_PROFILE on mac. fixes issues with editor primitive rendering with ES3.1 feature level preview.
	added -featureleveles2/31 commandline support to metalrhi.

Change 3223117 on 2016/12/06 by Allan.Bentham

	Initialise FPrimitiveSceneInfo::CachedReflectionCaptureProxies

Change 3223131 on 2016/12/06 by Allan.Bentham

	Fix translucency rendering when mobilehdr == false. (Disable mod shadows when mobilehdr == false.)
	#jira UE-38343

Change 3223162 on 2016/12/06 by Jack.Porter

	Disallow Absolute World Position with "excluding shader offset" on ES2
	#jra UE-25555

Change 3223204 on 2016/12/06 by Jack.Porter

	Fix for unable to save levels when landscape components with tessellation moved to another level
	#jira UE-39372

Change 3223677 on 2016/12/06 by Chris.Babcock

	Fix tabs

Change 3224139 on 2016/12/06 by Chris.Babcock

	Support modification of build.xml and add post import additions to GameActivity
	#jira UE-31372
	#PR #2440
	#ue4
	#android

Change 3224152 on 2016/12/06 by Chris.Babcock

	Add support for MadCatz C.T.R.L.R Android controller models
	#ue4
	#android

Change 3224162 on 2016/12/06 by Chris.Babcock

	Driver bug fix and using separate context for MediaPlayer14 (contributed by BrianHarris)
	#jira UE-35825
	#PR #2787
	#ue4
	#android

Change 3224581 on 2016/12/07 by Dmitriy.Dyomin

	Fixed black screen regression on iOS OpenGL
	Also now reporting shader compiler errors in iOS

Change 3224589 on 2016/12/07 by Allan.Bentham

	Increase mobile renderer's maximum CSM cascade limit to 4 and introduce max shadow cascade cvar for mobile which defaults to 2 retaining existing behaviour.
	#jira UEMOB-187

Change 3224774 on 2016/12/07 by Jack.Porter

	Added flags for mobile shader permutation reduction
	Renamed mobile lighting policies to better describe them
	Set flags to remove policies not used by SunTemple - saves 22MB package size on Android

	#jira: UEMOB-179

Change 3224782 on 2016/12/07 by Allan.Bentham

	Add project option to set maximum supported CSM cascades to mobile renderer.
	#jira UEMOB-187

Change 3224943 on 2016/12/07 by Dmitriy.Dyomin

	Metal iOS will use sRGB textures
	#jira UEMOB-189

Change 3225098 on 2016/12/07 by Dmitriy.Dyomin

	fix for compile error from 3224943

Change 3225188 on 2016/12/07 by Chris.Babcock

	Fix #includes in deferred Android OpenGL
	#jira UE-39440
	#ue4
	#android

Change 3226402 on 2016/12/07 by Dmitriy.Dyomin

	Fixed: wrong condition for r8 srgb on mac
	#jira UE-39471

Change 3226485 on 2016/12/08 by Dmitriy.Dyomin

	Fixed: Rendering Artifacts and invisible objects in Fortnite
	regression from nobile custom stencil changes
	#jira UE-39452, UE-39455

Change 3226637 on 2016/12/08 by Dmitriy.Dyomin

	Fixed: Odin Ensure Texture passed to ClearDepthStencil is not what is currently set as RenderTarget
	#jira UE-39482

Change 3226922 on 2016/12/08 by Jack.Porter

	Merging //UE4/Dev-Main to Dev-Mobile (//UE4/Dev-Mobile)

Change 3227353 on 2016/12/08 by Chris.Babcock

	Remove CopyVisualizers batch call again

Change 3228013 on 2016/12/08 By Chris.Babcock

	Merging //UE4/Dev-Main to Dev-Mobile (//UE4/Dev-Mobile)

[CL 3228374 by Jack Porter in Main branch]
2016-12-08 22:53:00 -05:00

409 lines
15 KiB
C++

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
/*=============================================================================
PostProcessSelectionOutline.cpp: Post processing outline effect.
=============================================================================*/
#include "PostProcess/PostProcessSelectionOutline.h"
#include "StaticBoundShaderState.h"
#include "SceneUtils.h"
#include "PostProcess/SceneRenderTargets.h"
#include "SceneRenderTargetParameters.h"
#include "SceneHitProxyRendering.h"
#include "ScenePrivate.h"
#include "EngineGlobals.h"
#if WITH_EDITOR
#include "PostProcess/PostProcessing.h"
#include "PostProcess/SceneFilterRendering.h"
///////////////////////////////////////////
// FRCPassPostProcessSelectionOutlineColor
///////////////////////////////////////////
void FRCPassPostProcessSelectionOutlineColor::Process(FRenderingCompositePassContext& Context)
{
#if WITH_EDITOR
SCOPED_DRAW_EVENT(Context.RHICmdList, PostProcessSelectionOutlineBuffer);
const FPooledRenderTargetDesc* SceneColorInputDesc = GetInputDesc(ePId_Input0);
if(!SceneColorInputDesc)
{
// input is not hooked up correctly
return;
}
const FViewInfo& View = Context.View;
FIntRect ViewRect = View.ViewRect;
FIntPoint SrcSize = SceneColorInputDesc->Extent;
FDrawingPolicyRenderState DrawRenderState(&Context.RHICmdList, View);
// Get the output render target
const FSceneRenderTargetItem& DestRenderTarget = PassOutputs[0].RequestSurface(Context);
// Set the render target/viewport.
SetRenderTarget(Context.RHICmdList, FTextureRHIParamRef(), DestRenderTarget.TargetableTexture);
// This is a reversed Z depth surface, so 0.0f is the far plane.
Context.RHICmdList.ClearDepthStencilTexture(DestRenderTarget.TargetableTexture, EClearDepthStencil::DepthStencil, (float)ERHIZBuffer::FarPlane, 0, FIntRect());
Context.SetViewportAndCallRHI(ViewRect);
if (View.Family->EngineShowFlags.Selection)
{
FHitProxyDrawingPolicyFactory::ContextType FactoryContext;
Context.RHICmdList.SetRasterizerState(TStaticRasterizerState<>::GetRHI());
DrawRenderState.SetBlendState(Context.RHICmdList, TStaticBlendStateWriteMask<CW_NONE, CW_NONE, CW_NONE, CW_NONE>::GetRHI());
// Note that the stencil value will overflow with enough selected objects
FEditorSelectionDrawingPolicy::ResetStencilValues();
// Run selection pass on static elements
FScene* Scene = View.Family->Scene->GetRenderScene();
if(Scene)
{
Scene->EditorSelectionDrawList.DrawVisible(Context.RHICmdList, View, DrawRenderState, View.StaticMeshEditorSelectionMap, View.StaticMeshBatchVisibility);
}
for (int32 MeshBatchIndex = 0; MeshBatchIndex < View.DynamicMeshElements.Num(); MeshBatchIndex++)
{
const FMeshBatchAndRelevance& MeshBatchAndRelevance = View.DynamicMeshElements[MeshBatchIndex];
const FPrimitiveSceneProxy* PrimitiveSceneProxy = MeshBatchAndRelevance.PrimitiveSceneProxy;
// Selected actors should be subdued if any component is individually selected
bool bActorSelectionColorIsSubdued = View.bHasSelectedComponents;
if (PrimitiveSceneProxy->IsSelected() && MeshBatchAndRelevance.Mesh->bUseSelectionOutline && PrimitiveSceneProxy->WantsSelectionOutline())
{
int32 StencilValue = 1;
if(PrimitiveSceneProxy->GetOwnerName() != NAME_BSP)
{
StencilValue = FEditorSelectionDrawingPolicy::GetStencilValue(View, PrimitiveSceneProxy);
}
// Note that the stencil value will overflow with enough selected objects
Context.RHICmdList.SetDepthStencilState(TStaticDepthStencilState<true, CF_DepthNearOrEqual, true, CF_Always, SO_Keep, SO_Keep, SO_Replace>::GetRHI(), StencilValue);
const FMeshBatch& MeshBatch = *MeshBatchAndRelevance.Mesh;
FHitProxyDrawingPolicyFactory::DrawDynamicMesh(Context.RHICmdList, View, FactoryContext, MeshBatch, true, DrawRenderState, MeshBatchAndRelevance.PrimitiveSceneProxy, MeshBatch.BatchHitProxyId);
}
}
// to get an outline around the objects if it's partly outside of the screen
{
FIntRect InnerRect = ViewRect;
// 1 as we have an outline that is that thick
InnerRect.InflateRect(-1);
// We could use Clear with InnerRect but this is just an optimization - on some hardware it might do a full clear (and we cannot disable yet)
// RHICmdList.Clear(false, FLinearColor(0, 0, 0, 0), true, 0.0f, true, 0, InnerRect);
// so we to 4 clears - one for each border.
// top
Context.RHICmdList.SetScissorRect(true, ViewRect.Min.X, ViewRect.Min.Y, ViewRect.Max.X, InnerRect.Min.Y);
//#todo-rco: Doesn't work on some RHIs!
Context.RHICmdList.ClearDepthStencilTexture(DestRenderTarget.TargetableTexture, EClearDepthStencil::DepthStencil, (float)ERHIZBuffer::FarPlane, 0, FIntRect());
// bottom
Context.RHICmdList.SetScissorRect(true, ViewRect.Min.X, InnerRect.Max.Y, ViewRect.Max.X, ViewRect.Max.Y);
//#todo-rco: Doesn't work on some RHIs!
Context.RHICmdList.ClearDepthStencilTexture(DestRenderTarget.TargetableTexture, EClearDepthStencil::DepthStencil, (float)ERHIZBuffer::FarPlane, 0, FIntRect());
// left
Context.RHICmdList.SetScissorRect(true, ViewRect.Min.X, ViewRect.Min.Y, InnerRect.Min.X, ViewRect.Max.Y);
//#todo-rco: Doesn't work on some RHIs!
Context.RHICmdList.ClearDepthStencilTexture(DestRenderTarget.TargetableTexture, EClearDepthStencil::DepthStencil, (float)ERHIZBuffer::FarPlane, 0, FIntRect());
// right
Context.RHICmdList.SetScissorRect(true, InnerRect.Max.X, ViewRect.Min.Y, ViewRect.Max.X, ViewRect.Max.Y);
//#todo-rco: Doesn't work on some RHIs!
Context.RHICmdList.ClearDepthStencilTexture(DestRenderTarget.TargetableTexture, EClearDepthStencil::DepthStencil, (float)ERHIZBuffer::FarPlane, 0, FIntRect());
Context.RHICmdList.SetScissorRect(false, 0, 0, 0, 0);
}
}
// Resolve to the output
Context.RHICmdList.CopyToResolveTarget(DestRenderTarget.TargetableTexture, DestRenderTarget.ShaderResourceTexture, false, FResolveParams());
#endif
}
FPooledRenderTargetDesc FRCPassPostProcessSelectionOutlineColor::ComputeOutputDesc(EPassOutputId InPassOutputId) const
{
FPooledRenderTargetDesc Ret = GetInput(ePId_Input0)->GetOutput()->RenderTargetDesc;
Ret.Reset();
Ret.Format = PF_DepthStencil;
Ret.Flags = TexCreate_None;
//mark targetable as TexCreate_ShaderResource because we actually do want to sample from the unresolved MSAA target in this case.
Ret.TargetableFlags = TexCreate_DepthStencilTargetable | TexCreate_ShaderResource;
Ret.DebugName = TEXT("SelectionDepthStencil");
Ret.NumSamples = FSceneRenderTargets::Get_FrameConstantsOnly().GetEditorMSAACompositingSampleCount();
return Ret;
}
///////////////////////////////////////////
// FRCPassPostProcessSelectionOutline
///////////////////////////////////////////
/**
* Pixel shader for rendering the selection outline
*/
template<uint32 MSAASampleCount>
class FPostProcessSelectionOutlinePS : public FGlobalShader
{
DECLARE_SHADER_TYPE(FPostProcessSelectionOutlinePS, Global);
static bool ShouldCache(EShaderPlatform Platform)
{
if(!IsFeatureLevelSupported(Platform, ERHIFeatureLevel::SM5))
{
if(MSAASampleCount > 1)
{
return false;
}
}
return IsPCPlatform(Platform);
}
static void ModifyCompilationEnvironment(EShaderPlatform Platform, FShaderCompilerEnvironment& OutEnvironment)
{
FGlobalShader::ModifyCompilationEnvironment(Platform, OutEnvironment);
OutEnvironment.SetDefine( TEXT("MSAA_SAMPLE_COUNT"), MSAASampleCount);
}
/** Default constructor. */
FPostProcessSelectionOutlinePS() {}
public:
FPostProcessPassParameters PostprocessParameter;
FDeferredPixelShaderParameters DeferredParameters;
FShaderParameter OutlineColor;
FShaderParameter SubduedOutlineColor;
FShaderParameter BSPSelectionIntensity;
FShaderResourceParameter PostprocessInput1MS;
FShaderResourceParameter EditorPrimitivesStencil;
FShaderParameter EditorRenderParams;
/** Initialization constructor. */
FPostProcessSelectionOutlinePS(const ShaderMetaType::CompiledShaderInitializerType& Initializer)
: FGlobalShader(Initializer)
{
PostprocessParameter.Bind(Initializer.ParameterMap);
DeferredParameters.Bind(Initializer.ParameterMap);
OutlineColor.Bind(Initializer.ParameterMap, TEXT("OutlineColor"));
SubduedOutlineColor.Bind(Initializer.ParameterMap, TEXT("SubduedOutlineColor"));
BSPSelectionIntensity.Bind(Initializer.ParameterMap, TEXT("BSPSelectionIntensity"));
PostprocessInput1MS.Bind(Initializer.ParameterMap, TEXT("PostprocessInput1MS"));
EditorRenderParams.Bind(Initializer.ParameterMap, TEXT("EditorRenderParams"));
EditorPrimitivesStencil.Bind(Initializer.ParameterMap,TEXT("EditorPrimitivesStencil"));
}
void SetPS(const FRenderingCompositePassContext& Context)
{
const FPixelShaderRHIParamRef ShaderRHI = GetPixelShader();
FGlobalShader::SetParameters(Context.RHICmdList, ShaderRHI, Context.View);
DeferredParameters.Set(Context.RHICmdList, ShaderRHI, Context.View);
const FPostProcessSettings& Settings = Context.View.FinalPostProcessSettings;
const FSceneViewFamily& ViewFamily = *(Context.View.Family);
FSceneViewState* ViewState = (FSceneViewState*)Context.View.State;
PostprocessParameter.SetPS(ShaderRHI, Context, TStaticSamplerState<SF_Point,AM_Clamp,AM_Clamp,AM_Clamp>::GetRHI());
// PostprocessInput1MS and EditorPrimitivesStencil
{
FRenderingCompositeOutputRef* OutputRef = Context.Pass->GetInput(ePId_Input1);
check(OutputRef);
FRenderingCompositeOutput* Input = OutputRef->GetOutput();
check(Input);
TRefCountPtr<IPooledRenderTarget> InputPooledElement = Input->RequestInput();
check(InputPooledElement);
FTexture2DRHIRef& TargetableTexture = (FTexture2DRHIRef&)InputPooledElement->GetRenderTargetItem().TargetableTexture;
SetTextureParameter(Context.RHICmdList, ShaderRHI, PostprocessInput1MS, TargetableTexture);
if(EditorPrimitivesStencil.IsBound())
{
// cache the stencil SRV to avoid create calls each frame (the cache element is stored in the state)
if(ViewState->SelectionOutlineCacheKey != TargetableTexture)
{
// release if not the right one (as the internally SRV stores a pointer to the texture we cannot get a false positive)
ViewState->SelectionOutlineCacheKey.SafeRelease();
ViewState->SelectionOutlineCacheValue.SafeRelease();
}
if(!ViewState->SelectionOutlineCacheValue)
{
// create if needed
ViewState->SelectionOutlineCacheKey = TargetableTexture;
ViewState->SelectionOutlineCacheValue = RHICreateShaderResourceView(TargetableTexture, 0, 1, PF_X24_G8);
}
SetSRVParameter(Context.RHICmdList, ShaderRHI, EditorPrimitivesStencil, ViewState->SelectionOutlineCacheValue);
}
}
#if WITH_EDITOR
{
FLinearColor OutlineColorValue = Context.View.SelectionOutlineColor;
FLinearColor SubduedOutlineColorValue = Context.View.SubduedSelectionOutlineColor;
OutlineColorValue.A = GEngine->SelectionHighlightIntensity;
SetShaderValue(Context.RHICmdList, ShaderRHI, OutlineColor, OutlineColorValue);
SetShaderValue(Context.RHICmdList, ShaderRHI, SubduedOutlineColor, SubduedOutlineColorValue);
SetShaderValue(Context.RHICmdList, ShaderRHI, BSPSelectionIntensity, GEngine->BSPSelectionHighlightIntensity);
}
#else
check(!"This shader is not used outside of the Editor.");
#endif
{
static const auto CVar = IConsoleManager::Get().FindTConsoleVariableDataFloat(TEXT("r.Editor.MovingPattern"));
FLinearColor Value(0, CVar->GetValueOnRenderThread(), 0, 0);
if(!ViewFamily.bRealtimeUpdate)
{
// no animation if realtime update is disabled
Value.G = 0;
}
SetShaderValue(Context.RHICmdList, ShaderRHI, EditorRenderParams, Value);
}
}
// FShader interface.
virtual bool Serialize(FArchive& Ar) override
{
bool bShaderHasOutdatedParameters = FGlobalShader::Serialize(Ar);
Ar << PostprocessParameter << OutlineColor << SubduedOutlineColor << BSPSelectionIntensity << DeferredParameters << PostprocessInput1MS << EditorPrimitivesStencil << EditorRenderParams;
return bShaderHasOutdatedParameters;
}
static const TCHAR* GetSourceFilename()
{
return TEXT("PostProcessSelectionOutline");
}
static const TCHAR* GetFunctionName()
{
return TEXT("MainPS");
}
};
// #define avoids a lot of code duplication
#define VARIATION1(A) typedef FPostProcessSelectionOutlinePS<A> FPostProcessSelectionOutlinePS##A; \
IMPLEMENT_SHADER_TYPE2(FPostProcessSelectionOutlinePS##A, SF_Pixel);
VARIATION1(1) VARIATION1(2) VARIATION1(4) VARIATION1(8)
#undef VARIATION1
template <uint32 MSAASampleCount>
static void SetSelectionOutlineShaderTempl(const FRenderingCompositePassContext& Context)
{
TShaderMapRef<FPostProcessVS> VertexShader(Context.GetShaderMap());
TShaderMapRef<FPostProcessSelectionOutlinePS<MSAASampleCount> > PixelShader(Context.GetShaderMap());
static FGlobalBoundShaderState BoundShaderState;
SetGlobalBoundShaderState(Context.RHICmdList, Context.GetFeatureLevel(), BoundShaderState, GFilterVertexDeclaration.VertexDeclarationRHI, *VertexShader, *PixelShader);
PixelShader->SetPS(Context);
}
void FRCPassPostProcessSelectionOutline::Process(FRenderingCompositePassContext& Context)
{
SCOPED_DRAW_EVENT(Context.RHICmdList, PostProcessSelectionOutline);
const FPooledRenderTargetDesc* SceneColorInputDesc = GetInputDesc(ePId_Input0);
const FPooledRenderTargetDesc* SelectionColorInputDesc = GetInputDesc(ePId_Input1);
if (!SceneColorInputDesc || !SelectionColorInputDesc)
{
// input is not hooked up correctly
return;
}
const FSceneView& View = Context.View;
FIntRect ViewRect = View.ViewRect;
FIntPoint SrcSize = SceneColorInputDesc->Extent;
const FSceneRenderTargetItem& DestRenderTarget = PassOutputs[0].RequestSurface(Context);
// Set the view family's render target/viewport.
SetRenderTarget(Context.RHICmdList, DestRenderTarget.TargetableTexture, FTextureRHIRef());
Context.SetViewportAndCallRHI(ViewRect);
// set the state
Context.RHICmdList.SetBlendState(TStaticBlendState<>::GetRHI());
Context.RHICmdList.SetRasterizerState(TStaticRasterizerState<>::GetRHI());
Context.RHICmdList.SetDepthStencilState(TStaticDepthStencilState<false, CF_Always>::GetRHI());
const uint32 MSAASampleCount = FSceneRenderTargets::Get(Context.RHICmdList).GetEditorMSAACompositingSampleCount();
if(MSAASampleCount == 1)
{
SetSelectionOutlineShaderTempl<1>(Context);
}
else if(MSAASampleCount == 2)
{
SetSelectionOutlineShaderTempl<2>(Context);
}
else if(MSAASampleCount == 4)
{
SetSelectionOutlineShaderTempl<4>(Context);
}
else if(MSAASampleCount == 8)
{
SetSelectionOutlineShaderTempl<8>(Context);
}
else
{
// not supported, internal error
check(0);
}
// Draw a quad mapping scene color to the view's render target
TShaderMapRef<FPostProcessVS> VertexShader(Context.GetShaderMap());
DrawRectangle(
Context.RHICmdList,
0, 0,
ViewRect.Width(), ViewRect.Height(),
ViewRect.Min.X, ViewRect.Min.Y,
ViewRect.Width(), ViewRect.Height(),
ViewRect.Size(),
SrcSize,
*VertexShader,
EDRF_UseTriangleOptimization);
Context.RHICmdList.CopyToResolveTarget(DestRenderTarget.TargetableTexture, DestRenderTarget.ShaderResourceTexture, false, FResolveParams());
}
FPooledRenderTargetDesc FRCPassPostProcessSelectionOutline::ComputeOutputDesc(EPassOutputId InPassOutputId) const
{
FPooledRenderTargetDesc Ret = GetInput(ePId_Input0)->GetOutput()->RenderTargetDesc;
Ret.DebugName = TEXT("SelectionComposited");
return Ret;
}
#endif