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

213 lines
7.2 KiB
C++
Raw Normal View History

Copying //UE4/Dev-Rendering to Dev-Main (//UE4/Dev-Main) #lockdown ben.marsh ========================== MAJOR FEATURES + CHANGES ========================== Change 2774277 on 2015/11/19 by Gil.Gribb UE4 - Did minor optimizations to the PS4 RHI and drawlists. Change 2791226 on 2015/12/04 by Uriel.Doyon Added source code for Embree 2.7.0 Removed duplicate files from the /doc folder. Change 2800193 on 2015/12/11 by Marcus.Wassmer SSAO AsyncCompute support. #rb Martin.Mittring Change 2801631 on 2015/12/14 by Olaf.Piesche Making auto deactivate true by default, moving checks to HasCompleted, eliminating some unnecessary logic #rb martin.mittring Change 2803240 on 2015/12/15 by Gil.Gribb UE4 - Added command to collect stats on spammy stats. Change 2803476 on 2015/12/15 by Rolando.Caloca DR - Allow toggling compute skin dispatch at runtime - r.SkinCacheShaders Now enable the shaders and feature - r.SkinCaching enables toggling at runtime - r.SkinCache.BufferSize Sets the size in bytes of buffer for outputting - Now uses 3 UAV buffers instead of one (avoid RenderDoc crashes) #codereview Marcus.Wassmer, Martin.Mittring Change 2803940 on 2015/12/15 by Marcus.Wassmer Add r.PS4.AsyncComputeBudgetMode to switch between CUMasking and WaveLimit modes. So far it looks like WaveLimits behave better in UE4. Also rearrange AsyncSSAO to run immediately after HZB to overlap with occlusion queries. In my testing this takes SSAO cost from .5ms -> .2ms. However it had to be hacked to run without normals. Hopefully Martin can get some real AsyncSSAO in. #rb Martin.Mittring #codereview Martin.Mittring Change 2803999 on 2015/12/15 by Uriel.Doyon Refactored the shader complexity material override logic to allow other viewmodes shader overrides. TexelFactorAccuracy ViewMode : shows the accuracy of the static mesh texel factors, used for streaming. WantedMipsAccuracy ViewMode : shows the accuracy of the static mesh wanted mips accuracy, used for streaming. Added an option to stream textures based on the AABB distance instead of using the sphere approximation. Added an option to only keep a the wanted mips. Moved optimization related viewmodes into a submenu to avoid polluting the interface. #jira UE-24502 #jira UE-24503 #jira UERNDR-89 Change 2804150 on 2015/12/15 by Olaf.Piesche make separate translucency screen percentage a bit more robust; add numsamples to the render target creation functions in preparation for MSAA support for higher quality with low res separate translucency #rb martin.mittring Change 2804367 on 2015/12/15 by Daniel.Wright Capsule shadow primitives are tracked separately on registration - saves 2.6ms of RT time doing the view frustum culling in a medium sized map Change 2805293 on 2015/12/16 by Olaf.Piesche logging if potentially immortal emitters are spawned from gameplay; this should catch if we spawn burst only emitters with indefinite life spans (muzzle flashes, hit impacts, etc.) #rb martin.mittring Change 2805586 on 2015/12/16 by Zabir.Hoque Adding support for decals to fade and destroy themselves automatically. #CodeReview: Martin.Mittring, Daniel.Wright, Olaf.Piesche Change 2807663 on 2015/12/17 by Rolando.Caloca DR - Remove expensive logging #codereview Marcus.Wassmer Change 2807903 on 2015/12/17 by Zabir.Hoque Refactored DecalComponent's lifetime management such that it can be set and reset from Blueprints. #CodeReview Daniel.Wright, Martin.Mittring, Olaf.Piesche Change 2809261 on 2015/12/18 by Martin.Mittring Added VisualizeShadingModels to track down issues like that: FORT-16913 Textures on Hero Mesh is not shown #rb:David.Hill #code_review:Bob.Tellez Change 2810136 on 2015/12/21 by Rolando.Caloca DR - Added back draw event colors PR #1602 #jira UE-21526 #codereview Mark.Satterthwaite, Keith.Judge, Marcus.Wassmer, Josh.Adams Change 2810680 on 2015/12/21 by Martin.Mittring moved SSAO ComputeShader running without per pixel normal (for AsyncCompute) into DevRendering #test:editor Change 2811205 on 2015/12/22 by Brian.Karis Pulled clear coat out of the reflection compute shader. Added permutation for skylight. Clear coat base layer now done in base pass. It only picks up the closest capture. This will cause popping when the object moves. Still needs a cross fade. Change 2811275 on 2015/12/22 by David.Hill UE-24675 #rb martin.mittring Corrected buffer-size related problem with fringe. Change 2811397 on 2015/12/22 by Brian.Karis
2016-01-08 11:12:28 -05:00
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
/*=============================================================================
PostProcessVisualizeShadingModels.cpp: Post processing VisualizeShadingModels implementation.
=============================================================================*/
#include "RendererPrivate.h"
#include "ScenePrivate.h"
#include "SceneFilterRendering.h"
#include "VisualizeShadingModels.h"
#include "PostProcessing.h"
#include "SceneUtils.h"
/** Encapsulates the post processing eye adaptation pixel shader. */
class FPostProcessVisualizeShadingModelsPS : public FGlobalShader
{
DECLARE_SHADER_TYPE(FPostProcessVisualizeShadingModelsPS, Global);
static bool ShouldCache(EShaderPlatform Platform)
{
return IsFeatureLevelSupported(Platform, ERHIFeatureLevel::SM4);
}
static void ModifyCompilationEnvironment(EShaderPlatform Platform, FShaderCompilerEnvironment& OutEnvironment)
{
FGlobalShader::ModifyCompilationEnvironment(Platform, OutEnvironment);
}
/** Default constructor. */
FPostProcessVisualizeShadingModelsPS() {}
public:
FPostProcessPassParameters PostprocessParameter;
FDeferredPixelShaderParameters DeferredParameters;
FShaderParameter ShadingModelMaskInView;
/** Initialization constructor. */
FPostProcessVisualizeShadingModelsPS(const ShaderMetaType::CompiledShaderInitializerType& Initializer)
: FGlobalShader(Initializer)
{
PostprocessParameter.Bind(Initializer.ParameterMap);
DeferredParameters.Bind(Initializer.ParameterMap);
ShadingModelMaskInView.Bind(Initializer.ParameterMap,TEXT("ShadingModelMaskInView"));
}
void SetPS(const FRenderingCompositePassContext& Context, uint16 InShadingModelMaskInView)
{
const FPixelShaderRHIParamRef ShaderRHI = GetPixelShader();
FGlobalShader::SetParameters(Context.RHICmdList, ShaderRHI, Context.View);
PostprocessParameter.SetPS(ShaderRHI, Context, TStaticSamplerState<SF_Point,AM_Clamp,AM_Clamp,AM_Clamp>::GetRHI());
DeferredParameters.Set(Context.RHICmdList, ShaderRHI, Context.View);
static FLinearColor SoftBits[sizeof(InShadingModelMaskInView) * 8] = {}; // init with 0.0f
for(uint32 i = 0; i < sizeof(InShadingModelMaskInView) * 8; ++i)
{
float& ref = SoftBits[i].R;
ref -= Context.View.Family->DeltaWorldTime;
ref = FMath::Max(0.0f, ref);
if(InShadingModelMaskInView & (1 << i))
{
ref = 1.0f;
}
}
SetShaderValueArray(Context.RHICmdList, ShaderRHI, ShadingModelMaskInView, SoftBits, sizeof(InShadingModelMaskInView) * 8);
}
// FShader interface.
virtual bool Serialize(FArchive& Ar) override
{
bool bShaderHasOutdatedParameters = FGlobalShader::Serialize(Ar);
Ar << PostprocessParameter << DeferredParameters << ShadingModelMaskInView;
return bShaderHasOutdatedParameters;
}
};
IMPLEMENT_SHADER_TYPE(,FPostProcessVisualizeShadingModelsPS,TEXT("VisualizeShadingModels"),TEXT("MainPS"),SF_Pixel);
FRCPassPostProcessVisualizeShadingModels::FRCPassPostProcessVisualizeShadingModels(FRHICommandList& RHICmdList)
{
// AdjustGBufferRefCount(-1) call is done when the pass gets executed
FSceneRenderTargets::Get_Todo_PassContext().AdjustGBufferRefCount(RHICmdList, 1);
}
void FRCPassPostProcessVisualizeShadingModels::Process(FRenderingCompositePassContext& Context)
{
SCOPED_DRAW_EVENT(Context.RHICmdList, PostProcessVisualizeShadingModels);
const FPooledRenderTargetDesc* InputDesc = GetInputDesc(ePId_Input0);
const FSceneView& View = Context.View;
const FViewInfo& ViewInfo = Context.View;
const FSceneViewFamily& ViewFamily = *(View.Family);
FIntRect SrcRect = View.ViewRect;
FIntRect DestRect = View.ViewRect;
FIntPoint SrcSize = InputDesc->Extent;
const FSceneRenderTargetItem& DestRenderTarget = PassOutputs[0].RequestSurface(Context);
// Set the view family's render target/viewport.
SetRenderTarget(Context.RHICmdList, DestRenderTarget.TargetableTexture, FTextureRHIRef());
Context.SetViewportAndCallRHI(DestRect);
// set the state
Context.RHICmdList.SetBlendState(TStaticBlendState<>::GetRHI());
Context.RHICmdList.SetRasterizerState(TStaticRasterizerState<>::GetRHI());
Context.RHICmdList.SetDepthStencilState(TStaticDepthStencilState<false, CF_Always>::GetRHI());
TShaderMapRef<FPostProcessVS> VertexShader(Context.GetShaderMap());
TShaderMapRef<FPostProcessVisualizeShadingModelsPS> PixelShader(Context.GetShaderMap());
static FGlobalBoundShaderState BoundShaderState;
SetGlobalBoundShaderState(Context.RHICmdList, Context.GetFeatureLevel(), BoundShaderState, GFilterVertexDeclaration.VertexDeclarationRHI, *VertexShader, *PixelShader);
PixelShader->SetPS(Context, ((FViewInfo&)View).ShadingModelMaskInView);
// Draw a quad mapping scene color to the view's render target
DrawRectangle(
Context.RHICmdList,
DestRect.Min.X, DestRect.Min.Y,
DestRect.Width(), DestRect.Height(),
SrcRect.Min.X, SrcRect.Min.Y,
SrcRect.Width(), SrcRect.Height(),
DestRect.Size(),
SrcSize,
*VertexShader,
EDRF_UseTriangleOptimization);
// this is a helper class for FCanvas to be able to get screen size
class FRenderTargetTemp : public FRenderTarget
{
public:
const FSceneView& View;
const FTexture2DRHIRef Texture;
FRenderTargetTemp(const FSceneView& InView, const FTexture2DRHIRef InTexture)
: View(InView), Texture(InTexture)
{
}
virtual FIntPoint GetSizeXY() const
{
return View.ViewRect.Size();
};
virtual const FTexture2DRHIRef& GetRenderTargetTexture() const
{
return Texture;
}
} TempRenderTarget(View, (const FTexture2DRHIRef&)DestRenderTarget.TargetableTexture);
FCanvas Canvas(&TempRenderTarget, NULL, 0, 0, 0, Context.GetFeatureLevel());
float X = 30;
float Y = 28;
const float YStep = 14;
const float ColumnWidth = 250;
FString Line;
Canvas.DrawShadowedString( X, Y += YStep, TEXT("Visualize ShadingModels (mostly to track down bugs)"), GetStatsFont(), FLinearColor(1, 1, 1));
Y = 160 - YStep - 4;
uint32 Value = ((FViewInfo&)View).ShadingModelMaskInView;
Line = FString::Printf(TEXT("View.ShadingModelMaskInView = 0x%x"), Value);
Canvas.DrawShadowedString( X, Y, *Line, GetStatsFont(), FLinearColor(0.5f, 0.5f, 0.5f));
Y += YStep;
UEnum* Enum = FindObject<UEnum>(NULL, TEXT("Engine.EMaterialShadingModel"));
check(Enum);
Y += 5;
for(uint32 i = 0; i < MSM_MAX; ++i)
{
FString Name = Enum->GetEnumName(i);
Line = FString::Printf(TEXT("%d. %s"), i, *Name);
bool bThere = (Value & (1 << i)) != 0;
Canvas.DrawShadowedString(X + 30, Y, *Line, GetStatsFont(), bThere ? FLinearColor(1, 1, 1) : FLinearColor(0, 0, 0) );
Y += 20;
}
Line = FString::Printf(TEXT("(On CPU, based on what gets rendered)"));
Canvas.DrawShadowedString( X, Y, *Line, GetStatsFont(), FLinearColor(0.5f, 0.5f, 0.5f)); Y += YStep;
Canvas.Flush_RenderThread(Context.RHICmdList);
Context.RHICmdList.CopyToResolveTarget(DestRenderTarget.TargetableTexture, DestRenderTarget.ShaderResourceTexture, false, FResolveParams());
// AdjustGBufferRefCount(1) call is done in constructor
FSceneRenderTargets::Get(Context.RHICmdList).AdjustGBufferRefCount(Context.RHICmdList, -1);
}
FPooledRenderTargetDesc FRCPassPostProcessVisualizeShadingModels::ComputeOutputDesc(EPassOutputId InPassOutputId) const
{
FPooledRenderTargetDesc Ret = GetInput(ePId_Input0)->GetOutput()->RenderTargetDesc;
Ret.Reset();
Ret.DebugName = TEXT("VisualizeShadingModels");
return Ret;
}