Detailed render flow

The start of Deferred Rendering is

Engine / Source / Runtime / Renderer / Private / DeferredShadingRenderer.cpp (532)

FDeferredShadingSceneRenderer :: Render ()

It starts from here.

Number of lines Code piece Contents
539 GRenderTargetPool.TransitionTargetsWritable () Transition to the state where the target of the target pool can be drawn
542 SceneContext.ReleaseSceneColor () Release scene color buffer
546 to 552 FRHICommandListExecutor :: WaitOnRHIThreadFence () If RHI is running in a separate thread, wait for OcculusionSubmittedFence here Wait for completion of the OcculusionCulling process of the previous stage?
568 GSystemTextures.InitializeTextures () Initialization of system texture Nothing is done if initialized
571 SceneContext.Allocate () Secure the buffer for the render target matching the ViewFamily Information on whether ViewFamily has FeatureLevel or SceneCapture
573 SceneContext.AllocDummyGBufferTargets () Assign dummy black texture to GBuffer
579 InitViews () Various initialization of view About crawling of transformation meshes, translucent sorting, initialization of shadow and write cash
581-588 PostInitViewFamily_RenderThread () etc. Unimplemented
599 to 606 GetEyeAdaptation () It is meaningless because it calls the const function but it does not store the acquired one?
608 to 631 if (ShouldPrepareDistanceFieldScene ()) This block becomes effective when the DistanceField system (AO, Shadow, etc.) is used However, IntelHD 4000 series seems to fail to generate 3D texture, and processing contents which are forcibly invalidated are required for DF technology Creation, update, etc. of Volume texture aligned in View space
720 to 727 FGlobalDynamicVertexBuffer :: Get (). Commit () Commit processing of dynamic vertex buffer and index buffer Mainly unlock vertices and index buffers for particles (unmapped)
732 to 737 Scene-> FXSystem-> PreRender () Preprocessing rendering effects It is not done here if planar reflection mainly for updating GPU particles is effective or render thread is effective
767 to 788 RenderPrePass () Performing Z Pre-Pass rendering
807 SceneContext.ResolveSceneDepthTexture () Deployment of resolve compression depth of depth buffer rendered with Z Pre-Pass and resolve processing of MSAA
811 ComputeLightGrid () From the computational shader code of the light grid, it is mainly for semi-transparent Forward Rendering which is generating light link list for Clusterd lighting
821 - 826 SceneContext.AllocGBufferTargets () Memory allocation for GBuffer
830 - 841 RenderOcclusion () Occlusion related rendering We also create a hierarchical depth buffer here, such as occlusion queries for low resolution buffers It is effective when Z Pre-Pass draws everything in the depth buffer When parallel processing of SSAO is performed, processing starts here
845 to 849 RenderShadowDepthMaps () Draw shadow map Render it to an atlased shadow map unlike in the past
852 to 857 ClearLPVs () Clear the buffer used for Light Propagation Volume
859 to 863 RenderCustomDepthPassAtLocation () Draw CustomDepth before base pass If you set 0 in r.CustomDepth.Order, draw at this stage It can be used in the DBuffer path
865 to 868 ComputeVolumetricFog () In order to apply volume fog, only one parallel light source that lights space-divided 3D texture (probably) corresponds to light function
870 - 878 RenderForwardShadingShadowProjections () Project shadow on scene in case of Forward Rendering In Forward, it is difficult to process multiple shadows at the time of material calculation, so calculate the shadow attenuation in a pure white buffer called a white buffer
885 to 900 if (bDBuffer) Draw Deferred Decal when DBuffer is enabled
902 to 934 AllocateDeferredShadingPathRenderTargets () Secure render target for Deferred shading Depending on conditions, clear GBuffer and volume write buffer for translucency
936 to 946 BeginRenderingGBuffer () Render target setting For wire frame display, use MSAA buffer
951 to 958 RenderBasePass () Drawing the base path Resolving the depth buffer after the end of the base pass which seems to be loading commands in parallel by multiple threads
976 to 985 ClearGBufferAtMaxZ () Clear GBuffer of unpainted part Usually it is not necessary, but for GBuffer display correspondence?
987 VisualizeVolumetricLightmap () Visualization of volume light map
989 ResolveSceneDepthToAuxiliaryTexture () Resolve the depth buffer to another buffer Depth Test for hardware that can not be fetched while testing
991 to 1002 RenderOcclusion () Occlusion drawing after base pass If rendering is not done at line 830, rendering here
1012 to 1017 RenderShadowDepthMaps () Draw shadow map and volume fog If the occlusion drawing is after the base pass, do it here
1019 to 1023 RenderCustomDepthPassAtLocation () Custom depth drawing after base pass Normally it will be drawn here
1028 to 1038 FXSystem-> PostRenderOpaque () Effect drawing after base pass Maintenance of GPU particles taking a collision judgment is done
1042 to 1054 RenderVelocities () Draw speed buffer
1057 CopyStencilToLightingChannelTexture () Copy the write channel information written to the stencil buffer
1059 to 1061 GfxWaitForAsyncSSAO () Wait for rendering of parallel processing SSAO
1065 to 1081 ProcessAfterBasePass () Post process after base pass If unprocessed yet, perform Deferred Decal or SSAO processing
1084 to 1101 SetRenderTargetsAndClear () Clear stencil buffer only
1111 to 1114 RenderIndirectCapsuleShadows () Indirect lighting calculation by capsule shadow Multiplication with SceneColor and SSAO At this stage, SceneColor should have the base pass emissivity written
1118 RenderDFAOAsIndirectShadowing () We also calculate the vent normal for the drawing of DistanceFieldAO, and then use it in several stages
1121 to 1124 ClearTranslucentVolumeLighting () Clear the translucent volume light
1127 RenderLights () Rendering lights

