Exemple #1
0
        public static ShaderInfo CreateShaderInfo(string assetPath)
        {
            if (!EditorPath.IsShader(assetPath))
            {
                return(null);
            }

            ShaderInfo shaderInfo = null;

            if (!_dictShaderInfo.TryGetValue(assetPath, out shaderInfo))
            {
                shaderInfo = new ShaderInfo();
                _dictShaderInfo.Add(assetPath, shaderInfo);
            }
            Shader shader     = AssetDatabase.LoadAssetAtPath <Shader>(assetPath);
            string shaderText = File.ReadAllText(assetPath);

            //ShaderUtil.OpenCompiledShader(shader, (int)ShaderPlatformModes.Custom, 1 << (int)ShaderUtil.ShaderCompilerPlatformType.D3D11, false);

            typeof(ShaderUtil).GetMethod("OpenCompiledShader", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, new object[] { shader, (int)ShaderPlatformModes.Custom, 1 << (int)ShaderCompilerPlatformType.D3D11, false });
            try
            {
                CompiledShaderInfo compiledShaderInfo = CompiledShaderInfo.CreateCompiledShaderInfo(shaderText);
                shaderInfo.Path = assetPath;
                //shaderInfo.MaxLOD = ShaderUtil.GetLOD(shader);
                //shaderInfo.Variant = ShaderUtil.GetVariantCount(shader, true);
                shaderInfo.Property    = ShaderUtil.GetPropertyCount(shader);
                shaderInfo.RenderQueue = shader.renderQueue;
                shaderInfo.Pass        = compiledShaderInfo.GetPass();
                shaderInfo.Instruction = compiledShaderInfo.GetInstruction();
                shaderInfo.SubShader   = compiledShaderInfo.GetSubShaderCount();
                shaderInfo.Sample      = compiledShaderInfo.GetSample();
                shaderInfo.RenderType  = compiledShaderInfo.GetRenderType();
                shaderInfo.CompiledShaderInfoList.Add(compiledShaderInfo);
            }
            catch (Exception ex)
            {
                Debug.LogError(ex.Message);
                return(null);
            }
            return(shaderInfo);
        }