Create new volumetric fog material and disable old one, create new wetness material and tie to settings, fixes for audio, rework weather data asset, optimize lamps

This commit is contained in:
2026-10-29 23:17:55 +01:00
parent 734b80a792
commit b42a4b5dc8
236 changed files with 869 additions and 541 deletions

View File

@@ -15,35 +15,31 @@ class PROJECTELERI_API UWeatherPresetDataAsset : public UDataAsset
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "General")
UCurveFloat* IndirectGIIntensityCurve;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "General")
float CloudCoverage = 0.f;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Sky Dome")
UCurveFloat* SkyDomeIntensityCurve;
FRuntimeFloatCurve SkyDomeIntensityCurve;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Sky Dome")
UCurveLinearColor* SkyDomeTopBottomGradient;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Sky Dome")
UCurveLinearColor* SkyDomeMiddleGradient;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Sunlight")
UCurveFloat* SunRotationCurve;
FRuntimeFloatCurve SunRotationCurve;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Sunlight")
UCurveFloat* SunlightCurve;
FRuntimeFloatCurve SunlightCurve;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Moonlight")
UCurveFloat* MoonRotationCurve;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Moonlight")
UCurveFloat* MoonlightCurve;
FRuntimeFloatCurve MoonlightCurve;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "SkyLight")
UCurveFloat* SkylightCurve;
FRuntimeFloatCurve SkylightCurve;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "SkyLight")
UCurveLinearColor* SkylightColorCurve;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Fog")
UCurveFloat* FogIntensityCurve;
FRuntimeFloatCurve FogIntensityCurve;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Rain")
bool bIsRain = false;
@@ -55,10 +51,10 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Atmosphere")
FLinearColor RaylightScattering;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Atmosphere")
UCurveFloat* MieScatteringScale;
FRuntimeFloatCurve MieScatteringScale;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Clouds")
UCurveFloat* CloudsBrightnessCurve;
FRuntimeFloatCurve CloudsBrightnessCurve;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Clouds")
float CloudDensity = 0.3f;

View File

