Level Coloration:

- FPrimitiveSceneProxy derived classes no longer need to implement custom logic to set their level color, as it is now fetched directly from the FPrimitiveSceneProxyDesc owner's level and pushed into the corresponding FPrimitiveSceneProxy when creating the proxies.
  - World Partition level streaming objects will push a deterministic random color based on the obejct's name in the level streaming objects.
  - Added Nanite support for level coloration debug view mode.

This will then serves as a base for existing and future coloring debug view modes, instead of doing custom debug views.

#rb Sebastien.Lussier

[CL 29951102 by jeanfrancois dube in ue5-main branch]
This commit is contained in:
jeanfrancois dube
2023-11-27 18:51:14 -05:00
parent 25d1c6b9bb
commit 71b3987465
15 changed files with 24 additions and 105 deletions
@@ -10,8 +10,6 @@
#include "RayTracingInstance.h"
#include "SceneManagement.h"
#include "Engine/Engine.h"
#include "Engine/LevelStreaming.h"
#include "LevelUtils.h"
#include "Materials/MaterialInstanceDynamic.h"
#include "DynamicMeshBuilder.h"
#include "Components/SceneCaptureComponent2D.h"
@@ -67,19 +65,6 @@ namespace
: FPrimitiveSceneProxy(InComponent)
, VertexFactory(GetScene().GetFeatureLevel(), "FImagePlateSceneProxy")
{
AActor* Owner = InComponent->GetOwner();
if (Owner)
{
// Level colorization
ULevel* Level = Owner->GetLevel();
ULevelStreaming* LevelStreaming = FLevelUtils::FindStreamingLevel( Level );
if ( LevelStreaming )
{
// Selection takes priority over level coloration.
SetLevelColor(LevelStreaming->LevelColor);
}
}
Material = InComponent->GetPlate().DynamicMaterial ? InComponent->GetPlate().DynamicMaterial : InComponent->GetPlate().Material;
if (Material)
{
@@ -33,6 +33,7 @@ float3 SelectionColor;
#define DEBUG_VIEW_WIREFRAME 1
#define DEBUG_VIEW_SHADER_COMPLEXITY 2
#define DEBUG_VIEW_LIGHTMAP_DENSITY 3
#define DEBUG_VIEW_LEVEL_COLOR 4
uint DebugViewMode;
#define SOBEL_WIREFRAME_FILTER_ONLY 0
@@ -282,6 +283,12 @@ void ExportDebugViewPS(
// Alpha channel needs to be 1 to have decals working where the framebuffer blend is setup to multiply with alpha
OutColor = float4(FinalComplexity.xyz, 1.0f);
}
else if (DebugViewMode == DEBUG_VIEW_LEVEL_COLOR)
{
const bool bIsSelected = IsInstanceSelected(InstanceData, VisibleCluster, TriIndex);
const float3 SolidColor = CondMask(bIsSelected, SelectionColor, PrimitiveData.LevelColor);
OutColor = float4(SolidColor, 1.0f);
}
#endif
else
{
@@ -11,8 +11,6 @@
#include "SceneManagement.h"
#include "Engine/Light.h"
#include "Engine/Engine.h"
#include "Engine/LevelStreaming.h"
#include "LevelUtils.h"
#include "TextureResource.h"
#include UE_INLINE_GENERATED_CPP_BY_NAME(BillboardComponent)
@@ -103,14 +101,6 @@ public:
#else // WITH_EDITORONLY_DATA
bIsActorLocked = false;
#endif // WITH_EDITORONLY_DATA
// Level colorization
ULevel* Level = Owner->GetLevel();
if (ULevelStreaming* LevelStreaming = FLevelUtils::FindStreamingLevel(Level))
{
// Selection takes priority over level coloration.
SetLevelColor(LevelStreaming->LevelColor);
}
}
FColor NewPropertyColor;
@@ -9,8 +9,6 @@
#include "SceneInterface.h"
#include "SceneManagement.h"
#include "Engine/Engine.h"
#include "Engine/LevelStreaming.h"
#include "LevelUtils.h"
#include "PrimitiveSceneProxy.h"
#include "StaticMeshResources.h"
#include "PSOPrecache.h"
@@ -64,19 +62,6 @@ public:
, BaseColor(FColor::White)
, VertexFactory(GetScene().GetFeatureLevel(), "FMaterialSpriteSceneProxy")
{
AActor* Owner = InComponent->GetOwner();
if (Owner)
{
// Level colorization
ULevel* Level = Owner->GetLevel();
ULevelStreaming* LevelStreaming = FLevelUtils::FindStreamingLevel( Level );
if ( LevelStreaming )
{
// Selection takes priority over level coloration.
SetLevelColor(LevelStreaming->LevelColor);
}
}
for (int32 ElementIndex = 0; ElementIndex < Elements.Num(); ElementIndex++)
{
UMaterialInterface* Material = Elements[ElementIndex].Material;
@@ -17,8 +17,6 @@
#include "Materials/Material.h"
#include "Materials/MaterialRenderProxy.h"
#include "Engine/Engine.h"
#include "Engine/LevelStreaming.h"
#include "LevelUtils.h"
#include "HModel.h"
#include "Components/ModelComponent.h"
#include "Engine/Brush.h"
@@ -264,18 +262,6 @@ public:
bGoodCandidateForCachedShadowmap = CacheShadowDepthsFromPrimitivesUsingWPO() || (!MaterialRelevance.bUsesWorldPositionOffset && !MaterialRelevance.bUsesDisplacement);
// Try to find a color for level coloration.
UObject* ModelOuter = InComponent->GetModel()->GetOuter();
ULevel* Level = Cast<ULevel>( ModelOuter );
if ( Level )
{
ULevelStreaming* LevelStreaming = FLevelUtils::FindStreamingLevel( Level );
if ( LevelStreaming )
{
SetLevelColor(LevelStreaming->LevelColor);
}
}
// Get a color for property coloration.
FColor NewPropertyColor;
GEngine->GetPropertyColorationColor( (UObject*)InComponent, NewPropertyColor );
@@ -6533,7 +6533,6 @@ FParticleSystemSceneProxy::FParticleSystemSceneProxy(UParticleSystemComponent* C
, FirstFreeMeshBatch(0)
{
SetWireframeColor(FLinearColor(3.0f, 0.0f, 0.0f));
SetLevelColor(FLinearColor(1.0f, 1.0f, 0.0f));
SetPropertyColor(FLinearColor(1.0f, 1.0f, 1.0f));
LODMethod = Component->LODMethod;
@@ -8,7 +8,9 @@
#include "PrimitiveSceneProxyDesc.h"
#include "PrimitiveViewRelevance.h"
#include "UObject/Package.h"
#include "LevelUtils.h"
#include "Engine/Engine.h"
#include "Engine/LevelStreaming.h"
#include "EngineUtils.h"
#include "Components/BrushComponent.h"
#include "PrimitiveSceneInfo.h"
@@ -413,7 +415,6 @@ FPrimitiveSceneProxy::FPrimitiveSceneProxy(const UPrimitiveComponent* InComponen
FPrimitiveSceneProxy::FPrimitiveSceneProxy(const FPrimitiveSceneProxyDesc& InProxyDesc, FName InResourceName) :
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
WireframeColor(FLinearColor::White)
, LevelColor(FLinearColor::White)
, PropertyColor(FLinearColor::White)
,
#endif
@@ -551,6 +552,13 @@ FPrimitiveSceneProxy::FPrimitiveSceneProxy(const FPrimitiveSceneProxyDesc& InPro
{
SetForceHidden(!Level->bIsVisible);
}
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
if (ULevelStreaming* LevelStreaming = FLevelUtils::FindStreamingLevel(Level))
{
SetLevelColor(LevelStreaming->LevelColor);
}
#endif
}
#if STATS
@@ -717,7 +717,6 @@ FSceneProxy::FSceneProxy(const FMaterialAudit& MaterialAudit, const FStaticMeshS
InstanceWPODisableDistance = ProxyDesc.WorldPositionOffsetDisableDistance;
SetLevelColor(FLinearColor::White);
SetPropertyColor(FLinearColor::White);
SetWireframeColor(ProxyDesc.GetWireframeColor());
@@ -5608,9 +5608,6 @@ void USkeletalMeshSocket::Serialize(FArchive& Ar)
/*-----------------------------------------------------------------------------
FSkeletalMeshSceneProxy
-----------------------------------------------------------------------------*/
#include "Engine/LevelStreaming.h"
#include "LevelUtils.h"
#include UE_INLINE_GENERATED_CPP_BY_NAME(SkeletalMesh)
const FQuat SphylBasis(FVector(1.0f / FMath::Sqrt(2.0f), 0.0f, 1.0f / FMath::Sqrt(2.0f)), UE_PI);
@@ -5768,17 +5765,6 @@ FSkeletalMeshSceneProxy::FSkeletalMeshSceneProxy(const USkinnedMeshComponent* Co
bCastDynamicShadow = bCastDynamicShadow && bAnySectionCastsShadow;
// Try to find a color for level coloration.
if( Owner )
{
ULevel* Level = Owner->GetLevel();
ULevelStreaming* LevelStreaming = FLevelUtils::FindStreamingLevel( Level );
if ( LevelStreaming )
{
SetLevelColor(LevelStreaming->LevelColor);
}
}
// Get a color for property coloration
FColor NewPropertyColor;
if (GEngine->GetPropertyColorationColor((UObject*)Component, NewPropertyColor))
@@ -24,8 +24,6 @@
#include "StaticMeshSceneProxy.h"
#include "PhysicalMaterials/PhysicalMaterialMask.h"
#include "Engine/LevelStreaming.h"
#include "LevelUtils.h"
#include "DistanceFieldAtlas.h"
#include "MeshCardRepresentation.h"
#include "Components/BrushComponent.h"
@@ -295,7 +293,6 @@ FStaticMeshSceneProxy::FStaticMeshSceneProxy(const FStaticMeshSceneProxyDesc& In
ClampedMinLOD = FMath::Clamp(EffectiveMinLOD, FirstAvailableLOD, RenderData->LODResources.Num() - 1);
SetWireframeColor(InProxyDesc.GetWireframeColor());
SetLevelColor(FLinearColor(1,1,1));
SetPropertyColor(FLinearColor(1,1,1));
// Copy the pointer to the volume data, async building of the data may modify the one on FStaticMeshLODResources while we are rendering
@@ -378,17 +375,6 @@ FStaticMeshSceneProxy::FStaticMeshSceneProxy(const FStaticMeshSceneProxyDesc& In
#if STATICMESH_ENABLE_DEBUG_RENDERING
if( GIsEditor )
{
// Try to find a color for level coloration.
ULevel* Level = InProxyDesc.GetComponentLevel();
if (Level)
{
ULevelStreaming* LevelStreaming = FLevelUtils::FindStreamingLevel( Level );
if ( LevelStreaming )
{
SetLevelColor(LevelStreaming->LevelColor);
}
}
// Get a color for property coloration.
FColor TempPropertyColor;
if (GEngine->GetPropertyColorationColor( InProxyDesc.GetObjectForPropertyColoration(), TempPropertyColor ))
@@ -186,6 +186,8 @@ void UWorldPartitionLevelStreamingDynamic::CreateRuntimeLevel()
// Attach ourself to Level cleanup to do our own cleanup
OnCleanupLevelDelegateHandle = RuntimeLevel->OnCleanupLevel.AddUObject(this, &UWorldPartitionLevelStreamingDynamic::OnCleanupLevel);
LevelColor = FLinearColor::MakeRandomSeededColor(GetTypeHash(GetName()));
}
/**
@@ -215,6 +215,7 @@ struct FPrimitiveSceneProxyDesc
bool IsOwnerEditorOnly() const { return bIsOwnerEditorOnly; }
#if WITH_EDITOR
FLinearColor GetLevelColor() const { return GetLevel() ? GetLevel()->LevelColor : FLinearColor::White; }
bool IsHiddenEd() const { return bIsHiddenEd; }
uint64 GetHiddenEditorViews() const { return HiddenEditorViews; }
bool IsOwnedByFoliage() const { return bIsOwnedByFoliage; }
@@ -22,8 +22,6 @@ LandscapeRender.cpp: New terrain rendering
#include "ShaderParameterUtils.h"
#include "LandscapeEdit.h"
#include "Engine/Level.h"
#include "Engine/LevelStreaming.h"
#include "LevelUtils.h"
#include "Materials/MaterialExpressionTextureSample.h"
#include "LandscapeMaterialInstanceConstant.h"
#include "Engine/ShadowMapTexture2D.h"
@@ -1234,8 +1232,6 @@ FLandscapeComponentSceneProxy::FLandscapeComponentSceneProxy(ULandscapeComponent
LODIndexToMaterialIndex = InComponent->LODIndexToMaterialIndex;
check(LODIndexToMaterialIndex.Num() == MaxLOD + 1);
SetLevelColor(FLinearColor(1.f, 1.f, 1.f));
HeightmapSubsectionOffsetU = 0;
HeightmapSubsectionOffsetV = 0;
if (HeightmapTexture)
@@ -1419,22 +1415,6 @@ FLandscapeComponentSceneProxy::FLandscapeComponentSceneProxy(ULandscapeComponent
Algo::Transform(AvailableMaterialInterfaces, MaterialRelevances, [FeatureLevel](UMaterialInterface* InMaterialInterface) { check(InMaterialInterface != nullptr); return InMaterialInterface->GetRelevance_Concurrent(FeatureLevel); });
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST) || (UE_BUILD_SHIPPING && WITH_EDITOR)
if (GIsEditor)
{
// Try to find a color for level coloration.
if (Proxy)
{
ULevel* Level = Proxy->GetLevel();
ULevelStreaming* LevelStreaming = FLevelUtils::FindStreamingLevel(Level);
if (LevelStreaming)
{
SetLevelColor(LevelStreaming->LevelColor);
}
}
}
#endif
const int8 SubsectionSizeLog2 = static_cast<int8>(FMath::CeilLogTwo(InComponent->SubsectionSizeQuads + 1));
SharedBuffersKey = (SubsectionSizeLog2 & 0xf) | ((NumSubsections & 0xf) << 4) | (XYOffsetmapTexture == nullptr ? 0 : 1 << 31);
@@ -1330,6 +1330,10 @@ void FDeferredShadingSceneRenderer::RenderBasePassInternal(
{
NaniteDebugViewMode = Nanite::EDebugViewMode::LightmapDensity;
}
else if (ViewFamily.EngineShowFlags.LevelColoration)
{
NaniteDebugViewMode = Nanite::EDebugViewMode::LevelColor;
}
else if (ViewFamily.UseDebugViewPS())
{
switch (ViewFamily.GetDebugViewShaderMode())
@@ -36,6 +36,7 @@ enum class EDebugViewMode : uint8
Wireframe = 1,
ShaderComplexity = 2,
LightmapDensity = 3,
LevelColor = 4,
};
void RenderDebugViewMode(