Lumen:代码层面全流程

Lumen:代码层面全流程_第1张图片

Lumen离线预处理

MeshCard生成

目前从代码来看,MeshCard生成,必须要在Editor上才可以,运行时不行。后面如果运行时加载vrscene,这个会是难点。

具体代码如下:

Engine/Source/Runtime/Engine/Private/MeshCardRepresentation.cpp

void FAsyncCardRepresentationTaskWorker::DoWork()
{
	// Put on background thread to avoid interfering with game-thread bound tasks
	FQueuedThreadPoolTaskGraphWrapper TaskGraphWrapper(ENamedThreads::AnyBackgroundThreadNormalTask);
	GCardRepresentationAsyncQueue->Build(&Task, TaskGraphWrapper);
}
 
void FCardRepresentationAsyncQueue::Build(FAsyncCardRepresentationTask* Task, FQueuedThreadPool& BuildThreadPool)
{
#if WITH_EDITOR
	
	// Editor 'force delete' can null any UObject pointers which are seen by reference collecting (eg UProperty or serialized)
	if (Task->StaticMesh && Task->GenerateSource)
	{
		TRACE_CPUPROFILER_EVENT_SCOPE(FCardRepresentationAsyncQueue::Build);
 
		const FStaticMeshLODResources& LODModel = Task->GenerateSource->GetRenderData()->LODResources[0];
 
		Task->bSuccess = MeshUtilities->GenerateCardRepresentationData(
			Task->StaticMesh->GetName(),
			Task->SourceMeshData,
			LODModel,
			BuildThreadPool,
			Task->MaterialBlendModes,
			Task->GenerateSource->GetRenderData()->Bounds,
			Task->GenerateSource->GetRenderData()->LODResources[0].DistanceFieldData,
			Task->MaxLumenMeshCards,
			Task->bGenerateDistanceFieldAsIfTwoSided,
			*Task->GeneratedCardRepresentation);
	}
#endif
}

Engine/Source/Developer/MeshUtilities/Private/MeshCardRepresentationUtilities.cpp

主要函数:

  • FMeshUtilities::GenerateCardRepresentationData
  • MeshRepresentation::SetupEmbreeScene
  • BuildMeshCards

MeshDistanceField生成

在导入模型时,异步生成。

Lumen运行时流程

GlobalDistanceField生成

Engine/Source/Runtime/Renderer/Private/DeferredShadingRenderer.cpp

Render:PrepareDistanceFieldScene,在RenderPrePass之前。

  • 具体执行:Engine/Source/Runtime/Renderer/Private/GlobalDistanceField.cpp
    • UpdateGlobalDistanceFieldVolume()

LumenScene Init

Render: BeginUpdateLumenSceneTasks -> UpdateSurfaceCachePrimitives(AddMeshCards-> AddMeshCardsFromBuildData) -> UpdateSurfaceCacheMeshCards -> ProcessLumenSurfaceCacheRequests -> AddCardCaptureDraws

具体代码:

  • LumenSceneData 初始化 [1]-CSDN博客
  • LumenSceneData 初始化 [2]-CSDN博客

LumenScene Update

材质相关,生成SurfaceCache。

BuildRenderingCommands → ClearCardCapture → MeshCardCapture → CopyCardsToSurfaceCache.

具体代码:

  • https://blog.csdn.net/sh15285118586/article/details/132211067

LumenScene Lighting

BuildCardUpdateContext -> RenderDirectLightingForLumenScene -> RenderRadiosityForLumenScene

具体代码:

  • Lumen:Radiosity-CSDN博客
  • Lumen DirectLighting:CullTiles-CSDN博客
  • Lumen Directlighting: CombineLighting-CSDN博客

文章参考:

  • 游戏引擎随笔 0x31:UE5 Lumen 源码解析(三)光影篇 - 知乎
  • 游戏引擎随笔 0x32:UE5 Lumen 源码解析(四)Radiosity 篇 - 知乎

LumenScene ProbeGather

UniformPlacement Probe -> AdaptivePlacement Probe -> GenerateBRDF_PDF -> UpdateRadianceCache → ComputeLightingPDF(重要性采样) → TraceScreenProbes → FilterScreenProbes → InterpolateAndIntegrate

具体代码:

  • CSDN

文章参考:

  • 游戏引擎随笔 0x29:UE5 Lumen 源码解析(一)原理篇 - 知乎
  • 游戏引擎随笔 0x34:UE5 Lumen 源码解析(六)Importance Sampling 篇 - 知乎

Reference

  • UE5 Lumen实现分析 - 知乎
  • UE5 Lumen原理介绍 - 知乎
  • UE5 Lumen GI 实现分析 - 知乎

你可能感兴趣的:(#,UE之Lumen,UE,Lumen)