当前位置:网站首页>[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.
边栏推荐
- Adobe Premiere Pro 15.4 has been released. It natively supports Apple M1 and adds the function of speech to text
- Protobuf and grpc
- C language memory function
- The latest M1 dedicated Au update Adobe audit CC 2021 Chinese direct installation version has solved the problems of M1 installation without flash back!
- Detailed explanation of four modes of distributed transaction (Seata)
- Zzuli:1041 sum of sequence 2
- Zzuli:1053 sine function
- Some concepts about agile
- ShowMeBug入驻腾讯会议,开启专业级技术面试时代
- Zzuli:1057 prime number determination
猜你喜欢

Tonybot humanoid robot starts for the first time 0630

Solve the problem that PR cannot be installed on win10 system. Pr2021 version -premiere Pro 2021 official Chinese version installation tutorial

US stock listing of polar: how can the delivery of 55000 units support the valuation of more than 20billion US dollars

Paper sharing: generating playful palettes from images

Adobe Premiere Pro 15.4 has been released. It natively supports Apple M1 and adds the function of speech to text

ShowMeBug入驻腾讯会议,开启专业级技术面试时代

Use of form text box (I) select text

Niuke: crossing the river

Tonybot humanoid robot infrared remote control play 0630

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
随机推荐
The picture quality has been improved! LR enhancement details_ Lightroom turns on AI photo detail enhancement: picture clarity increases by 30%
Address book sorting
7-3 count the number of words in a line of text
Tonybot humanoid robot checks the port and corresponds to port 0701
Statistical capital consonants
puzzle(016.3)千丝万缕
分布式事务(Seata) 四大模式详解
PHP GD image upload bypass
[qingniaochangping campus of Peking University] in the Internet industry, which positions are more popular as they get older?
光猫超级账号密码、宽带账号密码 获取
NPM install is stuck with various strange errors of node NPY
Write a 2-minute countdown.
Zzuli: sum of 1051 square roots
Piwigo 2.7.1 sqli learning
Dllexport et dllimport
On MEM series functions of C language
Understand the application scenario and implementation mechanism of differential segment
Programming language: the essence of type system
Zzuli:1059 highest score
ShowMeBug入驻腾讯会议,开启专业级技术面试时代