#34 Do not set custom depth pass if semantic segmentation is not needed
This commit is contained in:
parent
ca5951df22
commit
2309ffb184
|
@ -224,7 +224,7 @@ void ACityMapGenerator::GenerateRoadMap()
|
|||
check(GetWorld() != nullptr);
|
||||
check(RoadMap != nullptr);
|
||||
|
||||
ATagger::TagActorsInLevel(*GetWorld()); // We need the tags.
|
||||
ATagger::TagActorsInLevel(*GetWorld(), bTagForSemanticSegmentation); // We need the tags.
|
||||
|
||||
const float IntersectionSize = CityMapMeshTag::GetRoadIntersectionSize();
|
||||
const uint32 Margin = IntersectionSize / 2u;
|
||||
|
|
|
@ -152,6 +152,14 @@ private:
|
|||
UPROPERTY(Category = "Road Map", EditAnywhere, AdvancedDisplay)
|
||||
bool bGenerateRoadMapOnSave = true;
|
||||
|
||||
/** If true, activate the custom depth pass of each tagged actor in the level.
|
||||
* This pass is necessary for rendering the semantic segmentation. However,
|
||||
* it may add a performance penalty since occlusion doesn't seem to be
|
||||
* applied to objects having this value active.
|
||||
*/
|
||||
UPROPERTY(Category = "Road Map", EditAnywhere, AdvancedDisplay)
|
||||
bool bTagForSemanticSegmentation = false;
|
||||
|
||||
UPROPERTY()
|
||||
URoadMap *RoadMap;
|
||||
|
||||
|
|
|
@ -70,7 +70,9 @@ void ACarlaGameMode::RestartPlayer(AController* NewPlayer)
|
|||
void ACarlaGameMode::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
TagActorsForSemanticSegmentation();
|
||||
if (GameInstance->GetCarlaSettings().bSemanticSegmentationEnabled) {
|
||||
TagActorsForSemanticSegmentation();
|
||||
}
|
||||
GameController->BeginPlay();
|
||||
}
|
||||
|
||||
|
@ -105,7 +107,7 @@ void ACarlaGameMode::AttachCaptureCamerasToPlayer(AController &Player)
|
|||
void ACarlaGameMode::TagActorsForSemanticSegmentation()
|
||||
{
|
||||
check(GetWorld() != nullptr);
|
||||
ATagger::TagActorsInLevel(*GetWorld());
|
||||
ATagger::TagActorsInLevel(*GetWorld(), true);
|
||||
}
|
||||
|
||||
APlayerStart *ACarlaGameMode::FindUnOccupiedStartPoints(
|
||||
|
|
|
@ -112,6 +112,11 @@ static void ValidateCameraDescription(FCameraDescription &Camera)
|
|||
Camera.ImageSizeY = (Camera.ImageSizeY == 0u ? 512u : Camera.ImageSizeY);
|
||||
}
|
||||
|
||||
static bool RequestedSemanticSegmentation(const FCameraDescription &Camera)
|
||||
{
|
||||
return (Camera.PostProcessEffect == EPostProcessEffect::SemanticSegmentation);
|
||||
}
|
||||
|
||||
static void LoadSettingsFromFile(const FString &FileName, UCarlaSettings &Settings)
|
||||
{
|
||||
UE_LOG(LogCarla, Log, TEXT("Loading settings from \"%s\""), *FileName);
|
||||
|
@ -141,6 +146,7 @@ static void LoadSettingsFromFile(const FString &FileName, UCarlaSettings &Settin
|
|||
}
|
||||
|
||||
ValidateCameraDescription(Camera);
|
||||
Settings.bSemanticSegmentationEnabled |= RequestedSemanticSegmentation(Camera);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -183,7 +189,7 @@ void UCarlaSettings::LoadSettings()
|
|||
}
|
||||
}
|
||||
|
||||
void UCarlaSettings::LogSettings()
|
||||
void UCarlaSettings::LogSettings() const
|
||||
{
|
||||
UE_LOG(LogCarla, Log, TEXT("== CARLA Settings =============================================================="));
|
||||
UE_LOG(LogCarla, Log, TEXT("Settings file: %s"), *CurrentFileName);
|
||||
|
@ -194,6 +200,7 @@ void UCarlaSettings::LogSettings()
|
|||
UE_LOG(LogCarla, Log, TEXT("Read Port = %d"), ReadPort);
|
||||
UE_LOG(LogCarla, Log, TEXT("[%s]"), S_CARLA_SCENECAPTURE);
|
||||
UE_LOG(LogCarla, Log, TEXT("Added %d cameras."), CameraDescriptions.Num());
|
||||
UE_LOG(LogCarla, Log, TEXT("Semantic Segmentation = %s"), (bSemanticSegmentationEnabled ? TEXT("enabled") : TEXT("disabled")));
|
||||
for (auto &Item : CameraDescriptions) {
|
||||
UE_LOG(LogCarla, Log, TEXT("[%s/%s]"), S_CARLA_SCENECAPTURE, *Item.Key);
|
||||
UE_LOG(LogCarla, Log, TEXT("Image Size = %dx%d"), Item.Value.ImageSizeX, Item.Value.ImageSizeY);
|
||||
|
|
|
@ -18,7 +18,7 @@ public:
|
|||
void LoadSettings();
|
||||
|
||||
/** Log settings values. */
|
||||
void LogSettings();
|
||||
void LogSettings() const;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -59,5 +59,12 @@ public:
|
|||
UPROPERTY(Category = "Scene Capture", EditDefaultsOnly)
|
||||
TMap<FString, FCameraDescription> CameraDescriptions;
|
||||
|
||||
/** Whether semantic segmentation should be activated. The mechanisms for
|
||||
* semantic segmentation impose some performance penalties even if it is not
|
||||
* used, we only enable it if necessary.
|
||||
*/
|
||||
UPROPERTY(Category = "Scene Capture", EditDefaultsOnly)
|
||||
bool bSemanticSegmentationEnabled = false;
|
||||
|
||||
/// @}
|
||||
};
|
||||
|
|
|
@ -62,18 +62,21 @@ static ECityObjectLabel GetLabelByPath(const T *Object)
|
|||
return (StringArray.Num() > 3 ? GetLabelByFolderName(StringArray[3]) : ECityObjectLabel::None);
|
||||
}
|
||||
|
||||
static void SetStencilValue(UPrimitiveComponent *comp, const ECityObjectLabel &Label) {
|
||||
if (Label != ECityObjectLabel::None) {
|
||||
comp->SetRenderCustomDepth(true);
|
||||
comp->SetCustomDepthStencilValue(CastEnum(Label));
|
||||
}
|
||||
static void SetStencilValue(
|
||||
UPrimitiveComponent &Component,
|
||||
const ECityObjectLabel &Label,
|
||||
const bool bSetRenderCustomDepth) {
|
||||
Component.SetRenderCustomDepth(
|
||||
bSetRenderCustomDepth &&
|
||||
!ATagger::MatchComponent(Component, ECityObjectLabel::None));
|
||||
Component.SetCustomDepthStencilValue(CastEnum(Label));
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// -- static ATagger functions -------------------------------------------------
|
||||
// =============================================================================
|
||||
|
||||
void ATagger::TagActor(const AActor &Actor)
|
||||
void ATagger::TagActor(const AActor &Actor, bool bTagForSemanticSegmentation)
|
||||
{
|
||||
#ifdef CARLA_TAGGER_EXTRA_LOG
|
||||
UE_LOG(LogCarla, Log, TEXT("Actor: %s"), *Actor.GetName());
|
||||
|
@ -84,7 +87,7 @@ void ATagger::TagActor(const AActor &Actor)
|
|||
Actor.GetComponents<UStaticMeshComponent>(StaticMeshComponents);
|
||||
for (UStaticMeshComponent *Component : StaticMeshComponents) {
|
||||
const auto Label = GetLabelByPath(Component->GetStaticMesh());
|
||||
SetStencilValue(Component, Label);
|
||||
SetStencilValue(*Component, Label, bTagForSemanticSegmentation);
|
||||
#ifdef CARLA_TAGGER_EXTRA_LOG
|
||||
UE_LOG(LogCarla, Log, TEXT(" + StaticMeshComponent: %s"), *Component->GetName());
|
||||
UE_LOG(LogCarla, Log, TEXT(" - Label: \"%s\""), *GetLabelAsString(Label));
|
||||
|
@ -96,7 +99,7 @@ void ATagger::TagActor(const AActor &Actor)
|
|||
Actor.GetComponents<USkeletalMeshComponent>(SkeletalMeshComponents);
|
||||
for (USkeletalMeshComponent *Component : SkeletalMeshComponents) {
|
||||
const auto Label = GetLabelByPath(Component->GetPhysicsAsset());
|
||||
SetStencilValue(Component, Label);
|
||||
SetStencilValue(*Component, Label, bTagForSemanticSegmentation);
|
||||
#ifdef CARLA_TAGGER_EXTRA_LOG
|
||||
UE_LOG(LogCarla, Log, TEXT(" + SkeletalMeshComponent: %s"), *Component->GetName());
|
||||
UE_LOG(LogCarla, Log, TEXT(" - Label: \"%s\""), *GetLabelAsString(Label));
|
||||
|
@ -104,21 +107,13 @@ void ATagger::TagActor(const AActor &Actor)
|
|||
}
|
||||
}
|
||||
|
||||
void ATagger::TagActorsInLevel(UWorld &World)
|
||||
void ATagger::TagActorsInLevel(UWorld &World, bool bTagForSemanticSegmentation)
|
||||
{
|
||||
for (TActorIterator<AActor> it(&World); it; ++it) {
|
||||
TagActor(**it);
|
||||
TagActor(**it, bTagForSemanticSegmentation);
|
||||
}
|
||||
}
|
||||
|
||||
ECityObjectLabel ATagger::GetTagOfTaggedComponent(const UPrimitiveComponent &Component)
|
||||
{
|
||||
return
|
||||
(Component.bRenderCustomDepth ?
|
||||
static_cast<ECityObjectLabel>(Component.CustomDepthStencilValue) :
|
||||
ECityObjectLabel::None);
|
||||
}
|
||||
|
||||
void ATagger::GetTagsOfTaggedActor(const AActor &Actor, TArray<ECityObjectLabel> &Tags)
|
||||
{
|
||||
TArray<UPrimitiveComponent *> Components;
|
||||
|
@ -148,7 +143,7 @@ void ATagger::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent
|
|||
Super::PostEditChangeProperty(PropertyChangedEvent);
|
||||
if (PropertyChangedEvent.Property) {
|
||||
if (bTriggerTagObjects && (GetWorld() != nullptr)) {
|
||||
TagActorsInLevel(*GetWorld());
|
||||
TagActorsInLevel(*GetWorld(), bTagForSemanticSegmentation);
|
||||
}
|
||||
}
|
||||
bTriggerTagObjects = false;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "GameFramework/Actor.h"
|
||||
#include "Components/PrimitiveComponent.h"
|
||||
#include "Tagger.generated.h"
|
||||
|
||||
enum class ECityObjectLabel : uint8
|
||||
|
@ -34,15 +35,29 @@ class CARLA_API ATagger : public AActor
|
|||
public:
|
||||
|
||||
/// Set the tag of an actor.
|
||||
static void TagActor(const AActor &Actor);
|
||||
///
|
||||
/// If bTagForSemanticSegmentation true, activate the custom depth pass. This
|
||||
/// pass is necessary for rendering the semantic segmentation. However, it may
|
||||
/// add a performance penalty since occlusion doesn't seem to be applied to
|
||||
/// objects having this value active.
|
||||
static void TagActor(const AActor &Actor, bool bTagForSemanticSegmentation);
|
||||
|
||||
/// Set the tag of every actor in level.
|
||||
static void TagActorsInLevel(UWorld &World);
|
||||
///
|
||||
/// If bTagForSemanticSegmentation true, activate the custom depth pass. This
|
||||
/// pass is necessary for rendering the semantic segmentation. However, it may
|
||||
/// add a performance penalty since occlusion doesn't seem to be applied to
|
||||
/// objects having this value active.
|
||||
static void TagActorsInLevel(UWorld &World, bool bTagForSemanticSegmentation);
|
||||
|
||||
/// Retrieve the tag of an already tagged component.
|
||||
static ECityObjectLabel GetTagOfTaggedComponent(const UPrimitiveComponent &Component);
|
||||
static ECityObjectLabel GetTagOfTaggedComponent(const UPrimitiveComponent &Component)
|
||||
{
|
||||
return static_cast<ECityObjectLabel>(Component.CustomDepthStencilValue);
|
||||
}
|
||||
|
||||
/// Retrieve the tags of an already tagged actor.
|
||||
/// Retrieve the tags of an already tagged actor. ECityObjectLabel::None is
|
||||
/// not added to the array.
|
||||
static void GetTagsOfTaggedActor(const AActor &Actor, TArray<ECityObjectLabel> &Tags);
|
||||
|
||||
/// Return true if @a Component has been tagged with the given @a Tag.
|
||||
|
@ -63,4 +78,7 @@ private:
|
|||
|
||||
UPROPERTY(Category = "Tagger", EditAnywhere)
|
||||
bool bTriggerTagObjects = false;
|
||||
|
||||
UPROPERTY(Category = "Tagger", EditAnywhere)
|
||||
bool bTagForSemanticSegmentation = false;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue