Transfer from http://www.waitingfy.com/archives/1741
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-x, here is a list of shader codes:
12345678910111213 |
#ifdef GL_ES
precision mediump
float
;
#endif
varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
void
main(
void
)
{
vec4 c = texture2D(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!
123456789101112131415161718 |
#ifdef GL_ES
precision mediump
float
;
#endif
varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
void
main(
void
)
{
vec4 c = texture2D(CC_Texture0, v_texCoord);
float
greyNum = 0.75;
vec4 final = c;
final.r = c.r * greyNum;
final.g = c.g * greyNum;
final.b = c.b * greyNum;
gl_FragColor = final;
}
|
I set the 0.75 here.
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.
Source URL: http://www.waitingfy.com/archives/1741
Cocos2d 3.X Shader dimming and darkening