NiagaraFluids: Add ShallowWater-WaterBody integration WIP

- Niagara system
- WaterBody context Helper

[CL 29604156 by asher zhu in ue5-main branch]
This commit is contained in:
asher zhu
2023-11-09 14:05:23 -05:00
parent f23bcc2d68
commit d0d28d705b
7 changed files with 177 additions and 8 deletions

View File

@@ -75452,6 +75452,7 @@
<File Name="Engine/Plugins/FX/NiagaraFluids/Content/Templates/Liquid/2D/Systems/Grid2D_FLIP_Pool.uasset" Hash="3b975b96f278ba746a970b71800971ecec3687a8" />
<File Name="Engine/Plugins/FX/NiagaraFluids/Content/Templates/Liquid/2D/Systems/Grid2D_FLIP_Splash.uasset" Hash="f5c0bf1525655b342d71133a3d41fc4883cc184f" />
<File Name="Engine/Plugins/FX/NiagaraFluids/Content/Templates/Liquid/2D/Systems/ShallowWater/Grid2D_SW_Drop.uasset" Hash="69f5a505b1a5808b7c93f76d7794ed696e8a1997" />
<File Name="Engine/Plugins/FX/NiagaraFluids/Content/Templates/Liquid/2D/Systems/ShallowWater/Grid2D_SW_FollowPlayer.uasset" Hash="fdd812e57d6d5658431b952d4b9f462775ff95e5" />
<File Name="Engine/Plugins/FX/NiagaraFluids/Content/Templates/Liquid/2D/Systems/ShallowWater/Grid2D_SW_ParticleCollisions.uasset" Hash="e1c301f256a76b374b468986c0f3f1bf8c2b66af" />
<File Name="Engine/Plugins/FX/NiagaraFluids/Content/Templates/Liquid/2D/Systems/ShallowWater/Grid2D_SW_Pool.uasset" Hash="85e017665ec5ff250dc0b07c8fe5e095714a49fd" />
<File Name="Engine/Plugins/FX/NiagaraFluids/Content/Templates/Liquid/3D/Emitters/Grid3D_FLIP_CoupledParticles_Emitter.uasset" Hash="b1a6777d1366d4a4c306021f2fa4f9184ff36a20" />
@@ -162822,6 +162823,7 @@
<Blob Hash="fdd4a6a6b5f1ddb6dc0ab3ab3a11157c0e8c15ff" Size="6336" PackHash="01a7ef3bb3f5235cb97b2bb0a57b8f4abd5463e5" PackOffset="1186848" />
<Blob Hash="fdd4c78c7a9ef570e3f328a37fa38b73bd518065" Size="132" PackHash="9125ddee7aa48ac70839eb3442c5945955556d58" PackOffset="858560" />
<Blob Hash="fdd7b9a960a0dcf79f458a9c81c4a9390f7d087e" Size="5601" PackHash="680ec4c85147ef48ad4442ccd01f4748284e7378" PackOffset="1999770" />
<Blob Hash="fdd812e57d6d5658431b952d4b9f462775ff95e5" Size="5000901" PackHash="87f2d9ca5f9397ef8e8d55febbf12747f88feebc" PackOffset="8" />
<Blob Hash="fdd9df3748c3168f40c165afe5f2c8d5613c4245" Size="135090" PackHash="0735b69f2de5f9e26cd971625b2d4ae0b7630b77" PackOffset="182525" />
<Blob Hash="fdda764b8416b2f9402f2f63ce96c0ecfbc16b0b" Size="10936" PackHash="8f718d56c4cba3f9fd3137667c1f6c5ac208578e" PackOffset="1418471" />
<Blob Hash="fddbb84fb362312e7c76dc317a3110cdec768fcb" Size="18072" PackHash="1e71c6756763adb28a0aae48567aa16340a9a777" PackOffset="799072" />
@@ -167470,6 +167472,7 @@
<Pack Hash="87e6f16b58c69d8e100e8e8890272e98394cc994" Size="3819898" CompressedSize="1214821" RemotePath="UnrealEngine-25357016" />
<Pack Hash="87ed2cc1b072527e158ca4da6883bd11a129d12e" Size="97426" CompressedSize="26512" RemotePath="UnrealEngine-25357016" />
<Pack Hash="87f146ad95e35fa2aedae2f465e657d5eae67da7" Size="1928330" CompressedSize="1297698" RemotePath="UnrealEngine-25357016" />
<Pack Hash="87f2d9ca5f9397ef8e8d55febbf12747f88feebc" Size="5000909" CompressedSize="544834" RemotePath="UnrealEngine-29604156" />
<Pack Hash="87f9081b839dd50b50677f943504b49c75f21983" Size="2097123" CompressedSize="683732" RemotePath="UnrealEngine-25328963" />
<Pack Hash="880faecff5215e1164ccc34d24e256fda6251452" Size="11401472" CompressedSize="1157331" RemotePath="UnrealEngine-26060622" />
<Pack Hash="88118c43d42564541832368d282cc915c76fc36b" Size="371208" CompressedSize="159649" RemotePath="UnrealEngine-25328963" />

