Skip to content

Commit

Permalink
Merge branch 'preview' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoPKFX committed Apr 1, 2022
2 parents 4099175 + 5fd8efc commit 4c3c03c
Show file tree
Hide file tree
Showing 25 changed files with 216 additions and 123 deletions.
2 changes: 1 addition & 1 deletion Download_SDK_Desktop.bat
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ setlocal

bitsadmin /reset
bitsadmin /create third_party_download_desktop
bitsadmin /addfile third_party_download_desktop https://downloads.popcornfx.com/Plugins/UE4/UnrealEngine_PopcornFXPlugin_2.11.3_Win64_Linux64_Mac64.7z "%~dp0\_PopcornFX_Runtime_SDK_Desktop.7z"
bitsadmin /addfile third_party_download_desktop https://downloads.popcornfx.com/Plugins/UE4/UnrealEngine_PopcornFXPlugin_2.12.0_Win64_Linux64_Mac64.7z "%~dp0\_PopcornFX_Runtime_SDK_Desktop.7z"
bitsadmin /setpriority third_party_download_desktop "FOREGROUND"
bitsadmin /resume third_party_download_desktop

Expand Down
2 changes: 1 addition & 1 deletion Download_SDK_Mobile.bat
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ setlocal

bitsadmin /reset
bitsadmin /create third_party_download_mobile
bitsadmin /addfile third_party_download_mobile https://downloads.popcornfx.com/Plugins/UE4/UnrealEngine_PopcornFXPlugin_2.11.3_iOS_Android.7z "%~dp0\_PopcornFX_Runtime_SDK_Mobile.7z"
bitsadmin /addfile third_party_download_mobile https://downloads.popcornfx.com/Plugins/UE4/UnrealEngine_PopcornFXPlugin_2.12.0_iOS_Android.7z "%~dp0\_PopcornFX_Runtime_SDK_Mobile.7z"
bitsadmin /setpriority third_party_download_mobile "FOREGROUND"
bitsadmin /resume third_party_download_mobile

Expand Down
4 changes: 2 additions & 2 deletions PopcornFX.uplugin
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"FileVersion": 3,
"Version": 21103,
"VersionName": "2.11.3",
"Version": 21200,
"VersionName": "2.12.0",
"FriendlyName": "PopcornFX",
"Description": "PopcornFX Realtime Particle Solution integration into Unreal Engine",
"Category": "PopcornFX",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Unreal Engine PopcornFX Plugin

Integrates the **PopcornFX Runtime SDK** into **Unreal Engine 4** and **Unreal Engine 5** as a Plugin.
* **Version:** `v2.11.3`
* **Version:** `v2.12.0`
* **Unreal Engine:** `4.26` to `4.27` and `5.0`
* **Supported platforms:** `Windows`, `MacOS`, `Linux`, `iOS`, `Android`, `PS4`, `PS5`, `XboxOne`, `Xbox Series`, `Switch`

Expand Down
68 changes: 35 additions & 33 deletions Source/PopcornFX/Private/Assets/PopcornFXEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <pk_base_object/include/hbo_details.h>

