Cocos2d 3.X Shader dimming and darkening

Source: Internet
Author: User


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

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.