当前位置:网站首页>[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.
边栏推荐
- Statistical capital consonants
- Luogu p5018 [noip2018 popularization group] symmetric binary tree problem solution
- Code writing and playing method of tonybot humanoid robot at fixed distance
- Rasterization: a practical implementation (2)
- Pyqt interface production (login + jump page)
- Why is this error reported when modifying records in the database
- ZABBIX saves the page blank after adding calculated items
- 论文分享:Generating Playful Palettes from Images
- C language to implement a password manager (under update)
- 556. The next larger element III: simple construction simulation questions
猜你喜欢
Tonybot Humanoïde Robot Infrared Remote play 0630
天谋科技 Timecho 完成近亿元人民币天使轮融资,打造工业物联网原生时序数据库
puzzle(016.4)多米诺效应
Why is this error reported when modifying records in the database
Accelerating strategy learning using parallel differentiable simulation
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
Implement Gobang with C language
Understand the application scenario and implementation mechanism of differential segment
C language to realize mine sweeping
Niuke: crossing the river
随机推荐
洛谷P5194 [USACO05DEC]Scales S 题解
论文分享:Generating Playful Palettes from Images
Solr series of full-text search engines - basic principles of full-text search
Zzuli:1055 rabbit reproduction
【7.3】146. LRU缓存机制
Implement Gobang with C language
Get permissions dynamically
Zzuli:1043 max
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
Zzuli:1048 factorial table
Analysis of gene family characteristics - chromosome location analysis
tonybot 人形机器人 首次开机 0630
My QT learning path -- how qdatetimeedit is empty
Luogu p5536 [xr-3] core city solution
Why is this error reported when modifying records in the database
To improve efficiency or increase costs, how should developers understand pair programming?
2021-10-16 initial programming
556. The next larger element III
Zzuli:1053 sine function
C language DUP function