当前位置:网站首页>UE4 engine customizes screenpass and MRT output
UE4 engine customizes screenpass and MRT output
2022-07-28 08:22:00 【Elder martial brother Dai Dai】
Preface
In front of the blog (UE4 4.27) Plug in add GlobalShder We define a GlobalShader Right one RT After treatment , That blog is also customized VertexShader, PixelShader, Vertex Format , Vertex array and so on , In fact, this is only used as a case teaching , In fact, UE4 There is a pattern in the engine ( Multiple sheets ) Texture post-processing has built-in RenderPass, It is ScreenPass.UE4 By default, we define FScreenVS And supporting DrawRectangle function , We just need to write ourselves easily PixelShader, After processing .
ScreenPass and MRT At the same time, output grayscale image and brightness adjustment image
here MRT yes MultiRenderTarget.
grayscale

Here I choose floating point algorithm .
Brightness adjustment chart
Color = Scale * Color
establish MRT Of ScreenPass Key code
FScreenVS + Self defined PixelShaderPass, The other is FRHIRenderPassInfo Input of must be specified FRHITexture Array
Self defined PixelShaderPass---DrawShader.usf
#include "/Engine/Public/Platform.ush"
Texture2D InTexture;
SamplerState InTextureSampler;
float4 MyColor;
float MyColorScale;
void MainPS(
in float2 UV : TEXCOORD0,
out float4 OutColor1 : SV_Target0,
out float4 OutColor2 : SV_Target1)
{
float4 TextureColor = InTexture.Sample(InTextureSampler, UV);
float Gray = 0.3 * TextureColor.r + 0.59 * TextureColor.g + 0.11 * TextureColor.b;
OutColor1 = float4(Gray, Gray, Gray, 1.0);
OutColor2 = MyColor * TextureColor * MyColorScale;
}RenderPass Code
static void DrawTestShaderToRenderTexture_RenderThread(
FRHICommandListImmediate& RHICmdList,
FTexture* InTextureResource,
FTextureRenderTargetResource* OutGrayRTReource,
FTextureRenderTargetResource* OutScaleRTReource,
ERHIFeatureLevel::Type FeatureLevel,
const FLinearColor& Color,
float ColorScale)
{
check(IsInRenderingThread());
FRHITexture2D* OutGrayRTT = OutGrayRTReource->GetRenderTargetTexture();
FRHITexture2D* OutScaleRTT = OutScaleRTReource->GetRenderTargetTexture();
if (nullptr == OutGrayRTT || nullptr == OutScaleRTT)
return;
if (OutGrayRTT->GetSizeX() != OutScaleRTT->GetSizeX() || OutGrayRTT->GetSizeY() != OutScaleRTT->GetSizeY())
return;
FRHITexture* RTS[] = { OutGrayRTT, OutScaleRTT };
IRendererModule* RendererModule = &FModuleManager::GetModuleChecked<IRendererModule>("Renderer");
RHICmdList.Transition(FRHITransitionInfo(OutGrayRTT, ERHIAccess::SRVMask, ERHIAccess::RTV));
RHICmdList.Transition(FRHITransitionInfo(OutScaleRTT, ERHIAccess::SRVMask, ERHIAccess::RTV));
FRHIRenderPassInfo RPInfo(2, RTS, ERenderTargetActions::DontLoad_Store);
RHICmdList.BeginRenderPass(RPInfo, TEXT("Render Test Shader To Texture"));
{
// Get Shaders
FGlobalShaderMap* GlobalShaderMap = GetGlobalShaderMap(FeatureLevel);
TShaderMapRef<FScreenVS> VertexShader(GlobalShaderMap);
TShaderMapRef<FDrawPS> PixelShader(GlobalShaderMap);
// Setup Pipeline state
FGraphicsPipelineStateInitializer GraphicsPSOInit;
RHICmdList.ApplyCachedRenderTargets(GraphicsPSOInit);
GraphicsPSOInit.DepthStencilState = TStaticDepthStencilState<false, CF_Always>::GetRHI();
GraphicsPSOInit.BlendState = TStaticBlendState<>::GetRHI();
GraphicsPSOInit.RasterizerState = TStaticRasterizerState<>::GetRHI();
GraphicsPSOInit.PrimitiveType = PT_TriangleList;
GraphicsPSOInit.BoundShaderState.VertexDeclarationRHI = GFilterVertexDeclaration.VertexDeclarationRHI;
GraphicsPSOInit.BoundShaderState.VertexShaderRHI = VertexShader.GetVertexShader();
GraphicsPSOInit.BoundShaderState.PixelShaderRHI = PixelShader.GetPixelShader();
SetGraphicsPipelineState(RHICmdList, GraphicsPSOInit);
// Upate viewport
FIntPoint ViewportSize(OutGrayRTT->GetSizeX(), OutGrayRTT->GetSizeY());
RHICmdList.SetViewport(0, 0, 0.0f, ViewportSize.X, ViewportSize.Y, 1.0f);
// update shader uniform parameters
PixelShader->SetParam(RHICmdList, InTextureResource, Color, ColorScale);
RendererModule->DrawRectangle(RHICmdList, 0, 0, ViewportSize.X, ViewportSize.Y, 0, 0, 1, 1, ViewportSize, FIntPoint(1, 1), VertexShader);
}
RHICmdList.EndRenderPass();
RHICmdList.Transition(FRHITransitionInfo(OutGrayRTT, ERHIAccess::RTV, ERHIAccess::SRVMask));
RHICmdList.Transition(FRHITransitionInfo(OutScaleRTT, ERHIAccess::RTV, ERHIAccess::SRVMask));
}
According to the effect

