当前位置:网站首页>[ue4] geometry drawing pipeline
[ue4] geometry drawing pipeline
2022-07-03 14:43:00 【ZJU_ fish1996】
Geometry drawing routes , Generally speaking , It's notification GPU A complete process of drawing object information ;ue4 It encapsulates a relatively complex framework to maintain the whole process , This article will briefly introduce the whole process .
introduce
ue4 Most of the core rendering code entries are FDeferredShadingSceneRenderer::Render(FRHICommandListImmediate& RHICmdList) In this function ( And corresponding Mobile edition ), Here you can see in more detail what has been done in the whole rendering process . among , In the early stage of rendering , An important function is InitViews:
stay InitViews in , I did the following two important things :
(1) Calculate visibility
(2) Build visible primitive drawing instructions
All elements in the scene are stored in FScene in , We first need to filter all elements , Determine which primitives we need to draw in the current frame ( Eliminate those that are not in the cone , Eliminate completely occluded , Eliminate small objects at a long distance, etc ).
After determining the elements to be drawn , Our ultimate goal is to submit the drawing of these primitives to GPU(drawcall). To achieve this , We need to construct MeshCommand structure , It contains the rendering information of the object , Such as vertex buffer 、 Index buffer 、 Shader binding, etc .
In order to build visible primitive drawing instructions ,ue4 Implemented a set of mechanisms , Simply speaking , It is to generate an intermediate data structure for different types of primitives , Different rendering channels load corresponding intermediate data structures , And set the rendering state , structure MeshCommand, Add rendering instructions to DrawList. The overall flow chart is as follows :

Generate MeshBatch
As mentioned earlier, we will generate an intermediate temporary data structure , This structure is FMeshBatch, It contains everything the channel needs to determine the final shader binding and render state .
Proxy
ue4 There are various types of UPrimitiveComponent, Such as StaticMesh,Sprite,Landscape,Particle,ISM,HISM etc. . In order to do special processing during generation for different types ,ue4 For each UPrimitiveComponent The corresponding FPrimitiveSceneProxy, Different types of Proxy A unified intermediate format will be generated MeshBatch.
about Proxy for , It is similar to a OEM factory , Just care about how to generate MeshBatch, Don't care about this MeshBatch When, where and how it will be used . As shown in the figure below , from FPrimitiveSceneProxy Derived many types , They have their own corresponding UPrimitiveComponent.

Static and dynamic generation
For some objects , Its rendering state will not change in most cases , under these circumstances , Generated MeshBatch Is to determine the , So it can be cached , Regenerate only when necessary . We will generate this kind of MeshBatch The path of is called static path .
Allied , For another part of the object , Their rendering state may change frequently , Therefore, each frame needs to be generated MeshBatch, We call it dynamic path .
In order to determine Proxy Generate from static or dynamic paths MeshBatch, You can call GetViewRelevance() function , obtain bDynamicRelevance/bStaticRelevance attribute .
For static paths , Will call Proxy Medium DrawStaticElements Construct correspondence MeshBatch; For dynamic paths , Will call Proxy Medium GetDynamicMeshElements To construct the corresponding MeshBatch.
stay InitViews Medium ComputeViewVisibility Function , We can see two calls in succession , Respectively used to collect static MeshBatch And dynamic MeshBatch:


Static generation
For statically generated primitive drawing instructions , When we add primitives to the scene (AddToScene), Create at the same time MeshBatch, And will MeshBatch Relevant information is bound to the scene . We call Proxy Of DrawStaticElements To construct static objects MeshBatch:

When necessary, , We generate cached MeshCommand:

For each element , collect MeshBatch It mainly includes ComputeRelevance() and MarkRelevant() Two processes .
among ,ComputeRelevance Mainly collect all static objects ; and MarkRelevance Mainly responsible for acquiring MeshDrawCommand, And will MeshBatch And the related RenderPass Connect .
The cache MeshBatch The information is recorded in PrimitiveSceneInfo in :

StaticMeshBatch Corresponding MeshDrawCommand There are also caching mechanisms , If you use caching , We find the corresponding Command And collect ; If not used , Directly collect MeshBatch, Wait until later to deal with the relevant logic .
Cached and uncached MeshBatch The data are recorded in ViewCommands.MeshCommands and ViewCommands.DynamicMeshCommandBuildRequests in .
Dynamic generation
Each frame of the dynamic object will regenerate the corresponding MeshBatch, Its overall logic is relatively simple .
First it will pass Proxy Of GetDynamicMeshElements Function construction corresponds to MeshBatch, after , stay ComputeDynamicMeshRelevance Function , And the related RenderPass Connect .
Dynamic object MeshBatch adopt Collector To collect , Recorded in the View.DynamicMeshElements in .
Generate MeshBatchCommand
ue4 Contains multiple drawings pass, Such as DepthPass, BasePass, ShadowPass etc. , It's through inheritance FMeshPassProcessor Realized , The final drawing takes place here .
stay ComputeViewVisibility in , When we collect all the static / dynamic MeshBatch after , Then we will submit MeshBatch Convert to the corresponding MeshDrawCommand Request , The whole process takes place in SetupMeshPass in :

We have already mentioned , Whether static or dynamic MeshBatch, Will be associated with specific RenderPass relation . there RenderPass contain DepthPass, BasePass, ShadowPass etc. , Different Pass By inheritance FMeshPassProcessor Realized , Every FMeshPassProcessor There will be a AddMeshBatch function .
And in the SetupMeshPass in , We will traverse all pass, And get the corresponding MeshBatch, call AddMeshBatch, Here's the picture , Two places marked AddMeshBatch Deal with dynamic and static separately ( nothing cache command) Of MeshBatch.

AddMeshBatch By each pass Separate implementation , It mainly includes the following two parts : One is based on MeshBatch Get relevant rendering information , Such as bound shaders , Render states ( Mixed mode , Deep reading and writing mode ); The other is to call general BuildMeshDrawCommands function , from MeshBatch And the rendering state calculated in the previous step MeshDrawCommands.
边栏推荐
- Qt development - scrolling digital selector commonly used in embedded system
- 洛谷P5018 [NOIP2018 普及组] 对称二叉树 题解
- Amazon, express, lazada, shopee, eBay, wish, Wal Mart, Alibaba international, meikeduo and other cross-border e-commerce platforms evaluate how Ziyang account can seize traffic by using products in th
- tonybot 人形机器人 红外遥控玩法 0630
- tonybot 人形机器人 查看端口并对应端口 0701
- 7-10 stack of hats (25 points) (C language solution)
- 洛谷P5536 【XR-3】核心城市 题解
- Solr series of full-text search engines - basic principles of full-text search
- 动态获取权限
- How to query the baby category of tmall on Taobao
猜你喜欢

How to color ordinary landscape photos, PS tutorial

Tonybot Humanoïde Robot Infrared Remote play 0630

Doris学习笔记之数据表的创建
![洛谷P5018 [NOIP2018 普及组] 对称二叉树 题解](/img/89/da1a3a38e02671628f385de0f30369.png)
洛谷P5018 [NOIP2018 普及组] 对称二叉树 题解

如何查询淘宝天猫的宝贝类目

dllexport和dllimport

Bibit pharmaceutical rushed to the scientific innovation board: annual revenue of 970000, loss of 137million, proposed to raise 2billion

The latest M1 dedicated Au update Adobe audit CC 2021 Chinese direct installation version has solved the problems of M1 installation without flash back!

Amazon, express, lazada, shopee, eBay, wish, Wal Mart, Alibaba international, meikeduo and other cross-border e-commerce platforms evaluate how Ziyang account can seize traffic by using products in th

tonybot 人形机器人 首次开机 0630
随机推荐
Awvs batch operation script
puzzle(016.4)多米诺效应
dllexport和dllimport
DDK for XP
创业团队如何落地敏捷测试,提升质量效能?丨声网开发者创业讲堂 Vol.03
Plane vector addition
牛客 BM83 字符串變形(大小寫轉換,字符串反轉,字符串替換)
分布式事务(Seata) 四大模式详解
数学常数表 by q779
dllexport和dllimport
556. The next larger element III
My QT learning path -- how qdatetimeedit is empty
Zzuli:1052 sum of sequence 4
【北大青鸟昌平校区】互联网行业中,哪些岗位越老越吃香?
Zzuli:1049 square sum and cubic sum
Statistical capital consonants
C language to implement a password manager (under update)
On MEM series functions of C language
Luogu p3065 [usaco12dec]first! G problem solution
556. The next larger element III: simple construction simulation questions