コード例 #1
0
        private static RuntimeShaderProfilesAsset Create()
        {
            RuntimeShaderProfilesAsset asset = ScriptableObject.CreateInstance <RuntimeShaderProfilesAsset>();

            asset.ShaderInfo = new List <RuntimeShaderInfo>();

            ShaderInfo[]     allShaderInfo = ShaderUtil.GetAllShaderInfo().OrderBy(si => si.name).ToArray();
            HashSet <string> shaderNames   = new HashSet <string>();

            for (int i = 0; i < allShaderInfo.Length; ++i)
            {
                ShaderInfo shaderInfo = allShaderInfo[i];
                Shader     shader     = Shader.Find(shaderInfo.name);

                RuntimeShaderInfo profile = Create(shader);
                asset.ShaderInfo.Add(profile);

                if (shaderNames.Contains(shaderInfo.name))
                {
                    Debug.LogWarning("Shader with same name already exists. Consider renaming " + shaderInfo.name + " shader. File: " + AssetDatabase.GetAssetPath(shader));
                }
                else
                {
                    shaderNames.Add(shaderInfo.name);
                }
            }
            return(asset);
        }
コード例 #2
0
        public RuntimeShaderUtil()
        {
            RuntimeShaderProfilesAsset asset = Resources.Load <RuntimeShaderProfilesAsset>("Lists/ShaderProfiles");

            if (asset == null)
            {
                Debug.LogError("Unable to find RuntimeShaderProfilesAsset. Click Tools->Runtime SaveLoad2->Libraries->Create Shader Profiles");
                return;
            }
            m_nameToShaderInfo = new Dictionary <string, RuntimeShaderInfo>();
            for (int i = 0; i < asset.ShaderInfo.Count; ++i)
            {
                RuntimeShaderInfo info = asset.ShaderInfo[i];
                if (info != null)
                {
                    if (m_nameToShaderInfo.ContainsKey(info.Name))
                    {
                        Debug.LogWarning("Shader with " + info.Name + " already exists.");
                    }
                    else
                    {
                        m_nameToShaderInfo.Add(info.Name, info);
                    }
                }
            }
        }
コード例 #3
0
        public RuntimeShaderInfo GetShaderInfo(Shader shader)
        {
            RuntimeShaderInfo shaderInfo = null;

            if (m_nameToShaderInfo.TryGetValue(shader.name, out shaderInfo))
            {
                return(shaderInfo);
            }
            return(null);
        }
コード例 #4
0
        private static RuntimeShaderInfo Create(Shader shader)
        {
            if (shader == null)
            {
                throw new System.ArgumentNullException("shader");
            }

            int propertyCount = ShaderUtil.GetPropertyCount(shader);

            RuntimeShaderInfo shaderInfo = new RuntimeShaderInfo();

            shaderInfo.Name                 = shader.name;
            shaderInfo.PropertyCount        = propertyCount;
            shaderInfo.PropertyDescriptions = new string[propertyCount];
            shaderInfo.PropertyNames        = new string[propertyCount];
            shaderInfo.PropertyRangeLimits  = new RuntimeShaderInfo.RangeLimits[propertyCount];
            shaderInfo.PropertyTexDims      = new TextureDimension[propertyCount];
            shaderInfo.PropertyTypes        = new RTShaderPropertyType[propertyCount];
            shaderInfo.IsHidden             = new bool[propertyCount];

            for (int i = 0; i < propertyCount; ++i)
            {
                shaderInfo.PropertyDescriptions[i] = ShaderUtil.GetPropertyDescription(shader, i);
                shaderInfo.PropertyNames[i]        = ShaderUtil.GetPropertyName(shader, i);
                shaderInfo.PropertyRangeLimits[i]  = new RuntimeShaderInfo.RangeLimits(
                    ShaderUtil.GetRangeLimits(shader, i, 0),
                    ShaderUtil.GetRangeLimits(shader, i, 1),
                    ShaderUtil.GetRangeLimits(shader, i, 2));
                shaderInfo.PropertyTexDims[i] = ShaderUtil.GetTexDim(shader, i);

                RTShaderPropertyType          rtType = RTShaderPropertyType.Unknown;
                ShaderUtil.ShaderPropertyType type   = ShaderUtil.GetPropertyType(shader, i);
                if (m_typeToType.ContainsKey(type))
                {
                    rtType = m_typeToType[type];
                }

                shaderInfo.PropertyTypes[i] = rtType;
                shaderInfo.IsHidden[i]      = ShaderUtil.IsShaderPropertyHidden(shader, i);
            }
            return(shaderInfo);
        }