View File

@@ -1,5 +1,5 @@
{
"FileVersion": 1,
"FileVersion": 3,
"Version": 1,
"VersionName": "1.0",
"FriendlyName": "NiagaraFluids",
@@ -20,11 +20,15 @@
"Type": "Runtime",
"LoadingPhase": "Default"
}
],
],
"Plugins": [
{
"Name": "Niagara",
"Enabled": true
}
{
"Name": "Niagara",
"Enabled": true
},
{
"Name": "Water",
"Enabled": true
}
]
}

View File

@@ -7,8 +7,18 @@ namespace UnrealBuildTool.Rules
public NiagaraFluids(ReadOnlyTargetRules Target) : base(Target)
{
PublicDependencyModuleNames.Add("Core");
PrivateDependencyModuleNames.Add("RenderCore");
PrivateDependencyModuleNames.Add("Projects");
PrivateDependencyModuleNames.AddRange(
new string[] {
"Core",
"CoreUObject",
"Engine",
"RenderCore",
"Niagara",
"Water",
"DeveloperSettings",
"Projects"
}
);
}
}
}

View File

@@ -0,0 +1,77 @@
// Copyright Epic Games, Inc. All Rights Reserved.
#include "ShallowWaterComponent.h"
#include "ShallowWaterSettings.h"
#include "NiagaraComponent.h"
#include "NiagaraFunctionLibrary.h"
#include "WaterBodyActor.h"
#include "WaterSubsystem.h"
#include "Components/SkeletalMeshComponent.h"
#include "Engine/TextureRenderTarget2D.h"
UShallowWaterComponent::UShallowWaterComponent()
{
PrimaryComponentTick.bCanEverTick = true;
SetComponentTickEnabled(true);
SetUsingAbsoluteRotation(true);
}
void UShallowWaterComponent::BeginPlay()
{
Super::BeginPlay();
GetOwner()->OnActorBeginOverlap.AddDynamic(this, &UShallowWaterComponent::OnOwnerBeginOverlap);
TArray<USkeletalMeshComponent*> SKMs;
GetOwner()->GetComponents<USkeletalMeshComponent>(SKMs);
for(USkeletalMeshComponent* SKM : SKMs)
{
SKM->ComponentTags.Add(FName("RigidMesh_ShallowWaterCollider"));
}
ShallowWaterNiagaraSimulation = UNiagaraFunctionLibrary::SpawnSystemAttached(GetDefault<UShallowWaterSettings>()->DefaultShallowWaterNiagaraSimulation.LoadSynchronous(), this, FName(""),
FVector::Zero(), FRotator::ZeroRotator, EAttachLocation::SnapToTarget, false);
ShallowWaterNiagaraSimulation->SetGpuComputeDebug(GetDefault<UShallowWaterSettings>()->bGPUComputeDebug);
}
void UShallowWaterComponent::TickComponent(float DeltaTime, ELevelTick TickType,
FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
if(CurrentWaterBody == nullptr)
{
return;
}
// #todo this query gets the closest water surface in 3D space, not a XY-plane projection as we instinctively assumed
// Could be better and could be worse
const FWaterBodyQueryResult WaterInfo = CurrentWaterBody->GetWaterBodyComponent()->QueryWaterInfoClosestToWorldLocation(
GetOwner()->GetActorLocation(), EWaterBodyQueryFlags::ComputeLocation);
const FVector WaterLocation = WaterInfo.GetWaterSurfaceLocation();
SetWorldLocation(FVector(GetOwner()->GetActorLocation().X, GetOwner()->GetActorLocation().Y, WaterLocation.Z));
}
void UShallowWaterComponent::OnRegister()
{
Super::OnRegister();
}
void UShallowWaterComponent::OnOwnerBeginOverlap(AActor* Owner, AActor* OtherActor)
{
AWaterBody* OtherWaterBody = Cast<AWaterBody>(OtherActor);
if(OtherWaterBody != nullptr && OtherWaterBody != CurrentWaterBody)
{
CurrentWaterBody = OtherWaterBody;
UpdateNiagaraVariables();
}
}
void UShallowWaterComponent::UpdateNiagaraVariables()
{
TObjectPtr<UTextureRenderTarget2D> WaterInfoTexture = CurrentWaterBody->GetWaterBodyComponent()->GetWaterZone()->
WaterInfoTexture;
ShallowWaterNiagaraSimulation->SetVariableTexture(FName("WaterInfoTexture"), Cast<UTexture>(WaterInfoTexture));
}

