Skip to content

Commit

Permalink
Merge branch 'v2.15-LTS' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
PopcornFX Bot committed Jan 12, 2024
2 parents 165746b + 7a64138 commit db4f00a
Show file tree
Hide file tree
Showing 51 changed files with 674 additions and 611 deletions.
12 changes: 12 additions & 0 deletions Native/ManagedToNative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,18 @@ extern "C"

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

MANAGED_TO_POPCORN_CONVENTION int GetStackLogNumber()
{
if (!CRuntimeManager::IsInstanceInitialized())
return 0;

CUnityLog *logger = CRuntimeManager::Instance().GetLogger();

return (int)logger->Count();
}

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

MANAGED_TO_POPCORN_CONVENTION int UnstackLog(char *dstBuffer, int dstSize, int &logSeverity)
{
// DO NOT LOG ANYTHING IN THIS FUNCTION! INFINITE LOOP...
Expand Down
2 changes: 2 additions & 0 deletions Native/ManagedToNative.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ extern "C"
MANAGED_TO_POPCORN_CONVENTION void PopcornFXShutdown();
//Log
MANAGED_TO_POPCORN_CONVENTION void SetMaxLogStack(int maxLogStack);
MANAGED_TO_POPCORN_CONVENTION int GetStackLogNumber();
MANAGED_TO_POPCORN_CONVENTION int UnstackLog(char *dstBuffer, int dstSize, int &logSeverity);
// Update and rendering:
MANAGED_TO_POPCORN_CONVENTION void SetMaxCameraCount(int number);
Expand Down Expand Up @@ -395,6 +396,7 @@ extern "C"
MANAGED_TO_POPCORN_CONVENTION const char *GetRuntimeVersion();

MANAGED_TO_POPCORN_CONVENTION void SetApplicationLoopbackAudioVolume(float volume);
MANAGED_TO_POPCORN_CONVENTION bool CanSkipUpdate();

MANAGED_TO_POPCORN_CONVENTION void SetQualityLevelSettings(const char **qualityLevelNames, int qualityLevelCount, int current, bool updateCookery);

Expand Down
1 change: 1 addition & 0 deletions Native/PKUnity_Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class CUnityLog : public ILogListener
s32 PopFront(SPopcornLogData &out);
void SetMaxLogsCount(u32 maxLogsCount);
void ClearLogs();
u32 Count() const { return m_LogStackMain.Count(); }

void StartLogs();
void ValidateLogsAtLevel(CLog::ELogLevel level, const CString &header);
Expand Down
26 changes: 25 additions & 1 deletion Native/PKUnity_Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,29 @@ void CPKFXScene::SyncPreviousUpdateAndRunDeferredCallsIFN()

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

bool CPKFXScene::ShouldUpdatePopcorn()
{
if (!m_WaitForUpdateOnRenderThread)
{
PK_ASSERT(m_ParticleMediumCollection != null);
if (m_ParticleMediumCollection->CanSkipUpdate())
return false;
}
else
{
PK_ASSERT(m_ParticleMeshMediumCollection != null);
PK_ASSERT(m_ParticleMediumCollection != null);

if (m_ParticleMediumCollection->CanSkipUpdate() &&
m_ParticleMeshMediumCollection->CanSkipUpdate())
return false;
}

return true;
}

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

void CPKFXScene::LaunchUpdate(float dt)
{
PK_SCOPEDPROFILE();
Expand All @@ -204,7 +227,7 @@ void CPKFXScene::LaunchUpdate(float dt)

if (UpdateMode() != UpdateMode_NoUpdate)
{
if (dt != 0.0f)
if (dt != 0.0f && ShouldUpdatePopcorn())
{
CRuntimeManager::Instance().BeforeUpdate();
CRuntimeManager::Instance().Update(dt);
Expand All @@ -217,6 +240,7 @@ void CPKFXScene::LaunchUpdate(float dt)
PopcornFX::CTimer updateTimer;
updateTimer.Start();
#endif // (PK_PARTICLES_HAS_STATS != 0)

m_ParticleMediumCollection->Update(dt);

while (m_ParticleMediumCollection->UpdateFence(1)) { }
Expand Down
1 change: 1 addition & 0 deletions Native/PKUnity_Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class CPKFXScene : public CRefCountedObject, public IParticleScene
void TransformAllParticles(const CFloat3 &worldOffset);

void ResolveDynamicCollisionsIFN();
bool ShouldUpdatePopcorn();

// Both of those need to be called for the particles to be correctly updated:
void SyncPreviousUpdateAndRunDeferredCallsIFN();
Expand Down
7 changes: 6 additions & 1 deletion Native/RenderingIntegration/UnityRendererCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ bool CParticleMaterialDescMesh::InitFromRenderer(const CRendererDataMesh &render
const SRendererFeaturePropertyValue *atlasBlending = renderer.m_Declaration.FindProperty(BasicRendererProperties::SID_Atlas_Blending());

m_Flags.m_ShaderVariationFlags = 0;

if (diffuse != null && diffuse->ValueB() && diffuseMap != null && !diffuseMap->ValuePath().Empty())
m_Flags.m_ShaderVariationFlags |= ShaderVariationFlags::Has_DiffuseMap;
if (alphaRemap != null && alphaRemap->ValueB() && alphaRemapAlphaMap != null && !alphaRemapAlphaMap->ValuePath().Empty() && alphaRemapCursor.Valid())
Expand Down Expand Up @@ -524,7 +525,10 @@ bool CParticleMaterialDescMesh::InitFromRenderer(const CRendererDataMesh &render
m_Flags.m_BlendMode = BlendMode::Solid;

if (transparent != null && transparent->ValueB() && transparentType != null)
{
{
const SRendererFeaturePropertyValue *globalSortOverride = renderer.m_Declaration.FindProperty(BasicRendererProperties::SID_Transparent_GlobalSortOverride());
m_Flags.m_DrawOrder = globalSortOverride != null ? globalSortOverride->ValueI().x() : 0;

if (transparentType->ValueI().x() == BasicRendererProperties::Additive)
{
m_Flags.m_BlendMode = BlendMode::Additive;
Expand Down Expand Up @@ -923,6 +927,7 @@ bool CUnityRendererCache::GetRendererInfo(SMeshRendererDesc &desc)
desc.m_InvSoftnessDistance = m_MaterialDescMesh.m_InvSoftnessDistance;
desc.m_AlphaClipThreshold = m_MaterialDescMesh.m_AlphaThreshold;
desc.m_DoubleSided = m_MaterialDescMesh.m_DoubleSided;
desc.m_DrawOrder = m_MaterialDescMesh.m_Flags.m_DrawOrder;

bool fluidVAT = (m_MaterialDescMesh.m_Flags.m_ShaderVariationFlags & ShaderVariationFlags::Has_FluidVAT) != 0;
bool softVAT = (m_MaterialDescMesh.m_Flags.m_ShaderVariationFlags & ShaderVariationFlags::Has_SoftVAT) != 0;
Expand Down
7 changes: 7 additions & 0 deletions Native/RuntimeManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1668,6 +1668,13 @@ void CRuntimeManager::AfterUpdate()

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

bool CRuntimeManager::CanSkipUpdate()
{
return !m_ParticleScene->ShouldUpdatePopcorn();
}

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

bool CRuntimeManager::KickBackgroundTasksIFN()
{
if (m_HasBackgroundTasksToKick)
Expand Down
1 change: 1 addition & 0 deletions Native/RuntimeManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ class CRuntimeManager : public CNonCopyable

void BeforeUpdate();
void AfterUpdate();
bool CanSkipUpdate();

template<class T>
bool AddBackgroundTask(T *functor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ public override Material ResolveParticleMaterial(SBatchDesc batchDesc, PKFxEffec
Debug.LogError("[PopcornFX] Trying to resolve material from PKFxEffectAsset that is not holding materials");
if (material == null)
return null;
if (batchDesc.m_Type != ERendererType.Mesh)
material.renderQueue = m_RenderQueue + batchDesc.m_DrawOrder;
material.renderQueue = m_RenderQueue + batchDesc.m_DrawOrder;
return material;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,8 @@ public override void OnInspectorGUI()
SerializedProperty rdrs = serializedObject.FindProperty("m_RendererDescs");
SerializedProperty mats = serializedObject.FindProperty("m_Materials");
SerializedProperty customMats = serializedObject.FindProperty("m_CustomMaterials");

int rdrsListSize = rdrs.arraySize;
if (rdrsListSize > 0)
EditorGUILayout.LabelField("Renderers : ");

// Upgrade if material wasn't set in import (2.12.7 ++)
if (mats.arraySize < rdrsListSize)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ static void UpdatePKFxFXReferencesInScene()

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

public static void CreatePKFxFXMaterialsIFN()
public static void CreatePKFxFXMaterialsIFN(bool reimport = false)
{
string[] pkfxEffectAssets = AssetDatabase.FindAssets("t:PKFxEffectAsset");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ public int RenderPass

bool SetupDistortionPassIFN()
{
if (GraphicsSettings.renderPipelineAsset != null &&
(GraphicsSettings.renderPipelineAsset.name == "HDRenderPipelineAsset" ||
GraphicsSettings.renderPipelineAsset.name == "UniversalRenderPipelineAsset"))
if (PKFxSettings.MaterialFactory.m_FactoryType == PKFxMaterialFactory.FactoryType.URP ||
PKFxSettings.MaterialFactory.m_FactoryType == PKFxMaterialFactory.FactoryType.HDRP)
return false; // HDRP, we are using distortion builtin shaders
// URP, Distortion is handled as forward rendering
if (PKFxSettings.EnableSoftParticles == false)
Expand Down Expand Up @@ -193,13 +192,11 @@ internal void SetCullingMask(short ID, LayerMask targetMask, LayerMask allPKMask

if (PKFxSettings.EnableDistortion)
{
if (GraphicsSettings.renderPipelineAsset == null ||
!(GraphicsSettings.renderPipelineAsset.name == "HDRenderPipelineAsset" ||
GraphicsSettings.renderPipelineAsset.name == "UniversalRenderPipelineAsset"))
if (PKFxSettings.MaterialFactory.m_FactoryType != PKFxMaterialFactory.FactoryType.URP &&
PKFxSettings.MaterialFactory.m_FactoryType != PKFxMaterialFactory.FactoryType.HDRP)
{
// We disable the rendering of the distortion objects, this is going to be handled in a command buffer:
m_Camera.cullingMask &= ~(1 << LayerMask.NameToLayer(PKFxManagerImpl.m_DistortionLayer));

}
else
m_Camera.cullingMask |= 1 << LayerMask.NameToLayer(PKFxManagerImpl.m_DistortionLayer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static void LogUpdate(PKFxManager.EPopcornLogLevels minimumLogLevel)
if (minimumLogLevel == PKFxManager.EPopcornLogLevels.Level_None)
return;

while (PKFxManager.GetPopcornFXLog(ref currentLog, ref level) >= 0)
while (PKFxManager.GetPopcornFXLogNumber() > 0 && PKFxManager.GetPopcornFXLog(ref currentLog, ref level) >= 0)
{
if ((int)level < (int)minimumLogLevel)
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ public void UpdateSimulation()

void Update()
{
if (PKFxManager.CanSkipUpdate())
return;
for (int i = 0; i < m_Cameras.Count; ++i)
{
if (i < MaxCameraSupport())
Expand All @@ -197,8 +199,9 @@ private void LateUpdate()

void _LateUpdate()
{
if (PKFxManager.CanSkipUpdate())
return;
PKFxManager.UpdateParticles();

for (int i = 0; i < m_Cameras.Count; ++i)
{
if (i < MaxCameraSupport())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ internal partial class PKFxManagerImpl : object
[DllImport(kPopcornPluginName, CallingConvention = kCallingConvention)]
public static extern int UnstackLog(StringBuilder dstBuffer, int dstSize, ref int logSeverity);
[DllImport(kPopcornPluginName, CallingConvention = kCallingConvention)]
public static extern int GetStackLogNumber();
[DllImport(kPopcornPluginName, CallingConvention = kCallingConvention)]
public static extern void SetMaxCameraCount(int number);
[DllImport(kPopcornPluginName, CallingConvention = kCallingConvention)]
public static extern void SetCurrentQualityLevel(string currentQualityLevel);
Expand Down Expand Up @@ -326,6 +328,9 @@ internal partial class PKFxManagerImpl : object
[DllImport(kPopcornPluginName, CallingConvention = kCallingConvention)]
public static extern void SetQualityLevelSettings(string[] QualityLevels, int qualityLevelCount, int currentQualityLevel, bool updateCookery);

[DllImport(kPopcornPluginName, CallingConvention = kCallingConvention)]
public static extern bool CanSkipUpdate();

#if UNITY_EDITOR
[DllImport(kPopcornPluginName, CallingConvention = kCallingConvention)]
public static extern bool PopcornFXEditorStartup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,21 @@ public void BindMaterialProperties(SBatchDesc batchDesc, Material material, PKFx
int dstMode = 0;
UnityBlendMode blend = UnityBlendMode.Alpha;
// Additive and distortion
if (batchDesc.HasShaderVariationFlag(EShaderVariationFlags.Has_DistortionMap) ||
batchDesc.m_BlendMode == EBlendMode.Additive)
if (batchDesc.HasShaderVariationFlag(EShaderVariationFlags.Has_DistortionMap))
{
blend = UnityBlendMode.Additive;
srcMode = (int)UnityEngine.Rendering.BlendMode.SrcAlpha;
if (GraphicsSettings.renderPipelineAsset != null && GraphicsSettings.renderPipelineAsset.name == "UniversalRenderPipelineAsset")
if (PKFxSettings.MaterialFactory.m_FactoryType == PKFxMaterialFactory.FactoryType.URP)
dstMode = (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha;
else
dstMode = (int)UnityEngine.Rendering.BlendMode.One;
}
else if (batchDesc.m_BlendMode == EBlendMode.Additive)
{
blend = UnityBlendMode.Additive;
srcMode = (int)UnityEngine.Rendering.BlendMode.SrcAlpha;
dstMode = (int)UnityEngine.Rendering.BlendMode.One;
}
else if (batchDesc.m_BlendMode == EBlendMode.AdditiveNoAlpha)
{
blend = UnityBlendMode.Additive;
Expand All @@ -140,6 +145,10 @@ public void BindMaterialProperties(SBatchDesc batchDesc, Material material, PKFx
dstMode = (int)UnityEngine.Rendering.BlendMode.One;
}

if (batchDesc.m_DrawOrder != 0 && PKFxSettings.MaterialFactory.m_FactoryType == PKFxMaterialFactory.FactoryType.URP)
{
material.SetFloat("_QueueOffset", batchDesc.m_DrawOrder);
}
if (!string.IsNullOrEmpty(m_SourceBlendPropertyName))
{
material.SetInt(m_SourceBlendPropertyName, srcMode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ public static void SetMaxLogsPerFrame(int maxLogs)
PKFxManagerImpl.SetMaxLogStack(maxLogs);
}

public static int GetPopcornFXLogNumber()
{
if (!PKFxManagerImpl._IsDllLoaded())
return 0;

return PKFxManagerImpl.GetStackLogNumber();
}

public static int GetPopcornFXLog(ref string log, ref EPopcornLogLevels level)
{
if (!PKFxManagerImpl._IsDllLoaded())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,30 +101,28 @@ public static string GetSelectedPathOrFallback()
return path;
}

public virtual Material EditorGetDefaultMaterial(SBatchDesc batchDesc, PKFxEffectAsset asset = null, bool logError = true)
public string EditorResolveMaterialName(SBatchDesc batchDesc)
{
if (batchDesc.m_Type == ERendererType.Light || batchDesc.m_Type == ERendererType.Sound)
return null;
PKFxRenderFeatureBinding binding = ResolveBatchBinding(batchDesc);
Material material;
Material material = null;

if (binding == null)
{
Debug.LogError("[PopcornFX] Error No shader found for " + batchDesc.m_GeneratedName + "in effect: " + asset.name);
return null;
}

string matName;
if (PKFxSettings.UseHashesAsMaterialName)
string matName = EditorResolveMaterialName(batchDesc);
string materialPath = "Assets/" + PKFxSettings.UnityPackFxPath + "/UnityMaterials/" + matName + ".mat";
Material assetMat = (Material)AssetDatabase.LoadAssetAtPath(materialPath, typeof(Material));

if (reimport && assetMat != null)
{
Hash128 hash = new Hash128();
hash.Append(batchDesc.m_GeneratedName);
matName = hash.ToString();
assetMat = null;
AssetDatabase.DeleteAsset(materialPath);
}
else
matName = batchDesc.GenerateShortNameFromDescription();

Material assetMat = (Material)AssetDatabase.LoadAssetAtPath("Assets/" + PKFxSettings.UnityPackFxPath + "/UnityMaterials/" + matName + ".mat", typeof(Material));
if (assetMat == null)
{
material = new Material(binding.m_Shader);
Expand All @@ -143,16 +141,6 @@ public virtual Material EditorGetDefaultMaterial(SBatchDesc batchDesc, PKFxEffec
AssetDatabase.SaveAssets();
return material;
}

public virtual Material EditorResolveMaterial(SBatchDesc batchDesc, PKFxEffectAsset asset = null, bool logError = true)
{
if (!AssetDatabase.IsValidFolder("Assets" + PKFxSettings.UnityPackFxPath))
AssetDatabase.CreateFolder("Assets", PKFxSettings.UnityPackFxPath.Substring(1));
if (!AssetDatabase.IsValidFolder("Assets" + PKFxSettings.UnityPackFxPath + "/UnityMaterials"))
AssetDatabase.CreateFolder("Assets" + PKFxSettings.UnityPackFxPath, "UnityMaterials");

return EditorGetDefaultMaterial(batchDesc, asset, logError);
}
#endif

public PKFxRenderFeatureBinding ResolveBatchBinding(SBatchDesc batchDesc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ public SBatchDesc(SMeshRendererDesc desc)
m_Type = ERendererType.Mesh;
m_ShaderVariationFlags = desc.m_ShaderVariationFlags;
m_BlendMode = desc.m_BlendMode;
m_DrawOrder = desc.m_DrawOrder;
m_RotateUVs = false;
m_DiffuseMap = diffuseStr;
m_DiffuseRampMap = diffuseRampStr;
Expand Down Expand Up @@ -506,6 +507,7 @@ public SBatchDesc(SMeshRendererDesc desc)
for (int i = 0; i < desc.m_TextureAtlasCount; ++i)
{
Vector4 curCol = subRects[i];
curCol.w = 1 - curCol.y - curCol.w; // Unity sampling is reversed in Y.
m_AtlasSubRects.SetPixel(i, 0, curCol);
}
}
Expand Down Expand Up @@ -628,6 +630,7 @@ public string GenerateNameFromDescription()
finalName += " ";
finalName += m_DoubleSided ? "DoubleSided" : "OneSided";
}
finalName += " " + m_DrawOrder;
return finalName;
}
public static string BlendModeToShortString(EBlendMode blendMode)
Expand Down Expand Up @@ -692,7 +695,6 @@ public static string MaterialFlagsToShortString(int materialFlags)

public string GenerateShortNameFromDescription()
{

string finalName;

if (m_Type == ERendererType.Billboard)
Expand Down
Loading

0 comments on commit db4f00a

Please sign in to comment.