예제 #1
0
 public new static string Export(WXEffect wxbb_shader)
 {
     return(string.Format(
                "#include <common.inc>\n\n// vertex的输出,pixel的输入,请根据原shader文件修改\nstruct FVertexOutput\n{{\n    float4 Position : SV_Position;\n    float2 TexCoord : TEXCOORD0;\n}};\n\n// 根据原shader的properties自动生成\n{0}\n\n// 根据原shader的properties自动生成\n{1}\n\nvoid Main(in FEffect3DVertexInput In, out FVertexOutput Out)\n{{\n    FVertexProcessOutput VPOut;\n	Effect3DVertexProcess(In, VPOut);\n\n    Out.Position = WorldToClipPosition(VPOut.WorldPosition);\n\n  Out.TexCoord = TRANSFER_TEXCOORD(VPOut.TexCoord, _MainTex_ST);\n }}",
                GetUniformString(wxbb_shader),
                GetTextureDeclaration(wxbb_shader)
                ));
 }
예제 #2
0
        public override void onParse(WXMaterial wxbb_material)
        {
            Material material = this.m_material;

            // 生成shader模板
            Shader   shader      = m_material.shader;
            WXEffect wxbb_effect = new WXEffect(shader);

            this.dependenciesAdder(wxbb_effect);

            if (shader == null)
            {
                Debug.LogErrorFormat("材质{0}缺少自定义shader", material.name);
                return;
            }

            // 指定shader名字
            SetEffect(wxbb_effect.Export(null));

            for (int i = 0; i < ShaderUtil.GetPropertyCount(shader); i++)
            {
                string name = ShaderUtil.GetPropertyName(shader, i);
                ShaderUtil.ShaderPropertyType type = ShaderUtil.GetPropertyType(shader, i);
                switch (type)
                {
                case ShaderUtil.ShaderPropertyType.Float:
                case ShaderUtil.ShaderPropertyType.Range:
                    AddShaderParam(name, material.GetFloat(name));
                    break;

                case ShaderUtil.ShaderPropertyType.Vector:
                    Vector4 v = material.GetVector(name);
                    AddShaderParam(name, new float[] { v.x, v.y, v.z, v.w });
                    break;

                case ShaderUtil.ShaderPropertyType.Color:
                    AddShaderParam(name, material.GetColor(name), true);
                    break;

                case ShaderUtil.ShaderPropertyType.TexEnv:
                    AddTexture(name, name);
                    Vector4 st = material.GetVector(name + "_ST");
                    AddShaderParam(name + "_ST", new float[] { st.x, st.y, st.z, st.w });
                    break;
                }
            }
        }
예제 #3
0
        static protected string GetTextureDeclaration(WXEffect wxbb_shader)
        {
            string result = "";

            foreach (WXEffect.property texture in wxbb_shader.textures)
            {
                if (texture.type == "TextureCube")
                {
                    result += string.Format("DECLARE_CUBEMAP({0});\n", texture.key);
                }
                else
                {
                    result += string.Format("DECLARE_TEXTURE({0});\n", texture.key);
                }
            }
            return(result);
        }
예제 #4
0
        static protected string GetUniformString(WXEffect wxbb_shader)
        {
            string result = "cbuffer custom {\n";

            foreach (WXEffect.property property in wxbb_shader.properties)
            {
                string typeName;
                if (!typeMap.TryGetValue(property.type, out typeName))
                {
                    typeName = "float";
                }
                result += string.Format("    {0} {1};\n", typeName, property.key);
            }
            foreach (WXEffect.property texture in wxbb_shader.textures)
            {
                result += string.Format("    float4 {0}_ST;\n", texture.key);
            }
            return(result + "}\n");
        }
 public WXPixelFile(WXEffect effect) : base(effect.unityAssetPath)
 {
     this.effect = effect;
 }
 public WXVertexFile(WXEffect effect) : base(effect.unityAssetPath)
 {
     this.effect = effect;
 }
예제 #7
0
 static public string Export(WXEffect wxbb_shader)
 {
     return("");
 }