View File

@@ -0,0 +1,16 @@
// Copyright Epic Games, Inc. All Rights Reserved.
#include "ShallowWaterSettings.h"
UShallowWaterSettings::UShallowWaterSettings()
{
DefaultShallowWaterNiagaraSimulation = TSoftObjectPtr<UNiagaraSystem>(FSoftObjectPath(TEXT("/NiagaraFluids/Templates/Liquid/2D/Systems/ShallowWater/Grid2D_SW_FollowPlayer.Grid2D_SW_FollowPlayer")));
}
FName UShallowWaterSettings::GetCategoryName() const
{
return FName("Plugins");
}

View File

@@ -0,0 +1,35 @@
// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Components/SceneComponent.h"
#include "ShallowWaterComponent.generated.h"
class AWaterBody;
class UNiagaraComponent;
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class NIAGARAFLUIDS_API UShallowWaterComponent : public USceneComponent
{
GENERATED_BODY()
public:
UShallowWaterComponent();
virtual void BeginPlay() override;
virtual void TickComponent(float DeltaTime, ELevelTick TickType,
FActorComponentTickFunction* ThisTickFunction) override;
virtual void OnRegister() override;
protected:
// Asset can be set in Project Settings - Plugins - Water ShallowWaterSimulation
UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Category="Shallow Water")
TObjectPtr<UNiagaraComponent> ShallowWaterNiagaraSimulation;
UFUNCTION()
void OnOwnerBeginOverlap(AActor* Owner, AActor* OtherActor);
void UpdateNiagaraVariables();
AWaterBody* CurrentWaterBody = nullptr;
};

View File

@@ -0,0 +1,24 @@
// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Engine/DeveloperSettings.h"
#include "NiagaraSystem.h"
#include "ShallowWaterSettings.generated.h"
UCLASS(config = Engine, defaultconfig, meta=(DisplayName="Water Shallow Water"))
class NIAGARAFLUIDS_API UShallowWaterSettings : public UDeveloperSettings
{
GENERATED_BODY()
UShallowWaterSettings();
public:
virtual FName GetCategoryName() const override;
UPROPERTY(Config, BlueprintReadOnly, EditAnywhere, Category="Shallow Water Simulation")
TSoftObjectPtr<UNiagaraSystem> DefaultShallowWaterNiagaraSimulation;
UPROPERTY(Config, BlueprintReadOnly, EditAnywhere, Category="Shallow Water Simulation")
bool bGPUComputeDebug = false;
};