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

    private static void ApplyPKImportSetting(PKFxFxAsset.DependencyDesc dependency, string path)
    {
        string fExt = Path.GetExtension(path);

        if (PKFxManager.IsSupportedTextureExtension(fExt))
        {
            TextureImporter importer = AssetImporter.GetAtPath(path) as TextureImporter;
            bool            reimport = false;
            if (importer == null)
            {
                return;
            }
            if (importer.sRGBTexture != !dependency.m_IsTextureLinear)
            {
                importer.sRGBTexture = !dependency.m_IsTextureLinear;
                reimport             = true;
            }
            if (dependency.m_IsTextureSampler)
            {
                importer.isReadable = true;
                reimport            = true;
            }
            if (reimport)
            {
                importer.SaveAndReimport();
            }
        }
    }
Esempio n. 2
0
        private static void PlaymodeStateChanged(PlayModeStateChange state)
        {
            if (state == PlayModeStateChange.ExitingPlayMode)
            {
                // Start by clearing the FXs in the C# so they don't get updated
                foreach (KeyValuePair <int, PKFxFX> effect in PKFxFX.g_ListEffects)
                {
                    effect.Value.DestroyIFN(false);
                }
                PKFxFX.g_ListEffects.Clear();
                // Then clear the native side:
                PKFxManager.ClearRenderers();
                PKFxManager.SetSceneMesh(null);
                PKFxManager.ResetAndUnloadAllEffects();

                // We also save the configuration file:
                if (PKFxSettings.AutomaticMeshResizing)
                {
                    EditorUtility.SetDirty(PKFxSettings.Instance);
                }
                PKFxManager.StartupPopcorn(false);
                PKFxManager.RestartPackWatcher();
            }
            else if (state == PlayModeStateChange.EnteredPlayMode)
            {
                PKFxManager.PausePackWatcher();
            }
        }
Esempio n. 3
0
 public PKFxAttributesContainer(PKFxFxAsset asset, int fxId)
 {
     m_WasModified      = false;
     m_FxAsset          = asset;
     m_FxGuid           = fxId;
     m_AttributesBuffer = PKFxManager.GetAttributesBuffer(fxId);
 }
Esempio n. 4
0
    //----------------------------------------------------------------------------

    public void StartEffect()
    {
        if (m_IsStopped)
        {
            Debug.LogWarning("[PKFX] Attempt to start an effect while the stopped effect is still running.");
            return;
        }
        if (this.m_IsPlaying)
        {
            return;
        }
        if (!string.IsNullOrEmpty(m_FxName))
        {
            this.m_FXGUID = PKFxManager.CreateEffect(this.FxPath, this.transform);
        }
        this.m_IsPlaying = (this.m_FXGUID != -1);

        if (this.m_FXGUID != -1)
        {
            if (m_ListEffects.ContainsKey(this.m_FXGUID))
            {
                m_ListEffects[this.m_FXGUID] = this;
            }
            else
            {
                m_ListEffects.Add(this.m_FXGUID, this);
            }
        }

        this.LoadAttributes(PKFxManager.ListEffectAttributesFromGUID(this.m_FXGUID), false);
        this.LoadSamplers(PKFxManager.ListEffectSamplersFromFx(this.m_FxName), false);
        UpdateAttributes(true);
    }
    IEnumerator Start()
    {
        base.BaseInitialize();
        yield return(WaitForPack(true));

        PKFxFX fx = this.gameObject.GetComponent <PKFxFX>();

        if (fx == null)
        {
            yield break;
        }
        fx.LoadAttributes(PKFxManager.ListEffectAttributesFromFx(m_FxName), false);
        for (int i = 0; i < m_FloatAttributesNames.Count; i++)
        {
            if (i < m_FloatAttributes.Count)
            {
                fx.SetAttribute(new PKFxManager.Attribute(m_FloatAttributesNames[i], m_FloatAttributes[i]));
            }
        }
        for (int i = 0; i < m_Float3AttributesNames.Count; i++)
        {
            if (i < m_Float3Attributes.Count)
            {
                fx.SetAttribute(new PKFxManager.Attribute(m_Float3AttributesNames[i], m_Float3Attributes[i]));
            }
        }
        fx.StartEffect();
    }
 private static void PlaymodeStateChanged()
 {
     if (!EditorApplication.isPlaying && !EditorApplication.isPaused)
     {
         PKFxManager.Reset();
     }
 }
