Ejemplo n.º 1
0
    private Shader                          ResolveShader(PKFxManagerImpl.SBatchDesc batchDesc)
    {
        Shader shader     = null;
        string shaderPath = ExtractShaderPath(batchDesc.m_UserData);

        if (!string.IsNullOrEmpty(shaderPath))
        {
            shader = Shader.Find(shaderPath);
        }
        if (shader == null)
        {
            if (batchDesc.m_Type != PKFxManagerImpl.ERendererType.Mesh)
            {
                shader = m_ParticleShader;
            }
            else
            {
                if (batchDesc.HasUniformFlag(PKFxManagerImpl.EUniformFlags.Is_Additive) ||
                    batchDesc.HasUniformFlag(PKFxManagerImpl.EUniformFlags.Is_AdditiveNoAlpha))
                {
                    shader = m_TransparentMeshShader;
                }
                else
                {
                    shader = m_OpaqueMeshShader;
                }
            }
        }
        return(shader);
    }
Ejemplo n.º 2
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.º 3
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);
    }