9#include "Components/StaticMeshComponent.h"
10#include "Engine/DirectionalLight.h"
11#include "Engine/Engine.h"
12#include "Engine/LocalPlayer.h"
13#include "Engine/PostProcessVolume.h"
14#include "Engine/StaticMesh.h"
15#include "GameFramework/HUD.h"
16#include "InstancedFoliageActor.h"
17#include "Kismet/GameplayStatics.h"
19#include "Scalability.h"
28 : ActorSpawnedDelegate(FOnActorSpawned::FDelegate::CreateUObject(
46 if (InActor !=
nullptr &&
IsValid(InActor) && !InActor->IsPendingKill() &&
47 !InActor->IsA<AInstancedFoliageActor>() &&
48 !InActor->IsA<ALandscape>() &&
52 TArray<UPrimitiveComponent *> components;
53 InActor->GetComponents(components);
56 case EQualityLevel::Low: {
59 const float maxscale = InActor->GetActorScale().GetMax();
85 Scalability::ToggleTemporaryQualityLevels(
true);
89 case EQualityLevel::Low:
104 UE_LOG(LogCarla, Warning, TEXT(
"Unknown quality level, falling back to default."));
105 case EQualityLevel::Epic:
122 if (!
IsValid(InWorld) || InWorld->IsPendingKill())
127 APlayerController *playercontroller = UGameplayStatics::GetPlayerController(InWorld, 0);
128 if (playercontroller)
130 ULocalPlayer *player = playercontroller->GetLocalPlayer();
136 AHUD *hud = playercontroller->GetHUD();
147 return GEngine->GetWorldFromContextObjectChecked(
this);
156 if (world ==
nullptr || !
IsValid(world) || world->IsPendingKill())
160 check(world !=
nullptr);
161 auto GameInstance = Cast<UCarlaGameInstance>(world->GetGameInstance());
162 check(GameInstance !=
nullptr);
175 GEngine->Exec(world, TEXT(
"r.DefaultFeature.MotionBlur 0"));
176 GEngine->Exec(world, TEXT(
"r.DefaultFeature.Bloom 0"));
177 GEngine->Exec(world, TEXT(
"r.DefaultFeature.AmbientOcclusion 0"));
178 GEngine->Exec(world, TEXT(
"r.AmbientOcclusionLevels 0"));
179 GEngine->Exec(world, TEXT(
"r.DefaultFeature.AmbientOcclusionStaticFraction 0"));
180 GEngine->Exec(world, TEXT(
"r.RHICmdBypass 0"));
181 GEngine->Exec(world, TEXT(
"r.DefaultFeature.AntiAliasing 1"));
182 GEngine->Exec(world, TEXT(
"r.Streaming.PoolSize 2000"));
183 GEngine->Exec(world, TEXT(
"r.HZBOcclusion 0"));
184 GEngine->Exec(world, TEXT(
"r.MinScreenRadiusForLights 0.01"));
185 GEngine->Exec(world, TEXT(
"r.SeparateTranslucency 0"));
186 GEngine->Exec(world, TEXT(
"r.FinishCurrentFrame 0"));
187 GEngine->Exec(world, TEXT(
"r.MotionBlurQuality 0"));
188 GEngine->Exec(world, TEXT(
"r.PostProcessAAQuality 0"));
189 GEngine->Exec(world, TEXT(
"r.BloomQuality 1"));
190 GEngine->Exec(world, TEXT(
"r.SSR.Quality 0"));
191 GEngine->Exec(world, TEXT(
"r.DepthOfFieldQuality 0"));
192 GEngine->Exec(world, TEXT(
"r.SceneColorFormat 2"));
193 GEngine->Exec(world, TEXT(
"r.TranslucencyVolumeBlur 0"));
194 GEngine->Exec(world, TEXT(
"r.TranslucencyLightingVolumeDim 4"));
195 GEngine->Exec(world, TEXT(
"r.MaxAnisotropy 8"));
196 GEngine->Exec(world, TEXT(
"r.LensFlareQuality 0"));
197 GEngine->Exec(world, TEXT(
"r.SceneColorFringeQuality 0"));
198 GEngine->Exec(world, TEXT(
"r.FastBlurThreshold 0"));
199 GEngine->Exec(world, TEXT(
"r.SSR.MaxRoughness 0.1"));
200 GEngine->Exec(world, TEXT(
"r.AllowOcclusionQueries 1"));
201 GEngine->Exec(world, TEXT(
"r.SSR 0"));
203 GEngine->Exec(world, TEXT(
"r.EarlyZPass 2"));
204 GEngine->Exec(world, TEXT(
"r.EarlyZPassMovable 1"));
205 GEngine->Exec(world, TEXT(
"Foliage.DitheredLOD 0"));
207 GEngine->Exec(world, TEXT(
"sg.PostProcessQuality 0"));
210 GEngine->Exec(world, TEXT(
"sg.ShadowQuality 0"));
211 GEngine->Exec(world, TEXT(
"sg.TextureQuality 0"));
212 GEngine->Exec(world, TEXT(
"sg.EffectsQuality 0"));
213 GEngine->Exec(world, TEXT(
"sg.FoliageQuality 0"));
214 GEngine->Exec(world, TEXT(
"foliage.DensityScale 0"));
215 GEngine->Exec(world, TEXT(
"grass.DensityScale 0"));
216 GEngine->Exec(world, TEXT(
"r.TranslucentLightingVolume 0"));
217 GEngine->Exec(world, TEXT(
"r.LightShaftDownSampleFactor 4"));
218 GEngine->Exec(world, TEXT(
"r.OcclusionQueryLocation 1"));
221 GEngine->Exec(world, TEXT(
"r.DefaultFeature.AutoExposure 1"));
227 const float max_draw_distance,
228 const TArray<FStaticMaterial> &road_pieces_materials)
const
230 if (!world || !
IsValid(world) || world->IsPendingKill())
234 AsyncTask(ENamedThreads::GameThread, [=]() {
235 if (!world || !
IsValid(world) || world->IsPendingKill())
239 TArray<AActor *> actors;
242 for (int32 i = 0; i < actors.Num(); i++)
244 AActor *actor = actors[i];
245 if (!
IsValid(actor) || actor->IsPendingKill())
249 TArray<UStaticMeshComponent *> components;
250 actor->GetComponents(components);
251 for (int32 j = 0; j < components.Num(); j++)
253 UStaticMeshComponent *staticmeshcomponent = Cast<UStaticMeshComponent>(components[j]);
254 if (staticmeshcomponent)
256 staticmeshcomponent->bAllowCullDistanceVolume = (max_draw_distance > 0);
257 staticmeshcomponent->bUseAsOccluder =
false;
258 staticmeshcomponent->LDMaxDrawDistance = max_draw_distance;
259 staticmeshcomponent->CastShadow = (max_draw_distance == 0);
260 if (road_pieces_materials.Num() > 0)
262 TArray<FName> meshslotsnames = staticmeshcomponent->GetMaterialSlotNames();
263 for (int32 k = 0; k < meshslotsnames.Num(); k++)
265 const FName &slotname = meshslotsnames[k];
266 road_pieces_materials.ContainsByPredicate(
267 [staticmeshcomponent, slotname](
const FStaticMaterial &material)
269 if (material.MaterialSlotName.IsEqual(slotname))
271 staticmeshcomponent->SetMaterial(
272 staticmeshcomponent->GetMaterialIndex(slotname),
273 material.MaterialInterface);
291 const float max_draw_distance)
const
297 TArray<UPrimitiveComponent *> components;
298 actor->GetComponents(components,
false);
299 float dist = max_draw_distance;
300 const float maxscale = actor->GetActorScale().GetMax();
305 for (int32 j = 0; j < components.Num(); j++)
308 if (
IsValid(primitivecomponent))
310 primitivecomponent->SetCullDistance(dist);
311 primitivecomponent->bAllowCullDistanceVolume = dist > 0;
319 if (!world || !
IsValid(world) || world->IsPendingKill())
323 AsyncTask(ENamedThreads::GameThread, [=]() {
324 if (!world || !
IsValid(world) || world->IsPendingKill())
328 TArray<AActor *> actors;
330 UGameplayStatics::GetAllActorsOfClass(world, AActor::StaticClass(), actors);
331 for (int32 i = 0; i < actors.Num(); i++)
333 AActor *actor = actors[i];
334 if (!
IsValid(actor) || actor->IsPendingKill() ||
335 actor->IsA<AInstancedFoliageActor>() ||
337 actor->IsA<ALandscape>() ||
350 TArray<AActor *> actors;
351 UGameplayStatics::GetAllActorsOfClass(world, APostProcessVolume::StaticClass(), actors);
352 for (int32 i = 0; i < actors.Num(); i++)
354 AActor *actor = actors[i];
355 if (!
IsValid(actor) || actor->IsPendingKill())
359 APostProcessVolume *postprocessvolume = Cast<APostProcessVolume>(actor);
360 if (postprocessvolume)
362 postprocessvolume->bEnabled = enabled;
374 GEngine->Exec(world, TEXT(
"r.AmbientOcclusionLevels -1"));
375 GEngine->Exec(world, TEXT(
"r.RHICmdBypass 1"));
376 GEngine->Exec(world, TEXT(
"r.DefaultFeature.AntiAliasing 1"));
377 GEngine->Exec(world, TEXT(
"r.Streaming.PoolSize 2000"));
378 GEngine->Exec(world, TEXT(
"r.MinScreenRadiusForLights 0.03"));
379 GEngine->Exec(world, TEXT(
"r.SeparateTranslucency 1"));
380 GEngine->Exec(world, TEXT(
"r.PostProcessAAQuality 4"));
381 GEngine->Exec(world, TEXT(
"r.BloomQuality 5"));
382 GEngine->Exec(world, TEXT(
"r.SSR.Quality 3"));
383 GEngine->Exec(world, TEXT(
"r.DepthOfFieldQuality 2"));
384 GEngine->Exec(world, TEXT(
"r.SceneColorFormat 4"));
385 GEngine->Exec(world, TEXT(
"r.TranslucencyVolumeBlur 1"));
386 GEngine->Exec(world, TEXT(
"r.TranslucencyLightingVolumeDim 64"));
387 GEngine->Exec(world, TEXT(
"r.MaxAnisotropy 8"));
388 GEngine->Exec(world, TEXT(
"r.LensFlareQuality 2"));
389 GEngine->Exec(world, TEXT(
"r.SceneColorFringeQuality 1"));
390 GEngine->Exec(world, TEXT(
"r.FastBlurThreshold 100"));
391 GEngine->Exec(world, TEXT(
"r.SSR.MaxRoughness -1"));
393 GEngine->Exec(world, TEXT(
"r.EarlyZPass 3"));
394 GEngine->Exec(world, TEXT(
"r.EarlyZPassMovable 1"));
395 GEngine->Exec(world, TEXT(
"Foliage.DitheredLOD 1"));
396 GEngine->Exec(world, TEXT(
"sg.PostProcessQuality 3"));
397 GEngine->Exec(world, TEXT(
"r.ViewDistanceScale 1"));
399 GEngine->Exec(world, TEXT(
"sg.ShadowQuality 3"));
400 GEngine->Exec(world, TEXT(
"sg.TextureQuality 3"));
401 GEngine->Exec(world, TEXT(
"sg.EffectsQuality 3"));
402 GEngine->Exec(world, TEXT(
"sg.FoliageQuality 3"));
403 GEngine->Exec(world, TEXT(
"foliage.DensityScale 1"));
404 GEngine->Exec(world, TEXT(
"grass.DensityScale 1"));
405 GEngine->Exec(world, TEXT(
"r.TranslucentLightingVolume 1"));
406 GEngine->Exec(world, TEXT(
"r.LightShaftDownSampleFactor 2"));
409 GEngine->Exec(world, TEXT(
"r.DetailMode 2"));
414 const float max_distance_fade,
415 const bool cast_shadows,
416 const bool hide_non_directional)
const
418 if (!world || !
IsValid(world) || world->IsPendingKill())
422 AsyncTask(ENamedThreads::GameThread, [=]() {
423 if (!world || !
IsValid(world) || world->IsPendingKill())
427 TArray<AActor *> actors;
428 UGameplayStatics::GetAllActorsOfClass(world, ALight::StaticClass(), actors);
429 for (int32 i = 0; i < actors.Num(); i++)
431 if (!
IsValid(actors[i]) || actors[i]->IsPendingKill())
436 ADirectionalLight *directionallight = Cast<ADirectionalLight>(actors[i]);
437 if (directionallight)
439 directionallight->SetCastShadows(cast_shadows);
440 directionallight->SetLightFunctionFadeDistance(max_distance_fade);
444 actors[i]->SetActorHiddenInGame(hide_non_directional);
UE_LOG(LogCarla, Log, TEXT("UActorDispatcher::Destroying actor: '%s' %x"), *Id, Actor)
for(int32 i=0;i< ResultPropJsonArray.Num();++i)
static constexpr float CARLA_SETTINGS_MAX_SCALE_SIZE
static bool IsValid(const ACarlaWheeledVehicle *Vehicle)
void SetAllRoads(UWorld *world, float max_draw_distance, const TArray< FStaticMaterial > &road_pieces_materials) const
void SetPostProcessEffectsEnabled(UWorld *world, bool enabled) const
void ApplyQualityLevelPreRestart()
加载关卡之前,应用当前设置
void LaunchLowQualityCommands(UWorld *world) const
执行引擎命令,将低质量水平应用于世界
void ApplyQualityLevelPostRestart()
加载关卡后,应用当前设置
UCarlaSettings * CarlaSettings
void LaunchEpicQualityCommands(UWorld *world) const
执行引擎命令,将史诗般的质量水平应用于世界
void CheckCarlaSettings(UWorld *world)
检查世界、实例和设置是否有效,并保存CarlaSettings实例
void SetAllActorsDrawDistance(UWorld *world, float max_draw_distance) const
void RegisterSpawnHandler(UWorld *World)
在此处为所有新生成的参与者创建事件触发器处理程序,以便使用自定义函数进行处理。
FOnActorSpawned::FDelegate ActorSpawnedDelegate
static EQualityLevel AppliedLowPostResetQualityLevel
重新启动级别后当前应用的质量级别
void SetAllLights(UWorld *world, float max_distance_fade, bool cast_shadows, bool hide_non_directional) const
void OnActorSpawned(AActor *Actor)
函数应用于正在生成的参与者,以应用当前设置
void SetActorComponentsDrawDistance(AActor *actor, float max_draw_distance) const
bool bDisableRendering
启用或禁用世界的视窗渲染。默认情况下禁用。
EQualityLevel GetQualityLevel() const
static const FName CARLA_SKY_TAG
CARLA_SKY 名称用于标记场景中的天空球(sky sphere, BPS)参与者。
static const FName CARLA_ROAD_TAG
CARLA_ROAD 名称用于标记道路网格参与者。
float LowLightFadeDistance
光照函数应完全淡化为 禁用亮度(DisabledBrightness)的距离。 这对于隐藏在远处应用的光照函数的混叠很有用。