Esempio n. 7
0
    void OnPreRender()
    {
        if (!PKFxManager.m_PackLoaded)
        {
            return;
        }
        if (m_CurrentFrameID != m_LastUpdateFrameID)
        {
            m_CurrentCameraID = m_CameraID;
            SetupRendering();
            m_LastUpdateFrameID = m_CurrentFrameID;
        }
        else
        {
            m_CurrentCameraID = m_VRReservedID;
            SetupRendering();
        }

        if (m_LastFrameCount != Time.frameCount)
        {
            PKFxManager.UpdateParticles(m_CameraDescription);
            m_LastFrameCount = Time.frameCount;
        }
        PKFxManager.Render(m_CurrentCameraID);
    }
Esempio n. 8
0
    //----------------------------------------------------------------------------

    void UpdateFrame()
    {
        m_CameraDescription.m_ViewportWidth  = (uint)m_Camera.pixelWidth;
        m_CameraDescription.m_ViewportHeight = (uint)m_Camera.pixelHeight;
        m_CameraDescription.m_NearClip       = m_Camera.nearClipPlane;
        m_CameraDescription.m_FarClip        = m_Camera.farClipPlane;

        float frameDt = Time.smoothDeltaTime * PKFxSettings.TimeMultiplier;

        PKFxManager.UpdateLogic(frameDt);

        if (!m_Camera.stereoEnabled)
        {
            UpdateViewMatrix();
            UpdateProjectionMatrix();
            m_CurrentCameraID = m_CameraID;
            PKFxManager.UpdateCamera(m_CurrentCameraID, ref m_CameraDescription);
        }
        else
        {
            // stereo-cam's first eye.
            UpdateViewMatrix(true, Camera.StereoscopicEye.Left);
            UpdateProjectionMatrix(true, Camera.StereoscopicEye.Left);
            m_CurrentCameraID = m_CameraID;
            PKFxManager.UpdateCamera(m_CurrentCameraID, ref m_CameraDescription);
            // second eye.
            UpdateViewMatrix(true, Camera.StereoscopicEye.Right);
            UpdateProjectionMatrix(true, Camera.StereoscopicEye.Right);
            m_CurrentCameraID = m_VRReservedID;
            PKFxManager.UpdateCamera(m_CurrentCameraID, ref m_CameraDescription);
        }
    }
 // Update is called once per frame
 void Update()
 {
     if (PKFxSettings.SplitUpdateInComponents)
     {
         PKFxManager.UpdateParticlesEvolve();
     }
 }
    //----------------------------------------------------------------------------

    private void ReloadConstants(bool flush)
    {
        serializedObject.Update();
        PkFxCustomShader customShader = (serializedObject.targetObject as PkFxCustomShader);

        int count = -1;

        if (customShader.m_Api == PkFxCustomShader.EShaderApi.GL && !m_InShaderConstantsLoading)
        {
            PKFxManager.ShaderConstantsCount(customShader.m_ShaderName, (int)customShader.m_Api);
            GL.IssuePluginEvent(PKFxManager.GetGLConstantsCountEvent(), (int)(PKFxManager.POPCORN_MAGIC_NUMBER | 0x00004000));
            m_InShaderConstantsLoading = true;
        }
        else
        {
            count = PKFxManager.ShaderConstantsCount(customShader.m_ShaderName, (int)customShader.m_Api);
        }

        if (count != -1)
        {
            m_InShaderConstantsLoading = false;
            List <PKFxManager.ShaderConstantDesc> FxAttributesDesc = PKFxManager.ListShaderConstantsFromName(customShader.m_ShaderName, count);
            customShader.LoadShaderConstants(FxAttributesDesc, flush);
            EditorUtility.SetDirty(target as PkFxCustomShader);
            AssetDatabase.SaveAssets();
            serializedObject.ApplyModifiedProperties();
            serializedObject.Update();
        }
    }
    //----------------------------------------------------------------------------

    void OnEnable()
    {
        PKFxManager.Startup();
        if (!PKFxManager.TryLoadPackRelative())
        {
            PKFxManager.LoadPack(PKFxManager.m_PackPath + "/PackFx");
        }

        m_InShaderConstantsLoading = false;
        ReloadConstants(false);

        m_IsSoft           = serializedObject.FindProperty("m_IsSoft");
        m_HasSoftAnimBlend = serializedObject.FindProperty("m_HasSoftAnimBlend");
        m_IsDistortion     = serializedObject.FindProperty("m_IsDistortion");
        m_IsMesh           = serializedObject.FindProperty("m_IsMesh");
        m_HasMeshTexture   = serializedObject.FindProperty("m_HasMeshTexture");
        m_IsGL3            = serializedObject.FindProperty("m_IsGL3");

        m_Api                 = serializedObject.FindProperty("m_Api");
        m_VertexType          = serializedObject.FindProperty("m_VertexType");
        m_PixelType           = serializedObject.FindProperty("m_PixelType");
        m_ShaderName          = serializedObject.FindProperty("m_ShaderName");
        m_ShaderGroup         = serializedObject.FindProperty("m_ShaderGroup");
        m_ShaderConstantList  = serializedObject.FindProperty("m_ShaderConstantList");
        m_ShowShaderTypes     = false;
        m_ShowShaderConstants = true;
    }
