Download RenderDoc,
choose to open the RenderDoc Plugin plugin in the UE plugin, use it to capture frames at runtime, and we can view the rendering process of UE.
0. Pre-stage
The pre-stage is mainly a set of things such as perspective transformation, projection, and initialization parameters...
You can refer to: GAMES101: Introduction to Modern Computer Graphics (1) Transformation, rasterization, and coloring
1. PrePass (pre-rendering processing stage)
We can check the rendered depth map on the right, and we can see that it is rendered one by one.
In fact, here we can see the vertex information and attributes of each Mesh when we click in.
The vertex data is obviously input in the PrePass and BasePre stages; in AO, Lights, and PostProcessing, the triangles in the screen space are mainly used for input.
2. BuildHZB
The HZB technology (Hierarchical Z-Buffer Occlusion Culling) is used in the BuildHZB below, which is to use the Z-Buffer technology and then according to the radius of the object's bounding ball, remove the objects that are occluded by other objects in the PrePass stage, and layer the mipmap internally. Select different levels of mipmaps for depth testing according to the radius.
Note: The culling here is the linear culling of ParallelFor instead of the octree.
3. BasePass
Rendering is performed in BasePass. If there are 5 objects in the scene, and each object performs 5 lighting calculations, the final 5×5=25 times, and deferred rendering is to delay the lighting rendering calculation. First, each time rendering, the It will render the object's BaseColor (basic color), surface normal, roughness, pixel depth, etc. into different images, and then calculate the 5 light sources 5 times, and finally only calculate 5+5=10 times.
It can be seen that first ClearRenderTargetView clears out 7 RTs for the next BasePass rendering, and then performs 6 parallel renderings in BasePassParallel.
The above is the result of 6 renderings. Of course, 7 RTs are actually drawn. Only the first 3 are shown here. It can be found that the characters are divided into 3 renderings, 1 ball, 1 floor, and 1 chair, a total of 6 times Rendering, this is also the process of the entire BasePass. The SceneDepth in BasePass is the output value in PrePass.
The rendered shader code is placed in \UnrealEngine\UE_5.1\Engine\Shaders\Private of the engine. We can find the BasePassPixelShader.usf file, which stores the main shader code of BasePass. According to the source code, the parameters in the material are taken out, and according to the geometry information of the input Mesh, the corresponding shader code is generated when BasePass renders.
4. ShadowDepths
Then generate a Shadowmap for it.
5. DiffuseIndirectAndAO
AO: In the new version, Lumen is used to replace some AO operations, and a layer of ambient light mask is added
Input the RT and SceneDepthZ of A and B of the previous BasePass, in which the normal map of the screen as a whole is calculated
Lumen is not analyzed here, and Lumen will be analyzed in detail in a new article in the future. Here, Lumen has done a lot of calculations, generated many pictures, and finally superimposed AO into it, and finally got the following picture.
6. Lights
There is a directionalLight in our scene, so the light source is calculated and shadow generated here.
If it is not parallel light, it will be troublesome, because if the point light source (non-parallel light) shines on the object that the camera has culled, it will not be rendered. Therefore, it is necessary to determine whether the camera is in the lighting geometry, and if it is, the depth test will be turned off.
7. Handle other
After the specific light sources in the scene are processed, volumetric clouds, atmosphere, height fog, and finally transparent volumes are processed.
8. PostProcess (post-processing)
Above, after the processing is completed, the output result is still very bad, so anti-aliasing, exposure, color correction and other operations are performed in the post-processing.
Therefore, a post-processing operation is performed subsequently.
The final result is not bad.