Exemple #1
0
        public static MaterialContext GetContext()
        {
            MaterialContext context = new MaterialContext();

            context.textureValue   = new List <ShaderTexPropertyValue>();
            context.shaderIDs      = new List <ShaderPropertyValue>();
            context.customMatIndex = -1;
            return(context);
        }
Exemple #2
0
        internal static void AddMaterialProperty(ref MaterialContext context, Vector4 param, int shaderID)
        {
            ShaderPropertyValue stpv = new ShaderPropertyValue()
            {
                shaderID = shaderID,
                value    = param,
            };

            context.shaderIDs.Add(stpv);
        }
Exemple #3
0
        internal static void AddMaterialProperty(ref MaterialContext context, Texture tex, int shaderID)
        {
            ShaderTexPropertyValue stpv = new ShaderTexPropertyValue()
            {
                shaderID = shaderID,
                value    = tex,
                path     = tex.name
            };

            context.textureValue.Add(stpv);
        }
Exemple #4
0
        internal static bool AddMaterialProperty(
            ref MaterialContext context,
            Material material,
            ShaderValue sv,
            List <ShaderProperty> shaderPropertyKey)
        {
            if (sv.name == "_Cutoff" ||
                sv.name == "_SrcBlend" ||
                sv.name == "_DstBlend" ||
                sv.name == "_ZWrite" ||
                sv.name == "_DebugMode")
            {
                return(false);
            }

            ShaderProperty sp = shaderPropertyKey.Find((x) => { return(x.shaderProperty == sv.name); });

            if (sp != null)
            {
                return(AddMaterialProperty(ref context, material, sp));
            }
            else
            {
                if (shaderNameKeys == null)
                {
                    shaderNameKeys = System.Enum.GetNames(typeof(EShaderKeyID));
                    for (int i = 0; i < shaderNameKeys.Length; ++i)
                    {
                        shaderNameKeys[i] = "_" + shaderNameKeys[i];
                    }
                }
                for (int i = 0; i < shaderNameKeys.Length; ++i)
                {
                    if (shaderNameKeys[i] == sv.name)
                    {
                        shareSp.shaderID       = i;
                        shareSp.isTex          = sv is ShaderTexValue;
                        shareSp.shaderProperty = sv.name;
                        return(AddMaterialProperty(ref context, material, shareSp));
                    }
                }
                Debug.LogErrorFormat("null property:{0} mat:{1}", sv.name, material.name);
                return(false);
            }
        }
Exemple #5
0
 internal static bool AddMaterialProperty(ref MaterialContext context, Material material, ShaderProperty sp)
 {
     if (material.HasProperty(sp.shaderProperty))
     {
         if (sp.isTex)
         {
             Texture tex = material.GetTexture(sp.shaderProperty);
             if (tex != null)
             {
                 ShaderTexPropertyValue stpv = new ShaderTexPropertyValue()
                 {
                     shaderID = sp.shaderID,
                     value    = tex,
                     path     = tex.name
                 };
                 context.textureValue.Add(stpv);
                 return(true);
             }
             else
             {
                 Debug.LogErrorFormat("null tex property:{0} mat:{1}", sp.shaderProperty, material.name);
                 return(false);
             }
         }
         else
         {
             Vector4             param = material.GetVector(sp.shaderProperty);
             ShaderPropertyValue spv   = new ShaderPropertyValue()
             {
                 shaderID = sp.shaderID,
                 value    = param,
             };
             context.shaderIDs.Add(spv);
             return(true);
         }
     }
     return(false);
 }