Exemplo n.º 1
0
        public static bool ExportShader(AssetItem item, string exportPath)
        {
            var exportFullName = exportPath + item.Text + ".shader";

            if (ExportFileExists(exportFullName))
            {
                return(false);
            }
            var m_Shader = (Shader)item.Asset;

            if (m_Shader.compressedBlob != null) //5.5 and up
            {
                var strs = ShaderConverter.ConvertMultiple(m_Shader);
                for (int i = 0; i < strs.Length; i++)
                {
                    var platformName = ShaderConverter.GetPlatformString(m_Shader.platforms[i]);
                    File.WriteAllText($"{exportPath}{item.Text}_{platformName}.shader", strs[i]);
                }
            }
            else
            {
                var str = ShaderConverter.Convert(m_Shader);
                File.WriteAllText(exportFullName, str);
            }
            return(true);
        }
Exemplo n.º 2
0
        public static bool ExportShader(AssetItem item, string exportPath)
        {
            var exportFullName = exportPath + item.Text + ".shader";

            if (ExportFileExists(exportFullName))
            {
                return(false);
            }
            var str = ShaderConverter.Convert((Shader)item.Asset);

            File.WriteAllText(exportFullName, str ?? "Serialized Shader can't be read");
            return(true);
        }
Exemplo n.º 3
0
        public static void FixPixelShader(PixelShader ps)
        {
            FixDrawModeList(ps.DrawModes);

            // Disable z_only
            if (ps.DrawModes.Count > 18)
            {
                ps.DrawModes[18].Index = 0;
                ps.DrawModes[18].Count = 0;
            }

            var usedShaders = new bool[ps.PixelShaders.Count];

            for (var i = 0; i < ps.DrawModes.Count; i++)
            {
                var mode = ps.DrawModes[i];
                for (var j = 0; j < mode.Count; j++)
                {
                    if (i != 0 || IsDecalShader)
                    {
                        Console.WriteLine("- Recompiling pixel shader {0}...", mode.Index + j);
                        var shader      = ps.PixelShaders[mode.Index + j];
                        var newBytecode = ShaderConverter.ConvertNewPixelShaderToOld(shader.Unknown2, i);
                        if (newBytecode != null)
                        {
                            shader.Unknown2 = newBytecode;
                        }
                    }
                    usedShaders[mode.Index + j] = true;
                }
            }

            // Null unused shaders
            for (var i = 0; i < ps.PixelShaders.Count; i++)
            {
                if (!usedShaders[i])
                {
                    ps.PixelShaders[i].Unknown2 = null;
                }
            }
        }
Exemplo n.º 4
0
        public static bool ExportShader(AssetItem item, string exportPath)
        {
            var m_Shader = (Shader)item.Asset;

            if (m_Shader.compressedBlob != null) //5.5 and up
            {
                var strs = ShaderConverter.ConvertMultiple(m_Shader);
                for (int i = 0; i < strs.Length; i++)
                {
                    var platformName   = ShaderConverter.GetPlatformString(m_Shader.platforms[i]);
                    var exportFullName = GetExportFullName(exportPath, item.Text + "_" + platformName, ".shader");
                    File.WriteAllText(exportFullName, strs[i]);
                }
            }
            else
            {
                var str = ShaderConverter.Convert(m_Shader);
                File.WriteAllText(GetExportFullName(exportPath, item.Text, ".shader"), str);
            }
            return(true);
        }
Exemplo n.º 5
0
        public static void FixGlobalVertexShader(GlobalVertexShader glvs)
        {
            var usedShaders = new bool[glvs.VertexShaders.Count];

            for (var i = 0; i < glvs.VertexTypes.Count; i++)
            {
                FixDrawModeList(glvs.VertexTypes[i].DrawModes);
                if (glvs.VertexTypes[i].DrawModes.Count > 18)
                {
                    glvs.VertexTypes[i].DrawModes[18].ShaderIndex = -1; // Disable z_only
                }
                var type = (VertexType)i;
                for (var j = 0; j < glvs.VertexTypes[i].DrawModes.Count; j++)
                {
                    var mode = glvs.VertexTypes[i].DrawModes[j];
                    if (mode.ShaderIndex < 0)
                    {
                        continue;
                    }
                    Console.WriteLine("- Recompiling vertex shader {0}...", mode.ShaderIndex);
                    var shader      = glvs.VertexShaders[mode.ShaderIndex];
                    var newBytecode = ShaderConverter.ConvertNewVertexShaderToOld(shader.Unknown2, j, type);
                    if (newBytecode != null)
                    {
                        shader.Unknown2 = newBytecode;
                    }
                    usedShaders[mode.ShaderIndex] = true;
                }
            }

            // Null unused shaders
            for (var i = 0; i < glvs.VertexShaders.Count; i++)
            {
                if (!usedShaders[i])
                {
                    glvs.VertexShaders[i].Unknown2 = null;
                }
            }
        }
Exemplo n.º 6
0
 // Uses StubbedShaderConverter to convert all materials within the Asset Bundle on Awake().
 // This now sorts out CloudRemap materials as well! Woo!
 private static void ConvertBundleMaterials(AssetBundle inAssetBundle)
 {
     ShaderConverter.ConvertStubbedShaders(inAssetBundle);
 }