Esempio n. 12
0
    //----------------------------------------------------------------------------

    public static bool UpdateMeshBones(int effectID, int samplerID, SkinnedMeshRenderer skinnedMesh)
    {
        if (skinnedMesh.bones.Length == 0)
        {
            Debug.Log("The skinned mesh does not have bones");
            return(false);
        }

        Matrix4x4 rootMat     = skinnedMesh.transform.parent.worldToLocalMatrix;
        IntPtr    matricesPtr = PKFxManager.UpdateSamplerSkinningSetMatrices(effectID, samplerID);

        if (matricesPtr == IntPtr.Zero)
        {
            Debug.Log("Could not retrieve the bones matrices");
            return(false);
        }

        unsafe
        {
            Matrix4x4 * matrices          = (Matrix4x4 *)matricesPtr.ToPointer();
            Transform[] curBonesTransform = skinnedMesh.bones;
            Matrix4x4[] bindPos           = skinnedMesh.sharedMesh.bindposes;

            for (int i = 0; i < skinnedMesh.bones.Length; ++i)
            {
                Matrix4x4 boneLocalToWorld = curBonesTransform[i].localToWorldMatrix;
                matrices[i] = rootMat * boneLocalToWorld * bindPos[i];
            }
        }
        return(true);
    }
Esempio n. 13
0
    //----------------------------------------------------------------------------

    #region PreloadEffect from asset

    public static void PreloadEffectFromAsset(PKFxFxAsset fxAsset)
    {
        PKFxManager.SetBuiltAsset(fxAsset);
        PKFxManager.PreloadEffectDependencies(fxAsset);
        PKFxManager.PreloadEffectIFN(fxAsset.m_AssetName, fxAsset.m_UsesMeshRenderer);
        PKFxManager.SetBuiltAsset(null);
    }
Esempio n. 14
0
    static bool Initialize()
    {
        if (PKFxManager.IsDllLoaded() && !Application.isPlaying)
        {
            PKFxManager.StartupPopcorn(false);
            PKFxManager.StartupPopcornFileWatcher();
            m_DllLoaded = true;

            if (!Directory.Exists("Assets" + PKFxSettings.UnityPackFxPath))
            {
                string DirName = PKFxSettings.UnityPackFxPath;
                if (DirName.StartsWith("/"))
                {
                    DirName = DirName.Substring(1);
                }
                if (DirName.EndsWith("/"))
                {
                    DirName = DirName.Substring(DirName.Length - 1, 1);
                }
                AssetDatabase.CreateFolder("Assets", DirName);
            }

            return(true);
        }
        return(false);
    }
    //----------------------------------------------------------------------------

    private void BuildMeshes()
    {
        string outputPkmm = m_OutputPkmmPath.stringValue;

        if (outputPkmm.Length <= 0)
        {
            Debug.LogError("[PKFX] SceneMeshBuilder: invalid mesh path", this);
            return;
        }
        PKFxManager.StartupPopcorn(false);
        PKFxManager.SetSceneMesh(null);
        for (int meshi = 0; meshi < m_MeshGameObjects.arraySize; meshi++)
        {
            GameObject obj  = m_MeshGameObjects.GetArrayElementAtIndex(meshi).objectReferenceValue as GameObject;
            Mesh       mesh = obj.GetComponent <MeshFilter>().sharedMesh;

            if (!PKFxManager.AddMeshToSceneMesh(mesh, obj.transform))
            {
                Debug.LogError("[PKFX] SceneMeshBuilder: failed to load mesh " + obj.name + "", this);
            }
        }
        // Disabled for the moment as we do not have a PackFx folder in the streaming assets
        int primCount = PKFxManager.SceneMeshBuild(outputPkmm);

        if (primCount < 0)
        {
            Debug.LogError("[PKFX] SceneMeshBuilder: failed to save scene mesh " + this.name + "", this);
        }
        else
        {
            Debug.Log("[PKFX] SceneMeshBuilder: mesh ok " + this.name + " (prim count: " + primCount.ToString() + ")");
        }
    }
