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 2981877 on 2016/05/18 by Rolando.Caloca
DR - Fix some PVS warnings
- Removed 'uniform' as a keyword on hlslcc as it's ignored/causes issues/doesn't really optimize
#jira UE-30996
Change 2981966 on 2016/05/18 by Rolando.Caloca
DR - Fix OpenGL crash quitting editor
#jira UE-25549
Change 2982072 on 2016/05/18 by Uriel.Doyon
Fixed a "Build Texture Streaming" crash related to custom outputs.
Fixed issue with debug view mode and translucent primitives
Fix bug with visibility that made some texture low res.
Enabled per instance visibility in the texture streaming order (in game only).
Improved InvestigateTexture Logs.
Tweaked the mip computations from screen size.
Change 2982077 on 2016/05/18 by Uriel.Doyon
Removed debug options!
Change 2982108 on 2016/05/18 by Olaf.Piesche
#jira UE-30772
moving AMD hacks to console variables
Change 2982422 on 2016/05/18 by Gil.Gribb
UE4 - Potential crash fix on foliage occlusion queries and reflection captures.
Change 2982547 on 2016/05/18 by Martin.Mittring
UE-26409 Crash when Light Propagation Volume Plugin is disabled on a Project
Change 2982548 on 2016/05/18 by Martin.Mittring
Refactored MRT and outer Pixel Shader output to a struct
to allow it passed in/out of functions allowing for a more readable code (less #ifdefs, reducing the boolean hell)
Needed for upcoming MeshDecals
Change 2982601 on 2016/05/18 by Daniel.Wright
Movable skylight now matches stationary for subsurface shading models
* Two sided was broken in 4.11, Subsurface had never been handled
Change 2982603 on 2016/05/18 by Daniel.Wright
DrawMaterialToRenderTarget / BeginDrawCanvasToRenderTarget now work correctly with material parameter collections and Time
* FCanvas stores an optional scene to render to, UWorld caches the UCanvas needed for implementing these functions
Change 2982618 on 2016/05/18 by Daniel.Wright
Better categories for some Rendering project settings
Change 2982619 on 2016/05/18 by Daniel.Wright
Scene capture 2d improvements
* Orthographic projection supported
* Opacity is now captured in alpha, allows partial rendering in a scene capture and compositing into another scene later
* Various GBuffer attributes are now available to be captured, including depth
* Changed Blueprint capture function to CaptureScene, which happens immediately (was previously deferred), allowing multiple captures with different parameters
Change 2982664 on 2016/05/18 by Daniel.Wright
Fading out planar reflections based on roughness since they don't have support for variable roughness (fade starts at .2 roughness, ends at .3)
Change 2982684 on 2016/05/18 by Martin.Mittring
polish ImageValidator
Change 2982685 on 2016/05/18 by Martin.Mittring
show testimage on sm4 as well
Change 2982736 on 2016/05/18 by Uriel.Doyon
Improved overbudget retention logic.
Updated ListStreamingTextures stats.
Change 2982854 on 2016/05/18 by Martin.Mittring
ImageValidator can now save/load IVxml file
Change 2982863 on 2016/05/18 by Daniel.Wright
Fixed shader compile error
Change 2982864 on 2016/05/18 by Daniel.Wright
Removed deprecation message
Change 2982927 on 2016/05/18 by Martin.Mittring
ImageValidator is now sorting by time
Change 2983743 on 2016/05/19 by Chris.Bunner
Saturated tri-planar UV function outputs to prevent negative blending
#jira UE-30964
Change 2983747 on 2016/05/19 by Martin.Wilson
Fix for morph curves not getting applied to meshes in cooked builds (smart names were not being corrected).
Change 2984008 on 2016/05/19 by Brian.Karis
New contact shadows feature.
Hair uses ray cast for nonshadow lights
Change 2984009 on 2016/05/19 by Brian.Karis
changed to ShadowedBits
Change 2984054 on 2016/05/19 by Brian.Karis
Deleted old motion blur
Change 2984420 on 2016/05/19 by Daniel.Wright
Shorter display name for WorldPosition material node
Change 2984423 on 2016/05/19 by Daniel.Wright
Fixed WorldPosition and ScreenPosition for downsampled separate translucency by scaling SvPosition before those computations. The View uniform buffer still contains incorrect buffer sizes for this pass.
Change 2984432 on 2016/05/19 by Rolando.Caloca
DR - Disable PPCombineLUT for Vulkan to work around glslang issue (will need to be reenabled when adding SM4/5 path)
Change 2985415 on 2016/05/20 by Daniel.Wright
Added a Texture2D exporter for .hdr
Texture2D exporters now implement SupportsObject properly, so you only see extensions that are valid based on the format
Change 2985439 on 2016/05/20 by Daniel.Wright
Scene color alpha clear value validation
Change 2987173 on 2016/05/23 by Martin.Mittring
ImageValidator Report with Thumbnail (cannot be copied and pasted into email), non Thumbnail version could be.
Change 2987248 on 2016/05/23 by Martin.Mittring
ImageValidator: added Summary, removed timer hack
Change 2987369 on 2016/05/23 by Martin.Mittring
ImageValidator polish
Change 2987390 on 2016/05/23 by Brian.Karis
Improvement to temporal aa sharpness and speed.
Change 2988038 on 2016/05/24 by Gil.Gribb
Merging //UE4/Dev-Main@2987977 to Dev-Rendering (//UE4/Dev-Rendering)
Change 2988304 on 2016/05/24 by Martin.Mittring
added const to prevent coding errors
Change 2988332 on 2016/05/24 by Brian.Karis
Fixed motion blur crash on SM4
Change 2988446 on 2016/05/24 by Martin.Mittring
nicer UI
Change 2988990 on 2016/05/24 by Martin.Mittring
fixed UE-31227 Building lighting produces bad results
#jira:UE-31227
Change 2989729 on 2016/05/25 by Uriel.Doyon
Fixed lightmaps and shadowmaps having low resolutions after building the lighting.
#jira UE-31254
Change 2989752 on 2016/05/25 by Olaf.Piesche
CVar to disable/freeze GPU particle simulation
Change 2989811 on 2016/05/25 by Daniel.Wright
Making use of MATERIALBLENDING_ANY_TRANSLUCENT
Change 2989812 on 2016/05/25 by Daniel.Wright
Hide DFGI show flags from UI
Change 2989901 on 2016/05/25 by Daniel.Wright
Height fog now works properly in planar reflections
* The ray used for computing fog is first clipped by the reflection plane
Change 2989904 on 2016/05/25 by Daniel.Wright
Always use PF_FloatRGBA for LightAccumulation to guarantee alpha channel and negative range
Change 2989991 on 2016/05/25 by Daniel.Wright
Improved usability for DBuffer Decals
* 'Show Decals' works correctly, previously would fetch from uninitialized textures
* DBuffer being enabled forces a full prepass, previously decals would render incorrectly unless correct settings of r.EarlyZPass were used
* Improved the PrePass draw event to indicate whether it's full or partial
* Materials using DBuffer blend modes will fail to compile when the DBuffer project setting is disabled, instead of just being invisible
* r.EarlyZPass can now be changed at runtime, which is useful for profiling
Change 2990008 on 2016/05/25 by Daniel.Wright
Fixed capsule shadows on skeletal meshes with scaling
Change 2990274 on 2016/05/25 by Daniel.Wright
Fixed DFAO (from cl 2961310)
Change 2990304 on 2016/05/25 by Martin.Mittring
OR-22233 GPU Sprites invisible unless solo'd
#jira:OR-22233
Change 2990309 on 2016/05/25 by Martin.Mittring
Added SubDSurface actor (using CPU code of OpenSubDiv), component, asset as starting point for more work in that direction,
(Early work in progress)
Change 2990363 on 2016/05/25 by Daniel.Wright
Spreading precomputed visibility to neighbors now uses a 2d grid to find neighbors, speeds up the process for 800k cells from 40 mins to 20s
Change 2990392 on 2016/05/25 by Daniel.Wright
Added r.AOSpecularOcclusionMode, which determines how specular should be occluded by DFAO
0: Apply non-directional AO to specular.
1: (default) Intersect the reflection cone with the unoccluded cone produced by DFAO. This gives more accurate occlusion than 0, but can bring out DFAO sampling artifacts.
2: (experimental) Cone trace through distance fields along the reflection vector. Costs about the same as DFAO again because more cone tracing is done, but produces more accurate occlusion.
Change 2990454 on 2016/05/25 by Martin.Mittring
polish readme
Change 2990610 on 2016/05/25 by Martin.Mittring
fixed building with VS2015, the right OpenSubDiv .lib files are missing, temporarily disabled the relevant code
#code_review:Shane.Caudle
Change 2990754 on 2016/05/25 by Zabir.Hoque
Fix compiler warning: C4456: declaration of 'NewStaticMesh' hides previous local declaration.
#CodeReview: Martin.Mittring
Change 2990801 on 2016/05/25 by Zabir.Hoque
Only allocate reflection capture cubemaps if we are actually doing a reflection capture. The old approach always allocated based on CVar and worked with a warning on D3D since if SRC was larger than the DST, the extra SRC area was dropped. New approach only allocates when necessary and is correctly sized everytime. Also hardened access to CVar and what users are allowed to set.
#CodeReview Marcus.Wassmer, Rolando.Caloca, Daniel.Wright, Martin.Mittring
Change 2991169 on 2016/05/26 by Martin.Mittring
fixed compiler warning
WARNING: Non-editor build cannot depend on non-redistributable modules. Details:
#lockdown: gil.gribb
Change 2991238 on 2016/05/26 by Martin.Mittring
fixed build
fatal error C1083: Cannot open include file: 'RawMesh.h': No such file or directory (when RawMesh is not part of PrivateDependencyModuleNames in Engine.Build.cs)
#lockdown:Gil.Gribb
Change 2991726 on 2016/05/26 by Daniel.Wright
Subsurface materials are now handled with simple forward shading
#jira OR-22237
#lockdown gil.gribb
Change 2991727 on 2016/05/26 by Daniel.Wright
Emissive decals are now supported with simple forward shading
#jira OR-22282
#lockdown Gil.Gribb
Change 2994849 on 2016/05/31 by Daniel.Wright
Disabled fix for WorldPosition and ScreenPosition in downsampled separate translucency, since it breaks GetScreenAlignedUV (used in DepthFade), since the uniform buffer still contains full res buffer sizes
#lockdown Gil.Gribb
Change 2997243 on 2016/06/01 by Gil.Gribb
Merging //UE4/Dev-Main@2996565 to Dev-Rendering (//UE4/Dev-Rendering)
#lockdown nick.penwarden
[CL 2998067 by Gil Gribb in Main branch]
1090 lines
33 KiB
C++
1090 lines
33 KiB
C++
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
|
|
|
|
/*=============================================================================
|
|
RenderingCompositionGraph.cpp: Scene pass order and dependency system.
|
|
=============================================================================*/
|
|
|
|
#include "RendererPrivate.h"
|
|
#include "RenderingCompositionGraph.h"
|
|
#include "HighResScreenshot.h"
|
|
#include "IHeadMountedDisplay.h"
|
|
|
|
void ExecuteCompositionGraphDebug();
|
|
|
|
static TAutoConsoleVariable<int32> CVarCompositionGraphOrder(
|
|
TEXT("r.CompositionGraphOrder"),
|
|
1,
|
|
TEXT("Defines in which order the nodes in the CompositionGraph are executed (affects postprocess and some lighting).\n")
|
|
TEXT("Option 1 provides more control, which can be useful for preserving ESRAM, avoid GPU sync, cluster up compute shaders for performance and control AsyncCompute.\n")
|
|
TEXT(" 0: tree order starting with the root, first all inputs then dependencies (classic UE4, unconnected nodes are not getting executed)\n")
|
|
TEXT(" 1: RegisterPass() call order, unless the dependencies (input and additional) require a different order (might become new default as it provides more control, executes all registered nodes)"),
|
|
ECVF_RenderThreadSafe);
|
|
|
|
#if !UE_BUILD_SHIPPING
|
|
FAutoConsoleCommand CmdCompositionGraphDebug(
|
|
TEXT("r.CompositionGraphDebug"),
|
|
TEXT("Execute this command to get a single frame dump of the composition graph of one frame (post processing and lighting)."),
|
|
FConsoleCommandDelegate::CreateStatic(ExecuteCompositionGraphDebug)
|
|
);
|
|
#endif
|
|
|
|
|
|
// render thread, 0:off, >0 next n frames should be debugged
|
|
uint32 GDebugCompositionGraphFrames = 0;
|
|
|
|
class FGMLFileWriter
|
|
{
|
|
public:
|
|
// constructor
|
|
FGMLFileWriter()
|
|
: GMLFile(0)
|
|
{
|
|
}
|
|
|
|
void OpenGMLFile(const TCHAR* Name)
|
|
{
|
|
#if !UE_BUILD_SHIPPING
|
|
// todo: do we need to create the directory?
|
|
FString FilePath = FPaths::ScreenShotDir() + TEXT("/") + Name + TEXT(".gml");
|
|
GMLFile = IFileManager::Get().CreateDebugFileWriter(*FilePath);
|
|
#endif
|
|
}
|
|
|
|
void CloseGMLFile()
|
|
{
|
|
#if !UE_BUILD_SHIPPING
|
|
if(GMLFile)
|
|
{
|
|
delete GMLFile;
|
|
GMLFile = 0;
|
|
}
|
|
#endif
|
|
}
|
|
|
|
// .GML file is to visualize the post processing graph as a 2d graph
|
|
void WriteLine(const char* Line)
|
|
{
|
|
#if !UE_BUILD_SHIPPING
|
|
if(GMLFile)
|
|
{
|
|
GMLFile->Serialize((void*)Line, FCStringAnsi::Strlen(Line));
|
|
GMLFile->Serialize((void*)"\r\n", 2);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
private:
|
|
FArchive* GMLFile;
|
|
};
|
|
|
|
FGMLFileWriter GGMLFileWriter;
|
|
|
|
|
|
bool ShouldDebugCompositionGraph()
|
|
{
|
|
#if !UE_BUILD_SHIPPING
|
|
return GDebugCompositionGraphFrames > 0;
|
|
#else
|
|
return false;
|
|
#endif
|
|
}
|
|
|
|
void Test()
|
|
{
|
|
struct ObjectSize4
|
|
{
|
|
void SetBaseValues(){}
|
|
static FName GetFName()
|
|
{
|
|
static const FName Name(TEXT("ObjectSize4"));
|
|
return Name;
|
|
}
|
|
uint8 Data[4];
|
|
};
|
|
|
|
MS_ALIGN(16) struct ObjectAligned16
|
|
{
|
|
void SetBaseValues(){}
|
|
static FName GetFName()
|
|
{
|
|
static const FName Name(TEXT("ObjectAligned16"));
|
|
return Name;
|
|
}
|
|
uint8 Data[16];
|
|
} GCC_ALIGN(16);
|
|
|
|
// https://udn.unrealengine.com/questions/274066/fblendablemanager-returning-wrong-or-misaligned-da.html
|
|
FBlendableManager Manager;
|
|
Manager.GetSingleFinalData<ObjectSize4>();
|
|
ObjectAligned16& AlignedData = Manager.GetSingleFinalData<ObjectAligned16>();
|
|
|
|
check((reinterpret_cast<ptrdiff_t>(&AlignedData) & 16) == 0);
|
|
}
|
|
|
|
void ExecuteCompositionGraphDebug()
|
|
{
|
|
ENQUEUE_UNIQUE_RENDER_COMMAND(
|
|
StartDebugCompositionGraph,
|
|
{
|
|
GDebugCompositionGraphFrames = 1;
|
|
Test();
|
|
}
|
|
);
|
|
}
|
|
|
|
// main thread
|
|
void CompositionGraph_OnStartFrame()
|
|
{
|
|
#if !UE_BUILD_SHIPPING
|
|
ENQUEUE_UNIQUE_RENDER_COMMAND(
|
|
DebugCompositionGraphDec,
|
|
{
|
|
if(GDebugCompositionGraphFrames)
|
|
{
|
|
--GDebugCompositionGraphFrames;
|
|
}
|
|
}
|
|
);
|
|
#endif
|
|
}
|
|
|
|
FRenderingCompositePassContext::FRenderingCompositePassContext(FRHICommandListImmediate& InRHICmdList, const FViewInfo& InView)
|
|
: View(InView)
|
|
, ViewState((FSceneViewState*)InView.State)
|
|
, Pass(0)
|
|
, RHICmdList(InRHICmdList)
|
|
, ViewPortRect(0, 0, 0 ,0)
|
|
, FeatureLevel(View.GetFeatureLevel())
|
|
, ShaderMap(InView.ShaderMap)
|
|
, bWasProcessed(false)
|
|
, bHasHmdMesh(false)
|
|
{
|
|
check(!IsViewportValid());
|
|
}
|
|
|
|
FRenderingCompositePassContext::~FRenderingCompositePassContext()
|
|
{
|
|
Graph.Free();
|
|
}
|
|
|
|
void FRenderingCompositePassContext::Process(FRenderingCompositePass* Root, const TCHAR *GraphDebugName)
|
|
{
|
|
// call this method only once after the graph is finished
|
|
check(!bWasProcessed);
|
|
|
|
bWasProcessed = true;
|
|
|
|
// query if we have a custom HMD post process mesh to use
|
|
static const auto* const HiddenAreaMaskCVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("vr.HiddenAreaMask"));
|
|
bHasHmdMesh = (HiddenAreaMaskCVar != nullptr &&
|
|
HiddenAreaMaskCVar->GetValueOnRenderThread() == 1 &&
|
|
GEngine &&
|
|
GEngine->HMDDevice.IsValid() &&
|
|
GEngine->HMDDevice->HasVisibleAreaMesh());
|
|
|
|
if(Root)
|
|
{
|
|
if(ShouldDebugCompositionGraph())
|
|
{
|
|
UE_LOG(LogConsoleResponse,Log, TEXT(""));
|
|
UE_LOG(LogConsoleResponse,Log, TEXT("FRenderingCompositePassContext:Debug '%s' ---------"), GraphDebugName);
|
|
UE_LOG(LogConsoleResponse,Log, TEXT(""));
|
|
|
|
GGMLFileWriter.OpenGMLFile(GraphDebugName);
|
|
GGMLFileWriter.WriteLine("Creator \"UnrealEngine4\"");
|
|
GGMLFileWriter.WriteLine("Version \"2.10\"");
|
|
GGMLFileWriter.WriteLine("graph");
|
|
GGMLFileWriter.WriteLine("[");
|
|
GGMLFileWriter.WriteLine("\tcomment\t\"This file can be viewed with yEd from yWorks. Run Layout/Hierarchical after loading.\"");
|
|
GGMLFileWriter.WriteLine("\thierarchic\t1");
|
|
GGMLFileWriter.WriteLine("\tdirected\t1");
|
|
}
|
|
|
|
bool bNewOrder = CVarCompositionGraphOrder.GetValueOnRenderThread() != 0;
|
|
|
|
Graph.RecursivelyGatherDependencies(Root);
|
|
|
|
if(bNewOrder)
|
|
{
|
|
// process in the order the nodes have been created (for more control), unless the dependencies require it differently
|
|
for (FRenderingCompositePass* Node : Graph.Nodes)
|
|
{
|
|
// only if this is true the node is actually needed - no need to compute it when it's not needed
|
|
if(Node->WasComputeOutputDescCalled())
|
|
{
|
|
Graph.RecursivelyProcess(Node, *this);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// process in the order of the dependencies, starting from the root (without processing unreferenced nodes)
|
|
Graph.RecursivelyProcess(Root, *this);
|
|
}
|
|
|
|
if(ShouldDebugCompositionGraph())
|
|
{
|
|
UE_LOG(LogConsoleResponse,Log, TEXT(""));
|
|
|
|
GGMLFileWriter.WriteLine("]");
|
|
GGMLFileWriter.CloseGMLFile();
|
|
}
|
|
}
|
|
}
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
FRenderingCompositionGraph::FRenderingCompositionGraph()
|
|
{
|
|
}
|
|
|
|
FRenderingCompositionGraph::~FRenderingCompositionGraph()
|
|
{
|
|
Free();
|
|
}
|
|
|
|
void FRenderingCompositionGraph::Free()
|
|
{
|
|
for(uint32 i = 0; i < (uint32)Nodes.Num(); ++i)
|
|
{
|
|
FRenderingCompositePass *Element = Nodes[i];
|
|
if (FMemStack::Get().ContainsPointer(Element))
|
|
{
|
|
Element->~FRenderingCompositePass();
|
|
}
|
|
else
|
|
{
|
|
// Call release on non-stack allocated elements
|
|
Element->Release();
|
|
}
|
|
}
|
|
|
|
Nodes.Empty();
|
|
}
|
|
|
|
void FRenderingCompositionGraph::RecursivelyGatherDependencies(FRenderingCompositePass *Pass)
|
|
{
|
|
checkSlow(Pass);
|
|
|
|
if(Pass->bComputeOutputDescWasCalled)
|
|
{
|
|
// already processed
|
|
return;
|
|
}
|
|
Pass->bComputeOutputDescWasCalled = true;
|
|
|
|
// iterate through all inputs and additional dependencies of this pass
|
|
uint32 Index = 0;
|
|
while(const FRenderingCompositeOutputRef* OutputRefIt = Pass->GetDependency(Index++))
|
|
{
|
|
FRenderingCompositeOutput* InputOutput = OutputRefIt->GetOutput();
|
|
|
|
if(InputOutput)
|
|
{
|
|
// add a dependency to this output as we are referencing to it
|
|
InputOutput->AddDependency();
|
|
}
|
|
|
|
if(FRenderingCompositePass* OutputRefItPass = OutputRefIt->GetPass())
|
|
{
|
|
// recursively process all inputs of this Pass
|
|
RecursivelyGatherDependencies(OutputRefItPass);
|
|
}
|
|
}
|
|
|
|
// the pass is asked what the intermediate surface/texture format needs to be for all its outputs.
|
|
for(uint32 OutputId = 0; ; ++OutputId)
|
|
{
|
|
EPassOutputId PassOutputId = (EPassOutputId)(OutputId);
|
|
FRenderingCompositeOutput* Output = Pass->GetOutput(PassOutputId);
|
|
|
|
if(!Output)
|
|
{
|
|
break;
|
|
}
|
|
|
|
Output->RenderTargetDesc = Pass->ComputeOutputDesc(PassOutputId);
|
|
}
|
|
}
|
|
|
|
template<typename TColor> struct TAsyncBufferWrite;
|
|
|
|
struct FAsyncBufferWriteQueue
|
|
{
|
|
template<typename T>
|
|
static TFuture<void> Dispatch(TAsyncBufferWrite<T>&& In)
|
|
{
|
|
NumInProgressWrites.Increment();
|
|
|
|
while (NumInProgressWrites.GetValue() >= MaxAsyncWrites)
|
|
{
|
|
// Yield until we can write another
|
|
FPlatformProcess::Sleep(0.f);
|
|
}
|
|
|
|
return Async<void>(EAsyncExecution::ThreadPool, MoveTemp(In));
|
|
}
|
|
|
|
static FThreadSafeCounter NumInProgressWrites;
|
|
static const int32 MaxAsyncWrites = 6;
|
|
};
|
|
FThreadSafeCounter FAsyncBufferWriteQueue::NumInProgressWrites;
|
|
|
|
/** Callable type used to save a color buffer on an async task without allocating/copying into a new one */
|
|
template<typename TColor>
|
|
struct TAsyncBufferWrite
|
|
{
|
|
TAsyncBufferWrite(FString InFilename, FIntPoint InDestSize, TArray<TColor> InBitmap) : Filename(MoveTemp(InFilename)), DestSize(InDestSize), Bitmap(MoveTemp(InBitmap)) {}
|
|
|
|
TAsyncBufferWrite(TAsyncBufferWrite&& In) : Filename(MoveTemp(In.Filename)), DestSize(In.DestSize), Bitmap(MoveTemp(In.Bitmap)) {}
|
|
TAsyncBufferWrite& operator=(TAsyncBufferWrite&& In) { Filename = MoveTemp(In.Filename); DestSize = In.DestSize; Bitmap = MoveTemp(In.Bitmap); return *this; }
|
|
|
|
/** Call operator that saves the color buffer data */
|
|
void operator()()
|
|
{
|
|
FString ResultPath;
|
|
GetHighResScreenshotConfig().SaveImage(Filename, Bitmap, DestSize, &ResultPath);
|
|
UE_LOG(LogConsoleResponse, Display, TEXT("Content was saved to \"%s\""), *ResultPath);
|
|
|
|
FAsyncBufferWriteQueue::NumInProgressWrites.Decrement();
|
|
}
|
|
|
|
/** Copy semantics are only defined to appease TFunction, whose virtual CloneByCopy function is always instantiated, even if the TFunction itself is never copied */
|
|
TAsyncBufferWrite(const TAsyncBufferWrite& In) : Filename(In.Filename), DestSize(In.DestSize), Bitmap(In.Bitmap) { ensureMsgf(false, TEXT("Type should not be copied")); }
|
|
TAsyncBufferWrite& operator=(const TAsyncBufferWrite& In) { Filename = In.Filename; DestSize = In.DestSize; Bitmap = In.Bitmap; ensureMsgf(false, TEXT("Type should not be copied")); return *this; }
|
|
|
|
private:
|
|
|
|
/** The filename to save to */
|
|
FString Filename;
|
|
/** The size of the bitmap */
|
|
FIntPoint DestSize;
|
|
/** The bitmap data itself */
|
|
TArray<TColor> Bitmap;
|
|
};
|
|
|
|
TFuture<void> FRenderingCompositionGraph::DumpOutputToFile(FRenderingCompositePassContext& Context, const FString& Filename, FRenderingCompositeOutput* Output) const
|
|
{
|
|
FSceneRenderTargetItem& RenderTargetItem = Output->PooledRenderTarget->GetRenderTargetItem();
|
|
FHighResScreenshotConfig& HighResScreenshotConfig = GetHighResScreenshotConfig();
|
|
FTextureRHIRef Texture = RenderTargetItem.TargetableTexture ? RenderTargetItem.TargetableTexture : RenderTargetItem.ShaderResourceTexture;
|
|
check(Texture);
|
|
check(Texture->GetTexture2D());
|
|
|
|
FIntRect SourceRect = Context.View.ViewRect;
|
|
|
|
int32 MSAAXSamples = Texture->GetNumSamples();
|
|
|
|
if (GIsHighResScreenshot && HighResScreenshotConfig.CaptureRegion.Area())
|
|
{
|
|
SourceRect = HighResScreenshotConfig.CaptureRegion;
|
|
}
|
|
|
|
SourceRect.Min.X *= MSAAXSamples;
|
|
SourceRect.Max.X *= MSAAXSamples;
|
|
|
|
FIntPoint DestSize(SourceRect.Width(), SourceRect.Height());
|
|
|
|
EPixelFormat PixelFormat = Texture->GetFormat();
|
|
|
|
switch (PixelFormat)
|
|
{
|
|
case PF_FloatRGBA:
|
|
{
|
|
TArray<FFloat16Color> Bitmap;
|
|
Context.RHICmdList.ReadSurfaceFloatData(Texture, SourceRect, Bitmap, (ECubeFace)0, 0, 0);
|
|
|
|
return FAsyncBufferWriteQueue::Dispatch(TAsyncBufferWrite<FFloat16Color>(Filename, DestSize, MoveTemp(Bitmap)));
|
|
}
|
|
|
|
case PF_R8G8B8A8:
|
|
case PF_B8G8R8A8:
|
|
{
|
|
FReadSurfaceDataFlags ReadDataFlags;
|
|
ReadDataFlags.SetLinearToGamma(false);
|
|
TArray<FColor> Bitmap;
|
|
Context.RHICmdList.ReadSurfaceData(Texture, SourceRect, Bitmap, ReadDataFlags);
|
|
FColor* Pixel = Bitmap.GetData();
|
|
for (int32 i = 0, Count = Bitmap.Num(); i < Count; i++, Pixel++)
|
|
{
|
|
Pixel->A = 255;
|
|
}
|
|
|
|
return FAsyncBufferWriteQueue::Dispatch(TAsyncBufferWrite<FColor>(Filename, DestSize, MoveTemp(Bitmap)));
|
|
}
|
|
}
|
|
|
|
return TFuture<void>();
|
|
}
|
|
|
|
void FRenderingCompositionGraph::RecursivelyProcess(const FRenderingCompositeOutputRef& InOutputRef, FRenderingCompositePassContext& Context) const
|
|
{
|
|
FRenderingCompositePass *Pass = InOutputRef.GetPass();
|
|
FRenderingCompositeOutput *Output = InOutputRef.GetOutput();
|
|
|
|
#if !UE_BUILD_SHIPPING
|
|
if(!Pass || !Output)
|
|
{
|
|
// to track down a crash bug
|
|
if(Context.Pass)
|
|
{
|
|
UE_LOG(LogRenderer,Fatal, TEXT("FRenderingCompositionGraph::RecursivelyProcess %s"), *Context.Pass->ConstructDebugName());
|
|
}
|
|
}
|
|
#endif
|
|
|
|
check(Pass);
|
|
check(Output);
|
|
|
|
if(Pass->bProcessWasCalled)
|
|
{
|
|
// already processed
|
|
return;
|
|
}
|
|
Pass->bProcessWasCalled = true;
|
|
|
|
// iterate through all inputs and additional dependencies of this pass
|
|
{
|
|
uint32 Index = 0;
|
|
|
|
while(const FRenderingCompositeOutputRef* OutputRefIt = Pass->GetDependency(Index++))
|
|
{
|
|
if(OutputRefIt->GetPass())
|
|
{
|
|
if(!OutputRefIt)
|
|
{
|
|
// Pass doesn't have more inputs
|
|
break;
|
|
}
|
|
|
|
FRenderingCompositeOutput* Input = OutputRefIt->GetOutput();
|
|
|
|
// to track down an issue, should never happen
|
|
check(OutputRefIt->GetPass());
|
|
|
|
if(GRenderTargetPool.IsEventRecordingEnabled())
|
|
{
|
|
GRenderTargetPool.AddPhaseEvent(*Pass->ConstructDebugName());
|
|
}
|
|
|
|
Context.Pass = Pass;
|
|
RecursivelyProcess(*OutputRefIt, Context);
|
|
}
|
|
}
|
|
}
|
|
|
|
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
|
|
if(ShouldDebugCompositionGraph())
|
|
{
|
|
GGMLFileWriter.WriteLine("\tnode");
|
|
GGMLFileWriter.WriteLine("\t[");
|
|
|
|
int32 PassId = ComputeUniquePassId(Pass);
|
|
FString PassDebugName = Pass->ConstructDebugName();
|
|
|
|
ANSICHAR Line[MAX_SPRINTF];
|
|
|
|
{
|
|
GGMLFileWriter.WriteLine("\t\tgraphics");
|
|
GGMLFileWriter.WriteLine("\t\t[");
|
|
FCStringAnsi::Sprintf(Line, "\t\t\tw\t%d", 200);
|
|
GGMLFileWriter.WriteLine(Line);
|
|
FCStringAnsi::Sprintf(Line, "\t\t\th\t%d", 80);
|
|
GGMLFileWriter.WriteLine(Line);
|
|
GGMLFileWriter.WriteLine("\t\t\tfill\t\"#FFCCCC\"");
|
|
GGMLFileWriter.WriteLine("\t\t]");
|
|
}
|
|
|
|
{
|
|
FCStringAnsi::Sprintf(Line, "\t\tid\t%d", PassId);
|
|
GGMLFileWriter.WriteLine(Line);
|
|
GGMLFileWriter.WriteLine("\t\tLabelGraphics");
|
|
GGMLFileWriter.WriteLine("\t\t[");
|
|
FCStringAnsi::Sprintf(Line, "\t\t\ttext\t\"#%d\r%s\"", PassId, (const char *)TCHAR_TO_ANSI(*PassDebugName));
|
|
GGMLFileWriter.WriteLine(Line);
|
|
GGMLFileWriter.WriteLine("\t\t\tanchor\t\"t\""); // put label internally on top
|
|
GGMLFileWriter.WriteLine("\t\t\tfontSize\t14");
|
|
GGMLFileWriter.WriteLine("\t\t\tfontStyle\t\"bold\"");
|
|
GGMLFileWriter.WriteLine("\t\t]");
|
|
}
|
|
|
|
UE_LOG(LogConsoleResponse,Log, TEXT("Node#%d '%s'"), PassId, *PassDebugName);
|
|
|
|
GGMLFileWriter.WriteLine("\t\tisGroup\t1");
|
|
GGMLFileWriter.WriteLine("\t]");
|
|
|
|
uint32 InputId = 0;
|
|
while(FRenderingCompositeOutputRef* OutputRefIt = Pass->GetInput((EPassInputId)(InputId++)))
|
|
{
|
|
if(OutputRefIt->Source)
|
|
{
|
|
// source is hooked up
|
|
FString InputName = OutputRefIt->Source->ConstructDebugName();
|
|
|
|
int32 TargetPassId = ComputeUniquePassId(OutputRefIt->Source);
|
|
|
|
UE_LOG(LogConsoleResponse,Log, TEXT(" ePId_Input%d: Node#%d @ ePId_Output%d '%s'"), InputId - 1, TargetPassId, (uint32)OutputRefIt->PassOutputId, *InputName);
|
|
|
|
// input connection to another node
|
|
{
|
|
GGMLFileWriter.WriteLine("\tedge");
|
|
GGMLFileWriter.WriteLine("\t[");
|
|
{
|
|
FCStringAnsi::Sprintf(Line, "\t\tsource\t%d", ComputeUniqueOutputId(OutputRefIt->Source, OutputRefIt->PassOutputId));
|
|
GGMLFileWriter.WriteLine(Line);
|
|
FCStringAnsi::Sprintf(Line, "\t\ttarget\t%d", PassId);
|
|
GGMLFileWriter.WriteLine(Line);
|
|
}
|
|
{
|
|
FString EdgeName = FString::Printf(TEXT("ePId_Input%d"), InputId - 1);
|
|
|
|
GGMLFileWriter.WriteLine("\t\tLabelGraphics");
|
|
GGMLFileWriter.WriteLine("\t\t[");
|
|
FCStringAnsi::Sprintf(Line, "\t\t\ttext\t\"%s\"", (const char *)TCHAR_TO_ANSI(*EdgeName));
|
|
GGMLFileWriter.WriteLine(Line);
|
|
GGMLFileWriter.WriteLine("\t\t\tmodel\t\"three_center\"");
|
|
GGMLFileWriter.WriteLine("\t\t\tposition\t\"tcentr\"");
|
|
GGMLFileWriter.WriteLine("\t\t]");
|
|
}
|
|
GGMLFileWriter.WriteLine("\t]");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// source is not hooked up
|
|
UE_LOG(LogConsoleResponse,Log, TEXT(" ePId_Input%d:"), InputId - 1);
|
|
}
|
|
}
|
|
|
|
uint32 DepId = 0;
|
|
while(FRenderingCompositeOutputRef* OutputRefIt = Pass->GetAdditionalDependency(DepId++))
|
|
{
|
|
check(OutputRefIt->Source);
|
|
|
|
FString InputName = OutputRefIt->Source->ConstructDebugName();
|
|
int32 TargetPassId = ComputeUniquePassId(OutputRefIt->Source);
|
|
|
|
UE_LOG(LogConsoleResponse,Log, TEXT(" Dependency: Node#%d @ ePId_Output%d '%s'"), TargetPassId, (uint32)OutputRefIt->PassOutputId, *InputName);
|
|
|
|
// dependency connection to another node
|
|
{
|
|
GGMLFileWriter.WriteLine("\tedge");
|
|
GGMLFileWriter.WriteLine("\t[");
|
|
{
|
|
FCStringAnsi::Sprintf(Line, "\t\tsource\t%d", ComputeUniqueOutputId(OutputRefIt->Source, OutputRefIt->PassOutputId));
|
|
GGMLFileWriter.WriteLine(Line);
|
|
FCStringAnsi::Sprintf(Line, "\t\ttarget\t%d", PassId);
|
|
GGMLFileWriter.WriteLine(Line);
|
|
}
|
|
// dashed line
|
|
{
|
|
GGMLFileWriter.WriteLine("\t\tgraphics");
|
|
GGMLFileWriter.WriteLine("\t\t[");
|
|
GGMLFileWriter.WriteLine("\t\t\tstyle\t\"dashed\"");
|
|
GGMLFileWriter.WriteLine("\t\t]");
|
|
}
|
|
{
|
|
FString EdgeName = TEXT("Dependency");
|
|
|
|
GGMLFileWriter.WriteLine("\t\tLabelGraphics");
|
|
GGMLFileWriter.WriteLine("\t\t[");
|
|
FCStringAnsi::Sprintf(Line, "\t\t\ttext\t\"%s\"", (const char *)TCHAR_TO_ANSI(*EdgeName));
|
|
GGMLFileWriter.WriteLine(Line);
|
|
GGMLFileWriter.WriteLine("\t\t\tmodel\t\"three_center\"");
|
|
GGMLFileWriter.WriteLine("\t\t\tposition\t\"tcentr\"");
|
|
GGMLFileWriter.WriteLine("\t\t]");
|
|
}
|
|
GGMLFileWriter.WriteLine("\t]");
|
|
}
|
|
}
|
|
|
|
uint32 OutputId = 0;
|
|
while(FRenderingCompositeOutput* PassOutput = Pass->GetOutput((EPassOutputId)(OutputId)))
|
|
{
|
|
UE_LOG(LogConsoleResponse,Log, TEXT(" ePId_Output%d %s %s Dep: %d"), OutputId, *PassOutput->RenderTargetDesc.GenerateInfoString(), PassOutput->RenderTargetDesc.DebugName, PassOutput->GetDependencyCount());
|
|
|
|
GGMLFileWriter.WriteLine("\tnode");
|
|
GGMLFileWriter.WriteLine("\t[");
|
|
|
|
{
|
|
GGMLFileWriter.WriteLine("\t\tgraphics");
|
|
GGMLFileWriter.WriteLine("\t\t[");
|
|
FCStringAnsi::Sprintf(Line, "\t\t\tw\t%d", 220);
|
|
GGMLFileWriter.WriteLine(Line);
|
|
FCStringAnsi::Sprintf(Line, "\t\t\th\t%d", 40);
|
|
GGMLFileWriter.WriteLine(Line);
|
|
GGMLFileWriter.WriteLine("\t\t]");
|
|
}
|
|
|
|
{
|
|
FCStringAnsi::Sprintf(Line, "\t\tid\t%d", ComputeUniqueOutputId(Pass, (EPassOutputId)(OutputId)));
|
|
GGMLFileWriter.WriteLine(Line);
|
|
GGMLFileWriter.WriteLine("\t\tLabelGraphics");
|
|
GGMLFileWriter.WriteLine("\t\t[");
|
|
FCStringAnsi::Sprintf(Line, "\t\t\ttext\t\"ePId_Output%d '%s'\r%s\"",
|
|
OutputId,
|
|
(const char *)TCHAR_TO_ANSI(PassOutput->RenderTargetDesc.DebugName),
|
|
(const char *)TCHAR_TO_ANSI(*PassOutput->RenderTargetDesc.GenerateInfoString()));
|
|
GGMLFileWriter.WriteLine(Line);
|
|
GGMLFileWriter.WriteLine("\t\t]");
|
|
}
|
|
|
|
|
|
{
|
|
FCStringAnsi::Sprintf(Line, "\t\tgid\t%d", PassId);
|
|
GGMLFileWriter.WriteLine(Line);
|
|
}
|
|
|
|
GGMLFileWriter.WriteLine("\t]");
|
|
|
|
++OutputId;
|
|
}
|
|
|
|
UE_LOG(LogConsoleResponse,Log, TEXT(""));
|
|
}
|
|
#endif
|
|
|
|
Context.Pass = Pass;
|
|
Context.SetViewportInvalid();
|
|
|
|
// then process the pass itself
|
|
Pass->Process(Context);
|
|
|
|
// for VisualizeTexture and output buffer dumping
|
|
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
|
|
{
|
|
uint32 OutputId = 0;
|
|
|
|
while(FRenderingCompositeOutput* PassOutput = Pass->GetOutput((EPassOutputId)OutputId))
|
|
{
|
|
// use intermediate texture unless it's the last one where we render to the final output
|
|
if(PassOutput->PooledRenderTarget)
|
|
{
|
|
GRenderTargetPool.VisualizeTexture.SetCheckPoint(Context.RHICmdList, PassOutput->PooledRenderTarget);
|
|
|
|
// If this buffer was given a dump filename, write it out
|
|
const FString& Filename = Pass->GetOutputDumpFilename((EPassOutputId)OutputId);
|
|
if (!Filename.IsEmpty())
|
|
{
|
|
DumpOutputToFile(Context, Filename, PassOutput);
|
|
}
|
|
|
|
// If we've been asked to write out the pixel data for this pass to an external array, do it now
|
|
TArray<FColor>* OutputColorArray = Pass->GetOutputColorArray((EPassOutputId)OutputId);
|
|
if (OutputColorArray)
|
|
{
|
|
Context.RHICmdList.ReadSurfaceData(
|
|
PassOutput->PooledRenderTarget->GetRenderTargetItem().TargetableTexture,
|
|
Context.View.ViewRect,
|
|
*OutputColorArray,
|
|
FReadSurfaceDataFlags()
|
|
);
|
|
}
|
|
}
|
|
|
|
OutputId++;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
// iterate through all inputs of tghis pass and decrement the references for it's inputs
|
|
// this can release some intermediate RT so they can be reused
|
|
{
|
|
uint32 InputId = 0;
|
|
|
|
while(const FRenderingCompositeOutputRef* OutputRefIt = Pass->GetDependency(InputId++))
|
|
{
|
|
FRenderingCompositeOutput* Input = OutputRefIt->GetOutput();
|
|
|
|
if(Input)
|
|
{
|
|
Input->ResolveDependencies();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// for debugging purpose O(n)
|
|
int32 FRenderingCompositionGraph::ComputeUniquePassId(FRenderingCompositePass* Pass) const
|
|
{
|
|
for(uint32 i = 0; i < (uint32)Nodes.Num(); ++i)
|
|
{
|
|
FRenderingCompositePass *Element = Nodes[i];
|
|
|
|
if(Element == Pass)
|
|
{
|
|
return i;
|
|
}
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
int32 FRenderingCompositionGraph::ComputeUniqueOutputId(FRenderingCompositePass* Pass, EPassOutputId OutputId) const
|
|
{
|
|
uint32 Ret = Nodes.Num();
|
|
|
|
for(uint32 i = 0; i < (uint32)Nodes.Num(); ++i)
|
|
{
|
|
FRenderingCompositePass *Element = Nodes[i];
|
|
|
|
if(Element == Pass)
|
|
{
|
|
return (int32)(Ret + (uint32)OutputId);
|
|
}
|
|
|
|
uint32 OutputCount = 0;
|
|
while(Pass->GetOutput((EPassOutputId)OutputCount))
|
|
{
|
|
++OutputCount;
|
|
}
|
|
|
|
Ret += OutputCount;
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
FRenderingCompositeOutput *FRenderingCompositeOutputRef::GetOutput() const
|
|
{
|
|
if(Source == 0)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
return Source->GetOutput(PassOutputId);
|
|
}
|
|
|
|
FRenderingCompositePass* FRenderingCompositeOutputRef::GetPass() const
|
|
{
|
|
return Source;
|
|
}
|
|
|
|
// -----------------------------------------------------------------
|
|
|
|
void FPostProcessPassParameters::Bind(const FShaderParameterMap& ParameterMap)
|
|
{
|
|
BilinearTextureSampler0.Bind(ParameterMap,TEXT("BilinearTextureSampler0"));
|
|
BilinearTextureSampler1.Bind(ParameterMap,TEXT("BilinearTextureSampler1"));
|
|
ViewportSize.Bind(ParameterMap,TEXT("ViewportSize"));
|
|
ViewportRect.Bind(ParameterMap,TEXT("ViewportRect"));
|
|
ScreenPosToPixel.Bind(ParameterMap,TEXT("ScreenPosToPixel"));
|
|
|
|
for(uint32 i = 0; i < ePId_Input_MAX; ++i)
|
|
{
|
|
PostprocessInputParameter[i].Bind(ParameterMap, *FString::Printf(TEXT("PostprocessInput%d"), i));
|
|
PostprocessInputParameterSampler[i].Bind(ParameterMap, *FString::Printf(TEXT("PostprocessInput%dSampler"), i));
|
|
PostprocessInputSizeParameter[i].Bind(ParameterMap, *FString::Printf(TEXT("PostprocessInput%dSize"), i));
|
|
PostProcessInputMinMaxParameter[i].Bind(ParameterMap, *FString::Printf(TEXT("PostprocessInput%dMinMax"), i));
|
|
}
|
|
}
|
|
|
|
void FPostProcessPassParameters::SetPS(const FPixelShaderRHIParamRef& ShaderRHI, const FRenderingCompositePassContext& Context, FSamplerStateRHIParamRef Filter, EFallbackColor FallbackColor, FSamplerStateRHIParamRef* FilterOverrideArray)
|
|
{
|
|
Set(ShaderRHI, Context, Context.RHICmdList, Filter, FallbackColor, FilterOverrideArray);
|
|
}
|
|
|
|
template< typename TRHICmdList >
|
|
void FPostProcessPassParameters::SetCS(const FComputeShaderRHIParamRef& ShaderRHI, const FRenderingCompositePassContext& Context, TRHICmdList& RHICmdList, FSamplerStateRHIParamRef Filter, EFallbackColor FallbackColor, FSamplerStateRHIParamRef* FilterOverrideArray)
|
|
{
|
|
Set(ShaderRHI, Context, RHICmdList, Filter, FallbackColor, FilterOverrideArray);
|
|
}
|
|
template void FPostProcessPassParameters::SetCS< FRHICommandListImmediate >(
|
|
const FComputeShaderRHIParamRef& ShaderRHI,
|
|
const FRenderingCompositePassContext& Context,
|
|
FRHICommandListImmediate& RHICmdList,
|
|
FSamplerStateRHIParamRef Filter,
|
|
EFallbackColor FallbackColor,
|
|
FSamplerStateRHIParamRef* FilterOverrideArray
|
|
);
|
|
|
|
template void FPostProcessPassParameters::SetCS< FRHIAsyncComputeCommandListImmediate >(
|
|
const FComputeShaderRHIParamRef& ShaderRHI,
|
|
const FRenderingCompositePassContext& Context,
|
|
FRHIAsyncComputeCommandListImmediate& RHICmdList,
|
|
FSamplerStateRHIParamRef Filter,
|
|
EFallbackColor FallbackColor,
|
|
FSamplerStateRHIParamRef* FilterOverrideArray
|
|
);
|
|
|
|
void FPostProcessPassParameters::SetVS(const FVertexShaderRHIParamRef& ShaderRHI, const FRenderingCompositePassContext& Context, FSamplerStateRHIParamRef Filter, EFallbackColor FallbackColor, FSamplerStateRHIParamRef* FilterOverrideArray)
|
|
{
|
|
Set(ShaderRHI, Context, Context.RHICmdList, Filter, FallbackColor, FilterOverrideArray);
|
|
}
|
|
|
|
template< typename ShaderRHIParamRef, typename TRHICmdList >
|
|
void FPostProcessPassParameters::Set(
|
|
const ShaderRHIParamRef& ShaderRHI,
|
|
const FRenderingCompositePassContext& Context,
|
|
TRHICmdList& RHICmdList,
|
|
FSamplerStateRHIParamRef Filter,
|
|
EFallbackColor FallbackColor,
|
|
FSamplerStateRHIParamRef* FilterOverrideArray)
|
|
{
|
|
// assuming all outputs have the same size
|
|
FRenderingCompositeOutput* Output = Context.Pass->GetOutput(ePId_Output0);
|
|
|
|
// Output0 should always exist
|
|
check(Output);
|
|
|
|
// one should be on
|
|
check(FilterOverrideArray || Filter);
|
|
// but not both
|
|
check(!FilterOverrideArray || !Filter);
|
|
|
|
if(BilinearTextureSampler0.IsBound())
|
|
{
|
|
RHICmdList.SetShaderSampler(
|
|
ShaderRHI,
|
|
BilinearTextureSampler0.GetBaseIndex(),
|
|
TStaticSamplerState<SF_Bilinear>::GetRHI()
|
|
);
|
|
}
|
|
|
|
if(BilinearTextureSampler1.IsBound())
|
|
{
|
|
RHICmdList.SetShaderSampler(
|
|
ShaderRHI,
|
|
BilinearTextureSampler1.GetBaseIndex(),
|
|
TStaticSamplerState<SF_Bilinear>::GetRHI()
|
|
);
|
|
}
|
|
|
|
if(ViewportSize.IsBound() || ScreenPosToPixel.IsBound() || ViewportRect.IsBound())
|
|
{
|
|
FIntRect LocalViewport = Context.GetViewport();
|
|
|
|
FIntPoint ViewportOffset = LocalViewport.Min;
|
|
FIntPoint ViewportExtent = LocalViewport.Size();
|
|
|
|
{
|
|
FVector4 Value(ViewportExtent.X, ViewportExtent.Y, 1.0f / ViewportExtent.X, 1.0f / ViewportExtent.Y);
|
|
|
|
SetShaderValue(RHICmdList, ShaderRHI, ViewportSize, Value);
|
|
}
|
|
|
|
{
|
|
SetShaderValue(RHICmdList, ShaderRHI, ViewportRect, Context.GetViewport());
|
|
}
|
|
|
|
{
|
|
FVector4 ScreenPosToPixelValue(
|
|
ViewportExtent.X * 0.5f,
|
|
-ViewportExtent.Y * 0.5f,
|
|
ViewportExtent.X * 0.5f - 0.5f + ViewportOffset.X,
|
|
ViewportExtent.Y * 0.5f - 0.5f + ViewportOffset.Y);
|
|
SetShaderValue(RHICmdList, ShaderRHI, ScreenPosToPixel, ScreenPosToPixelValue);
|
|
}
|
|
}
|
|
|
|
//Calculate a base scene texture min max which will be pulled in by a pixel for each PP input.
|
|
FIntRect ContextViewportRect = Context.IsViewportValid() ? Context.GetViewport() : FIntRect(0,0,0,0);
|
|
const FIntPoint SceneRTSize = FSceneRenderTargets::Get(RHICmdList).GetBufferSizeXY();
|
|
FVector4 BaseSceneTexMinMax( ((float)ContextViewportRect.Min.X/SceneRTSize.X),
|
|
((float)ContextViewportRect.Min.Y/SceneRTSize.Y),
|
|
((float)ContextViewportRect.Max.X/SceneRTSize.X),
|
|
((float)ContextViewportRect.Max.Y/SceneRTSize.Y) );
|
|
|
|
IPooledRenderTarget* FallbackTexture = 0;
|
|
|
|
switch(FallbackColor)
|
|
{
|
|
case eFC_0000: FallbackTexture = GSystemTextures.BlackDummy; break;
|
|
case eFC_0001: FallbackTexture = GSystemTextures.BlackAlphaOneDummy; break;
|
|
case eFC_1111: FallbackTexture = GSystemTextures.WhiteDummy; break;
|
|
default:
|
|
ensure(!"Unhandled enum in EFallbackColor");
|
|
}
|
|
|
|
// ePId_Input0, ePId_Input1, ...
|
|
for(uint32 Id = 0; Id < (uint32)ePId_Input_MAX; ++Id)
|
|
{
|
|
FRenderingCompositeOutputRef* OutputRef = Context.Pass->GetInput((EPassInputId)Id);
|
|
|
|
if(!OutputRef)
|
|
{
|
|
// Pass doesn't have more inputs
|
|
break;
|
|
}
|
|
|
|
const auto FeatureLevel = Context.GetFeatureLevel();
|
|
|
|
FRenderingCompositeOutput* Input = OutputRef->GetOutput();
|
|
|
|
TRefCountPtr<IPooledRenderTarget> InputPooledElement;
|
|
|
|
if(Input)
|
|
{
|
|
InputPooledElement = Input->RequestInput();
|
|
}
|
|
|
|
FSamplerStateRHIParamRef LocalFilter = FilterOverrideArray ? FilterOverrideArray[Id] : Filter;
|
|
|
|
if(InputPooledElement)
|
|
{
|
|
check(!InputPooledElement->IsFree());
|
|
|
|
const FTextureRHIRef& SrcTexture = InputPooledElement->GetRenderTargetItem().ShaderResourceTexture;
|
|
|
|
SetTextureParameter(RHICmdList, ShaderRHI, PostprocessInputParameter[Id], PostprocessInputParameterSampler[Id], LocalFilter, SrcTexture);
|
|
|
|
if(PostprocessInputSizeParameter[Id].IsBound() || PostProcessInputMinMaxParameter[Id].IsBound())
|
|
{
|
|
float Width = InputPooledElement->GetDesc().Extent.X;
|
|
float Height = InputPooledElement->GetDesc().Extent.Y;
|
|
|
|
FVector2D OnePPInputPixelUVSize = FVector2D(1.0f / Width, 1.0f / Height);
|
|
|
|
FVector4 TextureSize(Width, Height, OnePPInputPixelUVSize.X, OnePPInputPixelUVSize.Y);
|
|
SetShaderValue(RHICmdList, ShaderRHI, PostprocessInputSizeParameter[Id], TextureSize);
|
|
|
|
//We could use the main scene min max here if it weren't that we need to pull the max in by a pixel on a per input basis.
|
|
FVector4 PPInputMinMax = BaseSceneTexMinMax;
|
|
PPInputMinMax.Z -= OnePPInputPixelUVSize.X;
|
|
PPInputMinMax.W -= OnePPInputPixelUVSize.Y;
|
|
SetShaderValue(RHICmdList, ShaderRHI, PostProcessInputMinMaxParameter[Id], PPInputMinMax);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// if the input is not there but the shader request it we give it at least some data to avoid d3ddebug errors and shader permutations
|
|
// to make features optional we use default black for additive passes without shader permutations
|
|
SetTextureParameter(RHICmdList, ShaderRHI, PostprocessInputParameter[Id], PostprocessInputParameterSampler[Id], LocalFilter, FallbackTexture->GetRenderTargetItem().TargetableTexture);
|
|
|
|
FVector4 Dummy(1, 1, 1, 1);
|
|
SetShaderValue(RHICmdList, ShaderRHI, PostprocessInputSizeParameter[Id], Dummy);
|
|
SetShaderValue(RHICmdList, ShaderRHI, PostProcessInputMinMaxParameter[Id], Dummy);
|
|
}
|
|
}
|
|
|
|
// todo warning if Input[] or InputSize[] is bound but not available, maybe set a specific input texture (blinking?)
|
|
}
|
|
|
|
#define IMPLEMENT_POST_PROCESS_PARAM_SET( ShaderRHIParamRef, TRHICmdList ) \
|
|
template void FPostProcessPassParameters::Set< ShaderRHIParamRef >( \
|
|
const ShaderRHIParamRef& ShaderRHI, \
|
|
const FRenderingCompositePassContext& Context, \
|
|
TRHICmdList& RHICmdList, \
|
|
FSamplerStateRHIParamRef Filter, \
|
|
EFallbackColor FallbackColor, \
|
|
FSamplerStateRHIParamRef* FilterOverrideArray \
|
|
);
|
|
|
|
IMPLEMENT_POST_PROCESS_PARAM_SET( FVertexShaderRHIParamRef, FRHICommandListImmediate );
|
|
IMPLEMENT_POST_PROCESS_PARAM_SET( FHullShaderRHIParamRef, FRHICommandListImmediate );
|
|
IMPLEMENT_POST_PROCESS_PARAM_SET( FDomainShaderRHIParamRef, FRHICommandListImmediate );
|
|
IMPLEMENT_POST_PROCESS_PARAM_SET( FGeometryShaderRHIParamRef, FRHICommandListImmediate );
|
|
IMPLEMENT_POST_PROCESS_PARAM_SET( FPixelShaderRHIParamRef, FRHICommandListImmediate );
|
|
IMPLEMENT_POST_PROCESS_PARAM_SET( FComputeShaderRHIParamRef, FRHICommandListImmediate );
|
|
IMPLEMENT_POST_PROCESS_PARAM_SET( FComputeShaderRHIParamRef, FRHIAsyncComputeCommandListImmediate );
|
|
|
|
FArchive& operator<<(FArchive& Ar, FPostProcessPassParameters& P)
|
|
{
|
|
Ar << P.BilinearTextureSampler0 << P.BilinearTextureSampler1 << P.ViewportSize << P.ScreenPosToPixel << P.ViewportRect;
|
|
|
|
for(uint32 i = 0; i < ePId_Input_MAX; ++i)
|
|
{
|
|
Ar << P.PostprocessInputParameter[i];
|
|
Ar << P.PostprocessInputParameterSampler[i];
|
|
Ar << P.PostprocessInputSizeParameter[i];
|
|
Ar << P.PostProcessInputMinMaxParameter[i];
|
|
}
|
|
|
|
return Ar;
|
|
}
|
|
|
|
// -----------------------------------------------------------------
|
|
|
|
const FSceneRenderTargetItem& FRenderingCompositeOutput::RequestSurface(const FRenderingCompositePassContext& Context)
|
|
{
|
|
if(PooledRenderTarget)
|
|
{
|
|
Context.RHICmdList.TransitionResource(EResourceTransitionAccess::EWritable, PooledRenderTarget->GetRenderTargetItem().TargetableTexture);
|
|
return PooledRenderTarget->GetRenderTargetItem();
|
|
}
|
|
|
|
if(!RenderTargetDesc.IsValid())
|
|
{
|
|
// useful to use the CompositingGraph dependency resolve but pass the data between nodes differently
|
|
static FSceneRenderTargetItem Null;
|
|
|
|
return Null;
|
|
}
|
|
|
|
if(!PooledRenderTarget)
|
|
{
|
|
GRenderTargetPool.FindFreeElement(Context.RHICmdList, RenderTargetDesc, PooledRenderTarget, RenderTargetDesc.DebugName);
|
|
}
|
|
|
|
check(!PooledRenderTarget->IsFree());
|
|
|
|
FSceneRenderTargetItem& RenderTargetItem = PooledRenderTarget->GetRenderTargetItem();
|
|
|
|
return RenderTargetItem;
|
|
}
|
|
|
|
|
|
const FPooledRenderTargetDesc* FRenderingCompositePass::GetInputDesc(EPassInputId InPassInputId) const
|
|
{
|
|
// to overcome const issues, this way it's kept local
|
|
FRenderingCompositePass* This = (FRenderingCompositePass*)this;
|
|
|
|
const FRenderingCompositeOutputRef* OutputRef = This->GetInput(InPassInputId);
|
|
|
|
if(!OutputRef)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
FRenderingCompositeOutput* Input = OutputRef->GetOutput();
|
|
|
|
if(!Input)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
return &Input->RenderTargetDesc;
|
|
}
|
|
|
|
uint32 FRenderingCompositePass::ComputeInputCount()
|
|
{
|
|
for(uint32 i = 0; ; ++i)
|
|
{
|
|
if(!GetInput((EPassInputId)i))
|
|
{
|
|
return i;
|
|
}
|
|
}
|
|
}
|
|
|
|
uint32 FRenderingCompositePass::ComputeOutputCount()
|
|
{
|
|
for(uint32 i = 0; ; ++i)
|
|
{
|
|
if(!GetOutput((EPassOutputId)i))
|
|
{
|
|
return i;
|
|
}
|
|
}
|
|
}
|
|
|
|
FString FRenderingCompositePass::ConstructDebugName()
|
|
{
|
|
FString Name;
|
|
|
|
uint32 OutputId = 0;
|
|
while(FRenderingCompositeOutput* Output = GetOutput((EPassOutputId)OutputId))
|
|
{
|
|
Name += Output->RenderTargetDesc.DebugName;
|
|
|
|
++OutputId;
|
|
}
|
|
|
|
if(Name.IsEmpty())
|
|
{
|
|
Name = TEXT("UnknownName");
|
|
}
|
|
|
|
return Name;
|
|
}
|