ue5-lumen's scene data update and write UpdateLumenScene

Lumen takes several steps when rendering:

The first is the distance field voxel reconstruction of the scene by BeginUpdateLumenSceneTasks

The second is UpdateLumenScene to update the lumen scene and the card that includes using nanite and uploading the lumen

The third is RenderLumenSceneLighting to obtain direct light and indirect light of lumen lighting

The fourth is the acquisition and setting of the RenderLumenSceneVisualization visualization probe, and the voxel step and radiance settings.

The fifth is to perform calculation on the probe of lumen in RenderDiffuseIndirectAndAmbientOcclusion to obtain the illumination of the probe to superimpose.

Set the uniform data through Lumen:: SetupViewUniformBufferParameters .

data is copied to memory

Rendering of lumen's card

Execute SubmitMeshDrawCommandsRange on all FCardRenderData objects in CardsToRender and submit them to the rendering command. The CardsToRender here is filtered by BeginUpdateLumenSceneTasks. The parameters have 4 rts, including albedoatlas, normalatlas, emissiveatlas and depthstencilatlas calculated by lumen.

Nanite culling

Later, nanite is used for culling. First, the rasterized context information is obtained through Nanite::InitRasterContext, and the culled context information is obtained through Nanite::InitCullingContext.

Anti-angle or single-angle culling

Then according to whether it is GLumenSceneNaniteMultiViewCapture to specify whether it is processed by multiple views or a single view.

Then organize into NaniteView to go to Nanite::CullRasterize for all CardsToRender. If it is a single view, perform Nanite::CullRasterize of PackedView on all CardsToRender.

Among them, NaniteInstanceDraws in Nanite::CullRasterize is the object rendered by nanite. Perform culling. Nanite::CullRasterize, including HZB, vsm culling.

distance field culling

Then the culling of the distance field will be performed, where the parameter Lumen::GetDistanceSceneNaniteLODScaleFactor() is 2

power. Then execute Nanite::CullRasterize to cull individual PackedViews.

CullRasterize quite a deal

The parameters required for Nanite::CullRasterize here are the scene, the field of view object, the culling context, the rasterization context, and then the rasterization state (such as the near clipping plane and the culling method is front and back, etc.).

Specifically in CullRasterize, if the number of view cones is greater than MAX_VIEWS_PER_CULL_RASTERIZE_PASS, another pass must be opened to cull.

Then use FInitArgs_CS to initialize the culling of the cluster

Use AddPass_InstanceHierarchyAndClusterCull to add a hierarchy culling and cluster culling.

Nanite's rendering of lumen:

Then use Nanite:: DrawLumenMeshCapturePass to render, and execute DrawLumenMeshCapturePass in NaniteRender.cpp .

First set the parameter FNaniteMarkStencilRectsParameters , and then execute to FPixelShaderUtils:: AddRasterizeToRectsPass , execute RHICmdList.DrawPrimitive inside, mark the template of all pixels that pass the depth test .

Then set the parameter FNaniteEmitMaterialIdRectsParameters , then execute FPixelShaderUtils:: AddRasterizeToRectsPass , use RHICmdList.DrawPrimitive to draw information, here is to use depth information to obtain material information .

Then set the parameters to FNaniteEmitGBufferParameters , including cluster information, albedo, normal, emissive, and set the uniform data to FNaniteUniformParameters , using const_cast<FScene&>(Scene).UniformBuffers.NaniteUniformBuffer.UpdateUniformBufferImmediate , which is the uniform data setting of nanite.

Submit rendering in two modes

Then there are two modes, a mode with distance fields, and an execution list mode.

Distance Field Mode:

In the mode with distance field, you can get the pass of NaniteMaterialPassCommands about nanite material through BuildNaniteMaterialPassCommands. Submit a SubmitNaniteMaterialPassCommand for each pass. here

The SubmitNaniteMaterialPassCommand here is the SubmitNaniteMaterialPassCommand executed to NaniteRender, and it is also the draw command executed to the specific platform through FMeshDrawCommand::SubmitDrawBegin and FMeshDrawCommand::SubmitDrawEnd.

nanite execute list mode

If it is not the distance field mode, traverse CardRenderData.NaniteCommandInfos and get the id inside, get FMeshDrawCommand through Scene.NaniteDrawCommands[ENaniteMeshPass::LumenCardCapture], and then use SubmitNaniteMaterialPassCommand to execute the draw of MeshDrawCommand.

Get depth information again:

Finally, he also executes the acquisition of the depth value again, mainly because if there is a modification, it can be written in the first time.

Upload the buffer of lumen

Then use FLumenCardIdUpload to upload lumen's card. Here is the upload of several IBuffers, including CardsToRenderIndexBuffer , CardsToRenderHashMapBuffer , VisibleCardsIndexBuffer .

The core of the upload here is the address copy, FPlatformMemory::Memcpy(DestCardIdPtr, CardIdPtr, CardIdBytes); the target address here is a buffer of RHI.

Filter the depth of the lumen:

Then after the upload is executed, the depth will be filtered again. PrefilterLumenSceneDepth. Here is the implementation to FDeferredShadingSceneRenderer:: PrefilterLumenSceneDepth .

First initialize the variables of CardScatterContext .

Then execute FLumenCardScatterContext:: CullCardsToShape , mainly to execute the computeshader of FCullCardsToShapeCS, which also executes CullCardsToShapeCS of LumenSceneLighting.usf . The main filtering method is whether the card is visible, whether the card is affected by the light range, and whether the card is within the visible range.

Then there is BuildScatterIndirectArgs, which is the same as the indirect light parameter initialization of BuildScatterIndirectArgs of RenderLumenSceneLighting .

Then FLumenCardCopyDepth performs a deep copy of the lumencard. It is mainly to execute the LumenCardPrefilterLightingPS of LumenSceneLighting.usf to perform the assignment of three colors through mrt, OutLighting, OutColor1, OutColor2. They are parent lighting information, direct irradiance color, and indirect irradiance color.

Guess you like

Origin blog.csdn.net/llsansun/article/details/123192334