Plug in links
边栏推荐
- Can a flinksql script write insert statements for two tables?
- What if you are prompted that your connection to this website is not a private connection?
- Matplotlib绘图笔记基础直线、折线、曲线
- Swm32 series tutorial 5-adc application
- Talk about row storage and column storage of database
- JUC原子类: CAS, Unsafe、CAS缺点、ABA问题如何解决详解
- Lecture notes a utility for everyone to generate PCG
- JS thoroughly understand this point
- 非关系型数据库之Redis【Jedis客户端+Jedis连接集群】
- A group of South University students rely on science and technology to go to sea, with an annual income of 1billion
猜你喜欢

OSPF comprehensive experiment (7.12)

Find out whether the number exists from the matrix

Will ordinary browsers disclose information? How to protect privacy by using a secure browser?

辨析覆盖索引/索引覆盖/三星索引
![[300 + selected interview questions from big companies continued to share] big data operation and maintenance sharp knife interview question column (VIII)](/img/86/8e97b4456e2ba9a8535debb099fee0.png)
[300 + selected interview questions from big companies continued to share] big data operation and maintenance sharp knife interview question column (VIII)

Elaborate on common mode interference and differential mode interference

Some experience of gd32 using Hal Library of ST and Gd official library

Delete the nodes in the linked list - daily question

Digital management insight into retail and e-commerce operations -- Introduction to digital management

Draw.io image saving path settings
随机推荐
SWM32系列教程5-ADC应用
使用FFmpeg来批量生成单图+单音频的一图流视频
Deluxe H5 Tetris game source code
Yaml parameter configuration based on singleton mode
Redis of non relational database [detailed setup of redis cluster]
DNA deoxyribonucleic acid modified platinum nanoparticles ptnps DNA | scientific research reagent
DNA modified noble metal nanoparticles | DNA deoxyribonucleic acid modified metal palladium Pd nanoparticles pdnps DNA
win系统添加打印机
Technology sharing | common proxy tools for interface testing
These mobile security browsers are more than a little easy to use
The penultimate node in the linked list - Double finger
Lecture notes a utility for everyone to generate PCG
Redis of non relational database [jedis client +jedis connection cluster]
Draw.io image saving path settings
谈谈DOM0,DOM1,DOM2,DOM3
任务管理器中,显示的CPU速度大于它的最大速度【主频】
Record a MYCAT connection and solve the problems of communications link failure
Qt使用信号量控制线程(QSemaphore)
protobuf 基本语法总结
And is two numbers of S - two questions per day