CARLA
Weather.cpp
Go to the documentation of this file.
1 // Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
2 // de Barcelona (UAB).
3 //
4 // This work is licensed under the terms of the MIT license.
5 // For a copy, see <https://opensource.org/licenses/MIT>.
6 
7 #include "Carla.h"
10 #include "Components/SceneCaptureComponent2D.h"
11 #include "Kismet/GameplayStatics.h"
12 #include "ConstructorHelpers.h"
13 
14 AWeather::AWeather(const FObjectInitializer& ObjectInitializer)
15  : Super(ObjectInitializer)
16 {
17  PrecipitationPostProcessMaterial = ConstructorHelpers::FObjectFinder<UMaterial>(
18  TEXT("Material'/Game/Carla/Static/GenericMaterials/00_MastersOpt/Screen_posProcess/M_screenDrops.M_screenDrops'")).Object;
19 
20  DustStormPostProcessMaterial = ConstructorHelpers::FObjectFinder<UMaterial>(
21  TEXT("Material'/Game/Carla/Static/GenericMaterials/00_MastersOpt/Screen_posProcess/M_screenDust_wind.M_screenDust_wind'")).Object;
22 
23  PrimaryActorTick.bCanEverTick = false;
24  RootComponent = ObjectInitializer.CreateDefaultSubobject<USceneComponent>(this, TEXT("RootComponent"));
25 }
26 
28 {
29  if (Weather.Precipitation > 0.0f)
31  else
33 
34  if (Weather.DustStorm > 0.0f)
36  else
38 
39  TArray<AActor*> SensorActors;
40  UGameplayStatics::GetAllActorsOfClass(GetWorld(), ASceneCaptureCamera::StaticClass(), SensorActors);
41  for (AActor* SensorActor : SensorActors)
42  {
43  ASceneCaptureCamera* Sensor = Cast<ASceneCaptureCamera>(SensorActor);
44  for (auto& ActiveBlendable : ActiveBlendables)
45  Sensor->GetCaptureComponent2D()->PostProcessSettings.AddBlendable(ActiveBlendable.Key, ActiveBlendable.Value);
46  }
47 }
48 
50 {
51  SetWeather(InWeather);
53 
54 #ifdef CARLA_WEATHER_EXTRA_LOG
55  UE_LOG(LogCarla, Log, TEXT("Changing weather:"));
56  UE_LOG(LogCarla, Log, TEXT(" - Cloudiness = %.2f"), Weather.Cloudiness);
57  UE_LOG(LogCarla, Log, TEXT(" - Precipitation = %.2f"), Weather.Precipitation);
58  UE_LOG(LogCarla, Log, TEXT(" - PrecipitationDeposits = %.2f"), Weather.PrecipitationDeposits);
59  UE_LOG(LogCarla, Log, TEXT(" - WindIntensity = %.2f"), Weather.WindIntensity);
60  UE_LOG(LogCarla, Log, TEXT(" - SunAzimuthAngle = %.2f"), Weather.SunAzimuthAngle);
61  UE_LOG(LogCarla, Log, TEXT(" - SunAltitudeAngle = %.2f"), Weather.SunAltitudeAngle);
62  UE_LOG(LogCarla, Log, TEXT(" - FogDensity = %.2f"), Weather.FogDensity);
63  UE_LOG(LogCarla, Log, TEXT(" - FogDistance = %.2f"), Weather.FogDistance);
64  UE_LOG(LogCarla, Log, TEXT(" - FogFalloff = %.2f"), Weather.FogFalloff);
65  UE_LOG(LogCarla, Log, TEXT(" - Wetness = %.2f"), Weather.Wetness);
66  UE_LOG(LogCarla, Log, TEXT(" - ScatteringIntensity = %.2f"), Weather.ScatteringIntensity);
67  UE_LOG(LogCarla, Log, TEXT(" - MieScatteringScale = %.2f"), Weather.MieScatteringScale);
68  UE_LOG(LogCarla, Log, TEXT(" - RayleighScatteringScale = %.2f"), Weather.RayleighScatteringScale);
69  UE_LOG(LogCarla, Log, TEXT(" - DustStorm = %.2f"), Weather.DustStorm);
70 #endif // CARLA_WEATHER_EXTRA_LOG
71 
72  // Call the blueprint that actually changes the weather.
74 }
75 
77 {
79 
80  // Call the blueprint that actually changes the weather.
82 }
83 
85 {
86  Weather = InWeather;
87 }
88 
89 void AWeather::SetDayNightCycle(const bool& active)
90 {
91  DayNightCycle = active;
92 }
void RefreshWeather(const FWeatherParameters &WeatherParameters)
void SetDayNightCycle(const bool &active)
Update the day night cycle.
Definition: Weather.cpp:89
UMaterial * PrecipitationPostProcessMaterial
Definition: Weather.h:66
FWeatherParameters Weather
Definition: Weather.h:64
USceneCaptureComponent2D * GetCaptureComponent2D()
A sensor that captures images from the scene.
AWeather(const FObjectInitializer &ObjectInitializer)
Definition: Weather.cpp:14
void SetWeather(const FWeatherParameters &WeatherParameters)
Update the weather parameters without notifing it to the blueprint&#39;s event.
Definition: Weather.cpp:84
UMaterial * DustStormPostProcessMaterial
Definition: Weather.h:68
void CheckWeatherPostProcessEffects()
Definition: Weather.cpp:27
bool DayNightCycle
Definition: Weather.h:73
void NotifyWeather(ASensor *Sensor=nullptr)
Notifing the weather to the blueprint&#39;s event.
Definition: Weather.cpp:76
TMap< UMaterial *, float > ActiveBlendables
Definition: Weather.h:70
void ApplyWeather(const FWeatherParameters &WeatherParameters)
Update the weather parameters and notifies it to the blueprint&#39;s event.
Definition: Weather.cpp:49