#if WITH_EDITOR
# include "Materials/MaterialInstanceConstant.h"
# include "HardwareInfo.h"
# include "Misc/FeedbackContext.h"
# include "Misc/FileHelper.h"
Expand Down Expand Up @@ -115,6 +116,7 @@ UPopcornFXEffect::UPopcornFXEffect(const FObjectInitializer& PCIP)
, EditorLoopDelay(2.0f)
#endif // WITH_EDITORONLY_DATA
, m_Loaded(false)
, m_Cooked(false) // TMP: Until proper implementation of platform cached data
{
m_Private = PK_NEW(CPopcornFXEffect(this));
DefaultAttributeList = CreateDefaultSubobject<UPopcornFXAttributeList>(TEXT("DefaultAttributeList"));
Expand Down Expand Up @@ -173,50 +175,50 @@ void UPopcornFXEffect::GetAssetRegistryTags(TArray<FAssetRegistryTag> &outTags)

//----------------------------------------------------------------------------

#endif // WITH_EDITOR
//----------------------------------------------------------------------------

void UPopcornFXEffect::Serialize(FArchive& Ar)
void UPopcornFXEffect::BeginCacheForCookedPlatformData(const ITargetPlatform *targetPlatform)
{
Super::Serialize(Ar);
if (IsTemplate() || IsGarbageCollecting() || GIsSavingPackage)
return;
if (m_Cooked) // TMP: Until proper implementation of platform cached data
return;

#if WITH_EDITOR
if (Ar.IsCooking() && !IsTemplate())
const FString path = GetPathName();
if (!path.IsEmpty())
{
if (!IsGarbageCollecting() && !GIsSavingPackage)
{
const FString path = GetPathName();
if (!path.IsEmpty())
{
// Rebake self for target platform
// Rebake self for target platform

// For debugging purposes only, helps inspect content of baked effects
if (FPopcornFXPlugin::Get().SettingsEditor()->bDebugBakedEffects)
{
const FString kPopcornCookedPath = TEXT("Saved/PopcornFX/Cooked/");
const FString cookedFilePath = FPaths::ConvertRelativePathToFull(FPaths::ProjectDir() / kPopcornCookedPath / FileSourceVirtualPath + "_Pre");
// For debugging purposes only, helps inspect content of baked effects
if (FPopcornFXPlugin::Get().SettingsEditor()->bDebugBakedEffects)
{
const FString kPopcornCookedPath = TEXT("Saved/PopcornFX/Cooked/");
const FString cookedFilePath = FPaths::ConvertRelativePathToFull(FPaths::ProjectDir() / kPopcornCookedPath / FileSourceVirtualPath + "_Pre");

FFileHelper::SaveArrayToFile(m_FileData, *cookedFilePath);
}
FFileHelper::SaveArrayToFile(m_FileData, *cookedFilePath);
}

FString bakedFilePath;
const ITargetPlatform* targetPlatform = Ar.CookingTarget();
if (_BakeFile(path, bakedFilePath, false, TCHAR_TO_ANSI(*targetPlatform->PlatformName())))
{
// For debugging purposes only, helps inspect content of baked effects
if (FPopcornFXPlugin::Get().SettingsEditor()->bDebugBakedEffects)
{
const FString kPopcornCookedPath = TEXT("Saved/PopcornFX/Cooked/");
const FString cookedFilePath = FPaths::ConvertRelativePathToFull(FPaths::ProjectDir() / kPopcornCookedPath / FileSourceVirtualPath);
FString bakedFilePath;
if (_BakeFile(path, bakedFilePath, false, TCHAR_TO_ANSI(*targetPlatform->PlatformName())))
{
// For debugging purposes only, helps inspect content of baked effects
if (FPopcornFXPlugin::Get().SettingsEditor()->bDebugBakedEffects)
{
const FString kPopcornCookedPath = TEXT("Saved/PopcornFX/Cooked/");
const FString cookedFilePath = FPaths::ConvertRelativePathToFull(FPaths::ProjectDir() / kPopcornCookedPath / FileSourceVirtualPath);

FFileHelper::SaveArrayToFile(m_FileData, *cookedFilePath);
}
}
FFileHelper::SaveArrayToFile(m_FileData, *cookedFilePath);
}

// Make sure to re-create serialized renderer materials, if necessary:
// Effect re-baked for a different platform can end up with different renderers, materials, textures..
ReloadRendererMaterials();

m_Cooked = true; // TMP: Until proper implementation of platform cached data
}
}
#endif

Super::BeginCacheForCookedPlatformData(targetPlatform);
}
#endif // WITH_EDITOR

//----------------------------------------------------------------------------

Expand Down
25 changes: 1 addition & 24 deletions Source/PopcornFX/Private/Assets/PopcornFXRendererMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1371,15 +1371,9 @@ bool UPopcornFXRendererMaterial::_ReloadInstance(uint32 subMatId)
FMaterialUpdateContext materialUpdateContext;

UMaterialInstanceConstant *newInstance = NewObject<UMaterialInstanceConstant>(this);
newInstance->SetFlags(RF_NeedPostLoad | RF_NeedPostLoadSubobjects | RF_Public);

newInstance->SetFlags(RF_Public);
newInstance->SetParentEditorOnly(subMat.Material);

// UE4.25: crashes in UMaterialInstance::CacheShadersForResources
// check(!HasAnyFlags(RF_NeedPostLoad));
// during UpdateStaticPermutation if mat instance is not loaded
newInstance->ConditionalPostLoad();

kRendererMaterialFuncs[subMat.m_RMId].m_ParamsConstFunc(this, newInstance, subMatId);

subMat.MaterialInstance = newInstance;
Expand Down Expand Up @@ -1409,23 +1403,6 @@ void UPopcornFXRendererMaterial::RenameDependenciesIFN(UObject* oldAsset, UObjec

//----------------------------------------------------------------------------

UMaterialInstanceDynamic *UPopcornFXRendererMaterial::CreateInstance(uint32 subMatId)
{
if (!PK_VERIFY(subMatId < uint32(SubMaterials.Num())))
return null;

UMaterialInstanceDynamic *material = UMaterialInstanceDynamic::Create(SubMaterials[subMatId].MaterialInstance, this);
if (material != null)
material->CopyParameterOverrides(SubMaterials[subMatId].MaterialInstance);
else
{
UE_LOG(LogPopcornFXRendererMaterial, Warning, TEXT("Couldn't create decal dynamic material instance"));
}
return material;
}

//----------------------------------------------------------------------------

//UMaterialInstanceDynamic *UPopcornFXRendererMaterial::GetInstance(uint32 subMatId, bool forRenderThread)
UMaterialInstanceConstant *UPopcornFXRendererMaterial::GetInstance(uint32 subMatId, bool forRenderThread) const
{
Expand Down
65 changes: 45 additions & 20 deletions Source/PopcornFX/Private/Attributes/PopcornFXAttributeSamplers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
#include <pk_particles/include/ps_font_metrics.h>

#if (PK_GPU_D3D12 != 0)
#include "Windows/HideWindowsPlatformTypes.h"
# include <pk_particles/include/Samplers/D3D12/rectangle_list_gpu_d3d12.h>
# include "Windows/HideWindowsPlatformTypes.h"
# include "D3D12RHIPrivate.h"
# include "D3D12Util.h"
#endif // (PK_GPU_D3D12 != 0)
Expand Down Expand Up @@ -1993,13 +1994,11 @@ struct FAttributeSamplerImageData
PopcornFX::PParticleSamplerDescriptor_Image_Default m_Desc;
PopcornFX::CImageSampler *m_ImageSampler = null;
PopcornFX::TResourcePtr<PopcornFX::CImage> m_TextureResource;
#if 0//(PK_GPU_D3D11 != 0)
PopcornFX::TResourcePtr<PopcornFX::CImageGPU_D3D11> m_TextureResource_D3D11;
#endif // (PK_GPU_D3D11 != 0)
PopcornFX::TResourcePtr<PopcornFX::CRectangleList> m_TextureAtlasResource;
#if (PK_GPU_D3D12 != 0)
PopcornFX::TResourcePtr<PopcornFX::CImageGPU_D3D12> m_TextureResource_D3D12;
PopcornFX::TResourcePtr<PopcornFX::CRectangleListGPU_D3D12> m_TextureAtlasResource_D3D12;
#endif // (PK_GPU_D3D12 != 0)
PopcornFX::TResourcePtr<PopcornFX::CRectangleList> m_TextureAtlasResource;
PopcornFX::SDensitySamplerData * m_DensityData = null;

bool m_ReloadTexture = true;
Expand All @@ -2010,11 +2009,9 @@ struct FAttributeSamplerImageData
{
m_Desc = null;
m_TextureResource.Clear();
#if 0//(PK_GPU_D3D11 != 0)
m_TextureResource_D3D11.Clear();
#endif // (PK_GPU_D3D11 != 0)
#if (PK_GPU_D3D12 != 0)
m_TextureResource_D3D12.Clear();
m_TextureAtlasResource_D3D12.Clear();
#endif // (PK_GPU_D3D12 != 0)
m_TextureAtlasResource.Clear();
if (m_DensityData != null)
Expand Down Expand Up @@ -2189,13 +2186,6 @@ bool UPopcornFXAttributeSamplerImage::_RebuildImageSampler()
// Try loading the image with GPU sim resource handlers:
// There is no way currently to know if the current sampler descriptor will be used by the CPU or GPU sim, so we'll have to load both, if possible
// GPU sim image load is trivial: it will just grab the ref to the native resource
#if 0//(PK_GPU_D3D11 != 0)
if (g_PopcornFXRHIAPI == SUERenderContext::D3D11)
{
m_Data->m_TextureResource_D3D11 = PopcornFX::Resource::DefaultManager()->Load<PopcornFX::CImageGPU_D3D11>(fullPath, true);
success |= (m_Data->m_TextureResource_D3D11 != null && !m_Data->m_TextureResource_D3D11->Empty());
}
#endif // (PK_GPU_D3D11 != 0)
#if (PK_GPU_D3D12 != 0)
if (g_PopcornFXRHIAPI == SUERenderContext::D3D12)
{
Expand All @@ -2211,12 +2201,34 @@ bool UPopcornFXAttributeSamplerImage::_RebuildImageSampler()
}
m_Data->m_ReloadTexture = false;
}
if (m_Data->m_ReloadTextureAtlas && TextureAtlas != null)
const bool reloadImageAtlas = m_Data->m_ReloadTextureAtlas;
if (reloadImageAtlas)
{
if (TextureAtlas != null)
{
bool success = false;
const PopcornFX::CString fullPath = TCHAR_TO_ANSI(*TextureAtlas->GetPathName());
m_Data->m_TextureAtlasResource = PopcornFX::Resource::DefaultManager()->Load<PopcornFX::CRectangleList>(fullPath, true);
if (m_Data->m_TextureAtlasResource == null || m_Data->m_TextureAtlasResource->Empty())
success |= (m_Data->m_TextureAtlasResource != null && !m_Data->m_TextureAtlasResource->Empty());

// Try loading the image atlas with GPU sim resource handlers:
// There is no way currently to know if the current sampler descriptor will be used by the CPU or GPU sim, so we'll have to load both, if possible
#if (PK_GPU_D3D12 != 0)
if (g_PopcornFXRHIAPI == SUERenderContext::D3D12)
{
m_Data->m_TextureAtlasResource_D3D12 = PopcornFX::Resource::DefaultManager()->Load<PopcornFX::CRectangleListGPU_D3D12>(fullPath, true);
success |= (m_Data->m_TextureAtlasResource_D3D12 != null && !m_Data->m_TextureAtlasResource_D3D12->Empty());
}
#endif // (PK_GPU_D3D12 != 0)

if (!success) // Couldn't load any of the resources (CPU/GPU)
{
UE_LOG(LogPopcornFXAttributeSampler, Warning, TEXT("AttrSamplerImage: couldn't load texture atlas '%s' for CPU/GPU sim sampling"), fullPath.Data());
return false;
}
}
else
m_Data->m_TextureAtlasResource.Clear();

m_Data->m_ReloadTextureAtlas = false;
}
Expand All @@ -2228,18 +2240,31 @@ bool UPopcornFXAttributeSamplerImage::_RebuildImageSampler()
}

#if (PK_GPU_D3D12 != 0)
if (rebuildImage) // We only want to reload bindings when m_Data->m_ReloadTexture is true (or if m_Data->m_ReloadTextureAtlas is true)
if (rebuildImage || reloadImageAtlas) // We only want to reload bindings when m_Data->m_ReloadTexture is true (or if m_Data->m_ReloadTextureAtlas is true)
{
if (m_Data->m_TextureResource_D3D12 != null)
if (m_Data->m_TextureResource_D3D12 != null && !m_Data->m_TextureResource_D3D12->Empty()) // Don't bind the atlas by itself, clear everything if the texture is invalid
{
ID3D12Resource *imageResource = m_Data->m_TextureResource_D3D12->Texture();

ID3D12Resource *imageAtlasResource = null;
u32 atlasRectCount = 0;
if (m_Data->m_TextureAtlasResource != null)
{
if (m_Data->m_TextureAtlasResource_D3D12 != null && !m_Data->m_TextureAtlasResource_D3D12->Empty())
{
imageAtlasResource = m_Data->m_TextureAtlasResource_D3D12->Buffer();
atlasRectCount = m_Data->m_TextureAtlasResource->AtlasRectCount();
}
}
const bool sRGB = PopcornFX::CImage::IsFormatGammaCorrected(m_Data->m_TextureResource_D3D12->StorageFormat());

PK_ASSERT(imageResource != null);

m_Data->m_Desc->SetupD3D12Resources(imageResource,
m_Data->m_TextureResource_D3D12->Dimensions(),
FindShaderResourceDXGIFormat(imageResource->GetDesc().Format, sRGB));
FindShaderResourceDXGIFormat(imageResource->GetDesc().Format, sRGB),
imageAtlasResource,
atlasRectCount);
}
else
m_Data->m_Desc->ClearD3D12Resources();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ FPopcornFXDependencyModule::FPopcornFXDependencyModule()
FPopcornFXDependencyModule::~FPopcornFXDependencyModule()
{
PK_ASSERT(!Loaded());
// Unload(); // vtable if fucked up here, cannot call the virtual function
// Unload(); // vtable destroyed here, don't call Unload()
}

//----------------------------------------------------------------------------
3 changes: 3 additions & 0 deletions Source/PopcornFX/Private/EmptyPCH.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
//--------------------------------------------------------------------------------------------------------
// Copyright Persistant Studios, SARL. All Rights Reserved. https://www.popcornfx.com/terms-and-conditions/
//--------------------------------------------------------------------------------------------------------

//#include "CoreMinimal.h"
Loading

0 comments on commit 4c3c03c

Please sign in to comment.