Ejemplo n.º 1
0
    public override void            SetupMeshRenderer(PKFxManagerImpl.SBatchDesc batchDesc, GameObject gameObject, PKFxMeshInstancesRenderer meshRenderer)
    {
        if (batchDesc.HasMaterialFlag(PKFxManagerImpl.EMaterialFlags.Has_Distortion))
        {
            gameObject.layer = PKFxManagerImpl.m_DistortionLayer;
        }

        PKFxFxAsset.DependencyDesc DepDesc = PKFxManager.GetBuiltAsset().m_Dependencies.Find(x => batchDesc.m_MeshAsset.Contains(x.m_Path));
        if (DepDesc != null)
        {
            GameObject       meshGO = DepDesc.m_Object as GameObject;
            List <Mesh>      meshes = new List <Mesh>();
            List <Matrix4x4> trans  = new List <Matrix4x4>();

            MeshFilter meshFilter = meshGO.GetComponent <MeshFilter>();
            if (meshFilter != null)
            {
                meshes.Add(meshFilter.sharedMesh);
                trans.Add(meshGO.transform.localToWorldMatrix);
            }
            if (meshes.Count == 0)
            {
                MeshFilter[] meshFilters = meshGO.GetComponentsInChildren <MeshFilter>();
                if (batchDesc.m_SubMeshID == -1)
                {
                    for (int i = 0; i < meshFilters.Length; ++i)
                    {
                        meshes.Add(meshFilters[i].sharedMesh);
                        trans.Add(meshGO.transform.localToWorldMatrix * meshFilters[i].transform.localToWorldMatrix);
                    }
                }
                else if (meshFilters.Length > batchDesc.m_SubMeshID)
                {
                    meshes.Add(meshFilters[batchDesc.m_SubMeshID].sharedMesh);
                    trans.Add(meshGO.transform.localToWorldMatrix * meshFilters[batchDesc.m_SubMeshID].transform.localToWorldMatrix);
                }
            }

            meshRenderer.m_MeshesImportTransform = trans.ToArray();
            meshRenderer.m_Meshes = meshes.ToArray();
        }
        meshRenderer.m_CastShadow = batchDesc.HasMaterialFlag(PKFxManagerImpl.EMaterialFlags.Has_CastShadow);
    }
Ejemplo n.º 2
0
 public override void            SetupRenderer(PKFxManagerImpl.SBatchDesc batchDesc, GameObject gameObject, MeshRenderer meshRenderer)
 {
     if (batchDesc.HasMaterialFlag(PKFxManagerImpl.EMaterialFlags.Has_Distortion))
     {
         gameObject.layer = PKFxManagerImpl.m_DistortionLayer;
     }
     if (m_UseSortingLayers)
     {
         if (IsUI(batchDesc.m_UserData))
         {
             meshRenderer.sortingLayerName = "PopcornFXUI";
         }
         else
         {
             meshRenderer.sortingLayerName = "PopcornFX";
         }
     }
 }
Ejemplo n.º 3
0
    public static Texture GetTextureLinear(PKFxManagerImpl.SBatchDesc batchDesc)
    {
        Texture distoTexture = null;

        if (batchDesc.m_NormalMap != null)
        {
            bool isLinear = batchDesc.HasMaterialFlag(PKFxManagerImpl.EMaterialFlags.Has_Distortion);
            PKFxFxAsset.DependencyDesc DepDesc = null;

            if (!isLinear)
            {
                return(null);
            }

            string path = Path.GetDirectoryName(batchDesc.m_NormalMap) + "/" + Path.GetFileNameWithoutExtension(batchDesc.m_NormalMap) + "_linear" + Path.GetExtension(batchDesc.m_NormalMap);
            DepDesc = PKFxManager.GetBuiltAsset().m_Dependencies.Find(x => path.Contains(x.m_Path));

            if (DepDesc == null)
            {
                DepDesc = PKFxManager.GetBuiltAsset().m_Dependencies.Find(x => batchDesc.m_NormalMap.Contains(x.m_Path));
            }
            if (DepDesc != null)
            {
                distoTexture = DepDesc.m_Object as Texture;
            }

            if (distoTexture != null)
            {
                if (batchDesc.m_Type != PKFxManagerImpl.ERendererType.Ribbon)
                {
                    distoTexture.wrapMode = TextureWrapMode.Clamp;
                }
            }
            else
            {
                Debug.LogError("[PKFX] Error while trying to create linear texture. Try to reimport \"" + batchDesc.m_NormalMap + "\" and check if its format is compatible with Unity.");
            }
        }
        return(distoTexture);
    }
