1 /**************************************************************************** 2 Copyright (c) 2008-2010 Ricardo Quesada 3 Copyright (c) 2011-2012 cocos2d-x.org 4 Copyright (c) 2013-2014 Chukong Technologies Inc. 5 6 http://www.cocos2d-x.org 7 8 Permission is hereby granted, free of charge, to any person obtaining a copy 9 of this software and associated documentation files (the "Software"), to deal 10 in the Software without restriction, including without limitation the rights 11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 copies of the Software, and to permit persons to whom the Software is 13 furnished to do so, subject to the following conditions: 14 15 The above copyright notice and this permission notice shall be included in 16 all copies or substantial portions of the Software. 17 18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 THE SOFTWARE. 25 ****************************************************************************/ 26 27 //-----------------------Shader_Position_uColor Shader Source-------------------------- 28 /** 29 * @constant 30 * @type {String} 31 */ 32 cc.SHADER_POSITION_UCOLOR_FRAG = 33 "precision lowp float;\n" 34 + "varying vec4 v_fragmentColor;\n" 35 + "void main() \n" 36 + "{ \n" 37 + " gl_FragColor = v_fragmentColor; \n" 38 + "}\n"; 39 /** 40 * @constant 41 * @type {String} 42 */ 43 cc.SHADER_POSITION_UCOLOR_VERT = 44 "attribute vec4 a_position;\n" 45 + "uniform vec4 u_color;\n" 46 + "uniform float u_pointSize;\n" 47 + "varying lowp vec4 v_fragmentColor; \n" 48 + "void main(void) \n" 49 + "{\n" 50 //+ " gl_Position = CC_MVPMatrix * a_position; \n" 51 + " gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position; \n" 52 + " gl_PointSize = u_pointSize; \n" 53 + " v_fragmentColor = u_color; \n" 54 + "}"; 55 56 //---------------------Shader_PositionColor Shader Source----------------------- 57 /** 58 * @constant 59 * @type {String} 60 */ 61 cc.SHADER_POSITION_COLOR_FRAG = 62 "precision lowp float; \n" 63 + "varying vec4 v_fragmentColor; \n" 64 + "void main() \n" 65 + "{ \n" 66 + " gl_FragColor = v_fragmentColor; \n" 67 + "} "; 68 69 /** 70 * @constant 71 * @type {String} 72 */ 73 cc.SHADER_POSITION_COLOR_VERT = 74 "attribute vec4 a_position;\n" 75 + "attribute vec4 a_color;\n" 76 + "varying lowp vec4 v_fragmentColor;\n" 77 + "void main()\n" 78 + "{\n" 79 //+ " gl_Position = CC_MVPMatrix * a_position; \n" 80 + " gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position; \n" 81 + " v_fragmentColor = a_color; \n" 82 + "}"; 83 84 // --------------------- Shader_PositionColorLengthTexture Shader source------------------------ 85 /** 86 * @constant 87 * @type {String} 88 */ 89 cc.SHADER_POSITION_COLOR_LENGTH_TEXTURE_FRAG = 90 "// #extension GL_OES_standard_derivatives : enable\n" 91 + "varying mediump vec4 v_color;\n" 92 + "varying mediump vec2 v_texcoord;\n" 93 + "void main() \n" 94 + "{ \n" 95 + "// #if defined GL_OES_standard_derivatives \n" 96 + "// gl_FragColor = v_color*smoothstep(0.0, length(fwidth(v_texcoord)), 1.0 - length(v_texcoord)); \n" 97 + "// #else \n" 98 + "gl_FragColor = v_color * step(0.0, 1.0 - length(v_texcoord)); \n" 99 + "// #endif \n" 100 + "}"; 101 102 /** 103 * @constant 104 * @type {String} 105 */ 106 cc.SHADER_POSITION_COLOR_LENGTH_TEXTURE_VERT = 107 "attribute mediump vec4 a_position; \n" 108 + "attribute mediump vec2 a_texcoord; \n" 109 + "attribute mediump vec4 a_color; \n" 110 + "varying mediump vec4 v_color; \n" 111 + "varying mediump vec2 v_texcoord; \n" 112 + "void main() \n" 113 + "{ \n" 114 + " v_color = a_color;//vec4(a_color.rgb * a_color.a, a_color.a); \n" 115 + " v_texcoord = a_texcoord; \n" 116 //+ " gl_Position = CC_MVPMatrix * a_position; \n" 117 + " gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position; \n" 118 + "}"; 119 120 // ----------------------Shader_PositionTexture Shader Source------------------------------------- 121 /** 122 * @constant 123 * @type {String} 124 */ 125 cc.SHADER_POSITION_TEXTURE_FRAG = 126 "precision lowp float; \n" 127 + "varying vec2 v_texCoord; \n" 128 + "void main() \n" 129 + "{ \n" 130 + " gl_FragColor = texture2D(CC_Texture0, v_texCoord); \n" 131 + "}"; 132 133 /** 134 * @constant 135 * @type {String} 136 */ 137 cc.SHADER_POSITION_TEXTURE_VERT = 138 "attribute vec4 a_position; \n" 139 + "attribute vec2 a_texCoord; \n" 140 + "varying mediump vec2 v_texCoord; \n" 141 + "void main() \n" 142 + "{ \n" 143 //+ " gl_Position = CC_MVPMatrix * a_position; \n" 144 + " gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position; \n" 145 + " v_texCoord = a_texCoord; \n" 146 + "}"; 147 148 // ------------------------Shader_PositionTexture_uColor Shader Source------------------------------- 149 /** 150 * @constant 151 * @type {String} 152 */ 153 cc.SHADER_POSITION_TEXTURE_UCOLOR_FRAG = 154 "precision lowp float; \n" 155 + "uniform vec4 u_color; \n" 156 + "varying vec2 v_texCoord; \n" 157 + "void main() \n" 158 + "{ \n" 159 + " gl_FragColor = texture2D(CC_Texture0, v_texCoord) * u_color; \n" 160 + "}"; 161 162 /** 163 * @constant 164 * @type {String} 165 */ 166 cc.SHADER_POSITION_TEXTURE_UCOLOR_VERT = 167 "attribute vec4 a_position;\n" 168 + "attribute vec2 a_texCoord; \n" 169 + "varying mediump vec2 v_texCoord; \n" 170 + "void main() \n" 171 + "{ \n" 172 //+ " gl_Position = CC_MVPMatrix * a_position; \n" 173 + " gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position; \n" 174 + " v_texCoord = a_texCoord; \n" 175 + "}"; 176 177 //---------------------Shader_PositionTextureA8Color Shader source------------------------------- 178 /** 179 * @constant 180 * @type {String} 181 */ 182 cc.SHADER_POSITION_TEXTURE_A8COLOR_FRAG = 183 "precision lowp float; \n" 184 + "varying vec4 v_fragmentColor; \n" 185 + "varying vec2 v_texCoord; \n" 186 + "void main() \n" 187 + "{ \n" 188 + " gl_FragColor = vec4( v_fragmentColor.rgb, \n" // RGB from uniform 189 + " v_fragmentColor.a * texture2D(CC_Texture0, v_texCoord).a \n" // A from texture and uniform 190 + " ); \n" 191 + "}"; 192 193 /** 194 * @constant 195 * @type {String} 196 */ 197 cc.SHADER_POSITION_TEXTURE_A8COLOR_VERT = 198 "attribute vec4 a_position; \n" 199 + "attribute vec2 a_texCoord; \n" 200 + "attribute vec4 a_color; \n" 201 + "varying lowp vec4 v_fragmentColor; \n" 202 + "varying mediump vec2 v_texCoord; \n" 203 + "void main() \n" 204 + "{ \n" 205 //+ " gl_Position = CC_MVPMatrix * a_position; \n" 206 + " gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position; \n" 207 + " v_fragmentColor = a_color; \n" 208 + " v_texCoord = a_texCoord; \n" 209 + "}"; 210 211 // ------------------------Shader_PositionTextureColor Shader source------------------------------------ 212 /** 213 * @constant 214 * @type {String} 215 */ 216 cc.SHADER_POSITION_TEXTURE_COLOR_FRAG = 217 "precision lowp float;\n" 218 + "varying vec4 v_fragmentColor; \n" 219 + "varying vec2 v_texCoord; \n" 220 + "void main() \n" 221 + "{ \n" 222 + " gl_FragColor = v_fragmentColor * texture2D(CC_Texture0, v_texCoord); \n" 223 + "}"; 224 225 /** 226 * @constant 227 * @type {String} 228 */ 229 cc.SHADER_POSITION_TEXTURE_COLOR_VERT = 230 "attribute vec4 a_position; \n" 231 + "attribute vec2 a_texCoord; \n" 232 + "attribute vec4 a_color; \n" 233 + "varying lowp vec4 v_fragmentColor; \n" 234 + "varying mediump vec2 v_texCoord; \n" 235 + "void main() \n" 236 + "{ \n" 237 //+ " gl_Position = CC_MVPMatrix * a_position; \n" 238 + " gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position; \n" 239 + " v_fragmentColor = a_color; \n" 240 + " v_texCoord = a_texCoord; \n" 241 + "}"; 242 243 //-----------------------Shader_PositionTextureColorAlphaTest_frag Shader Source---------------------------- 244 /** 245 * @constant 246 * @type {String} 247 */ 248 cc.SHADER_POSITION_TEXTURE_COLOR_ALPHATEST_FRAG = 249 "precision lowp float; \n" 250 + "varying vec4 v_fragmentColor; \n" 251 + "varying vec2 v_texCoord; \n" 252 + "uniform float CC_alpha_value; \n" 253 + "void main() \n" 254 + "{ \n" 255 + " vec4 texColor = texture2D(CC_Texture0, v_texCoord); \n" 256 // mimic: glAlphaFunc(GL_GREATER) 257 //pass if ( incoming_pixel >= CC_alpha_value ) => fail if incoming_pixel < CC_alpha_value 258 + " if ( texColor.a <= CC_alpha_value ) \n" 259 + " discard; \n" 260 + " gl_FragColor = texColor * v_fragmentColor; \n" 261 + "}"; 262 263 //-----------------------ShaderEx_SwitchMask_frag Shader Source---------------------------- 264 /** 265 * @constant 266 * @type {String} 267 */ 268 cc.SHADEREX_SWITCHMASK_FRAG = 269 "precision lowp float; \n" 270 + "varying vec4 v_fragmentColor; \n" 271 + "varying vec2 v_texCoord; \n" 272 + "uniform sampler2D u_texture; \n" 273 + "uniform sampler2D u_mask; \n" 274 + "void main() \n" 275 + "{ \n" 276 + " vec4 texColor = texture2D(u_texture, v_texCoord); \n" 277 + " vec4 maskColor = texture2D(u_mask, v_texCoord); \n" 278 + " vec4 finalColor = vec4(texColor.r, texColor.g, texColor.b, maskColor.a * texColor.a); \n" 279 + " gl_FragColor = v_fragmentColor * finalColor; \n" 280 + "}";