diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/MapGen/CityMapMeshHolder.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/MapGen/CityMapMeshHolder.cpp old mode 100644 new mode 100755 index 08977812e..f63229894 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/MapGen/CityMapMeshHolder.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/MapGen/CityMapMeshHolder.cpp @@ -10,8 +10,7 @@ #include "Components/InstancedStaticMeshComponent.h" #include "Engine/StaticMesh.h" #include - - +#include "Settings/CarlaSettings.h" using tag_size_t = std::underlying_type::type; @@ -141,7 +140,7 @@ void ACityMapMeshHolder::AddInstance(ECityMapMeshTag Tag, FTransform Transform) staticmeshcomponent->SetStaticMesh(instantiator.GetStaticMesh()); //occlussion - StaticMeshActor->Tags.Add(FName("CARLA_ROAD")); + StaticMeshActor->Tags.Add(UCarlaSettings::CARLA_ROAD_TAG); staticmeshcomponent->bAllowCullDistanceVolume=true; staticmeshcomponent->bUseAsOccluder=false; staticmeshcomponent->LDMaxDrawDistance = MaxDrawDistance; @@ -173,15 +172,13 @@ void ACityMapMeshHolder::ResetInstantiators() instantiator.SetStaticMesh(GetStaticMesh(CityMapMeshTag::FromUInt(i))); } - const FName roadtag = FName("CARLA_ROAD"); + TArray roadpieces; GetAttachedActors(roadpieces); for(int32 i=roadpieces.Num()-1; i>=0; i--) { - - //UE_LOG(LogTemp,Display,TEXT("ACityMapMeshHolder::ResetInstantiators Destroyed %s"),*Children[i]->GetName()); - if(roadpieces[i]->Tags.Contains(roadtag)) + if(roadpieces[i]->Tags.Contains(UCarlaSettings::CARLA_ROAD_TAG)) { roadpieces[i]->Destroy(); } diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaEncoder.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaEncoder.cpp index 408aad9f8..f958146c1 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaEncoder.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaEncoder.cpp @@ -25,7 +25,7 @@ static auto MakeCharBuffer(const FString &String) { const char *Ptr = TCHAR_TO_UTF8(*String); auto Buffer = MakeUnique(std::strlen(Ptr) + 1u); // + null terminator. - #if _WIN32 + #if defined(_WIN32) strcpy_s(Buffer.Get(),String.Len()+1, Ptr); #else std::strcpy(Buffer.Get(), Ptr); diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettings.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettings.cpp old mode 100644 new mode 100755 index 2aa09ca31..e4868cea6 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettings.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettings.cpp @@ -6,7 +6,6 @@ #include "Carla.h" #include "CarlaSettings.h" - #include "DynamicWeather.h" #include "Settings/CameraDescription.h" #include "Settings/LidarDescription.h" @@ -19,7 +18,8 @@ #include "Engine/DirectionalLight.h" #include "Engine/PointLight.h" //#include "Landscape.h" //--> needs Lanscape module in the build cs -#include "Components/StaticMeshComponent.h" +#include "Engine/StaticMesh.h" +#include "Materials/MaterialInstance.h" // INI file sections. @@ -28,6 +28,12 @@ #define S_CARLA_SENSOR TEXT("CARLA/Sensor") #define S_CARLA_QUALITYSETTINGS TEXT("CARLA/QualitySettings") +// ============================================================================= +// -- Static variables & constants --------------------------------------------- +// ============================================================================= +const FName UCarlaSettings::CARLA_ROAD_TAG = FName("CARLA_ROAD"); + + // ============================================================================= // -- Static methods ----------------------------------------------------------- // ============================================================================= @@ -118,7 +124,10 @@ static void LoadSettingsFromConfig( ConfigFile.GetString(S_CARLA_QUALITYSETTINGS, TEXT("DefaultLevel"), sDefaultLevel); if(!Settings.SetQualitySettingsLevel(FQualitySettings::FromString(sDefaultLevel))) { - ///apply pre-restart.... @todo + //error + } else + { + //apply pre-restart.... } @@ -186,121 +195,11 @@ bool UCarlaSettings::SetQualitySettingsLevel(EQualitySettingsLevel newDefaultLev void UCarlaSettings::ApplyQualitySettingsLevelPostRestart() const { - UWorld *world = GetWorld(); - if(!world) return ; - //set the quality settings now switch(DefaultQualitySettingsLevel) { - 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 0")); - 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.TranslucentLightingVolume 0")); - world->Exec(world,TEXT("r.LightShaftDownSampleFactor 4")); - world->Exec(world,TEXT("r.OcclusionQueryLocation 1")); - world->Exec(world,TEXT("r.BasePassOutputsVelocity 0")); - //world->Exec(world,TEXT("r.DetailMode 0")); //-->will change to lods 0 - //iterate all vehicles and people, set the draw distance - TArray actors; - int32 i; - - //iterate all terrain, deactivate the actor - /*UGameplayStatics::GetAllActorsOfClass(world, ALandscape::StaticClass(), actors); - for(i=0; i(actors[i]); - if(landscape) - { - landscape->DisableComponentsSimulatePhysics(); - landscape->bUseLandscapeForCullingInvisibleHLODVertices=true; - - } - }*/ - - //iterate all directional lights, deactivate shadows - UGameplayStatics::GetAllActorsOfClass(world, ALight::StaticClass(), actors); - for(i=0;i(actors[i]); - if(directionallight) - { - directionallight->SetCastShadows(false); - directionallight->SetLightFunctionFadeDistance(LowLightFadeDistance); - continue; - } - //disable point lights - /* - APointLight* pointlight = Cast(actors[i]); - if(pointlight) - { - actors[i]->SetActorHiddenInGame(true); - } - */ - //disable any other type of light - actors[i]->SetActorHiddenInGame(true); - } - - //Set all the roads the low quality material - /*UGameplayStatics::GetAllActorsWithTag(world, FName("CARLA_ROAD"),actors); - for(i=0; i components = actors[i]->GetComponentsByClass(UStaticMeshComponent::StaticClass()); - for(int32 j=0; j(components[j]); - if(staticmesh) - { - for(int32 k=0; kGetNumMaterials(); k++) - { - if(!RoadMaterials.IsValidIndex(k)) break; - staticmesh->SetMaterial(k, Cast(RoadMaterials[k])); - } - } - } - }*/ - - + case EQualitySettingsLevel::Low: + ApplyLowQualitySettings(); break; - } case EQualitySettingsLevel::Medium: break; case EQualitySettingsLevel::High: break; case EQualitySettingsLevel::Epic: break; @@ -431,6 +330,156 @@ void UCarlaSettings::ResetSensorDescriptions() bSemanticSegmentationEnabled = false; } +void UCarlaSettings::LaunchLowQualityCommands(UWorld * world) const +{ + //launch 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 0")); + 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 2")); //transparent before opaque + 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.TranslucentLightingVolume 0")); + world->Exec(world,TEXT("r.LightShaftDownSampleFactor 4")); + world->Exec(world,TEXT("r.OcclusionQueryLocation 1")); + world->Exec(world,TEXT("r.BasePassOutputsVelocity 0")); + //world->Exec(world,TEXT("r.DetailMode 0")); //-->will change to lods 0 +} + +void UCarlaSettings::SetAllLightsLowQuality(UWorld* world) const +{ + TArray actors; + UGameplayStatics::GetAllActorsOfClass(world, ALight::StaticClass(), actors); + for(int32 i=0;i(actors[i]); + if(directionallight) + { + directionallight->SetCastShadows(false); + directionallight->SetLightFunctionFadeDistance(LowLightFadeDistance); + continue; + } + //disable any other type of light + actors[i]->SetActorHiddenInGame(true); + } +} + +void UCarlaSettings::SetAllRoadsLowQuality(UWorld* world) const +{ + TArray actors; + UGameplayStatics::GetAllActorsWithTag(world, CARLA_ROAD_TAG,actors); + for(int32 i=0; i components = actors[i]->GetComponentsByClass(UStaticMeshComponent::StaticClass()); + for(int32 j=0; j(components[j]); + if(staticmesh) + { + for(int32 k=0; kGetNumMaterials(); k++) + { + if(LowRoadMaterials.IsValidIndex(k) && LowRoadMaterials[k].MaterialInterface && LowRoadMaterials[k].MaterialInterface->IsValidLowLevel()) + { + staticmesh->SetMaterial(k, LowRoadMaterials[k].MaterialInterface); + } + } + } + } + } +} + +void UCarlaSettings::SetAllActorsDrawDistance(UWorld* world, const float static_mesh_max_draw_distance) const +{ + ///@TODO: use semantics to grab all actors by type (vehicles,ground,people,props) and set different distances configured in the global properties + TArray actors; + #define _MAX_SCALE_SIZE 50.0f + //set the lower quality - max draw distance + UGameplayStatics::GetAllActorsOfClass(world, AActor::StaticClass(),actors); + for(int32 i=0; iIsPendingKillPending() || actors[i]->ActorHasTag(CARLA_ROAD_TAG)) continue; + TArray components = actors[i]->GetComponentsByClass(UStaticMeshComponent::StaticClass()); + float dist = static_mesh_max_draw_distance; + const float maxscale = actors[i]->GetActorScale().GetMax(); + if(maxscale>_MAX_SCALE_SIZE) dist *= 100.0f; + for(int32 j=0; j(components[j]); + if(IsValid(staticmeshcomp)) + { + staticmeshcomp->SetCullDistance(dist); + } + } + + } +} + + +void UCarlaSettings::ApplyLowQualitySettings() const +{ + UWorld *world = GetWorld(); + if(!world) return ; + LaunchLowQualityCommands(world); + + //iterate all terrain, deactivate the actor + /*UGameplayStatics::GetAllActorsOfClass(world, ALandscape::StaticClass(), actors); + for(i=0; i(actors[i]); + if(landscape) + { + landscape->DisableComponentsSimulatePhysics(); + landscape->bUseLandscapeForCullingInvisibleHLODVertices=true; + + } + }*/ + + //iterate all directional lights, deactivate shadows + SetAllLightsLowQuality(world); + + //Set all the roads the low quality material + SetAllRoadsLowQuality(world); + + //Set all actors with static meshes a max disntace configured in the global settings for the low quality + SetAllActorsDrawDistance(world, LowStaticMeshMaxDrawDistance); +} + void UCarlaSettings::LoadSettingsFromFile(const FString &FilePath, const bool bLogOnFailure) { if (FPaths::FileExists(FilePath)) { diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettings.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettings.h old mode 100644 new mode 100755 index 8f2bdd98a..1073d47c0 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettings.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettings.h @@ -36,7 +36,7 @@ public: }; class USensorDescription; -class UMaterial; +struct FStaticMaterial; /** 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 @@ -84,6 +84,7 @@ public: return nullptr; } + // Special overload for blueprints. UFUNCTION(BlueprintCallable) void GetActiveWeatherDescription( @@ -92,9 +93,25 @@ public: UFUNCTION(BlueprintCallable) const FWeatherDescription &GetWeatherDescriptionByIndex(int32 Index); - + ///----------- constants ------------------ +public: + /** + * CARLA_ROAD name to tag road mesh actors + */ + static const FName CARLA_ROAD_TAG; + private: - + /***/ + void LaunchLowQualityCommands(UWorld* world) const; + /***/ + void SetAllLightsLowQuality(UWorld* world) const; + /***/ + void SetAllRoadsLowQuality(UWorld* world) const; + /***/ + void SetAllActorsDrawDistance(UWorld* world, const float static_mesh_max_draw_distance) const; + /***/ + void ApplyLowQualitySettings() const; + /***/ void LoadSettingsFromFile(const FString &FilePath, bool bLogOnFailure); void ResetSensorDescriptions(); @@ -104,7 +121,7 @@ private: FString CurrentFileName; - // =========================================================================== + // =========================================================================== /// @name CARLA Server // =========================================================================== /// @{ @@ -180,13 +197,28 @@ private: EQualitySettingsLevel DefaultQualitySettingsLevel = EQualitySettingsLevel::None; public: - UPROPERTY(Category = "Quality Settings", EditAnywhere, config) - TArray> RoadMaterials; + /** @TODO : Move Low quality vars to a generic map of structs with the quality level as key*/ + + /** Low quality Road Materials. + * Using the index of array it will assign to the material with the same index in the mesh for each piece of road + * @TODO: Use slots name to set it for each part of the road + */ + UPROPERTY(Category = "Quality Settings/Low", EditAnywhere, config, DisplayName="Road Materials List for Low Quality") + TArray LowRoadMaterials; //distances + /** + * Distance at which the light function should be completely faded to DisabledBrightness. + * This is useful for hiding aliasing from light functions applied in the distance. + */ UPROPERTY(Category = "Quality Settings/Low", EditAnywhere, config) - float LowLightFadeDistance; + float LowLightFadeDistance = 1000.0f; + /** + * + */ + UPROPERTY(Category = "Quality Settings/Low", EditAnywhere, config, meta = (ClampMin = "500.0", ClampMax = "15000.0", UIMin = "500.0", UIMax = "15000.0")) + float LowStaticMeshMaxDrawDistance = 10000.0f; /// @}