@@ -0,0 +1,198 @@
#include "RainOcclusionActor.h"
#include "Components/SceneCaptureComponent2D.h"
#include "EngineUtils.h"
#include "TimeOfDayManager.h"
#include "GameFramework/GameUserSettings.h"
#include "GameFramework/Pawn.h"
#include "Kismet/GameplayStatics.h"
#include "ProfilingDebugging/CpuProfilerTrace.h"
#include "ProfilingDebugging/MiscTrace.h"
DEFINE_LOG_CATEGORY_STATIC(LogRainOcclusion, Log, All);
static bool IsWetnessEnabled()
{
if (const UGameUserSettings* Settings = UGameUserSettings::GetGameUserSettings())
{
const int32 ShadingQuality = Settings->GetShadingQuality(); // 0 = Low
return ShadingQuality > 0;
}
return false;
}
ARainOcclusionActor::ARainOcclusionActor()
{
PrimaryActorTick.bCanEverTick = true;
PrimaryActorTick.bStartWithTickEnabled = true;
}
void ARainOcclusionActor::BeginPlay()
{
Super::BeginPlay();
// Find and cache the capture component that the Blueprint added.
TInlineComponentArray<USceneCaptureComponent2D*> Captures(this);
for (USceneCaptureComponent2D* Candidate : Captures)
{
if (CaptureComponentName.IsNone() || Candidate->GetFName() == CaptureComponentName)
{
CaptureComponent = Candidate;
break;
}
}
if (!CaptureComponent)
{
UE_LOG(LogRainOcclusion, Warning, TEXT("%s: no SceneCaptureComponent2D found, gathering disabled."), *GetName());
SetActorTickEnabled(false);
return;
}
// Without this the ShowOnly list is ignored.
CaptureComponent->PrimitiveRenderMode = ESceneCapturePrimitiveRenderMode::PRM_UseShowOnlyList;
SetActorTickInterval(DistanceCheckInterval);
// Initial gather.
GatherOccluders();
TimeOfDayManager = Cast<ATimeOfDayManager>(UGameplayStatics::GetActorOfClass(this, ATimeOfDayManager::StaticClass()));
}
void ARainOcclusionActor::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
if (/*!IsWetnessEnabled() ||*/ !CaptureComponent || !TimeOfDayManager || !TimeOfDayManager->IsRaining())
{
return;
}
FVector PlayerLocation;
if (!GetPlayerLocation(PlayerLocation))
{
return;
}
// Pawn wasn't available at BeginPlay: take its first position as the reference instead of regathering.
if (!bHasGatherLocation)
{
LastGatherLocation = PlayerLocation;
bHasGatherLocation = true;
return;
}
if (FVector::DistSquared2D(PlayerLocation, LastGatherLocation) >= FMath::Square(RegatherDistance))
{
GatherOccluders();
}
CaptureRainOcclusionMap();
}
void ARainOcclusionActor::GatherOccluders()
{
UWorld* World = GetWorld();
if (!CaptureComponent || !World)
{
return;
}
TRACE_CPUPROFILER_EVENT_SCOPE(ARainOcclusionActor::GatherOccluders);
TRACE_BOOKMARK(TEXT("RainOcclusion Gather Start"));
// 1. Collect everything that should be in the list right now.
TSet<AActor*> Found;
for (const TSubclassOf<AActor>& ActorClass : IncludedClasses)
{
if (!ActorClass.Get())
{
continue;
}
for (TActorIterator<AActor> It(World, ActorClass); It; ++It)
{
Found.Add(*It);
}
}
// One pass over the world for all tags, instead of one pass per tag.
if (IncludedTags.Num() > 0)
{
for (TActorIterator<AActor> It(World); It; ++It)
{
AActor* Actor = *It;
for (const FName& Tag : IncludedTags)
{
if (Actor->ActorHasTag(Tag))
{
Found.Add(Actor);
break;
}
}
}
}
// 2. Remove actors we track that are no longer found (unloaded, destroyed, or no longer tagged).
int32 NumRemoved = 0;
for (auto It = TrackedActors.CreateIterator(); It; ++It)
{
AActor* Actor = It->Get();
if (!Actor || !Found.Contains(Actor))
{
if (Actor)
{
CaptureComponent->RemoveShowOnlyActorComponents(Actor, bIncludeFromChildActors);
}
It.RemoveCurrent();
++NumRemoved;
}
}
// 3. Add actors that are new. Existing ones are skipped, so the expensive call runs once per actor.
int32 NumAdded = 0;
for (AActor* Actor : Found)
{
bool bAlreadyTracked = false;
TrackedActors.Add(TWeakObjectPtr<AActor>(Actor), &bAlreadyTracked);
if (!bAlreadyTracked)
{
CaptureComponent->ShowOnlyActorComponents(Actor, bIncludeFromChildActors);
++NumAdded;
}
}
// 4. Remember where we gathered.
FVector PlayerLocation;
if (GetPlayerLocation(PlayerLocation))
{
LastGatherLocation = PlayerLocation;
bHasGatherLocation = true;
}
UE_LOG(LogRainOcclusion, Verbose, TEXT("Gather: %d found, +%d, -%d"), Found.Num(), NumAdded, NumRemoved);
TRACE_BOOKMARK(TEXT("RainOcclusion Gather End (found %d, +%d, -%d)"), Found.Num(), NumAdded, NumRemoved);
}
void ARainOcclusionActor::RebuildOccluders()
{
if (!CaptureComponent)
{
return;
}
CaptureComponent->ClearShowOnlyComponents();
TrackedActors.Reset();
GatherOccluders();
}
bool ARainOcclusionActor::GetPlayerLocation(FVector& OutLocation) const
{
if (const APawn* Pawn = UGameplayStatics::GetPlayerPawn(this, 0))
{
OutLocation = Pawn->GetActorLocation();
return true;
}
return false;
}

View File

