Cocos2d 3.X Shader dimming and darkening

Source: Internet
Author: User

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_ESprecision mediump float;#endif varying vec4 v_fragmentColor;varying vec2 v_texCoord;  voidmain(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_ESprecision mediump float;#endif varying vec4 v_fragmentColor;varying vec2 v_texCoord; voidmain(void){    vec4 c = texture2D(CC_Texture0, v_texCoord);    floatgreyNum = 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.