当前位置:网站首页>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
边栏推荐
- 非关系型数据库之Redis【redis安装】
- Analysis of collector principle
- Can a flinksql script write insert statements for two tables?
- 【青鸟学员故事】追风少年“李晓亮”
- EMC design strategy - clock
- Mechanical revolution Jiaolong P wired network card driver can't play
- Oracle local network service
- DNA modified noble metal nanoparticles | DNA modified copper nanoparticles cunps-dna | research points
- Meituan Er Mian: why does redis have sentinels?
- DNA modified noble metal nanoparticles | DNA deoxyribonucleic acid modified metal palladium Pd nanoparticles pdnps DNA
猜你喜欢

03 | project deployment: how to quickly deploy a website developed based on the laravel framework

node(一)

解析树形结构 js

Common solutions for distributed ID - take one

@Documented 的作用

Plantuml Usage Summary
![[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)

谈谈DOM0,DOM1,DOM2,DOM3

EMC design strategy - clock
![In the task manager, the CPU speed displayed is greater than its maximum speed [main frequency]](/img/90/a3f56ef8f08a8735febba16af227f9.png)
In the task manager, the CPU speed displayed is greater than its maximum speed [main frequency]
随机推荐
These mobile security browsers are more than a little easy to use
C language explanation series - array explanation, one-dimensional array, two-dimensional array
mysql,可以使用多少列创建索引?
辨析覆盖索引/索引覆盖/三星索引
聊一聊数据库的行存与列存
Analysis of collector principle
Chapter 01 introduction of [notes of Huashu]
Discrimination coverage index / index coverage / Samsung index
2022年湖南工学院ACM集训第五次周测AD题题解
记录一次mycat连接Communications link failure问题解决
[Err] 1055 - Expression#2 of select list is not in GROUP BY clause and contains nonaggregated column
豪华版h5俄罗斯方块小游戏源码
awk从入门到入土(16)awk变量类型探讨--关于数字和string两种类型
Google and Stanford jointly issued a document: why do we have to use large models?
Elaborate on common mode interference and differential mode interference
h5机甲射击类小游戏源码下载
Matplotlib绘图笔记基础直线、折线、曲线
node(一)
How to understand the adjective prefix of socket: "connection oriented" and "connectionless"
What are the different tables in MySQL?