Unity uses code to make the gray display of the arts and Sciences simple

Source: Internet
Author: User

1. Can be used for texture processing, also can be used for model display processing (such as a piece of preparation or clothing not acquired when the gray display)

On-line comparison chart:

Using system.collections;using system.collections.generic;using Unityengine;public class texturegrey:monobehaviour{    [Serializefield]    Uitexture tex = null;    Texture2d tex2d = null;  Vector3 grey = new Vector3 (0.299f, 0.587f, 0.114f);    Gray shader in the gray value, the specific meaning is not too clear now void Start () {tex2d = tex.maintexture as texture2d; } void Update () {if (Input.getkeyup (KEYCODE.A)) {//ashing Vector3 tempV3 = Vector3            . Zero;                if (null! = tex2d) {color[] cols = Tex2d.getpixels (); for (int i = 0, IMax = cols. Length; i < IMax;                    ++i) {Tempv3.set (COLS[I].R, COLS[I].G, cols[i].b);                    float dot = Vector3.dot (tempV3, grey);                Cols[i] = new Color (dot, dot, dot, cols[i].a);                } tex2d = new Texture2d (Tex2d.width, Tex2d.height, Textureformat.argb32, false);              Tex2d.setpixels (cols);  Tex2d.apply (FALSE);                            Actually transmit the changed pixel data to the video card tex.maintexture = tex2d as Texture; }        }    }}

  

Unity uses code to make the gray display of the arts and Sciences simple

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.