Esempio n. 16
0
 public void     UpdateAttributes()
 {
     if (m_WasModified)
     {
         m_WasModified = false;
         PKFxManager.UpdateAttributesBuffer(m_FxGuid);
     }
 }
Esempio n. 17
0
    //----------------------------------------------------------------------------

    public bool Alive()
    {
        if (!this.m_IsPlaying || this.m_FXGUID == -1)
        {
            return(false);
        }
        return(PKFxManager.IsFxAlive(this.m_FXGUID));
    }
Esempio n. 18
0
 void OnGUI()
 {
     if (!m_InCapture && GUI.Button(new Rect(10, 10, 500, 150), "Profiler capture"))
     {
         m_InCapture = true;
         PKFxManager.ProfilerEnable(true);
     }
 }
Esempio n. 19
0
    public static int CreateEffect(PKFxFxAsset fxAsset, Transform t, bool autoDestroy)
    {
        PKFxManager.SetBuiltAsset(fxAsset);
        int res = CreateEffect(fxAsset.m_AssetName, t.localToWorldMatrix, fxAsset.m_UsesMeshRenderer, autoDestroy);

        PKFxManager.SetBuiltAsset(null);
        return(res);
    }
Esempio n. 20
0
    //----------------------------------------------------------------------------

    public static int CreateEffect(PKFxFxAsset fxAsset, Matrix4x4 m, bool autoDestroy)
    {
        PKFxManager.SetBuiltAsset(fxAsset);
        int res = CreateEffect(fxAsset.m_AssetName, m, fxAsset.m_UsesMeshRenderer, autoDestroy);

        PKFxManager.SetBuiltAsset(null);
        return(res);
    }
Esempio n. 21
0
    //----------------------------------------------------------------------------

    void LateUpdate()
    {
        if (!this.m_IsPlaying)
        {
            return;
        }
        PKFxManager.UpdateTransformEffect(this.m_FXGUID, this.transform);
        UpdateAttributes(false);
    }
    //----------------------------------------------------------------------------

    public override void OnInspectorGUI()
    {
        if (string.IsNullOrEmpty(PKFxManager.m_CurrentVersionString))
        {
            PKFxManager.Startup();
        }
        EditorGUILayout.LabelField("PopcornFX plugin "
                                   + PKFxManager.m_PluginVersion
                                   + " (Build "
                                   + PKFxManager.m_CurrentVersionString + ")");

        DrawDefaultInspector();

        EditorGUILayout.PropertyField(m_ShowAdvanced);
        if (m_ShowAdvanced.boolValue)
        {
            EditorGUI.indentLevel++;

            EditorGUILayout.Slider(m_TimeMultiplier, 0.0f, 8.0f);
            EditorGUILayout.PropertyField(this.m_EnableSoftParticles);
            if (this.m_EnableSoftParticles.boolValue)
            {
                if (SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.Direct3D11)
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.PropertyField(this.m_DepthGrabFormat);
                    EditorGUILayout.PropertyField(this.m_UseDepthGrabToZTest);
                    EditorGUI.indentLevel--;
                }
            }
            EditorGUILayout.PropertyField(this.m_EnableDistortion);
            if (m_EnableDistortion.boolValue)
            {
                m_EnableSoftParticles.boolValue = true;
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(this.m_EnableBlur);
                if (m_EnableBlur.boolValue)
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.PropertyField(this.m_BlurFactor);
                    m_BlurFactor.floatValue = Mathf.Clamp(m_BlurFactor.floatValue, 0.0f, 1.0f);
                    EditorGUI.indentLevel--;
                }
                EditorGUI.indentLevel--;
            }
            EditorGUILayout.PropertyField(this.m_UseSceneMesh);
            if (m_UseSceneMesh.boolValue)
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(this.m_SceneMeshPkmmPath);
                EditorGUI.indentLevel--;
            }
            EditorGUILayout.PropertyField(this.m_TextureLODBias);
            EditorGUI.indentLevel--;
        }
        serializedObject.ApplyModifiedProperties();
    }
