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.