コード例 #1
0
    BuildUnifiedShader(
        string srcShaderText,
        _AlphaBlend alphaBlend)
    {
        string newShaderText = string.Copy(srcShaderText);
        string newShaderName = "UniColor" + alphaBlend.name;

        newShaderText = newShaderText.Replace("%SHADER_NAME%", newShaderName);
        newShaderText = newShaderText.Replace("%BLEND_ARGUMENTS%", alphaBlend.blendMode);

        // create file as .shader text file
        string shaderFilePath = _shaderPath + "/_Ss" + newShaderName + ".shader";

        File.WriteAllText(shaderFilePath, newShaderText);        //, SsEncoding.SJIS);
        AssetDatabase.ImportAsset(shaderFilePath);

        // add to container.
        _shaderContainer._shaders.Add(AssetDatabase.LoadAssetAtPath(shaderFilePath, typeof(Shader)) as Shader);
    }
コード例 #2
0
    BuildShader(
        string srcShaderText,
        string betterShader,
        _ColorBlend colorBlend,
        _AlphaBlend alphaBlend,
        _MaterialColorBlends matColorBlend)
    {
        string newShaderText = string.Copy(srcShaderText);

        // make shader name by combination of each blend method
        string newShaderName = colorBlend.name + alphaBlend.name + matColorBlend.name;

        newShaderText = newShaderText.Replace("%SHADER_NAME%", newShaderName);

        // add properties
        newShaderText = newShaderText.Replace("%COLOR_PROPERTY%", matColorBlend.property);
        newShaderText = newShaderText.Replace("%PROPERTY%", colorBlend.property);

        // add material color setting in Category area
        newShaderText = newShaderText.Replace("%MATERIAL%", matColorBlend.category);

        // add alpha blend setting in Category area
        newShaderText = newShaderText.Replace("%BLEND_ARGUMENTS%", alphaBlend.blendMode);
        newShaderText = newShaderText.Replace("%BLEND_OP%",
                                              alphaBlend.blendOp == null ? "" : "BlendOp " + alphaBlend.blendOp);

        // add better shader written in Cg as SubShader
        newShaderText = newShaderText.Replace("%BETTER_SHADER%", betterShader);

        // add extra SetTexture depending on alpha/color blend method
        newShaderText = newShaderText.Replace("%SET_TEXTURE_0%", "SetTexture [_MainTex] {" + colorBlend.setTexture_0 + "}");
        string replaced = colorBlend.setTexture_1;

        if (replaced.Length > 0)
        {
            replaced = "SetTexture [_MainTex] {" + replaced + "}";
        }
        newShaderText = newShaderText.Replace("%SET_TEXTURE_1%", replaced);

        // add material color combiner
        newShaderText = newShaderText.Replace("%SET_TEXTURE_2%", matColorBlend.combiner);

        // add extra combiner for multiple alpha blending
        string additive = colorBlend.name == "NonColor" ? alphaBlend.additive : "";

        newShaderText = newShaderText.Replace("%ADDITIVE%", additive);

        // add something needed in fragment shader
        newShaderText = newShaderText.Replace("%COLOR_BLEND_FUNC%", colorBlend.cgCode);
        newShaderText = newShaderText.Replace("%FRAG_MAT_COLOR%", matColorBlend.cgCode);
        newShaderText = newShaderText.Replace("%FRAG_ADDITIVE%", alphaBlend.fragAdditive);

        // create file as .shader text file
        string shaderFilePath = _shaderPath + "/_Ss" + newShaderName + ".shader";

        File.WriteAllText(shaderFilePath, newShaderText);        //, SsEncoding.SJIS);
        AssetDatabase.ImportAsset(shaderFilePath);

        // add to container.
        _shaderContainer._shaders.Add(AssetDatabase.LoadAssetAtPath(shaderFilePath, typeof(Shader)) as Shader);
    }