[虚幻官方教程学习笔记]深入理解实时渲染(An In-Depth Look at Real-Time Rendering)
原英文教程地址深入理解实时渲染(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将多个网格体合并成一个网格体(但独立材质)
关于模型合并的几个建议
合并模型并不是必须的,而且很花时间。
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