CARLA
Loading...
Searching...
No Matches
Weather.h
Go to the documentation of this file.
1// Copyright (c) 2026 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#pragma once
8
10
11#include <util/ue-header-guard-begin.h>
12#include "GameFramework/Actor.h"
13#include "Camera/CameraModifier.h"
14#include <util/ue-header-guard-end.h>
15
16#include "Weather.generated.h"
17
18class ASensor;
20class UParticleSystem;
21class UParticleSystemComponent;
22
23/// Main-view lens pass; sensor passes are managed separately by AWeather.
24UCLASS()
26{
27 GENERATED_BODY()
28public:
29 UPROPERTY(Transient)
30 UMaterial* RainMaterial = nullptr;
31 float RainWeight = 0.0f;
32protected:
33 virtual void ModifyPostProcess(float DeltaTime, float& BlendWeight,
34 FPostProcessSettings& Settings) override;
35};
36
37UCLASS(Abstract)
38class CARLA_API AWeather : public AActor
39{
40 GENERATED_BODY()
41
42public:
43
44 AWeather(const FObjectInitializer& ObjectInitializer);
45
46 /// Update the weather parameters and notifies it to the blueprint's event
47 UFUNCTION(BlueprintCallable)
48 void ApplyWeather(const FWeatherParameters &WeatherParameters);
49
50 /// Notifing the weather to the blueprint's event
51 void NotifyWeather(ASensor* Sensor = nullptr);
52
53 /// Update the weather parameters without notifing it to the blueprint's event
54 UFUNCTION(BlueprintCallable)
55 void SetWeather(const FWeatherParameters &WeatherParameters);
56
57 /// Returns the current WeatherParameters
58 UFUNCTION(BlueprintCallable)
59 const FWeatherParameters &GetCurrentWeather() const
60 {
61 return Weather;
62 }
63
64 /// How many times ApplyWeather ran: Multi-GPU secondaries mirror every
65 /// apply, also the ones that set the same values again.
66 uint64 GetApplySerial() const
67 {
68 return ApplySerial;
69 }
70
71 /// Returns whether the day night cycle is active (automatic on/off switch when changin to night mode)
72 UFUNCTION(BlueprintCallable)
73 const bool &GetDayNightCycle() const
74 {
75 return DayNightCycle;
76 }
77
78 /// Update the day night cycle
79 void SetDayNightCycle(const bool &active);
80
81 /// Pushes Weather into a single ASkyBase rig (sun/fog/clouds/atmosphere/
82 /// exposure) and runs its blueprint refresh functions -- everything
83 /// PushWeatherToSky does per-actor, factored out so it works on any sky
84 /// actor directly, without requiring an AWeather instance to exist in the
85 /// world. Used by ASkyBase::RefreshWeather/LoadPreset for editor-time
86 /// preview when no BP_CarlaWeather is placed in the level, and by
87 /// PushWeatherToSky itself for the full runtime path.
88 UFUNCTION(BlueprintCallable, Category = "Weather")
89 static void ApplyWeatherToSkyActor(AActor* SkyActor, const FWeatherParameters& Weather);
90
91 /// Exposure / bloom defaults for the fields the sky's loaded camera profile
92 /// does not set (see the comment in ApplyWeatherToSkyActor).
93 static void FillSkyPostProcessFallback(class UPostProcessComponent* PostProcessComponent);
94
95 /// Environment-map override for the sky light (set_sky_light_map RPC):
96 /// every ASkyBase rig in World switches its sky light to the given cubemap
97 /// (SLS_SpecifiedCubemap, real-time capture off) at the given intensity,
98 /// and ApplyWeatherToSkyActor keeps it that way across weather pushes
99 /// until ClearSkyLightMap. Scoped to World: it is dropped when that world
100 /// is cleaned up (load_world / reload_world), so the next level starts on
101 /// its own real-time capture. The cubemap is rooted for as long as it is
102 /// set. Returns false if no sky rig was found.
103 static bool SetSkyLightMap(UWorld* World, class UTextureCube* Cubemap, float Intensity);
104
105 /// Drops the override and restores the real-time atmosphere capture with
106 /// the curve-driven intensity.
107 static void ClearSkyLightMap(UWorld* World);
108
109 static bool HasSkyLightMap();
110
111protected:
112
113#if WITH_EDITOR
114 virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
115#endif
116
117 UFUNCTION(BlueprintImplementableEvent)
118 void RefreshWeather(const FWeatherParameters &WeatherParameters);
119
120private:
121
122 virtual void Tick(float DeltaSeconds) override;
123 virtual void BeginPlay() override;
124 virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
125 void UpdateRain();
126 UParticleSystemComponent* CreateRainEmitter(AActor* Owner, bool bSensor);
127 void CheckWeatherPostProcessEffects();
128
129 UPROPERTY(Transient)
130 class UMaterialParameterCollection* RainParameters = nullptr;
131
132 UPROPERTY(Transient)
133 UParticleSystem* RainTemplate = nullptr;
134
135 UPROPERTY(Transient)
136 UParticleSystemComponent* ViewportRain = nullptr;
137
138 UPROPERTY(Transient)
139 UCarlaRainCameraModifier* RainCameraModifier = nullptr;
140
141 TMap<TWeakObjectPtr<ASceneCaptureCamera>, TWeakObjectPtr<UParticleSystemComponent>> SensorRain;
142
143
144 /// Push the current weather into the ASkyBase rig (BP_Carla_Sky) and run its
145 /// blueprint Update. The UE5 sky rig only refreshes itself from its
146 /// construction script, so without this call the sun/fog/atmosphere stay
147 /// frozen at the state saved in the map regardless of the weather API.
148 void PushWeatherToSky();
149
150 /// Broadcast the current day/night state (derived from SunAltitudeAngle) to
151 /// UCarlaLightSubsystem so registered CarlaLight components (street lamps)
152 /// react. BP_CarlaWeather's graph does reference the subsystem and
153 /// DayTimeChangeEvent, but measured behavior is that lights never receive
154 /// it (same blueprint has other confirmed-dead exec chains that
155 /// PushWeatherToSky already routes around) -- drive it from C++ instead so
156 /// it does not depend on that graph being reachable.
157 void UpdateStreetLightsForDayNight();
158
159 UPROPERTY(EditAnywhere, Category="Parameters")
161
162 UPROPERTY()
163 UMaterial* PrecipitationPostProcessMaterial;
164
165 UPROPERTY()
166 UMaterial* DustStormPostProcessMaterial;
167
168 TMap<UMaterial*, float> ActiveBlendables;
169
170 UPROPERTY(EditAnywhere, Category = "Weather")
171 bool DayNightCycle = true;
172
173 uint64 ApplySerial = 0u;
174};
A sensor that captures images from the scene.
uint64 GetApplySerial() const
How many times ApplyWeather ran: Multi-GPU secondaries mirror every apply, also the ones that set the...
Definition Weather.h:66
Main-view lens pass; sensor passes are managed separately by AWeather.
Definition Weather.h:26