public MaterialPropertyDescriptor(object target, string label, RTShaderPropertyType type, PropertyInfo propertyInfo, RuntimeShaderInfo.RangeLimits limits, TextureDimension dims, PropertyEditorCallback callback)
 {
     Target               = target;
     Label                = label;
     Type                 = type;
     PropertyInfo         = propertyInfo;
     Limits               = limits;
     TexDims              = dims;
     ValueChangedCallback = callback;
 }
Exemple #2
0
 public MaterialPropertyDescriptor(object[] targets, object[] acessors, string label, RTShaderPropertyType type, PropertyInfo propertyInfo, RuntimeShaderInfo.RangeLimits limits, TextureDimension dims, PropertyEditorCallback callback, Action <object, object> eraseTargetCallback)
 {
     Targets              = targets;
     Accessors            = acessors;
     Label                = label;
     Type                 = type;
     PropertyInfo         = propertyInfo;
     Limits               = limits;
     TexDims              = dims;
     ValueChangedCallback = callback;
     EraseTargetCallback  = eraseTargetCallback;
 }
        public static MaterialPropertyDescriptor[] GetProperties(Material material)
        {
            RuntimeShaderInfo  shaderInfo = null;
            IRuntimeShaderUtil shaderUtil = IOC.Resolve <IRuntimeShaderUtil>();

            if (shaderUtil != null)
            {
                shaderInfo = shaderUtil.GetShaderInfo(material.shader);
            }

            if (shaderInfo == null)
            {
                return(null);
            }

            List <MaterialPropertyDescriptor> descriptors = new List <MaterialPropertyDescriptor>();

            if (shaderInfo != null)
            {
                for (int i = 0; i < shaderInfo.PropertyCount; ++i)
                {
                    bool isHidden = shaderInfo.IsHidden[i];
                    if (isHidden)
                    {
                        continue;
                    }

                    string propertyDescr = shaderInfo.PropertyDescriptions[i];
                    string propertyName  = shaderInfo.PropertyNames[i];
                    RTShaderPropertyType          propertyType = shaderInfo.PropertyTypes[i];
                    RuntimeShaderInfo.RangeLimits limits       = shaderInfo.PropertyRangeLimits[i];
                    TextureDimension dim          = shaderInfo.PropertyTexDims[i];
                    PropertyInfo     propertyInfo = GetPropertyInfo(propertyType, dim);

                    if (propertyInfo == null)
                    {
                        continue;
                    }

                    MaterialPropertyDescriptor propertyDescriptor = CreatePropertyDescriptor(material, propertyInfo, propertyDescr, propertyName, propertyType, dim, limits);
                    descriptors.Add(propertyDescriptor);
                }
            }
            return(descriptors.ToArray());
        }
 public static MaterialPropertyDescriptor CreatePropertyDescriptor(Material material, PropertyInfo propertyInfo, string propertyDescr, string propertyName, RTShaderPropertyType propertyType, TextureDimension dim, RuntimeShaderInfo.RangeLimits limits)
 {
     return(new MaterialPropertyDescriptor(
                material,
                new MaterialPropertyAccessor(material, propertyName),
                propertyDescr, propertyType, propertyInfo, limits, dim, null,
                (accessorRef, newTarget) =>
     {
         MaterialPropertyAccessor accessor = (MaterialPropertyAccessor)accessorRef;
         accessor.Material = newTarget as Material;
     }));
 }
Exemple #5
0
        public MaterialPropertyDescriptor[] GetProperties(MaterialEditor editor)
        {
            RuntimeShaderInfo shaderInfo = RuntimeShaderUtil.GetShaderInfo(editor.Material.shader);

            if (shaderInfo == null)
            {
                return(null);
            }
            List <MaterialPropertyDescriptor> descriptors = new List <MaterialPropertyDescriptor>();

            for (int i = 0; i < shaderInfo.PropertyCount; ++i)
            {
                bool isHidden = shaderInfo.IsHidden[i];
                if (isHidden)
                {
                    continue;
                }

                string propertyDescr = shaderInfo.PropertyDescriptions[i];
                string propertyName  = shaderInfo.PropertyNames[i];
                if (propertyName != "_Color" && propertyName != "_MainTex")
                {
                    continue;
                }

                RTShaderPropertyType          propertyType = shaderInfo.PropertyTypes[i];
                RuntimeShaderInfo.RangeLimits limits       = shaderInfo.PropertyRangeLimits[i];
                TextureDimension dim          = shaderInfo.PropertyTexDims[i];
                PropertyInfo     propertyInfo = null;
                switch (propertyType)
                {
                case RTShaderPropertyType.Color:
                    propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Color);
                    break;

                case RTShaderPropertyType.Float:
                    propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Float);
                    break;

                case RTShaderPropertyType.Range:
                    propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Float);
                    break;

                case RTShaderPropertyType.TexEnv:
                    switch (dim)
                    {
                    case TextureDimension.Any:
                        propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Texture);
                        break;

                    case TextureDimension.Cube:
                        propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Cubemap);
                        break;

                    case TextureDimension.None:
                        propertyInfo = null;
                        break;

                    case TextureDimension.Tex2D:
                        propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Texture2D);
                        break;

                    case TextureDimension.Tex2DArray:
                        propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Texture2DArray);
                        break;

                    case TextureDimension.Tex3D:
                        propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Texture3D);
                        break;

                    case TextureDimension.Unknown:
                        propertyInfo = null;
                        break;
                    }

                    break;

                case RTShaderPropertyType.Vector:
                    propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Float);
                    break;
                }

                if (propertyInfo == null)
                {
                    continue;
                }

                MaterialPropertyAccessor   accessor           = new MaterialPropertyAccessor(editor.Material, propertyName);
                MaterialPropertyDescriptor propertyDescriptor = new MaterialPropertyDescriptor(accessor, propertyDescr, propertyType, propertyInfo, limits, dim, null);
                descriptors.Add(propertyDescriptor);
            }

            return(descriptors.ToArray());
        }