From here we enter the RenderLights () function once.

The source code is below.

Engine / Source / Runtime / Renderer / Private / LightRendering.cpp (316)

Number of lines Code piece Contents
329 - 332 GatherSimpleLights () Collect particle light as SimpleLight Mainly for tile based lighting
340 to 365 LightSceneInfo-> ShouldRenderLight () Create a list of lights to draw
368 to 375 SortedLights.Sort () Sort the light with shadow, with light function etc.
420 to 424 WaitComputeFence (TranslucencyLightingVolumeClearEndFence) Wait for asynchronous execution of translucent write volume
435 to 455 RenderTiledDeferredLighting () Perform tile-based Deferred Lighting
457-461 RenderSimpleLightsStandardDeferred () If tile-based rendering that renders SimpleLight is executed, rendering here is not performed
463-478 RenderLight () Render with light without shadows, no light function
480 - 495 InjectTranslucentVolumeLightingArray () Draw shadowless light, SimpleLight on translucent light volume 1 Write 1 for each slice with geometry shader Draw with DrawCall
499 to 559 UpdateLPVs () When LPV is valid, update LPV Reflective Shadow Maps and direct light into the volume
569 for (int32 LightIndex = AttenuationLightStart; ... From here shadowed or / and processing with light with write function
592 to 631 RenderShadowProjections () Shadow rendering shadow attenuation to the white buffer is not performed at lighting calculation but once drawn in the white buffer of the same size as the frame buffer It also draws to translucent volume light and height map light
633 to 637 HeightfieldLightingViewInfo.ComputeLighting () Heightfield lighting calculation Heightfield only Lighting results are rendered to an atlas texture
640 to 657 RenderPreviewShadowsIndicator () Draw attenuation by write function in white buffer
659 to 662 CopyToResolveTarget () White buffer resolve
664 to 669 InjectTranslucentVolumeLighting () If the shadow is not valid, render to the semitransparent light volume here
674 to 677 RenderLight () Direct rendering of lights

Light rendering is here.

After that we will return to DeferredShadingRenderer.cpp again.

Number of lines Code piece Contents
1133 InjectAmbientCubemapTranslucentVolumeLighting () Render Ambient CubeMap to translucent light volume
1137 FilterTranslucentVolumeLighting () Filtering translucent light volume 3 x 3 x 3 box filter
1142 to 1153 ProcessLpvIndirect () Post process process after lighting Currently only LPV application
1155 RenderDynamicSkyLighting () Drawing dynamic skylights
1159 ResolveSceneColor () Resolve the target of the SceneColor drawn so far Usually, you use the resolve command of RHI, but if mobile emulation is required special processing
1162 RenderDeferredReflections () Apply environmental reflection as post process Also
calculate Screen Space Reflection here
1169 to 1173 ProcessAfterLighting () Post process after applying reflection Currently only post process processing of Screen Space Subsurface Scattering
1180 to 1185 RenderLightShaftOcclusion () Drawing shielding information on the light shaft Although you can activate the light shaft without this, there is a difference in quality when there is a shielding near the camera
1188 to 1212 RenderAtmosphere () Drawing Atomospheric Fog
1217 to 1222 RenderFog () Drawing volume fog of Height Fog is also applied here
1224 to 1236 RenderPostOpaqueExtensions () Additional processing after opaque rendering is like a rendering process that the user can specify in C ++ ?
1252 to 1261 RenderTranslucency () Draw translucent objects In case of Separate Translucency, draw it in another buffer and do it until composition
1267 to 1275 RenderDistortion () Drawing material with Refraction enabled
1280 to 1286 RenderLightShaftBloom () Results differ depending on whether shielding information for drawing the light shaft is drawn or not
1288 to 1293 RenderOverlayExtensions () Perhaps user-executable rendering passes Like RenderPostOpaqueExtensions
1295 to 1303 RenderDistanceFieldLighting () DistanceField type lighting processing (GI etc.)
1306 to 1318 RenderMeshDistanceFieldVisualization () RenderStationaryLightOverlap () Information for debugging Information on visualized mesh DF and StationaryLight overlap information
1336 to 1341 GPostProcessing.Process () Drawing post process
1361 to 1366 RenderFinish () Drawing end processing Debug visualization etc.

that's all.

From here it is a post process.

Engine / Source / Runtime / Renderer / Private / PostProcess / PostProcessing.cpp (1262) From this location.

Number of lines Code piece Contents
1385 to 1451 AddPostProcessDepthOfFieldGaussian () AddPostProcessDepthOfFieldCircle () AddPostProcessDepthOfFieldBokeh () Drawing of depth of field (DoF) In the case of BokehDoF, synthesis with the Separate Translucency buffer is also done here
1453 - 1463 RegisterPass (new (FMemStack :: Get ()) FRCPassPostProcessBokehDOFRecombine (bIsComputePass)) If it is not BokehDoF, synthesize Separate Translucency here
1465 AddPostProcessMaterial (Context, BL_BeforeTonemapping, SeparateTranslucency) Apply post process material before tone map
1469 - 1482 AddTemporalAA () Apply TemporalAA
1484 to 1544 FRCPassPostProcessMotionBlur () Apply motion blur Using an improved version of [A Reconstruction Filter for Plausible Motion Blur ] It is also possible to apply higher quality blur by 2-pass rendering using scale values changed If 1 is specified for r.MotionBlurSeparable it becomes valid
1546 to 1559 FRCPassPostProcessVisualizeMotionBlur () Visualization of motion blur and bloom
1562 to 1572 FRCPassPostProcessDownsample () Downscaling the SceneColor buffer to a half resolution buffer
1574 to 1609 FRCPassPostProcessHistogram () Use the down-sampled SceneColor to obtain the histogram of the screen
1612 to 1625 CreateDownSampleArray () Perform multiple downsampling from the half resolution SceneColor for Bloom If Eye Adaptation is enabled, set up in this
1628 to 1653 AddPostProcessBasicEyeAdaptation () AddPostProcessHistogramEyeAdaptation If bloom which executes Eye Adaptation is invalid, it downsamples here
1655 to 1756 AddBloom () Apply blooming Also perform lens flare and lens blur in this function
1760 to 1790 AddTonemapper () Apply tone map
1792 - 1795 AddPostProcessAA () Apply FXAA
1797-1804 FRCPassPostProcessVisualizeDOF () DoF Visualization
1808 to 1823 AddGammaOnlyTonemapper () If it is not a full post process, apply Separate Translucency synthesis and simple tone mapper
1826 to 1906 FRCPassPostProcessVisualizeComplexity () etc. Various visualization etc.
1908 AddPostProcessMaterial (Context, BL_AfterTonemapping ... Apply post-process material after tone map
1910-1982 FRCPassPostProcessSubsurfaceVisualize () etc. Various visualization etc.
1986 to 2025 FRCPassPostProcessUpscale () If the screen percentage is valid, upscale here

Or more.

Congratulations!

Normally, when you use UE 4 , you do not need to be conscious of the order of these paths, but you should read the source code if you really want to replace the processing, or want to avoid wasteful processing.

I hope this article will help such people.

Reference From http://monsho.hatenablog.com/entry/2017/12/16/012502