1. To save a picture of the shader used
We notice that in this game, we often use some buttons, the art will give two pictures, a slightly darker point, indicating the state of the press. However, such a figure more up, it is more resource-intensive. The sprite changes color to show no such effect. Think of it shader can.
2. Gray is more common
There is a grayed out example in cocos2d, here is a list of shader codes:
#ifdef gl_esprecision mediump float; #endifvarying vec4 v_fragmentcolor;varying vec2 v_texcoord;void Main (void) {VEC4 c = t Exture2d (CC_TEXTURE0, v_texcoord); gl_fragcolor.xyz = VEC3 (0.2126*C.R + 0.7152*C.G + 0.0722*c.b); GL_FRAGCOLOR.W = C.W;}
The number of coefficients will be equal to 1, and the different adjustments will have different effects. :
The first one is the gray, but the effect from the 3rd is still a distance.
3. The principle of darkening
The graphics should be easier to know, I also search to know, we know that white is 1 or 255, black is 0. When a color gets closer to 0, the closer the Black is. That is, as long as the color of each pixel is multiplied by a number smaller than 1, there will be a darkening effect!
#ifdef gl_esprecision mediump float; #endifvarying vec4 v_fragmentcolor;varying vec2 v_texcoord;void Main (void) {VEC4 c = t Exture2d (CC_TEXTURE0, V_texcoord); float Greynum = 0.75;vec4 final = C;FINAL.R = C.R * GREYNUM;FINAL.G = C.G * GreyNum;fina l.b = c.b * Greynum;gl_fragcolor = final;}
What I'm setting up here is 0.75.
Eventually:
It's very close to the 3rd target map we need. So you can save half the picture. I wonder if the rendering speed will be slow.
http://www.waitingfy.com/archives/1741
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Cocos2d 3.X Shader dimming and darkening