Ejemplo n.º 4
0
    public override Material ResolveParticleMaterial(PKFxManagerImpl.SBatchDesc batchDesc)
    {
        Material customMat = TryFindAndInstantiateCustomMaterial(batchDesc);

        if (customMat != null)
        {
            return(customMat);
        }


        // First we handle the distortion with the material directly:
        if (batchDesc.HasMaterialFlag(PKFxManagerImpl.EMaterialFlags.Has_Distortion))
        {
            Material distoMat     = null;
            Texture  distoTexture = GetTextureDiffuse(batchDesc);

            if (batchDesc.HasMaterialFlag(PKFxManagerImpl.EMaterialFlags.Has_DoubleSided))
            {
                distoMat = new Material(m_DoubleSidedDistortionMaterial);
            }
            else
            {
                distoMat = new Material(m_DistortionMaterial);
            }

            distoMat.CopyPropertiesFromMaterial(m_DistortionMaterial);
            distoMat.SetTexture("_DistortionVectorMap", distoTexture);             // Set disto vector map

            return(distoMat);
        }

        // Set the diffuse texture:
        Texture diffuseTexture = GetTextureDiffuse(batchDesc);

        Shader shader = ResolveShader(batchDesc);

        Debug.Assert(shader != null);
        Material material = new Material(shader);

        // Set the diffuse texture:
        material.mainTexture = diffuseTexture;

        if (batchDesc.m_Type == PKFxManagerImpl.ERendererType.Mesh)
        {
            return(material);
        }

        // Set the alpha remap texture
        if (batchDesc.m_AlphaRemap != null)
        {
            string  alphaRemapPath    = Path.ChangeExtension(batchDesc.m_AlphaRemap, null);
            Texture alphaRemapTexture = Resources.Load <Texture>(alphaRemapPath);
            alphaRemapTexture.wrapMode = TextureWrapMode.Clamp;
            Debug.Assert(alphaRemapTexture != null);
            material.SetTexture("_AlphaMap", alphaRemapTexture);
        }

        // Set the material uniforms:
        material.SetInt("_UniformFlags", batchDesc.m_UniformFlags);

        int srcMode = 0;
        int dstMode = 0;

        // Additive and distortion
        if (batchDesc.HasUniformFlag(PKFxManagerImpl.EUniformFlags.Is_Additive) ||
            batchDesc.HasUniformFlag(PKFxManagerImpl.EUniformFlags.Is_AdditiveNoAlpha))
        {
            srcMode = (int)UnityEngine.Rendering.BlendMode.One;
            dstMode = (int)UnityEngine.Rendering.BlendMode.One;
        }
        else if (batchDesc.HasUniformFlag(PKFxManagerImpl.EUniformFlags.Is_AdditiveAlphaBlend))
        {
            srcMode = (int)UnityEngine.Rendering.BlendMode.One;
            dstMode = (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha;
        }
        else         // Alpha blended
        {
            srcMode = (int)UnityEngine.Rendering.BlendMode.SrcAlpha;
            dstMode = (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha;
        }

        material.SetInt("_SrcBlendMode", srcMode);
        material.SetInt("_DstBlendMode", dstMode);

        if (IsUI(batchDesc.m_UserData))
        {
            material.SetInt("_ZTestMode", (int)UnityEngine.Rendering.CompareFunction.Always);
        }
        else
        {
            material.SetInt("_ZTestMode", (int)UnityEngine.Rendering.CompareFunction.LessEqual);
        }

        if (batchDesc.HasMaterialFlag(PKFxManagerImpl.EMaterialFlags.Has_AlphaRemap))
        {
            material.EnableKeyword("PK_HAS_ALPHA_REMAP");
        }
        if (batchDesc.HasMaterialFlag(PKFxManagerImpl.EMaterialFlags.Has_AnimBlend))
        {
            material.EnableKeyword("PK_HAS_ANIM_BLEND");
        }
        if (batchDesc.HasMaterialFlag(PKFxManagerImpl.EMaterialFlags.Has_Distortion))
        {
            material.EnableKeyword("PK_HAS_DISTORTION");
        }
        if (batchDesc.HasMaterialFlag(PKFxManagerImpl.EMaterialFlags.Has_Lighting))
        {
            material.EnableKeyword("PK_HAS_LIGHTING");
        }
        if (batchDesc.HasMaterialFlag(PKFxManagerImpl.EMaterialFlags.Has_RibbonComplex))
        {
            material.EnableKeyword("PK_HAS_RIBBON_COMPLEX");
        }
        if (batchDesc.HasMaterialFlag(PKFxManagerImpl.EMaterialFlags.Has_Color))
        {
            material.EnableKeyword("PK_HAS_COLOR");
        }
        if (batchDesc.HasMaterialFlag(PKFxManagerImpl.EMaterialFlags.Has_Soft) && PKFxSettings.EnableSoftParticles)
        {
            material.EnableKeyword("PK_HAS_SOFT");
            material.SetFloat("_InvSoftnessDistance", batchDesc.m_InvSofnessDistance);
        }
        material.renderQueue = m_RenderQueue + batchDesc.m_DrawOrder;
        return(material);
    }
Ejemplo n.º 5
0
    public override Material        ResolveParticleMaterial(PKFxManagerImpl.SBatchDesc batchDesc)
    {
        Material customMat = TryFindAndInstantiateCustomMaterial(batchDesc);

        if (customMat != null)
        {
            return(customMat);
        }

        Shader shader = ResolveShader(batchDesc);

        Debug.Assert(shader != null);
        Material material = new Material(shader);

        // Set the diffuse texture:
        Texture diffuseTexture = GetTextureDiffuse(batchDesc);

        material.mainTexture = diffuseTexture;

        // Set the material uniforms:
        material.SetInt("_UniformFlags", batchDesc.m_UniformFlags);

        // We can stop here if the material is for a mesh particle:
        if (batchDesc.m_Type == PKFxManagerImpl.ERendererType.Mesh)
        {
            return(material);
        }

        // Set the alpha remap texture
        if (batchDesc.m_AlphaRemap != null)
        {
            string path = Path.GetDirectoryName(batchDesc.m_AlphaRemap) + "/" + Path.GetFileNameWithoutExtension(batchDesc.m_AlphaRemap) + "_linear" + Path.GetExtension(batchDesc.m_AlphaRemap);
            PKFxFxAsset.DependencyDesc DepDesc = PKFxManager.GetBuiltAsset().m_Dependencies.Find(x => path.Contains(x.m_Path));
            if (DepDesc != null)
            {
                Texture alphaRemapTexture = DepDesc.m_Object as Texture;
                alphaRemapTexture.wrapMode = TextureWrapMode.Clamp;
                Debug.Assert(alphaRemapTexture != null);
                material.SetTexture("_AlphaMap", alphaRemapTexture);
            }
        }

        // Set the blend mode:
        int srcMode = 0;
        int dstMode = 0;

        // Additive and distortion
        if (batchDesc.HasUniformFlag(PKFxManagerImpl.EUniformFlags.Is_Additive) ||
            batchDesc.HasUniformFlag(PKFxManagerImpl.EUniformFlags.Is_AdditiveNoAlpha) ||
            batchDesc.HasMaterialFlag(PKFxManagerImpl.EMaterialFlags.Has_Distortion))
        {
            srcMode = (int)UnityEngine.Rendering.BlendMode.One;
            dstMode = (int)UnityEngine.Rendering.BlendMode.One;
        }
        else if (batchDesc.HasUniformFlag(PKFxManagerImpl.EUniformFlags.Is_AdditiveAlphaBlend))
        {
            srcMode = (int)UnityEngine.Rendering.BlendMode.One;
            dstMode = (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha;
        }
        else         // Alpha blended
        {
            srcMode = (int)UnityEngine.Rendering.BlendMode.SrcAlpha;
            dstMode = (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha;
        }

        material.SetInt("_SrcBlendMode", srcMode);
        material.SetInt("_DstBlendMode", dstMode);

        if (IsUI(batchDesc.m_UserData))
        {
            material.SetInt("_ZTestMode", (int)UnityEngine.Rendering.CompareFunction.Always);
        }
        else
        {
            material.SetInt("_ZTestMode", (int)UnityEngine.Rendering.CompareFunction.LessEqual);
        }

        // Set the shader variation:
        if (batchDesc.HasMaterialFlag(PKFxManagerImpl.EMaterialFlags.Has_AlphaRemap))
        {
            material.EnableKeyword("PK_HAS_ALPHA_REMAP");
        }
        if (batchDesc.HasMaterialFlag(PKFxManagerImpl.EMaterialFlags.Has_AnimBlend))
        {
            material.EnableKeyword("PK_HAS_ANIM_BLEND");
        }
        if (batchDesc.HasMaterialFlag(PKFxManagerImpl.EMaterialFlags.Has_Distortion))
        {
            material.EnableKeyword("PK_HAS_DISTORTION");
        }
        if (batchDesc.HasMaterialFlag(PKFxManagerImpl.EMaterialFlags.Has_Lighting))
        {
            material.EnableKeyword("PK_HAS_LIGHTING");
        }
        if (batchDesc.HasMaterialFlag(PKFxManagerImpl.EMaterialFlags.Has_RibbonComplex))
        {
            material.EnableKeyword("PK_HAS_RIBBON_COMPLEX");
        }
        if (batchDesc.HasMaterialFlag(PKFxManagerImpl.EMaterialFlags.Has_Color))
        {
            material.EnableKeyword("PK_HAS_COLOR");
        }
        if (batchDesc.HasMaterialFlag(PKFxManagerImpl.EMaterialFlags.Has_Soft) && PKFxSettings.EnableSoftParticles)
        {
            material.EnableKeyword("PK_HAS_SOFT");
            material.SetFloat("_InvSoftnessDistance", batchDesc.m_InvSofnessDistance);
        }
        // Set the render queue:
        material.renderQueue = m_RenderQueue + batchDesc.m_DrawOrder;
        return(material);
    }