首先这不是UE4初学者的教程;是我记录学习的过程的博文;不过有兴趣可以讨论的可以联系我。
1、绘制编辑器的坐标轴。Mesh的两种渲染的方式;
UMeshComponent,PrimitiveDrawInterface绘制的dynamicMesh
二者在渲染线程中的处理不同
在render的不同过程的过程会先后的处理两种Mesh 牵涉到SceneProxy 例如在basepass的过程
for (int32 ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++)
{
SCOPED_CONDITIONAL_DRAW_EVENTF(RHICmdList, EventView, Views.Num() > 1, TEXT("View%d"), ViewIndex);
FViewInfo& View = Views[ViewIndex];
if (View.ShouldRenderView())
{
RenderBasePassViewParallel(View, RHICmdList);
}
RenderEditorPrimitives(RHICmdList, View, bDirty);
}
RenderBasePassViewParallel会把MeshCompoent的Mesh使用StaticMeshDrawList然后使用TBasePassDrawingPolicy进行渲染详见..\Engine\Source\Runtime\Renderer\Private\BasePassRendering.h
而UnrealWidget使用PDI绘制DynamicMesh的方式会现在主线程把Mesh转换成FMeshBatch保存在ViewMeshElementList中如下:
inline int32 FViewElementPDI::DrawMesh(const FMeshBatch& Mesh)
{
if (ensure(MeshBatchHasPrimitives(Mesh)))
{
// Keep track of view mesh elements whether that have translucency.
ViewInfo->bHasTranslucentViewMeshElements |= true;//Mesh.IsTranslucent() ? 1 : 0;
uint8 DPGIndex = Mesh.DepthPriorityGroup;
// Get the correct element list based on dpg index
// Translucent view mesh elements in the foreground dpg are not supported yet
TIndirectArray<FMeshBatch>& ViewMeshElementList = ( ( DPGIndex == SDPG_Foreground ) ? ViewInfo->TopViewMeshElements : ViewInfo->ViewMeshElements );
FMeshBatch* NewMesh = new(ViewMeshElementList) FMeshBatch(Mesh);
if( CurrentHitProxy != nullptr )
{
NewMesh->BatchHitProxyId = CurrentHitProxy->Id;
}
return 1;
}
return 0;
}