Cocos Creator Shader Tools

Source: Internet
Author: User

11 so passed, no big achievement, but still write a summary of it. A few days ago with Cocos Creator write a demo, involved in shader development, and Cocos has been no good shader tools, on the whim to develop a. Spent two days, simulation unity Shader completed a set of basic material framework, because do not know how to expand the editor, there is no writing tools, the back of the Cocos Creator Editor extension function more perfect.

The source has been put on GitHub, poke here. Shader's syntax is similar to Unity Shader, and the detailed instructions are written on the GitHub Project homepage, as follows:

Shader "Simpleshader" {properties{//material Properties _maintex ("Main Tex", texture) = "";
    _color ("Main Color", color) = (1, 1, 1, 1); } subshader{pass{//VARIANT shader macro list.
            Shader will generate different versions of shader variants = (Enable_color, enable_texture) depending on the arrangement of the macros;
                Vertex shader Source vsh = ' attribute Vec4 a_position;
                Attribute VEC2 A_texcoord;
                Varying VEC2 V_texcoord;
                    void Main () {gl_position = Cc_pmatrix * a_position;
                V_texcoord = A_texcoord;
            }
            `;
            Fragment shader Source FSH = ' #ifdef gl_es precision mediump float;
                #endif #ifdef enable_texture varying vec2 v_texcoord;
            Uniform sampler2d _maintex;
            #endif #ifdef enable_color uniform vec4 _color;
#endif                void Main () {VEC4 color = VEC4 (1, 1, 1, 1);
            #ifdef Enable_texture color = texture2d (_maintex, V_texcoord);
            #endif #ifdef enable_color COLOR *= _color;
                #endif gl_fragcolor = color;
        }
            `; }
    }
}

The material format is as follows:

{
    "Shaderpath": "Resources/shaders/simple-shader.shader",
    "values": {
        "_maintex": "Resources/textures /tex00.jpg ",
        " _color ": [1, 0, 0, 1]
    },
    " variants ": [" Enable_color "," Enable_texture "]
}

The source code contains a simple set of material frames, and a shader (non-GLSL) parser. The tool generates different shader objects (Glprogram) based on the list of Variant macros provided in the shader file, and the material system uses a macro list to match the appropriate shader object, then synthesizes the glprogramstate and finally assigns node.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.