@@ -0,0 +1,80 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "RainOcclusionActor.generated.h"
class ATimeOfDayManager;
class USceneCaptureComponent2D;
/**
* Base class for the rain occlusion capture actor.
* Add the Scene Capture Component 2D in the Blueprint child as before; this class finds it,
* keeps its ShowOnly list up to date incrementally, and re-gathers when the player has moved far enough.
*/
UCLASS()
class PROJECTELERI_API ARainOcclusionActor : public AActor
{
GENERATED_BODY()
public:
ARainOcclusionActor();
/** Gathers occluders and diffs against the current ShowOnly list (adds new, removes missing). */
UFUNCTION(BlueprintCallable, Category = "Rain Occlusion")
void GatherOccluders();
/** Clears the ShowOnly list and the tracked set, then gathers from scratch. */
UFUNCTION(BlueprintCallable, Category = "Rain Occlusion")
void RebuildOccluders();
UFUNCTION(BlueprintPure, Category = "Rain Occlusion")
USceneCaptureComponent2D* GetCaptureComponent() const { return CaptureComponent; }
protected:
virtual void BeginPlay() override;
virtual void Tick(float DeltaSeconds) override;
UFUNCTION(BlueprintImplementableEvent, Category = "Rain Occlusion")
void CaptureRainOcclusionMap();
/** Optional. If empty, the first Scene Capture Component 2D found on this actor is used. */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Rain Occlusion")
FName CaptureComponentName = NAME_None;
/** Every actor of these classes is added (e.g. LandscapeProxy catches Landscape and streaming proxies). */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Rain Occlusion|Gather")
TArray<TSubclassOf<AActor>> IncludedClasses;
/** Every actor carrying any of these tags is added. */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Rain Occlusion|Gather")
TArray<FName> IncludedTags;
/** Re-gather once the player has moved this far (cm, 2D) from where the last gather ran. */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Rain Occlusion|Gather", meta = (ClampMin = "0"))
float RegatherDistance = 2000.f;
/** How often (seconds) the distance check runs. */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Rain Occlusion|Gather", meta = (ClampMin = "0"))
float DistanceCheckInterval = 0.25f;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Rain Occlusion|Gather")
bool bIncludeFromChildActors = false;
private:
bool GetPlayerLocation(FVector& OutLocation) const;
UPROPERTY(Transient)
TObjectPtr<USceneCaptureComponent2D> CaptureComponent;
UPROPERTY(Transient)
TObjectPtr<ATimeOfDayManager> TimeOfDayManager;
/** Actors whose components are currently in the capture's ShowOnly list. */
TSet<TWeakObjectPtr<AActor>> TrackedActors;
FVector LastGatherLocation = FVector::ZeroVector;
bool bHasGatherLocation = false;
};

View File

