Fixed issues when combining weather-related postprocess materials with non-rgb sensors.

This commit is contained in:
MarcelPiNacy 2022-07-18 13:03:07 +02:00 committed by bernat
parent 93dddd0cd3
commit 910450ee71
4 changed files with 63 additions and 6 deletions

View File

@ -498,7 +498,7 @@ void ASceneCaptureSensor::BeginPlay()
// This ensures the camera is always spawning the raindrops in case the
// weather was previously set to have rain.
GetEpisode().GetWeather()->NotifyWeather();
GetEpisode().GetWeather()->NotifyWeather(this);
Super::BeginPlay();
}

View File

@ -133,6 +133,7 @@ FActorSpawnResult ASensorFactory::SpawnActor(
{
auto *Episode = GameInstance->GetCarlaEpisode();
check(Episode != nullptr);
Sensor->SetEpisode(*Episode);
Sensor->Set(Description);
Sensor->SetDataStream(GameInstance->GetServer().OpenStream());

View File

@ -6,10 +6,20 @@
#include "Carla.h"
#include "Carla/Weather/Weather.h"
#include "carla/Sensor/SceneCaptureCamera.h"
#include "Components/SceneCaptureComponent2D.h"
#include "Kismet/GameplayStatics.h"
#include "ConstructorHelpers.h"
AWeather::AWeather(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
PrecipitationPostProcessMaterial = ConstructorHelpers::FObjectFinder<UMaterial>(
TEXT("Material'/Game/Carla/Static/GenericMaterials/00_MastersOpt/Screen_posProcess/M_screenDrops.M_screenDrops'")).Object;
DustStormPostProcessMaterial = ConstructorHelpers::FObjectFinder<UMaterial>(
TEXT("Material'/Game/Carla/Static/GenericMaterials/00_MastersOpt/Screen_posProcess/M_screenDust_wind.M_screenDust_wind'")).Object;
PrimaryActorTick.bCanEverTick = false;
RootComponent = ObjectInitializer.CreateDefaultSubobject<USceneComponent>(this, TEXT("RootComponent"));
}
@ -18,6 +28,31 @@ void AWeather::ApplyWeather(const FWeatherParameters &InWeather)
{
SetWeather(InWeather);
if (Weather.Precipitation > 0.0f)
ActiveBlendables.Add(MakeTuple(PrecipitationPostProcessMaterial, Weather.Precipitation / 100.0f));
else
ActiveBlendables.Remove(PrecipitationPostProcessMaterial);
if (Weather.DustStorm > 0.0f)
ActiveBlendables.Add(MakeTuple(DustStormPostProcessMaterial, Weather.DustStorm / 100.0f));
else
ActiveBlendables.Remove(DustStormPostProcessMaterial);
for (int32 i = 0; i < Sensors.Num(); i++)
{
auto& Sensor = Sensors[i];
if (!IsValid(Sensor))
{
Sensors.RemoveAtSwap(i);
if (i == Sensors.Num())
break;
}
for (auto& ActiveBlendable : ActiveBlendables)
Sensor->GetCaptureComponent2D()->PostProcessSettings.AddBlendable(ActiveBlendable.Key, ActiveBlendable.Value);
}
#ifdef CARLA_WEATHER_EXTRA_LOG
UE_LOG(LogCarla, Log, TEXT("Changing weather:"));
UE_LOG(LogCarla, Log, TEXT(" - Cloudiness = %.2f"), Weather.Cloudiness);
@ -33,16 +68,23 @@ void AWeather::ApplyWeather(const FWeatherParameters &InWeather)
UE_LOG(LogCarla, Log, TEXT(" - ScatteringIntensity = %.2f"), Weather.ScatteringIntensity);
UE_LOG(LogCarla, Log, TEXT(" - MieScatteringScale = %.2f"), Weather.MieScatteringScale);
UE_LOG(LogCarla, Log, TEXT(" - RayleighScatteringScale = %.2f"), Weather.RayleighScatteringScale);
UE_LOG(LogCarla, Log, TEXT(" - DustStorm = %.2f"), Weather.DustStorm);
#endif // CARLA_WEATHER_EXTRA_LOG
// Call the blueprint that actually changes the weather.
RefreshWeather(Weather);
}
void AWeather::NotifyWeather()
void AWeather::NotifyWeather(ASensor* Sensor)
{
// Call the blueprint that actually changes the weather.
RefreshWeather(Weather);
#if 1
auto AsSceneCaptureCamera = Cast<ASceneCaptureCamera>(Sensor);
if (AsSceneCaptureCamera != nullptr)
Sensors.Add(AsSceneCaptureCamera);
#endif
// Call the blueprint that actually changes the weather.
RefreshWeather(Weather);
}
void AWeather::SetWeather(const FWeatherParameters &InWeather)

View File

@ -7,11 +7,13 @@
#pragma once
#include "GameFramework/Actor.h"
#include "Carla/Weather/WeatherParameters.h"
#include "Weather.generated.h"
class ASensor;
class ASceneCaptureCamera;
UCLASS(Abstract)
class CARLA_API AWeather : public AActor
{
@ -26,7 +28,7 @@ public:
void ApplyWeather(const FWeatherParameters &WeatherParameters);
/// Notifing the weather to the blueprint's event
void NotifyWeather();
void NotifyWeather(ASensor* Sensor = nullptr);
/// Update the weather parameters without notifing it to the blueprint's event
UFUNCTION(BlueprintCallable)
@ -59,6 +61,18 @@ private:
UPROPERTY(VisibleAnywhere)
FWeatherParameters Weather;
UPROPERTY(VisibleAnywhere)
UMaterial* PrecipitationPostProcessMaterial;
UPROPERTY(VisibleAnywhere)
UMaterial* DustStormPostProcessMaterial;
UPROPERTY(VisibleAnywhere)
TMap<UMaterial*, float> ActiveBlendables;
UPROPERTY(VisibleAnywhere)
TArray<ASceneCaptureCamera*> Sensors;
UPROPERTY(EditAnywhere, Category = "Weather")
bool DayNightCycle = true;
};