原英文教程地址深入理解實時渲染(An In-Depth Look at Real-Time Rendering)
文章目錄
- 1.Intro to An In-Depth Look at Real-Time Rendering
- CPU VS GPU
- Deferred VS Forward
- 2. Before Rendering and Occlusion
- Culling計算的步驟
- 使用console command:freezerendering鎖定當前渲染(實際上是當前Occlusion)
- Occlusion Performance Implications
- 3. Geometry Rendering Part 1
- Prepass / Early Z Pass
- Drawcalls
- 使用console command:**stat RHI** 查看Drawcall即DrawPrimitive Calls
- 4. Geometry Rendering Part 2
- 在構建場景時,使用整體大模型還是使用模塊化小模型
- Instanced Rendering
- Level Of Detail(LOD)
- HLOD( Hierarchical LOD )
- 5. Geometry Rendering Part 3
- Vertex Shaders
- Vertex Shader優化
- 6. Rasterization(柵格化), Overshading, and the GBuffer
- Quad Overdraw
- GBuffer
- Custom Depth
- 小結
- 7. Rendering and Textures
- Mipmap
- Texture Streaming
- 8. Shaders and Materials
- PBR Materials
- 使用Console Command: r.Streaming.PoolSize改變Streaming緩存池大小
- 9. An In-Depth look at Real-Time Rendering - Reflections
- Reflection Captures
- Sphere Reflection Capture
- Planar Reflection
- Screen Space Reflections(SSR)
- 使用Console Command: r.SSR.Quality 4提高SSR的質量
- 10. Static Lighting
- Static Light的優缺點
- Light Maps
- Lightmass
- Lightmass Importance Volume
- Indirect Lighting Cache
- 性能小結
- 11. Dynamic Lighting
- Dynamic Light的優缺點
- 性能小結
- 12. Fog and Transparency
- Fog
- Distance Fog
- Local Volumetric Fog
- Transparency
- 13. Post Processing
1.Intro to An In-Depth Look at Real-Time Rendering
RTR(Real-Time Rendering) is at its most efficient when there is nothing.RTR is about managing losses
當渲染一開始性能的消耗就已經無法避免,因此RTR的關鍵就在于如何管理消耗。
- 優化良好的項目應該始終運行在Target Frame rate以上,并且隨著一切功能的開啟性能的下降成一個較為緩慢的曲線;
- 而優化較差的項目其性能會陡然下降,最終低于Target Frame Rate。
You can not do RTR perfect.
RTR永遠無法達到完美,因此優化的實質就是再性能-畫質-功能之間進行妥協和平衡。
CPU VS GPU
CPU和GPU同步工作,它們可能互為對方的瓶頸(Bottleneck)
Deferred VS Forward
2. Before Rendering and Occlusion
- 簡單地說在Game Thread中我們會知道"All transforms of all models"
- 在Rendering Thread(Draw Thread)計算遮擋剔除Occlusion Culling
Culling計算的步驟
四個步驟的計算量逐漸增大
Step 1 Distance Culling(距離剔除): Distance culling removes any objects further than X from the camera
可以使用Cull Distance Volume對其內部對象進行統一(分類設置)
Step 2 Frustum Culling(視錐體剔除):
Step 3 Precomputed Visibility:
要使用PrexomputedVisibilityVolume
Step 4 Occlusion Culling(遮擋剔除):
該步驟在Rendering Thread(Draw Thread)中計算
使用console command:freezerendering鎖定當前渲染(實際上是當前Occlusion)
Occlusion Performance Implications
- Set up distance culling
- More the 10-15k objects can have an impact
- Mostly CPU bound,but some GPU impact
- Large open environments don’t occlude well
- Even things like particles occlude
- Large models will rarely occlude and thus increase GPU
- But combing models to large models will lower the CPU
3. Geometry Rendering Part 1
Prepass / Early Z Pass
Drawcalls
使用console command:stat RHI 查看Drawcall即DrawPrimitive Calls
左圖: 5 Drawcalls: Sky + Ground + 3 x Cylinders = 5
右圖: 6 Drawcalls: Sky + Ground + 2 x Cylinders + Half Cylinder with Gray Material + Half Cylinder with Red Material= 6
右圖的渲染順序
4. Geometry Rendering Part 2
RenderDoc插件:可以逐Drawcall查看一個畫面的渲染過程
在構建場景時,使用整體大模型還是使用模塊化小模型
討論:使用少量大模型 VS 使用大量小模型 對于Drawcall 的影響
對于Drawcall來講,使用少量大模型自然可以減少Drawcall,但是會帶來一些其它的性能問題。
討論:使用模塊化網格體模型的優勢和弊端“
總結: 模型的大小要適當
可以使用Editor>Tools>Merge Actors將多個網格體合并成一個網格體:Merge模式(獨立材質);Simplify模式(即Proxy Geometry Tool 合并材質)
關于模型合并的幾個建議
合并模型并不是必須的,而且很花時間。
Instanced Rendering
Level Of Detail(LOD)
HLOD( Hierarchical LOD )
對一個Mesh組(多個Mesh)進行LOD,這樣可以減少面數的同時,甚至可以減少Drawcall
Windows> Hierarchical LOD Outliner
5. Geometry Rendering Part 3
Vertex Shaders
Vertex Shader優化
6. Rasterization(柵格化), Overshading, and the GBuffer
Quad Overdraw
一般情況下Quad Overdraw雖然增加性能損耗,但并不是致命的,但如果開發VR等應用時使用Forward Render時,要關注Quad Overdraw。
- Very thin triangles affect overshading because they pass through many 2x2 pixel quads
下圖的圓柱中心部分,嚴重overshading.
GBuffer
The frame rendered out in multiple different images
These images are the used for compositing in anything ranging from materials to lighting to fog and so forth.
從此步驟開始渲染將不再利用集合體,而是全部依賴于GBuffer提供的圖片。
可以在Viewport Mode中選擇Buffer Visualization中的各個Buffer的預覽圖
Custom Depth
小結
7. Rendering and Textures
Mipmap
Texture Streaming
8. Shaders and Materials
DirectX使用HLSL即High Level Shader Language
一個Materials不只生成一個Shader,一個Materials會對每一種應用生成一個對應的Shader
PBR Materials
使用Console Command: r.Streaming.PoolSize改變Streaming緩存池大小
- Base Pass shader 的 Instruction在200左右是可以接受的,當達到700就太大了
- 復雜的Shader對性能的影響還取決于它在屏幕中的占比及它影響像素數,占比約大像素越多,復雜的Shader對性能影響越大
9. An In-Depth look at Real-Time Rendering - Reflections
Reflection Captures
Reflection Captures在關卡載入時進行捕獲
Sphere Reflection Capture
- 靜態
- 預計算
- 速度快
- 不準確
- 多個Sphere Reflection Capture可以混合,越近權重越大
Planar Reflection
- 不常用
- 計算量大
- 適合需要高精度的平面對象(如鏡子)
- 其它均不適用
- 僅限于用于下范圍(大的海洋湖泊不要用)
Screen Space Reflections(SSR)
- 默認的反射系統
- 實時影響所有對象
- 準確
- 會輸出嚴重的噪點
- 只會反射當前顯示(未被剔除)的對象
使用Console Command: r.SSR.Quality 4提高SSR的質量
10. Static Lighting
Static Light的優缺點
Light Maps
Lightmass
在World Settings中設置
Lightmass Importance Volume
Indirect Lighting Cache
性能小結
可以使用Viewport的Lightmap Density模式查看每個模型Lightmap的密度(分辨率),并在模型的Lighting>Overridden Light Map Res修改其分辨率
11. Dynamic Lighting
Dynamic Light的優缺點
- Regular Dynamic Shadows -Used throughout, very common
- Per Object Shadows -Stationary Light shadows
- Cascaded Shadow Maps (CSM)-Directional light shadowing
- Distance Field Shadows -Use DF info instead of tracing geometry
性能小結
Two more basic rule
- Use static only if you need the highest possible performance
- Use dynamic if you need to be freely or able to modify the lighting at any time
12. Fog and Transparency
Fog
Distance Fog
Distance Fog means the fog fades in the distance.They are also Height Fog - meaning fades towards the sky
- Atmospheric Fog
- Exponentional Fog
Local Volumetric Fog
Transparency
- Deferred renderers have difficulties with transparency.
- Therefore transparent surfaces are usually delayed until a late stage.
- Or rendered separately in Forward then merged with the Deferred pipeline.
透明材質區域:紅色Shader Complexity過大的部分
透明煙霧粒子充滿的場景
如果可能的話
- 將材質設為Unlit
- 或者設為Forward Render
13. Post Processing
常見的用Post Processing實現的效果
- Light Bloom
- Depth of Field/Blurring
- Some types of lens flares
- Light Shafts
- Vignette
- Tone mapping/Color correction
- Exposure
- Motion Blur