Exemple #6
0
 public MaterialPropertyDescriptor(object target, object acessor, string label, RTShaderPropertyType type, PropertyInfo propertyInfo, RuntimeShaderInfo.RangeLimits limits, TextureDimension dims, PropertyEditorCallback callback, Action <object, object> eraseTargetCallback)
     : this(new[] { target }, new[] { acessor }, label, type, propertyInfo, limits, dims, callback, eraseTargetCallback)
 {
 }
Exemple #7
0
        public MaterialPropertyDescriptor[] GetProperties(MaterialEditor editor, object converter)
        {
            RuntimeShaderInfo  shaderInfo = null;
            IRuntimeShaderUtil shaderUtil = IOC.Resolve <IRuntimeShaderUtil>();

            if (shaderUtil != null)
            {
                shaderInfo = shaderUtil.GetShaderInfo(editor.Material.shader);
            }


            if (shaderInfo == null)
            {
                return(null);
            }

            List <MaterialPropertyDescriptor> descriptors = new List <MaterialPropertyDescriptor>();

            if (shaderInfo != null)
            {
                for (int i = 0; i < shaderInfo.PropertyCount; ++i)
                {
                    bool isHidden = shaderInfo.IsHidden[i];
                    if (isHidden)
                    {
                        continue;
                    }

                    string propertyDescr = shaderInfo.PropertyDescriptions[i];
                    string propertyName  = shaderInfo.PropertyNames[i];
                    RTShaderPropertyType          propertyType = shaderInfo.PropertyTypes[i];
                    RuntimeShaderInfo.RangeLimits limits       = shaderInfo.PropertyRangeLimits[i];
                    TextureDimension dim          = shaderInfo.PropertyTexDims[i];
                    PropertyInfo     propertyInfo = null;
                    switch (propertyType)
                    {
                    case RTShaderPropertyType.Color:
                        propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Color, "Color");
                        break;

                    case RTShaderPropertyType.Float:
                        propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Float, "Float");
                        break;

                    case RTShaderPropertyType.Range:
                        propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Float, "Float");
                        break;

                    case RTShaderPropertyType.TexEnv:
                        switch (dim)
                        {
                        case TextureDimension.Any:
                            propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Texture, "Texture");
                            break;

                        case TextureDimension.Cube:
                            propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Cubemap, "Cubemap");
                            break;

                        case TextureDimension.None:
                            propertyInfo = null;
                            break;

                        case TextureDimension.Tex2D:
                            propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Texture2D, "Texture2D");
                            break;

                        case TextureDimension.Tex2DArray:
                            propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Texture2DArray, "Texture2DArray");
                            break;

                        case TextureDimension.Tex3D:
                            propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Texture3D, "Texture3D");
                            break;

                        case TextureDimension.Unknown:
                            propertyInfo = null;
                            break;
                        }

                        break;

                    case RTShaderPropertyType.Vector:
                        propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Vector, "Vector");
                        break;
                    }

                    if (propertyInfo == null)
                    {
                        continue;
                    }

                    MaterialPropertyDescriptor propertyDescriptor = new MaterialPropertyDescriptor(
                        editor.Material,
                        new MaterialPropertyAccessor(editor.Material, propertyName),
                        propertyDescr, propertyType, propertyInfo, limits, dim, null,
                        (accessorRef, newTarget) =>
                    {
                        MaterialPropertyAccessor accessor = (MaterialPropertyAccessor)accessorRef;
                        accessor.Material = newTarget as Material;
                    });
                    descriptors.Add(propertyDescriptor);
                }
            }

            return(descriptors.ToArray());
        }