@@ -41,18 +41,10 @@ AEleriPlayerController::AEleriPlayerController(const FObjectInitializer &ObjectI
void AEleriPlayerController::BeginPlay()
{
Super::BeginPlay();
PlayerCharacter = Cast<AMyCharacter>(GetCharacter());
MoveActorsComp = PlayerCharacter->GetComponentByClass<UMoveActorsComponent>();
MainGameUI = CreateWidget<UMainGameWidget>(this, MainGameWidgetBlueprint);
MainGameUI->AddToViewport();
if (UCharacterMovementComponent *CharMovement = PlayerCharacter->GetCharacterMovement())
{
CharMovement->MaxWalkSpeed = MinMovementSpeed;
}
MovementComponent = PlayerCharacter->GetComponentByClass<UCharacterMovementComponent>();
MovementDirection = FVector2D(0, -1);
bFlying = false;
BookOfAlchemyManager = Cast<ABookOfAlchemyManager>(UGameplayStatics::GetActorOfClass(GetWorld(), ABookOfAlchemyManager::StaticClass()));
@@ -74,6 +66,16 @@ void AEleriPlayerController::EndPlay(const EEndPlayReason::Type EndPlayReason)
Super::EndPlay(EndPlayReason);
}
void AEleriPlayerController::OnPossess(APawn* InPawn)
{
Super::OnPossess(InPawn);
PlayerCharacter = Cast<AMyCharacter>(InPawn);
MoveActorsComp = PlayerCharacter->GetComponentByClass<UMoveActorsComponent>();
MovementComponent = PlayerCharacter->GetComponentByClass<UCharacterMovementComponent>();
MovementComponent->MaxWalkSpeed = MinMovementSpeed;
}
void AEleriPlayerController::ToggleMovement(bool bActive)
{
UStatForgeComponent* StatForgeComponent = UMainBlueprintFunctionLibrary::GetStatForgeComponentFromPlayer(this);
@@ -93,18 +95,16 @@ void AEleriPlayerController::ToggleMovement(bool bActive)
void AEleriPlayerController::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (ACharacter *Char = GetCharacter())
if (MovementComponent)
{
if (UCharacterMovementComponent *CharMovement = Char->GetCharacterMovement())
if (MovementComponent->IsFalling())
{
if (CharMovement->IsFalling())
{
CharMovement->GravityScale = 25;
}
else
{
CharMovement->GravityScale = 3;
}
MovementComponent->GravityScale = 25;
}
else
{
MovementComponent->GravityScale = 3;
}
}

View File

@@ -47,8 +47,6 @@ ATimeOfDayManager::ATimeOfDayManager()
exponentialHeightFogComponent->SetupAttachment(RootComponent);
skyAtmosphereComponent = CreateDefaultSubobject<USkyAtmosphereComponent>("SkyAtmosphere");
skyAtmosphereComponent->SetupAttachment(RootComponent);
VolumetricCloudComponent = CreateDefaultSubobject<UVolumetricCloudComponent>("VolumetricCloudComponent");
VolumetricCloudComponent->SetupAttachment(RootComponent);
if (!WeatherPresetDistributionMap.IsEmpty())
{
@@ -98,9 +96,6 @@ void ATimeOfDayManager::BeginPlay()
void ATimeOfDayManager::PostLoad()
{
Super::PostLoad();
VolumetricCloudMaterialInstance = UKismetMaterialLibrary::CreateDynamicMaterialInstance(this, VolumetricCloudMaterial, FName("VolMat"), EMIDCreationFlags::Transient);
VolumetricCloudComponent->SetMaterial(VolumetricCloudMaterialInstance);
}
// Called every frame
@@ -165,12 +160,11 @@ void ATimeOfDayManager::UpdateLightning()
// Update fog
if (IsValid(exponentialHeightFogComponent))
{
float CurrentFogIntensity = CurrentWeatherPreset->FogIntensityCurve->GetFloatValue(FloatMinutes);
const float CurrentFogIntensity = UMainBlueprintFunctionLibrary::GetCurveValue(CurrentWeatherPreset->FogIntensityCurve, FloatMinutes);
exponentialHeightFogComponent->FogDensity =
QueuedWeatherPreset
? FMath::Lerp(QueuedWeatherPreset->FogIntensityCurve->GetFloatValue(FloatMinutes), CurrentFogIntensity,
CurrentWeaterFadeAlpha)
: CurrentFogIntensity;
QueuedWeatherPreset ?
FMath::Lerp(UMainBlueprintFunctionLibrary::GetCurveValue(QueuedWeatherPreset->FogIntensityCurve, FloatMinutes), CurrentFogIntensity,CurrentWeaterFadeAlpha) :
CurrentFogIntensity;
exponentialHeightFogComponent->MarkRenderStateDirty();
}
@@ -178,46 +172,26 @@ void ATimeOfDayManager::UpdateLightning()
if (IsValid(skyAtmosphereComponent))
{
FLinearColor CurrentRaylightScattering = CurrentWeatherPreset->RaylightScattering;
skyAtmosphereComponent->RayleighScattering = QueuedWeatherPreset
? FLinearColor::LerpUsingHSV(
QueuedWeatherPreset->RaylightScattering,
CurrentRaylightScattering, CurrentWeaterFadeAlpha)
: CurrentRaylightScattering;
skyAtmosphereComponent->RayleighScattering = QueuedWeatherPreset ?
FLinearColor::LerpUsingHSV(QueuedWeatherPreset->RaylightScattering,CurrentRaylightScattering, CurrentWeaterFadeAlpha) :
CurrentRaylightScattering;
float CurrentMieScattering = CurrentWeatherPreset->MieScatteringScale->GetFloatValue(FloatMinutes);
skyAtmosphereComponent->MieScatteringScale = QueuedWeatherPreset
? FMath::Lerp(
QueuedWeatherPreset->MieScatteringScale->GetFloatValue(FloatMinutes), CurrentMieScattering,
CurrentWeaterFadeAlpha)
: CurrentMieScattering;
const float CurrentMieScattering = UMainBlueprintFunctionLibrary::GetCurveValue(CurrentWeatherPreset->MieScatteringScale, FloatMinutes);
skyAtmosphereComponent->MieScatteringScale = QueuedWeatherPreset ?
FMath::Lerp(UMainBlueprintFunctionLibrary::GetCurveValue(QueuedWeatherPreset->MieScatteringScale, FloatMinutes), CurrentMieScattering,CurrentWeaterFadeAlpha) :
CurrentMieScattering;
skyAtmosphereComponent->MarkRenderStateDirty();
}
//Volumetric clouds
if (IsValid(VolumetricCloudComponent) && IsValid(VolumetricCloudMaterialInstance))
{
FLinearColor OutColor;
VolumetricCloudMaterialInstance->GetVectorParameterValue(FHashedMaterialParameterInfo(FName("Cloud Detail Control")), OutColor);
constexpr float LowCoverage = 0.5f;
constexpr float HighCoverage = 0.3f;
const float Alpha = QueuedWeatherPreset?
FMath::Lerp(QueuedWeatherPreset->CloudCoverage, CurrentWeatherPreset->CloudCoverage, CurrentWeaterFadeAlpha) :
CurrentWeatherPreset->CloudCoverage;
OutColor.G = FMath::Lerp(LowCoverage, HighCoverage, Alpha);
VolumetricCloudMaterialInstance->SetVectorParameterValue(FName("Cloud Detail Control"), OutColor);
}
// Update Material Parameter Collection
if (IsValid(WindMaterialParameterCollection))
{
float CurrentWindIntensity = CurrentWeatherPreset->WindIntensity;
const float CurrentWindIntensity = CurrentWeatherPreset->WindIntensity;
UKismetMaterialLibrary::SetScalarParameterValue(GetWorld(), WindMaterialParameterCollection,
FName("Wind Intensity"),
QueuedWeatherPreset
? FMath::Lerp(
QueuedWeatherPreset->WindIntensity,
CurrentWindIntensity, CurrentWeaterFadeAlpha)
: CurrentWindIntensity);
FName("Wind Intensity"),
QueuedWeatherPreset ?
FMath::Lerp(QueuedWeatherPreset->WindIntensity,CurrentWindIntensity, CurrentWeaterFadeAlpha) :
CurrentWindIntensity);
float CurrentWindSpeed = CurrentWeatherPreset->WindSpeed;
UKismetMaterialLibrary::SetScalarParameterValue(GetWorld(), WindMaterialParameterCollection,
@@ -230,60 +204,41 @@ void ATimeOfDayManager::UpdateLightning()
// Update sky dome intensity
if (GeneralMaterialParameterCollection)
{
float CurrentSkyDomeIntensity = CurrentWeatherPreset->SkyDomeIntensityCurve->GetFloatValue(FloatMinutes);
const float CurrentSkyDomeIntensity = UMainBlueprintFunctionLibrary::GetCurveValue(CurrentWeatherPreset->SkyDomeIntensityCurve, FloatMinutes);
UKismetMaterialLibrary::SetScalarParameterValue(GetWorld(), GeneralMaterialParameterCollection,
FName("SkyBrightness"),
QueuedWeatherPreset
? FMath::Lerp(
QueuedWeatherPreset->SkyDomeIntensityCurve->GetFloatValue(FloatMinutes), CurrentSkyDomeIntensity,
CurrentWeaterFadeAlpha)
: CurrentSkyDomeIntensity * FMath::Lerp(
1.0f, 0.25f, CurrentWeaterFadeAlpha));
FName("SkyBrightness"),
QueuedWeatherPreset?
FMath::Lerp(UMainBlueprintFunctionLibrary::GetCurveValue(QueuedWeatherPreset->SkyDomeIntensityCurve, FloatMinutes), CurrentSkyDomeIntensity, CurrentWeaterFadeAlpha) :
CurrentSkyDomeIntensity * FMath::Lerp(1.0f, 0.25f, CurrentWeaterFadeAlpha));
FLinearColor CurrentSkyDomeTopBottomGradient = CurrentWeatherPreset->SkyDomeTopBottomGradient->GetLinearColorValue(FloatMinutes);
FLinearColor CurrentSkyDomeMiddleGradient = CurrentWeatherPreset->SkyDomeMiddleGradient->GetLinearColorValue(FloatMinutes);
const FLinearColor CurrentSkyDomeTopBottomGradient = CurrentWeatherPreset->SkyDomeTopBottomGradient->GetLinearColorValue(FloatMinutes);
const FLinearColor CurrentSkyDomeMiddleGradient = CurrentWeatherPreset->SkyDomeMiddleGradient->GetLinearColorValue(FloatMinutes);
UKismetMaterialLibrary::SetVectorParameterValue(GetWorld(), GeneralMaterialParameterCollection,
FName("SkyGradientTopDown"),
QueuedWeatherPreset
? FMath::Lerp(
QueuedWeatherPreset->SkyDomeTopBottomGradient->GetLinearColorValue(FloatMinutes),
CurrentSkyDomeTopBottomGradient, CurrentWeaterFadeAlpha)
: CurrentSkyDomeTopBottomGradient);
FName("SkyGradientTopDown"),
QueuedWeatherPreset ?
FMath::Lerp(QueuedWeatherPreset->SkyDomeTopBottomGradient->GetLinearColorValue(FloatMinutes),CurrentSkyDomeTopBottomGradient, CurrentWeaterFadeAlpha) :
CurrentSkyDomeTopBottomGradient);
UKismetMaterialLibrary::SetVectorParameterValue(GetWorld(), GeneralMaterialParameterCollection,
FName("SkyGradientMiddle"),
QueuedWeatherPreset
? FMath::Lerp(
QueuedWeatherPreset->SkyDomeMiddleGradient->GetLinearColorValue(FloatMinutes),
CurrentSkyDomeMiddleGradient, CurrentWeaterFadeAlpha)
: CurrentSkyDomeMiddleGradient);
FName("SkyGradientMiddle"),
QueuedWeatherPreset ?
FMath::Lerp(QueuedWeatherPreset->SkyDomeMiddleGradient->GetLinearColorValue(FloatMinutes),CurrentSkyDomeMiddleGradient, CurrentWeaterFadeAlpha) :
CurrentSkyDomeMiddleGradient);
UKismetMaterialLibrary::SetScalarParameterValue(GetWorld(), GeneralMaterialParameterCollection,
FName("Cloud Coverage"),
QueuedWeatherPreset
? FMath::Lerp(
QueuedWeatherPreset->CloudCoverage,
CurrentWeatherPreset->CloudCoverage,
CurrentWeaterFadeAlpha)
: CurrentWeatherPreset->CloudCoverage);
// float DayAmount = 0.5f * (1 + FMath::Sin((PI * FloatMinutes) / 720.f - (PI/2.f)));
// DayAmount *= QueuedWeatherPreset ?
// FMath::Lerp(QueuedWeatherPreset->CloudsBrightnessCurve->GetFloatValue(FloatMinutes), CurrentWeatherPreset->CloudsBrightnessCurve->GetFloatValue(FloatMinutes), CurrentWeaterFadeAlpha)
// : CurrentWeatherPreset->CloudsBrightnessCurve->GetFloatValue(FloatMinutes);
// UKismetMaterialLibrary::SetScalarParameterValue(GetWorld(), GeneralMaterialParameterCollection, FName("Day Amount"), DayAmount);
FName("Cloud Coverage"),
QueuedWeatherPreset ?
FMath::Lerp(QueuedWeatherPreset->CloudCoverage,CurrentWeatherPreset->CloudCoverage,CurrentWeaterFadeAlpha) :
CurrentWeatherPreset->CloudCoverage);
}
// Update wetness
if (IsValid(GeneralMaterialParameterCollection))
{
UKismetMaterialLibrary::SetScalarParameterValue(GetWorld(), GeneralMaterialParameterCollection,
FName("Wetness"),
QueuedWeatherPreset
? FMath::Lerp(
static_cast<float>(QueuedWeatherPreset->bIsRain),
static_cast<float>(CurrentWeatherPreset->bIsRain),
CurrentWeaterFadeAlpha)
: static_cast<float>(CurrentWeatherPreset->bIsRain));
FName("Wetness"),
QueuedWeatherPreset ?
FMath::Lerp(static_cast<float>(QueuedWeatherPreset->bIsRain),static_cast<float>(CurrentWeatherPreset->bIsRain),CurrentWeaterFadeAlpha) :
static_cast<float>(CurrentWeatherPreset->bIsRain));
}
//Set clouds
@@ -309,11 +264,11 @@ void ATimeOfDayManager::RotateSun(const float &_rotator)
{
if (!enableTimeOfDay)
return;
if (!CurrentWeatherPreset || !CurrentWeatherPreset->SunRotationCurve)
if (!CurrentWeatherPreset)
return;
if (sunLight->IsValidLowLevel())
{
FVector currentRotInVectors = FVector(0.0f, CurrentWeatherPreset->SunRotationCurve->GetFloatValue(FloatMinutes),
FVector currentRotInVectors = FVector(0.0f, UMainBlueprintFunctionLibrary::GetCurveValue(CurrentWeatherPreset->SunRotationCurve, FloatMinutes),
110.0f);
FRotator currentSunRotation = FRotator(FRotator::MakeFromEuler(currentRotInVectors));
@@ -338,37 +293,25 @@ void ATimeOfDayManager::SetDirectionalLightIntensity(const float &_rotator)
{
if (!enableTimeOfDay)
return;
if (!CurrentWeatherPreset->SunlightCurve)
return;
float SunlightIntensity = CurrentWeatherPreset->SunlightCurve->GetFloatValue(FloatMinutes);
CurrentSunlightIntensity = QueuedWeatherPreset
? FMath::Lerp(QueuedWeatherPreset->SunlightCurve->GetFloatValue(FloatMinutes),
SunlightIntensity, CurrentWeaterFadeAlpha)
: SunlightIntensity;
float MoonlightIntensity = CurrentWeatherPreset->MoonlightCurve->GetFloatValue(FloatMinutes);
CurrentMoonlightIntensity = QueuedWeatherPreset
? FMath::Lerp(QueuedWeatherPreset->MoonlightCurve->GetFloatValue(FloatMinutes),
MoonlightIntensity, CurrentWeaterFadeAlpha)
: MoonlightIntensity;
const float SunlightIntensity = UMainBlueprintFunctionLibrary::GetCurveValue(CurrentWeatherPreset->SunlightCurve, FloatMinutes);
CurrentSunlightIntensity = QueuedWeatherPreset ?
FMath::Lerp(UMainBlueprintFunctionLibrary::GetCurveValue(QueuedWeatherPreset->SunlightCurve, FloatMinutes),SunlightIntensity, CurrentWeaterFadeAlpha)
: SunlightIntensity;
const float MoonlightIntensity = UMainBlueprintFunctionLibrary::GetCurveValue(CurrentWeatherPreset->MoonlightCurve, FloatMinutes);
CurrentMoonlightIntensity = QueuedWeatherPreset ?
FMath::Lerp(UMainBlueprintFunctionLibrary::GetCurveValue(QueuedWeatherPreset->MoonlightCurve, FloatMinutes),MoonlightIntensity, CurrentWeaterFadeAlpha)
: MoonlightIntensity;
sunLight->SetIntensity(CurrentSunlightIntensity);
moonLight->SetIntensity(CurrentMoonlightIntensity);
FPostProcessSettings Settings = MainPP->Settings;
float CurrentGiIntensity = CurrentWeatherPreset->IndirectGIIntensityCurve->GetFloatValue(FloatMinutes);
Settings.IndirectLightingIntensity = QueuedWeatherPreset
? FMath::Lerp(
QueuedWeatherPreset->IndirectGIIntensityCurve->GetFloatValue(FloatMinutes), CurrentGiIntensity,
CurrentWeaterFadeAlpha)
: CurrentGiIntensity;
MainPP->Settings = Settings;
bool bSunEnabled = CurrentSunlightIntensity > 0.001f;
const bool bSunEnabled = CurrentSunlightIntensity > 0.001f;
sunLight->SetVisibility(bSunEnabled);
sunLight->SetCastShadows(bSunEnabled);
bool bMoonEnabled = CurrentMoonlightIntensity > 0.001f;
const bool bMoonEnabled = CurrentMoonlightIntensity > 0.001f;
moonLight->SetVisibility(bMoonEnabled);
moonLight->SetCastShadows(bMoonEnabled);
}
@@ -377,22 +320,17 @@ void ATimeOfDayManager::SetSkylightIntensity(const float &_rotator)
{
if (!enableTimeOfDay)
return;
if (!CurrentWeatherPreset->SkylightCurve)
return;
float SkylightIntensity = CurrentWeatherPreset->SkylightCurve->GetFloatValue(FloatMinutes);
CurrentSkylightIntensity = QueuedWeatherPreset
? FMath::Lerp(QueuedWeatherPreset->SkylightCurve->GetFloatValue(FloatMinutes),
SkylightIntensity, CurrentWeaterFadeAlpha)
: SkylightIntensity;
const float SkylightIntensity = UMainBlueprintFunctionLibrary::GetCurveValue(CurrentWeatherPreset->SkylightCurve, FloatMinutes);
CurrentSkylightIntensity = QueuedWeatherPreset?
FMath::Lerp(UMainBlueprintFunctionLibrary::GetCurveValue(QueuedWeatherPreset->SkylightCurve, FloatMinutes),SkylightIntensity, CurrentWeaterFadeAlpha) :
SkylightIntensity;
skyLight->SetIntensity(CurrentSkylightIntensity);
FLinearColor CurrentEvaluatedColor = CurrentWeatherPreset->SkylightColorCurve->GetClampedLinearColorValue(FloatMinutes);
skyLight->SetLightColor(QueuedWeatherPreset
? FMath::Lerp(
QueuedWeatherPreset->SkylightColorCurve->GetClampedLinearColorValue(FloatMinutes),
CurrentEvaluatedColor, CurrentWeaterFadeAlpha)
: CurrentEvaluatedColor);
const FLinearColor CurrentEvaluatedColor = CurrentWeatherPreset->SkylightColorCurve->GetClampedLinearColorValue(FloatMinutes);
skyLight->SetLightColor(QueuedWeatherPreset ?
FMath::Lerp(QueuedWeatherPreset->SkylightColorCurve->GetClampedLinearColorValue(FloatMinutes),CurrentEvaluatedColor, CurrentWeaterFadeAlpha) :
CurrentEvaluatedColor);
}
void ATimeOfDayManager::CheckLateHours()

View File

@@ -109,6 +109,7 @@ public:
protected:
virtual void BeginPlay() override;
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
virtual void OnPossess(APawn* InPawn) override;
public:

View File

@@ -402,12 +402,8 @@ protected:
UExponentialHeightFogComponent* exponentialHeightFogComponent;
UPROPERTY(EditDefaultsOnly)
USkyAtmosphereComponent* skyAtmosphereComponent;
UPROPERTY(EditDefaultsOnly)
UVolumetricCloudComponent* VolumetricCloudComponent;
UPROPERTY()
TMap<UWeatherPresetDataAsset *, float> WeatherPresetDistributionMap;
UPROPERTY()
UMaterialInstanceDynamic* VolumetricCloudMaterialInstance;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
UInteractionWidgetComponent* WidgetComponent;

View File

@@ -90,4 +90,7 @@ public:
UFUNCTION(BlueprintPure, Category = "Eleri|Math")
static float NegateFloat(const float& Value) { return Value * -1.f; }
// NON BP
static float GetCurveValue(const FRuntimeFloatCurve& Curve, float InTime);
};

View File

@@ -216,3 +216,13 @@ void UMainBlueprintFunctionLibrary::ModifyExp(const UObject* WorldContext, const
StatForgeComponent->ApplyGameplayStatEffect(ExpIncreaseEffect, DataValueMap);
}
float UMainBlueprintFunctionLibrary::GetCurveValue(const FRuntimeFloatCurve& Curve, const float InTime)
{
if (const FRichCurve* RichCurve = Curve.GetRichCurveConst())
{
return RichCurve->Eval(InTime);
}
return 0.f;
}