1 /**************************************************************************** 2 Copyright (c) 2010-2012 cocos2d-x.org 3 Copyright (c) 2008-2010 Ricardo Quesada 4 Copyright (c) 2011 Zynga 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 " \n" 34 + "precision lowp float; \n" 35 + " \n" 36 + "varying vec4 v_fragmentColor; \n" 37 + " \n" 38 + "void main() \n" 39 + "{ \n" 40 + " gl_FragColor = v_fragmentColor; \n" 41 + "} \n"; 42 43 /** 44 * @constant 45 * @type {String} 46 */ 47 cc.SHADER_POSITION_UCOLOR_VERT = 48 " \n" 49 + "attribute vec4 a_position; \n" 50 + "uniform vec4 u_color; \n" 51 + "uniform float u_pointSize; \n" 52 + " \n" 53 + "varying lowp vec4 v_fragmentColor; \n" 54 + " \n" 55 + "void main(void) \n" 56 + "{ \n" 57 //+ " gl_Position = CC_MVPMatrix * a_position; \n" 58 + " gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position; \n" 59 + " gl_PointSize = u_pointSize; \n" 60 + " v_fragmentColor = u_color; \n" 61 + "}"; 62 63 64 //---------------------Shader_PositionColor Shader Source----------------------- 65 /** 66 * @constant 67 * @type {String} 68 */ 69 cc.SHADER_POSITION_COLOR_FRAG = 70 " \n" 71 + "precision lowp float; \n" 72 + "varying vec4 v_fragmentColor; \n" 73 + " \n" 74 + "void main() \n" 75 + "{ \n" 76 + " gl_FragColor = v_fragmentColor; \n" 77 + "} "; 78 79 80 /** 81 * @constant 82 * @type {String} 83 */ 84 cc.SHADER_POSITION_COLOR_VERT = 85 " \n" 86 + "attribute vec4 a_position; \n" 87 + "attribute vec4 a_color; \n" 88 + " \n" 89 + "varying lowp vec4 v_fragmentColor; \n" 90 + " \n" 91 + "void main() \n" 92 + "{ \n" 93 //+ " gl_Position = CC_MVPMatrix * a_position; \n" 94 + " gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position; \n" 95 + " v_fragmentColor = a_color; \n" 96 + "}"; 97 98 // --------------------- Shader_PositionColorLengthTexture Shader source------------------------ 99 /** 100 * @constant 101 * @type {String} 102 */ 103 cc.SHADER_POSITION_COLOR_LENGTH_TEXTURE_FRAG = 104 " \n" 105 + "// #extension GL_OES_standard_derivatives : enable \n" 106 + "\n" 107 + "varying mediump vec4 v_color; \n" 108 + "varying mediump vec2 v_texcoord; \n" 109 + "\n" 110 + "void main() \n" 111 + "{ \n" 112 + "// #if defined GL_OES_standard_derivatives \n" 113 + "// gl_FragColor = v_color*smoothstep(0.0, length(fwidth(v_texcoord)), 1.0 - length(v_texcoord)); \n" 114 + "// #else \n" 115 + "gl_FragColor = v_color * step(0.0, 1.0 - length(v_texcoord)); \n" 116 + "// #endif \n" 117 + "}"; 118 119 /** 120 * @constant 121 * @type {String} 122 */ 123 cc.SHADER_POSITION_COLOR_LENGTH_TEXTURE_VERT = 124 " \n" 125 + "attribute mediump vec4 a_position; \n" 126 + "attribute mediump vec2 a_texcoord; \n" 127 + "attribute mediump vec4 a_color; \n" 128 + "\n" 129 + "varying mediump vec4 v_color; \n" 130 + "varying mediump vec2 v_texcoord; \n" 131 + "\n" 132 + "void main() \n" 133 + "{ \n" 134 + " v_color = a_color;//vec4(a_color.rgb * a_color.a, a_color.a); \n" 135 + " v_texcoord = a_texcoord; \n" 136 + " \n" 137 //+ " gl_Position = CC_MVPMatrix * a_position; \n" 138 + " gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position; \n" 139 + "}"; 140 141 // ----------------------Shader_PositionTexture Shader Source------------------------------------- 142 /** 143 * @constant 144 * @type {String} 145 */ 146 cc.SHADER_POSITION_TEXTURE_FRAG = 147 " \n" 148 + "precision lowp float; \n" 149 + " \n" 150 + "varying vec2 v_texCoord; \n" 151 + "uniform sampler2D CC_Texture0; \n" 152 + " \n" 153 + "void main() \n" 154 + "{ \n" 155 + " gl_FragColor = texture2D(CC_Texture0, v_texCoord); \n" 156 + "}"; 157 158 /** 159 * @constant 160 * @type {String} 161 */ 162 cc.SHADER_POSITION_TEXTURE_VERT = 163 " \n" 164 + "attribute vec4 a_position; \n" 165 + "attribute vec2 a_texCoord; \n" 166 + " \n" 167 + "varying mediump vec2 v_texCoord; \n" 168 + " \n" 169 + "void main() \n" 170 + "{ \n" 171 //+ " gl_Position = CC_MVPMatrix * a_position; \n" 172 + " gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position; \n" 173 + " v_texCoord = a_texCoord; \n" 174 + "}"; 175 176 // ------------------------Shader_PositionTexture_uColor Shader Source------------------------------- 177 /** 178 * @constant 179 * @type {String} 180 */ 181 cc.SHADER_POSITION_TEXTURE_UCOLOR_FRAG = 182 " \n" 183 + "precision lowp float; \n" 184 + " \n" 185 + "uniform vec4 u_color; \n" 186 + "varying vec2 v_texCoord; \n" 187 + " \n" 188 + "uniform sampler2D CC_Texture0; \n" 189 + " \n" 190 + "void main() \n" 191 + "{ \n" 192 + " gl_FragColor = texture2D(CC_Texture0, v_texCoord) * u_color; \n" 193 + "}"; 194 195 /** 196 * @constant 197 * @type {String} 198 */ 199 cc.SHADER_POSITION_TEXTURE_UCOLOR_VERT = 200 " \n" 201 + "attribute vec4 a_position; \n" 202 + "attribute vec2 a_texCoord; \n" 203 + " \n" 204 + "varying mediump vec2 v_texCoord; \n" 205 + " \n" 206 + "void main() \n" 207 + "{ \n" 208 //+ " gl_Position = CC_MVPMatrix * a_position; \n" 209 + " gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position; \n" 210 + " v_texCoord = a_texCoord; \n" 211 + "}"; 212 213 //---------------------Shader_PositionTextureA8Color Shader source------------------------------- 214 /** 215 * @constant 216 * @type {String} 217 */ 218 cc.SHADER_POSITION_TEXTURE_A8COLOR_FRAG = 219 " \n" 220 + "precision lowp float; \n" 221 + " \n" 222 + "varying vec4 v_fragmentColor; \n" 223 + "varying vec2 v_texCoord; \n" 224 + "uniform sampler2D CC_Texture0; \n" 225 + " \n" 226 + "void main() \n" 227 + "{ \n" 228 + " gl_FragColor = vec4( v_fragmentColor.rgb, \n" // RGB from uniform 229 + " v_fragmentColor.a * texture2D(CC_Texture0, v_texCoord).a \n" // A from texture and uniform 230 + " ); \n" 231 + "}"; 232 233 /** 234 * @constant 235 * @type {String} 236 */ 237 cc.SHADER_POSITION_TEXTURE_A8COLOR_VERT = 238 " \n" 239 + "attribute vec4 a_position; \n" 240 + "attribute vec2 a_texCoord; \n" 241 + "attribute vec4 a_color; \n" 242 + " \n" 243 + "varying lowp vec4 v_fragmentColor; \n" 244 + "varying mediump vec2 v_texCoord; \n" 245 + " \n" 246 + "void main() \n" 247 + "{ \n" 248 //+ " gl_Position = CC_MVPMatrix * a_position; \n" 249 + " gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position; \n" 250 + " v_fragmentColor = a_color; \n" 251 + " v_texCoord = a_texCoord; \n" 252 + "}"; 253 254 // ------------------------Shader_PositionTextureColor Shader source------------------------------------ 255 /** 256 * @constant 257 * @type {String} 258 */ 259 cc.SHADER_POSITION_TEXTURE_COLOR_FRAG = 260 " \n" 261 + "precision lowp float; \n" 262 + " \n" 263 + "varying vec4 v_fragmentColor; \n" 264 + "varying vec2 v_texCoord; \n" 265 + "uniform sampler2D CC_Texture0; \n" 266 + " \n" 267 + "void main() \n" 268 + "{ \n" 269 + " gl_FragColor = v_fragmentColor * texture2D(CC_Texture0, v_texCoord); \n" 270 + "}"; 271 272 /** 273 * @constant 274 * @type {String} 275 */ 276 cc.SHADER_POSITION_TEXTURE_COLOR_VERT = 277 " \n" 278 + "attribute vec4 a_position; \n" 279 + "attribute vec2 a_texCoord; \n" 280 + "attribute vec4 a_color; \n" 281 + " \n" 282 + "varying lowp vec4 v_fragmentColor; \n" 283 + "varying mediump vec2 v_texCoord; \n" 284 + " \n" 285 + "void main() \n" 286 + "{ \n" 287 //+ " gl_Position = CC_MVPMatrix * a_position; \n" 288 + " gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position; \n" 289 + " v_fragmentColor = a_color; \n" 290 + " v_texCoord = a_texCoord; \n" 291 + "}"; 292 293 //-----------------------Shader_PositionTextureColorAlphaTest_frag Shader Source---------------------------- 294 /** 295 * @constant 296 * @type {String} 297 */ 298 cc.SHADER_POSITION_TEXTURE_COLOR_ALPHATEST_FRAG = 299 " \n" 300 + "precision lowp float; \n" 301 + " \n" 302 + "varying vec4 v_fragmentColor; \n" 303 + "varying vec2 v_texCoord; \n" 304 + "uniform sampler2D CC_Texture0; \n" 305 + "uniform float CC_alpha_value; \n" 306 + " \n" 307 + "void main() \n" 308 + "{ \n" 309 + " vec4 texColor = texture2D(CC_Texture0, v_texCoord); \n" 310 + " \n" 311 + " // mimic: glAlphaFunc(GL_GREATER) \n" 312 + " //pass if ( incoming_pixel >= CC_alpha_value ) => fail if incoming_pixel < CC_alpha_value \n" 313 + " \n" 314 + " if ( texColor.a <= CC_alpha_value ) \n" 315 + " discard; \n" 316 + " \n" 317 + " gl_FragColor = texColor * v_fragmentColor; \n" 318 + "}"; 319 320 //-----------------------ShaderEx_SwitchMask_frag Shader Source---------------------------- 321 /** 322 * @constant 323 * @type {String} 324 */ 325 cc.SHADEREX_SWITCHMASK_FRAG = 326 " \n" 327 + "precision lowp float; \n" 328 + " \n" 329 + "varying vec4 v_fragmentColor; \n" 330 + "varying vec2 v_texCoord; \n" 331 + "uniform sampler2D u_texture; \n" 332 + "uniform sampler2D u_mask; \n" 333 + " \n" 334 + "void main() \n" 335 + "{ \n" 336 + " vec4 texColor = texture2D(u_texture, v_texCoord); \n" 337 + " vec4 maskColor = texture2D(u_mask, v_texCoord); \n" 338 + " vec4 finalColor = vec4(texColor.r, texColor.g, texColor.b, maskColor.a * texColor.a); \n" 339 + " gl_FragColor = v_fragmentColor * finalColor; \n" 340 + "}";