Presented at the Gnomon School of VFX in January 2018, part two of the class offers an in-depth look at the rendering pipeline in Unreal Engine, its terminology and best practices for rendering scenes in real-time. This course also presents guidelines and profiling techniques that improve the debugging process for both CPU and GPU performance.ios
分7个部分介绍UE4中的渲染管线。app
1.Introless
2.Before Renderingide
3.Geometry Rendering布局
4.Rasterizing and Gbufferpost
5.Dynamic Lighting/Shadows性能
6.Static Lighting/Shadowsflex
7.Post Processing优化
Know how the load is distributed between the 2动画
进行预计算
Shadring techniques
Deferred Shading
1.Composition based using the GBuffer
2.Shading happens in deferred passes
3.Good at rendering dynamic lighting
4.More flexible when it comes to disabling feature,less flexible when it comes to surface attributes
延迟渲染:经过GBuffer,渲染动态光照更有优点。当涉及到禁用特性时,更灵活,在涉及表面属性时不那么灵活。
============================================
CPU-Game Thread
Calculate all logic and transforms
1.Animations
2.Position of models and objects
3.Physics
4.AI
5.Spawn and destroy,Hide and Unhide
Anything that relates to the posistion of objects to change
CPU阶段计算全部的逻辑和转换,动画,坐标,物理属性,建立和销毁
============================================
CPU-Draw Thread
Before we can use the transforms to rendering the image we need to know what to include in the rendering
Ignoring this question might make rendering expensive on GPU
Occlusion process-Builds up a list of all visible models/objects
Happens per object-Not per triangle
Stage process-in order of execution
1.Distance Culling
2.Frustum Culling
3.Precomputed Visibility
4.Occlusion Culling
几种剔除:距离剔除,视锥剔除,预计算,遮挡剔除。
剔除具体到物体,而不是三角面
============================================
Occlusion Performance Implications
UE4 has a list of models to render
1.Set up manual culling(i.e.distance culling,pre-coputed vis)
2.Even things like particles occlude
3.Many small objects cause more stress on CPU for culling
4.Large models will rarely occlude and thus increase GPU
5.Know your world and balance objects size vs count
性能分析,1.设置距离剔除,预计算来提升性能
2.小物体太多影响性能,大物体基本上不影响遮挡
3.找到平衡,场景中物体的大小的数量。
GPU-Prepass/Early z pass
The GPU now has a list of models and transforms but if we just render this info out we could possibly cause a lot of redundant pixel rendering
Similar to excluding objects,we need to exclude pixels
We need to figure out which pixels are occlluded
To do this, we generate a depth pass and use it to determine if the given pixel is in front and visible
z pass 来处理像素的渲染,被遮挡的不渲染。
============================================
Drawcalls
GPU renders drawcall by drawcall not triangle by traingle
A drawcall is group of tris sharing the same properties
Drawcalls are prepared by the CPU(Draw) thread
Distilling rendering info for objects into a GPU state ready for submission
GPU 渲染物体经过drawcall 而不是三角形,CPU阶段提交drawcall到GPU state
============================================
UE4 with current gen high-end PCs
2000-3000 is reasonable
More than 5000 is getting high
More than 10000 is probably a problem
On mobile this number is far lower(few hundred max)
Drawcalls count is determined by visible objects
Measure with "stat RHI"
UE4 三角面的数量问题。Drawcall 次数受可见物体的影响
============================================
Drawcalls have a huge impact on the CPU(Draw) thread
Has high overhaead for preparing GPU state
Usually we hit the issues with Drawcalls way before issues with tri count
GPU state以前,Drawcall相比tri count的问题,要优先解决。
============================================
Drawcalls Performance Implications
1.Render your triangles with as few Drawcalls as possible
2.50000 triangles can run worse than 50 million dependent on scene setup(Drawcalls)
3.When optimizing scene,know your bottleneck(Drawcalls vs Tri count)
性能分析
1.尽量少的drawcall
2.50000triangles有可能跑的比50million性能更差,视drawcall状况
3.优化场景的时候注意本身的瓶颈,是三角面仍是drawcall
============================================
Optimizing Drawcalls (Merging objects)
To lower the drawcalls it is better to use fewer larger models than many small ones
You cannot do that too much,it impacts other things negatively
Good balance between size and count is a good strategy
优化Drawcall:合并场景的,更少更大的模型,多个方面做用,剔除,光照贴图,遮挡计算,内存
============================================
Optimizing Drawcalls (Merging guidelines) 合并准则
1.Target low poly objects
2.Merge only meshes within the same area
3.Merge only meshes sharing the same material
4.Meshes with no or simple collision are better for merging
5.Distant geometry is usually great to merge(fine with culling)
合并准则:
1.低模多边形
2.相同区域的meshes
3.合并相同材质的mesh
4.相同遮挡或者不被遮挡的物体
5.远距离的mesh(被精确剔除的)
============================================
Optimizing Drawcalls (HLODs)
Hierarical level of Detail
优化Drawcalls(HLOD)
Lod 分层细节绘制。远距离视野的单个组合 静态网格体 替代多个 静态网格体,下降每帧的drawcalls数量以提高性能。
do Instanced Rendering
============================================
Strategy is to mix all prvious solutions
Some merged content(Materials merged)
Some modular content(instanced)
and swapable LODs and HLODs
多方面优化Drawcalls
============================================
Vertex Processing
First thing processing the Drawcall
Vertex shader takes care of this process
Vertex shader is a small program specialized in vertex processing
Runs completely on the GPU and so they are fast
Input is vertex data in 3D space output vertex data in screen-space
Vertex-Shaders-Common tasks
It converts local VTX positions to world position
It handles vertex shading/coloring
It can apply additional offsets to vertex positions
VS的做用:
本地空间到世界空间转换
处理顶点颜色
将偏移量做用在顶点上
============================================
Practical examples of world position offset vertex shaders are
1.Cloth
2.Water displacement
3.Foliage wind animation
具体应用:布料运动,水的运动,风中的叶子。
============================================
Vertex Shaders - Drawback
vertex Shaders do not modify the actual object or affect the scene state, it is purely a visual effect
The CPU is not aware of what the vertex shaders do
Thus things like physics or collisions will not take it into account
vs注意事项:
不影响实际场景,只是一种视觉效果
CPU不知道vs作了什么,物理碰撞不会在vs阶段考虑。
============================================
Vertex shader Performance Implications
性能分析:
动画越复杂,点越多性能越慢。远距离的能够禁用vs特效
============================================
Rasterzing
GPU ready to render pixels
Determine which pixels should be shaded called rasterizing
Done drawcall by drawcall then tri by tri
Pixel Shaders are responsible for calculating the pixel color
Input is generally interpolated vertex data, texture samplers
Rasterizing inefficiency
When rasterizing dense meshes at distance, they converge to only few pixels
A waste of vertex processing
A 100k tris object seen from so far away that it would be 1 pixel big,will only show 1 pixel of its closest triangle!
光栅化:ps处理vs阶段传来的顶点信息,距离特别远的mesh,可能占的像素特别小,会浪费许多vs阶段的性能。
============================================
Overshading
Due to hardware design, it always uses a 2x2 pixel quad for processing
If a traingle is very small or very thin then it means it might process 4 pixels while only 1 pixel is actually filled
因为硬件的缘由,每次处理2x2 4个像素
============================================
Rasterization and Overshading Performance Implications
性能分析:密度大的三角面,性能要求高。距离远密度会变大,尽量下降三角面个数,thin tri资源消耗大。
============================================
Results are written out to:
Multiple Gbuffers in case of deferred shading
Shaded buffer in case of forward shading
光栅化后的数据用在延迟光照的Gbuffer中。
GBuffer PPerformance Implications
The GBuffer takes up a lot of memory and bandwidth and thus has a limit on how many different GBuffer images you can render out
Gbuffers memory is resolutions dependent
性能分析:GBuffer占用大量内存带宽,能渲染出的GBuffer数量有限。
Two approaches for lighting and shadows
Lighting(Deferred Shading)
Is calclated and applied using pixel shaders
Dynamic point lights are rendered as spheres
The spheres act like a mask
Anything within the sphere is to receive a pixel shader operation to blend in the dynamic light
动态点光源渲染成球体,至关于一个蒙版遮罩,遮罩内的像素,在ps里面作混合
============================================
Light calculation requires position
Depth buffer used to get pixels pos in 3D
Use normal buffer to appley shading.Direct between Normal and light
计算光照,深度depth buffer和Normal buffer共同做用,计算光照。
============================================
Shadows
Common technique for rendering shadows is Shadow Maps
Check for each pixel if it is visible to the given light or no
Requires rendering depth for light Pov
在light view空间下,渲染shadow map。
Process Pros/Cons
利弊分析:
利:利用GBuffer实时渲染能够动态调整灯光
弊:性能代价
============================================
Quality Pros/Cons
质量利弊:
性能代价大,下降质量提升性能;没法渲染自发光和全局光照;动态软阴影效果差。
============================================
Dynamic Lighting Performance Implications
动态光照性能分析:
延迟渲染动态光源小,性能占用较小。
成本受ps影响,处理像素越多,越慢。
半径尽可能小。避免过分叠加。
============================================
Dynamic Shadows Performance Implication
动态阴影性能分析:
关闭没必要要的阴影,三角面数量影响阴影效果,距离远的时候简化阴影。
Dynamic lights and shadows expensive
Thus part of it is offloaded to pre-calculations/pre-rendering
This is referred as static lights and shadows
Lighting data stored mainly in lightmaps
动态光照昂贵,使用lightmap。
Lightmaps
A lightmap is a texture with the lighting and shadows baked into it
An object usually requires UV lightmap coordinates for this to work
This texture is then multiplied on top of the basecolor
将光照信息烘焙到原有的纹理信息上。
============================================
Lightmass
Stand alone application that handles light rendering,baking to lightmaps and integerating into materials
Raytracer supporting Gl
Supports distributed rendering over a network
Bake quality is determined by Light Build Quality as well as settings in the Lightmass section of each level
Better to have a lightmass importance Volume around part of the scene
光照烘焙:单独的模块处理光照渲染。支持全局光照,烘焙区域和质量可调节。
============================================
Process Pros/Cons
利弊分析:
速度更快,但内存增长;需要花时间预处理;场景改变从新烘焙;模型需要光照uv
============================================
Quality Pros/Cons
质量利弊:
能够处理辐射度和全局光照;
能够渲染逼真的阴影;
质量受lightmap分辨率和uv布局影响;
uv布局影响可能出现缝隙;
============================================
Static Lighting Performance Implications
静态光照性能分析:
光照贴图影响内存和文件大小。贴图分辨率增大,灯光和模型增长,质量提升,光源半径增大都会致使烘焙时间增多。
============================================
Visual effects applied at the very end of the rendering process
Uses the GBuffers to calculate its effects
Once more relies heavily on Pixel Shaders
后处理:
使用Gbuffer计算效果。
Example:
光晕效果,
景深/模糊,
光泽贴图/颜色校订,
曝光,
运动模糊。
Post Processing Performance Implications
Affected directly by final resolution
Affected by shader complexity
Parameter(e.g.DoF blur radius)
后处理性能分析:
受分辨率影响;受shader复杂度影响;参数影响,如模糊半径。
Gnomon Masterclass Part II: Rendering in UE4 | Event Coverage | Unreal Engine
https://www.youtube.com/watch?v=kp3zcyZZBVY
Presented at the Gnomon School of VFX in January 2018, part two of the class offers an in-depth look at the rendering pipeline in Unreal Engine, its terminology and best practices for rendering scenes in real-time. This course also presents guidelines and profiling techniques that improve the debugging process for both CPU and GPU performance.