Carla Settings added to the plugin preferences. New section for quality added in the settings file.

This commit is contained in:
CVC\jbelon 2018-02-26 17:58:40 +01:00
parent f637b0a6d1
commit 56652b769d
7 changed files with 323 additions and 16 deletions

View File

@ -105,3 +105,7 @@ PositionZ=140
RotationPitch=0
RotationYaw=0
RotationRoll=0
[CARLA/QualitySettings]
DefaultLevel=Epic

View File

@ -13,11 +13,10 @@ GameInstanceClass=/Script/Carla.CarlaGameInstance
TransitionMap=/Game/Maps/Town01.Town01
[/Script/Engine.RendererSettings]
r.DefaultFeature.MotionBlur=False
r.AllowStaticLighting=True
r.DiscardUnusedQuality=True
r.DefaultFeature.Bloom=False
r.DefaultFeature.AmbientOcclusion=True
r.DefaultFeature.MotionBlur=0
r.AllowStaticLighting=1
r.DiscardUnusedQuality=1
r.DefaultFeature.Bloom=0
r.DefaultFeature.AmbientOcclusion=0
r.AmbientOcclusionLevels=0
r.DefaultFeature.AmbientOcclusionStaticFraction=0

View File

@ -36,3 +36,6 @@ bSkipEditorContent=False
bNativizeBlueprintAssets=False
bNativizeOnlySelectedBlueprints=False
[/Script/Carla.CarlaSettings]
LowLightFadeDistance=1000.000000

View File

@ -1,6 +1,10 @@
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
#include "Carla.h"
#include "ISettingsModule.h"
#include "ISettingsSection.h"
#include "ISettingsContainer.h"
#include "Settings/CarlaSettings.h"
#define LOCTEXT_NAMESPACE "FCarlaModule"
@ -9,13 +13,73 @@ DEFINE_LOG_CATEGORY(LogCarlaServer);
void FCarlaModule::StartupModule()
{
// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module
RegisterSettings();
}
void FCarlaModule::ShutdownModule()
{
// This function may be called during shutdown to clean up your module. For modules that support dynamic reloading,
// we call this function before unloading the module.
if (UObjectInitialized())
{
UnregisterSettings();
}
}
void FCarlaModule::RegisterSettings()
{
// Registering some settings is just a matter of exposing the default UObject of
// your desired class, add here all those settings you want to expose
// to your LDs or artists.
if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings"))
{
// Create the new category
ISettingsContainerPtr SettingsContainer = SettingsModule->GetContainer("Project");
SettingsContainer->DescribeCategory("CARLASettings",
LOCTEXT("RuntimeWDCategoryName", "CARLA Settings"),
LOCTEXT("RuntimeWDCategoryDescription", "CARLA plugin settings"));
// Register the settings
ISettingsSectionPtr SettingsSection = SettingsModule->RegisterSettings("Project", "CARLASettings", "General",
LOCTEXT("RuntimeGeneralSettingsName", "General"),
LOCTEXT("RuntimeGeneralSettingsDescription", "General configuration for the CARLA plugin"),
GetMutableDefault<UCarlaSettings>()
);
// Register the save handler to your settings, you might want to use it to
// validate those or just act to settings changes.
if (SettingsSection.IsValid())
{
SettingsSection->OnModified().BindRaw(this, &FCarlaModule::HandleSettingsSaved);
}
}
}
void FCarlaModule::UnregisterSettings()
{
// Ensure to unregister all of your registered settings here, hot-reload would
// otherwise yield unexpected results.
if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings"))
{
SettingsModule->UnregisterSettings("Project", "CustomSettings", "General");
}
}
bool FCarlaModule::HandleSettingsSaved()
{
UCarlaSettings* Settings = GetMutableDefault<UCarlaSettings>();
bool ResaveSettings = false;
// Put any validation code in here and resave the settings in case an invalid
// value has been entered
if (ResaveSettings)
{
Settings->SaveConfig();
}
return true;
}
#undef LOCTEXT_NAMESPACE

View File

@ -14,7 +14,7 @@ DECLARE_LOG_CATEGORY_EXTERN(LogCarlaServer, Log, All);
// Options to compile with extra debug log.
#if WITH_EDITOR
// #define CARLA_AI_VEHICLES_EXTRA_LOG
#define CARLA_AI_WALKERS_EXTRA_LOG
// #define CARLA_AI_WALKERS_EXTRA_LOG
// #define CARLA_ROAD_GENERATOR_EXTRA_LOG
// #define CARLA_SERVER_EXTRA_LOG
// #define CARLA_TAGGER_EXTRA_LOG
@ -22,9 +22,15 @@ DECLARE_LOG_CATEGORY_EXTERN(LogCarlaServer, Log, All);
class FCarlaModule : public IModuleInterface
{
void RegisterSettings();
void UnregisterSettings();
bool HandleSettingsSaved();
public:
/** IModuleInterface implementation */
virtual void StartupModule() override;
virtual void ShutdownModule() override;
};

