当前位置:网站首页>[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.
边栏推荐
- J-luggage lock of ICPC Shenyang station in 2021 regional games (simple code)
- Accelerating strategy learning using parallel differentiable simulation
- 亚马逊、速卖通、Lazada、Shopee、eBay、wish、沃尔玛、阿里国际、美客多等跨境电商平台,测评自养号该如何利用产品上新期抓住流量?
- SSH access control, blocking the IP when logging in repeatedly to prevent brute force cracking
- On MEM series functions of C language
- How to color ordinary landscape photos, PS tutorial
- Zzuli:1041 sum of sequence 2
- 如何查询淘宝天猫的宝贝类目
- Dllexport and dllimport
- Bucket sorting in C language
猜你喜欢

Niuke: crossing the river

Creation of data table of Doris' learning notes

556. The next larger element III

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

Understand the application scenario and implementation mechanism of differential segment

创业团队如何落地敏捷测试,提升质量效能?丨声网开发者创业讲堂 Vol.03
![洛谷P4047 [JSOI2010]部落划分 题解](/img/7f/3fab3e94abef3da1f5652db35361df.png)
洛谷P4047 [JSOI2010]部落划分 题解

Timecho of Tianmou technology completed an angel round financing of nearly 100 million yuan to create a native timing database of the industrial Internet of things

X86 assembly language - Notes from real mode to protected mode

Bibit pharmaceutical rushed to the scientific innovation board: annual revenue of 970000, loss of 137million, proposed to raise 2billion
随机推荐
Tonybot Humanoïde Robot Infrared Remote play 0630
Add ZABBIX calculation type itemcalculated items
关于敏捷的一些概念
基因家族特征分析 - 染色体定位分析
tonybot 人形机器人 定距移动 代码编写玩法
Four data flows and cases of grpc
Mongodb index
创业团队如何落地敏捷测试,提升质量效能?丨声网开发者创业讲堂 Vol.03
Zzuli:1049 square sum and cubic sum
Luogu p5194 [usaco05dec]scales s solution
retrofit
Zzuli:1054 monkeys eat peaches
Output student grades
NOI OPENJUDGE 1.5(23)
The latest M1 dedicated Au update Adobe audit CC 2021 Chinese direct installation version has solved the problems of M1 installation without flash back!
洛谷P5536 【XR-3】核心城市 题解
puzzle(016.4)多米诺效应
Awvs batch operation script
提高效率 Or 增加成本,开发人员应如何理解结对编程?
ZABBIX saves the page blank after adding calculated items