Esempio n. 23
0
 static PlayModeChangeWatcher()
 {
     if (EditorApplication.isPlayingOrWillChangePlaymode)
     {
         PKFxManager.SetSceneMesh(null);
         PKFxManager.ResetAndUnloadAllEffects();
     }
     EditorApplication.playModeStateChanged += PlaymodeStateChanged;
 }
Esempio n. 24
0
    //----------------------------------------------------------------------------

    private static int CreateEffect(string path, Matrix4x4 m, bool usesMeshRenderer, bool autoDestroy)
    {
        PKFxManagerImpl.SFxDesc desc;

        desc.m_Transforms        = m;
        desc.m_FxPath            = path;
        desc.m_UsesMeshRenderer  = usesMeshRenderer;
        desc.m_AutoDestroyEffect = autoDestroy;
        return(PKFxManager.InstantiateEffect(ref desc));
    }
Esempio n. 25
0
    //----------------------------------------------------------------------------

    public void TerminateEffect()
    {
        if (!this.m_IsPlaying || this.m_FXGUID == -1)
        {
            return;
        }
        PKFxManager.TerminateFx(this.m_FXGUID);
        //this.m_FXGUID = -1;
        this.m_IsPlaying = false;
    }
Esempio n. 26
0
    //----------------------------------------------------------------------------

    public void KillEffect()
    {
        if (!this.m_IsPlaying || this.m_FXGUID == -1 || !PKFxManager.KillIndividualEffectEnabled())
        {
            return;
        }
        PKFxManager.KillFx(this.m_FXGUID);
        //this.m_FXGUID = -1;
        this.m_IsPlaying = false;
    }
Esempio n. 27
0
    //----------------------------------------------------------------------------

    public static int CreateEffect(PKFxFxAsset fxAsset, Vector3 position, Quaternion rotation, Vector3 scale, bool autoDestroy)
    {
        PKFxManager.SetBuiltAsset(fxAsset);
        Matrix4x4 m = Matrix4x4.identity;

        m.SetTRS(position, rotation, scale);
        int res = CreateEffect(fxAsset.m_AssetName, m, fxAsset.m_UsesMeshRenderer, autoDestroy);

        PKFxManager.SetBuiltAsset(null);
        return(res);
    }
Esempio n. 28
0
 static void OpenLog()
 {
     if (PKFxManager.FileLoggingEnabled() && File.Exists(PKFxManager.m_LogFilePath))
     {
         Application.OpenURL(PKFxManager.m_LogFilePath);
     }
     else
     {
         UnityEngine.Debug.LogError("[PKFX] Log file not found, try enabling the log in the PopcornFX Preferences and/or restarting Unity.");
     }
 }
Esempio n. 29
0
    //----------------------------------------------------------------------------

    void    Start()
    {
        if (m_EnableDistortion && !SystemInfo.supportsImageEffects)
        {
            Debug.LogWarning("[PKFX] Image effects not supported, distortions disabled.", this);
            m_EnableDistortion = false;
        }
        if (m_UseSceneMesh && m_SceneMesh != null && !PKFxSettings.EnableRaycastForCollisions)
        {
            PKFxManager.SetSceneMesh(m_SceneMesh);
        }
    }
Esempio n. 30
0
    //----------------------------------------------------------------------------

    void Reload(bool flushAttributes)
    {
        serializedObject.Update();
        Object[] effects = serializedObject.targetObjects;
        foreach (PKFxFX fx in effects)
        {
            List <PKFxManager.AttributeDesc> FxAttributesDesc = PKFxManager.ListEffectAttributesFromFx(fx.FxPath);
            fx.LoadAttributes(FxAttributesDesc, flushAttributes);
            List <PKFxManager.SamplerDesc> FxSamplersDesc = PKFxManager.ListEffectSamplersFromFx(fx.FxPath);
            fx.LoadSamplers(FxSamplersDesc, flushAttributes);
        }
        serializedObject.ApplyModifiedProperties();
    }