View File

@ -11,14 +11,22 @@
#include "Settings/CameraDescription.h"
#include "Settings/LidarDescription.h"
#include "Util/IniFile.h"
#include "Package.h"
#include "CommandLine.h"
#include "UnrealMathUtility.h"
#include "Engine/Engine.h"
#include "Kismet/GameplayStatics.h"
#include "Engine/DirectionalLight.h"
#include "Engine/PointLight.h"
#include "Landscape.h"
#include "Components/StaticMeshComponent.h"
// INI file sections.
#define S_CARLA_SERVER TEXT("CARLA/Server")
#define S_CARLA_LEVELSETTINGS TEXT("CARLA/LevelSettings")
#define S_CARLA_SENSOR TEXT("CARLA/Sensor")
#define S_CARLA_QUALITYSETTINGS TEXT("CARLA/QualitySettings")
// =============================================================================
// -- Static methods -----------------------------------------------------------
@ -104,6 +112,16 @@ static void LoadSettingsFromConfig(
ConfigFile.GetInt(S_CARLA_LEVELSETTINGS, TEXT("WeatherId"), Settings.WeatherId);
ConfigFile.GetInt(S_CARLA_LEVELSETTINGS, TEXT("SeedVehicles"), Settings.SeedVehicles);
ConfigFile.GetInt(S_CARLA_LEVELSETTINGS, TEXT("SeedPedestrians"), Settings.SeedPedestrians);
// QualitySettings.
FString sDefaultLevel;
ConfigFile.GetString(S_CARLA_QUALITYSETTINGS, TEXT("DefaultLevel"), sDefaultLevel);
if(!Settings.SetQualitySettingsLevel(FQualitySettings::FromString(sDefaultLevel)))
{
//ERROR! @TODO : fix settings
}
// Sensors.
FString Sensors;
ConfigFile.GetString(S_CARLA_SENSOR, TEXT("Sensors"), Sensors);
@ -135,6 +153,162 @@ static bool GetSettingsFilePathFromCommandLine(FString &Value)
// -- UCarlaSettings -----------------------------------------------------------
// =============================================================================
EQualitySettingsLevel FQualitySettings::FromString(const FString& SQualitySettingsLevel)
{
if(SQualitySettingsLevel.Equals("Low")) return EQualitySettingsLevel::Low;
if(SQualitySettingsLevel.Equals("Medium")) return EQualitySettingsLevel::Medium;
if(SQualitySettingsLevel.Equals("High")) return EQualitySettingsLevel::High;
if(SQualitySettingsLevel.Equals("Epic")) return EQualitySettingsLevel::Epic;
return EQualitySettingsLevel::None;
}
FString FQualitySettings::ToString(EQualitySettingsLevel QualitySettingsLevel)
{
const UEnum* ptr = FindObject<UEnum>(ANY_PACKAGE, TEXT("EQualitySettingsLevel"), true);
if(!ptr)
return FString("Invalid");
return ptr->GetNameStringByIndex(static_cast<int32>(QualitySettingsLevel));
}
bool UCarlaSettings::SetQualitySettingsLevel(EQualitySettingsLevel newDefaultLevel)
{
if(newDefaultLevel==EQualitySettingsLevel::None)
{
UE_LOG(LogCarla ,Warning, TEXT("Quality Settings Level not set!"));
return false;
}
/*if(newDefaultLevel!=DefaultQualitySettingsLevel)
{
return true;
}*/
UWorld *world = GetWorld();
//set the quality settings now
switch(newDefaultLevel)
{
case EQualitySettingsLevel::Low: {//r.SSR.qualitylaunch commands to lower quality settings
world->Exec(world,TEXT("r.DefaultFeature.MotionBlur 0"));
world->Exec(world,TEXT("r.DefaultFeature.Bloom 0"));
world->Exec(world,TEXT("r.DefaultFeature.AmbientOcclusion 0"));
world->Exec(world,TEXT("r.AmbientOcclusionLevels 0"));
world->Exec(world,TEXT("r.DefaultFeature.AmbientOcclusionStaticFraction 0"));
world->Exec(world,TEXT("r.DefaultFeature.AutoExposure 0"));
world->Exec(world,TEXT("r.RHICmdBypass 0"));
world->Exec(world,TEXT("r.DefaultFeature.AntiAliasing 2"));
world->Exec(world,TEXT("r.Streaming.PoolSize 2000"));
world->Exec(world,TEXT("r.HZBOcclusion 0"));
world->Exec(world,TEXT("r.MinScreenRadiusForLights 0.01"));
world->Exec(world,TEXT("r.SeparateTranslucency 0"));
world->Exec(world,TEXT("r.FinishCurrentFrame 1"));
world->Exec(world,TEXT("r.MotionBlurQuality 0"));
world->Exec(world,TEXT("r.PostProcessAAQuality 0"));
world->Exec(world,TEXT("r.BloomQuality 1"));
world->Exec(world,TEXT("r.SSR.Quality 0"));
world->Exec(world,TEXT("r.DepthOfFieldQuality 0"));
world->Exec(world,TEXT("r.SceneColorFormat 2"));
world->Exec(world,TEXT("r.TranslucencyVolumeBlur 0"));
world->Exec(world,TEXT("r.TranslucencyLightingVolumeDim 4"));
world->Exec(world,TEXT("r.MaxAnisotropy 8"));
world->Exec(world,TEXT("r.LensFlareQuality 0"));
world->Exec(world,TEXT("r.SceneColorFringeQuality 0"));
world->Exec(world,TEXT("r.FastBlurThreshold 0"));
world->Exec(world,TEXT("r.SSR.MaxRoughness 0.1"));
world->Exec(world,TEXT("r.AllowOcclusionQueries 1"));
world->Exec(world,TEXT("r.SSR 0"));
world->Exec(world,TEXT("r.StencilForLODDither 1"));
world->Exec(world,TEXT("r.EarlyZPass 1"));
world->Exec(world,TEXT("r.EarlyZPassMovable 1"));
world->Exec(world,TEXT("r.Foliage.DitheredLOD 0"));
world->Exec(world,TEXT("r.ForwardShading 0"));
world->Exec(world,TEXT("sg.PostProcessQuality 0"));
world->Exec(world,TEXT("r.ViewDistanceScale 0.1"));
world->Exec(world,TEXT("sg.ShadowQuality 0"));
world->Exec(world,TEXT("sg.TextureQuality 0"));
world->Exec(world,TEXT("sg.EffectsQuality 0"));
world->Exec(world,TEXT("FoliageQuality 0"));
world->Exec(world,TEXT("foliage.DensityScale 0"));
world->Exec(world,TEXT("grass.DensityScale 0"));
//world->Exec(world,TEXT("r.DetailMode 0")); //-->will change to lods 0
//iterate all vehicles and people, set the draw distance
TArray<AActor*> actors;
int32 i;
//iterate all terrain, deactivate the actor
/*UGameplayStatics::GetAllActorsOfClass(world, ALandscape::StaticClass(), actors);
for(i=0; i<actors.Num(); i++)
{
ALandscape* landscape = Cast<ALandscape>(actors[i]);
if(landscape)
{
landscape->DisableComponentsSimulatePhysics();
landscape->bUseLandscapeForCullingInvisibleHLODVertices=true;
}
}*/
//iterate all lights, deactivate shadows
UGameplayStatics::GetAllActorsOfClass(world, ALight::StaticClass(), actors);
for(i=0;i<actors.Num();i++)
{
ALight *light = Cast<ALight>(actors[i]);
if(light)
{
//disable all lights shadows
light->SetCastShadows(false);
//tweak directional lights
ADirectionalLight* directionallight = Cast<ADirectionalLight>(light);
if(directionallight)
{
directionallight->SetLightFunctionFadeDistance(LowLightFadeDistance);
}
//disable point lights
APointLight* pointlight = Cast<APointLight>(light);
if(pointlight)
{
actors[i]->SetActorHiddenInGame(true);
}
}
}
//Set all the roads the low quality material
/*UGameplayStatics::GetAllActorsWithTag(world, FName("CARLA_ROAD"),actors);
for(i=0; i<actors.Num(); i++)
{
TArray<UActorComponent*> components = actors[i]->GetComponentsByClass(UStaticMeshComponent::StaticClass());
for(int32 j=0; j<components.Num(); j++)
{
UStaticMeshComponent* staticmesh = Cast<UStaticMeshComponent>(components[j]);
if(staticmesh)
{
for(int32 k=0; k<staticmesh->GetNumMaterials(); k++)
{
if(!RoadMaterials.IsValidIndex(k)) break;
staticmesh->SetMaterial(k, Cast<UMaterialInterface>(RoadMaterials[k]));
}
}
}
}*/
break;
}
case EQualitySettingsLevel::Medium: break;
case EQualitySettingsLevel::High: break;
case EQualitySettingsLevel::Epic: break;
default: ;
}
DefaultQualitySettingsLevel = newDefaultLevel;
return true;
}
void UCarlaSettings::LoadSettings()
{
CurrentFileName = TEXT("");
@ -209,13 +383,18 @@ void UCarlaSettings::LogSettings() const
UE_LOG(LogCarla, Log, TEXT("Seed Vehicle Spawner = %d"), SeedVehicles);
UE_LOG(LogCarla, Log, TEXT("Seed Pedestrian Spawner = %d"), SeedPedestrians);
UE_LOG(LogCarla, Log, TEXT("Found %d available weather settings."), WeatherDescriptions.Num());
for (auto i = 0; i < WeatherDescriptions.Num(); ++i) {
for (auto i = 0; i < WeatherDescriptions.Num(); ++i)
{
UE_LOG(LogCarla, Log, TEXT(" * %d - %s"), i, *WeatherDescriptions[i].Name);
}
UE_LOG(LogCarla, Log, TEXT("[%s]"), S_CARLA_QUALITYSETTINGS);
UE_LOG(LogCarla, Log, TEXT("Default Quality Settings = %s"), *FQualitySettings::ToString(DefaultQualitySettingsLevel));
UE_LOG(LogCarla, Log, TEXT("[%s]"), S_CARLA_SENSOR);
UE_LOG(LogCarla, Log, TEXT("Added %d sensors."), SensorDescriptions.Num());
UE_LOG(LogCarla, Log, TEXT("Semantic Segmentation = %s"), EnabledDisabled(bSemanticSegmentationEnabled));
for (auto &&Sensor : SensorDescriptions) {
for (auto &&Sensor : SensorDescriptions)
{
check(Sensor.Value != nullptr);
Sensor.Value->Log();
}

View File

@ -12,15 +12,44 @@
#include "CarlaSettings.generated.h"
class USensorDescription;
UENUM(BlueprintType)
enum class EQualitySettingsLevel : uint8
{
None UMETA(DisplayName = "Not set"),
Low UMETA(DisplayName = "Low"),
Medium UMETA(DisplayName = "Medium"),
High UMETA(DisplayName = "High"),
Epic UMETA(DisplayName = "Epic") ,
};
/// Global settings for CARLA.
UCLASS()
class CARLA_API FQualitySettings
{
public:
using uint_type = typename std::underlying_type<EQualitySettingsLevel>::type;
static EQualitySettingsLevel FromString(const FString &SQualitySettingsLevel);
static FString ToString(EQualitySettingsLevel QualitySettingsLevel);
static constexpr uint_type ToUInt(EQualitySettingsLevel quality_settings_level)
{
return static_cast<uint_type>(quality_settings_level);
}
};
class USensorDescription;
class UMaterial;
/** Global settings for CARLA.
* Setting object used to hold both config settings and editable ones in one place
* To ensure the settings are saved to the specified config file make sure to add
* props using the globalconfig or config meta.
*/
UCLASS(config = Game, defaultconfig)
class CARLA_API UCarlaSettings : public UObject
{
GENERATED_BODY()
public:
/** Sets the new quality settings level and make changes in the game related to it. Returns the reuslt of the operation */
bool SetQualitySettingsLevel(EQualitySettingsLevel newDefaultLevel);
/** Load the settings based on the command-line arguments and the INI file if provided. */
void LoadSettings();
@ -64,7 +93,8 @@ private:
UPROPERTY(Category = "CARLA Settings|Debug", VisibleAnywhere)
FString CurrentFileName;
// ===========================================================================
// ===========================================================================
/// @name CARLA Server
// ===========================================================================
/// @{
@ -127,7 +157,29 @@ public:
UPROPERTY(Category = "Level Settings", VisibleAnywhere)
int32 SeedVehicles = 123456789;
/// @}
// ===========================================================================
/// @name Quality Settings
// ===========================================================================
/// @{
public:
/** Quality Settings level. */
UPROPERTY(Category = "Quality Settings", VisibleAnywhere)
EQualitySettingsLevel DefaultQualitySettingsLevel = EQualitySettingsLevel::None;
//UPROPERTY(Category = "Quality Settings", EditAnywhere, config)
//TArray<UMaterial*> RoadMaterials;
//distances
UPROPERTY(Category = "Quality Settings/Low", EditAnywhere, config)
float LowLightFadeDistance;
/// @}
// ===========================================================================
/// @name Sensors
// ===========================================================================