CARLA
Loading...
Searching...
No Matches
Sky.h
Go to the documentation of this file.
1#pragma once
2
3#include <util/ue-header-guard-begin.h>
4#include "Engine/Scene.h"
5#include "GameFramework/Actor.h"
6#include <util/ue-header-guard-end.h>
7
8#include "Sky.generated.h"
9
11class UPostProcessComponent;
12class UExponentialHeightFogComponent;
13class UDirectionalLightComponent;
14class USkyLightComponent;
15class UVolumetricCloudComponent;
16class USkyAtmosphereComponent;
17
18// Curated shortcuts into PostProcessComponent's Settings -- the handful of
19// camera/exposure/color-grading fields an artist actually reaches for per
20// shot, without hunting through the full "Post Process Volume" category
21// (hundreds of fields). This is NOT a second, parallel post process: editing
22// these pushes straight into the same Settings that category also edits, and
23// they're kept in sync with whatever PostProcess profile is loaded (see
24// ASkyBase::SyncCameraParametersFromPostProcess). For anything not listed
25// here, go edit "Post Process Volume" directly -- it's still the same volume.
26USTRUCT(BlueprintType)
28{
29 GENERATED_BODY()
30
31 // Exposure (FPostProcessSettings::AutoExposureMinBrightness/MaxBrightness,
32 // in EV100 -- what Weather's own exposure fallback also fills in for any
33 // PostProcess profile that doesn't claim them itself).
34 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Exposure")
35 float ExposureMinEV = 10.0f;
36
37 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Exposure")
38 float ExposureMaxEV = 12.0f;
39
40 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Exposure")
41 float HighlightContrast = 1.0f;
42
43 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Exposure")
44 float ShadowContrast = 1.0f;
45
46 // Camera (Lens|Camera in the full Post Process Volume category).
47 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Camera")
48 float ShutterSpeed = 60.0f;
49
50 // AKA metering/exposure method: AEM_Histogram (auto, scene-average --
51 // what every profile here uses) vs AEM_Manual (fixed, actually reads
52 // ShutterSpeed/ISO/Aperture below for real camera-triangle exposure).
53 // ISO/Aperture do nothing visible under Histogram -- flip this to Manual
54 // to make them matter.
55 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Camera")
56 TEnumAsByte<EAutoExposureMethod> ExposureMode = AEM_Histogram;
57
58 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Camera")
59 float ISO = 100.0f;
60
61 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Camera")
62 float Aperture = 4.0f;
63
64 // Depth of Field (Lens|Depth of Field).
65 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Depth Of Field")
66 float SensorWidth = 24.576f;
67
68 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Depth Of Field")
69 float FocalDistance = 1000.0f;
70
71 // Color Grading. GlobalSaturation/Contrast/Gamma are single-knob
72 // shortcuts onto the full RGB+luma FVector4 fields (ColorSaturation/
73 // ColorContrast/ColorGamma) -- they set all three color channels equally
74 // and leave the luma (w) channel untouched. Use "Post Process Volume" ->
75 // Color Grading|Global directly for per-channel control.
76 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Color Grading")
77 float Temperature = 6500.0f;
78
79 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Color Grading")
80 float Tint = 0.0f;
81
82 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Color Grading")
83 FLinearColor SceneColorTint = FLinearColor::White;
84
85 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Color Grading")
86 float GlobalSaturation = 1.0f;
87
88 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Color Grading")
89 float GlobalContrast = 1.0f;
90
91 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Color Grading")
92 float GlobalGamma = 1.0f;
93
94 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Color Grading")
95 float VignetteIntensity = 0.4f;
96};
97
98UCLASS(Abstract, PrioritizeCategories = "CustomParameters PostProcessProfile WeatherPreset")
99class CARLA_API ASkyBase :
100 public AActor
101{
102 GENERATED_BODY()
103
104public:
105
106 ASkyBase(const FObjectInitializer& ObjectInitializer);
107
108 // The actor's FWeatherParameters variable (a Blueprint-added variable on
109 // BP_Carla_Sky, currently named "WeatherParameters" -- but matched by
110 // TYPE, not name, so it survives being renamed again in the Blueprint
111 // editor). The single source of truth every lookup here and in
112 // AWeather::ApplyWeatherToSkyActor must go through -- don't re-implement
113 // a name-based search elsewhere, that's exactly what broke last time.
114 static FWeatherParameters* FindWeatherParameters(AActor* SkyActor);
115
116 // Tag of the rig ACarlaGameModeBase spawns on a World Partition map that
117 // has none loaded at InitGame.
118 static const FName FallbackSkyTag;
119
120 // The rig's sky light, for AWeather::SetSkyLightMap (environment-map
121 // override); may be null on a rig that lost the component.
122 USkyLightComponent* GetSkyLightComponent() const { return SkyLightComponent; }
123
124 // True while PostProcessComponent's bloom was filled in by
125 // AWeather::FillSkyPostProcessFallback (carla.Weather.BloomIntensity)
126 // rather than set by the loaded profile. Loading a profile clears it;
127 // SaveProfile leaves that bloom out of the file.
128 UPROPERTY(Transient)
129 bool bBloomFromWeatherFallback = false;
130
131 // Profile to load/save on PostProcessComponent, i.e. the JSON file name
132 // (without extension) under Content/Carla/Config/PostProcess/. Pick an
133 // existing one from the dropdown or type a new name to create it on the
134 // next SaveProfile.
135 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PostProcessProfile",
136 meta = (GetOptions = "GetAvailablePostProcessProfileNamesForPicker"))
137 FString ProfileName = TEXT("Cinematic");
138
139 // Writes PostProcessComponent's current Settings -- edited live, in the
140 // normal "Settings" category of the component, absolute values, no
141 // delta/remap -- to Config/PostProcess/<ProfileName>.json. This is
142 // exactly what a spawned camera loads at runtime for that profile.
143 UFUNCTION(BlueprintCallable, CallInEditor, Category = "PostProcessProfile")
144 void SaveProfile();
145
146 // Loads Config/PostProcess/<ProfileName>.json into PostProcessComponent's
147 // Settings, replacing whatever is currently set. Also refreshes
148 // CameraParameters (below) from the newly loaded Settings so those
149 // shortcuts never show a stale value, and re-applies Weather's exposure
150 // fallback immediately (see RefreshWeather) instead of waiting for some
151 // unrelated later property edit to do it.
152 UFUNCTION(BlueprintCallable, CallInEditor, Category = "PostProcessProfile")
153 void LoadProfile();
154
155 // Name for a brand new profile -- free text, not restricted to the
156 // dropdown above. CreateProfile sets ProfileName to this and saves.
157 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PostProcessProfile")
158 FString NewProfileName;
159
160 // Sets ProfileName = NewProfileName and saves the current Settings under
161 // it, creating Config/PostProcess/<NewProfileName>.json. Use this to
162 // start a new profile from the current PostProcessComponent state; the
163 // dropdown above picks it up on the next click.
164 UFUNCTION(BlueprintCallable, CallInEditor, Category = "PostProcessProfile")
165 void CreateProfile();
166
167 // Curated shortcuts onto PostProcessComponent's Settings -- see
168 // FCameraParameters. Kept in sync with whatever profile LoadProfile last
169 // loaded; edit here for the common cases, or go to "Post Process Volume"
170 // directly for anything not exposed here.
171 //
172 // Category is "CustomParameters", same as the Blueprint's own "Sky
173 // Parameters"/"Weather Parameters" variable -- sharing one category name
174 // (set on that BP variable too, from the Blueprint editor) groups both
175 // under a single header instead of two.
176 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CustomParameters")
177 FCameraParameters CameraParameters;
178
179 // Time-of-day preset (sun position only) and weather-condition preset
180 // (everything else -- cloudiness/rain/wind/fog/wetness/...), both named
181 // entries in the shared catalog Config/Weather/Presets.json. Independent
182 // axes: pick any time with any condition. Selecting either one applies it
183 // immediately (see PostEditChangeProperty) -- no separate Load button.
184 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "WeatherPreset",
185 meta = (GetOptions = "GetAvailableTimePresetNamesForPicker", DisplayName = "Time Preset"))
186 FString TimePresetName = TEXT("Noon");
187
188 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "WeatherPreset",
189 meta = (GetOptions = "GetAvailableConditionPresetNamesForPicker", DisplayName = "Condition Preset"))
190 FString ConditionPresetName = TEXT("Clear");
191
192 // CallInEditor buttons in one category are always shown together, above
193 // the category's properties, sorted alphabetically by function name --
194 // not declaration order, and Unreal doesn't offer a way to interleave
195 // them with the dropdowns/textboxes below. These are named B_/C_/D_...
196 // (no A_: that was LoadPreset, removed -- see PostEditChangeProperty) so
197 // that alphabetical order matches the intended reading order (the two
198 // Saves, then the two MapDefault buttons, then the two Creates, then
199 // LoadMapDefault); DisplayName keeps each button's own label clean.
200
201 // Saves the map's current sun position (AWeather::GetCurrentWeather) to
202 // the "time" catalog under TimePresetName.
203 UFUNCTION(BlueprintCallable, CallInEditor, Category = "WeatherPreset", meta = (DisplayName = "SaveTimePreset"))
204 void B_SaveTimePreset();
205
206 // Saves everything else in the map's current weather to the "conditions"
207 // catalog under ConditionPresetName.
208 UFUNCTION(BlueprintCallable, CallInEditor, Category = "WeatherPreset", meta = (DisplayName = "SaveConditionPreset"))
209 void C_SaveConditionPreset();
210
211 // Saves this actor's current "Sky Parameters" as this map's default
212 // directly -- a full inline snapshot in MapDefaults.json, not a reference
213 // to two named Presets.json entries. Use this for a one-off hand-tuned
214 // setup that doesn't need to exist as a reusable Time/Condition preset
215 // other maps could also pick.
216 UFUNCTION(BlueprintCallable, CallInEditor, Category = "WeatherPreset", meta = (DisplayName = "SaveCurrentWeatherAsMapDefault"))
217 void D_SaveCurrentWeatherAsMapDefault();
218
219 // Saves TimePresetName/ConditionPresetName as this map's default pair in
220 // MapDefaults.json -- what ACarlaGameModeBase::BeginPlay loads for this
221 // map from now on instead of the flat carla::rpc::WeatherParameters::Default.
222 UFUNCTION(BlueprintCallable, CallInEditor, Category = "WeatherPreset", meta = (DisplayName = "SetAsMapDefault"))
223 void E_SetAsMapDefault();
224
225 // Free-text name for a brand new time preset. CreateTimePreset sets
226 // TimePresetName to this and saves -- e.g. a bespoke "Town10_dusk" you
227 // can later pick as another map's default too, same shared catalog.
228 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "WeatherPreset")
229 FString NewTimePresetName;
230
231 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "WeatherPreset")
232 FString NewConditionPresetName;
233
234 UFUNCTION(BlueprintCallable, CallInEditor, Category = "WeatherPreset", meta = (DisplayName = "CreateTimePreset"))
235 void F_CreateTimePreset();
236
237 UFUNCTION(BlueprintCallable, CallInEditor, Category = "WeatherPreset", meta = (DisplayName = "CreateConditionPreset"))
238 void G_CreateConditionPreset();
239
240 // Loads and applies this map's current default weather from
241 // MapDefaults.json -- whichever shape it's in, a named Time/Condition
242 // preset pair or a hand-tuned inline snapshot (see
243 // UWeatherJsonUtils::GetMapDefaultWeather). There was no way to get back
244 // to a map's custom default once you'd hand-edited Sky Parameters away
245 // from it, short of re-entering the values by hand; this just re-applies
246 // whatever SetAsMapDefault/SaveCurrentWeatherAsMapDefault last saved.
247 UFUNCTION(BlueprintCallable, CallInEditor, Category = "WeatherPreset", meta = (DisplayName = "LoadMapDefault"))
248 void H_LoadMapDefault();
249
250protected:
251
252 // Editing ANY property on a placed Blueprint actor in the editor Details
253 // panel reruns its Construction Script, and BP_Carla_Sky's own
254 // construction resets components like VolumetricCloudComponent's material
255 // back to their authored/instance default -- undoing whatever
256 // RefreshWeather/LoadPreset just pushed the moment you touch an unrelated
257 // field. OnConstruction runs right after every such rerun (and once at
258 // spawn/Play), so re-push "Sky Parameters" here to make that self-healing:
259 // any edit still ends with the rig showing the current weather.
260 virtual void OnConstruction(const FTransform& Transform) override;
261
262 // A level-placed rig in a World Partition cell streams in after
263 // InitGame, which then spawned a second one: two suns at the same
264 // ForwardShadingPriority, and the main directional light flipping
265 // between them frame to frame. The level-placed rig wins.
266 virtual void BeginPlay() override;
267
268#if WITH_EDITOR
269 // Applies TimePresetName/ConditionPresetName as soon as either dropdown
270 // is changed -- OnConstruction can't do this itself (it fires on every
271 // property edit with no way to tell which one changed; re-applying the
272 // selected presets on every WeatherParameters/CameraParameters edit too
273 // would stomp hand-tuning right back to the preset every keystroke).
274 // Replaces the old separate LoadPreset button.
275 virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
276#endif
277
278 // Loads TimePresetName + ConditionPresetName and applies the merged
279 // result through the map's AWeather actor (same pipeline the API/client
280 // uses), so the sky rig actually refreshes -- not just this actor's own
281 // WeatherParameters variable, which the rig only reads from when told to.
282 void ApplyTimeAndConditionPresets();
283
284 // Writes CameraParameters into PostProcessComponent->Settings (claiming
285 // each field's bOverride_*), and the reverse -- reads Settings back into
286 // CameraParameters. See FCameraParameters and LoadProfile.
287 void PushCameraParameters();
288 void SyncCameraParametersFromPostProcess();
289
290 // Re-applies this actor's own "Sky Parameters" as they currently stand,
291 // through AWeather. Internal helper -- LoadProfile calls this to
292 // re-clamp exposure right after loading; OnConstruction does the
293 // equivalent push directly. Not exposed as a button: it was redundant
294 // there (OnConstruction already runs it on every edit), replaced by the
295 // more useful LoadMapDefault.
296 void RefreshWeather();
297
298 // GetOptions callbacks need a UFUNCTION taking no world-context args;
299 // thin wrappers around the shared JSON utils lookups.
300 UFUNCTION()
301 static TArray<FString> GetAvailablePostProcessProfileNamesForPicker();
302
303 UFUNCTION()
304 static TArray<FString> GetAvailableTimePresetNamesForPicker();
305
306 UFUNCTION()
307 static TArray<FString> GetAvailableConditionPresetNamesForPicker();
308
309
310 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Components")
311 UPostProcessComponent* PostProcessComponent;
312
313 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Components")
314 UExponentialHeightFogComponent* ExponentialHeightFogComponent;
315
316 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Components")
317 UDirectionalLightComponent* DirectionalLightComponentSun;
318
319 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Components")
320 UDirectionalLightComponent* DirectionalLightComponentMoon;
321
322 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Components")
323 USkyLightComponent* SkyLightComponent;
324
325 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Components")
326 UVolumetricCloudComponent* VolumetricCloudComponent;
327
328 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Components")
329 USkyAtmosphereComponent* SkyAtmosphereComponent;
330
331
332};
USkyLightComponent * GetSkyLightComponent() const
Definition Sky.h:122
static const FName FallbackSkyTag
Definition Sky.h:118