UNITY2D Sprite Grey Chart (Unity3d development 11)

Source: Internet
Author: User

Monkey Original, welcome reprint. Reprint Please specify: reproduced from COCOS2D Development network –cocos2dev.com, thank you!

Original address: http://www.cocos2dev.com/?p=596



Last night to see the group asked how the 2DSprite into a gray chart, at night to see the next, modify the shader is the most convenient.


Here is the implementation of Sprites-gray.shader, please put your own project:
Shader "Sprites/gray" {properties{[Perrendererdata] _maintex ("Sprite Texture", 2D) = "White" {} _color ("Tint", Col OR) = (1,1,1,1) [Materialtoggle] Pixelsnap ("Pixel snap", Float) = 0}subshader{Tags {"Queue" = "transpare NT "" Ignoreprojector "=" True "" rendertype "=" Transparent "" previewtype "=" Plane "" Canusesprite    Atlas "=" True "} Cull off Lighting off Zwrite off Fog {Mode Off} Blend one Oneminussrcalpha Pass        {cgprogram #pragma vertex vert #pragma fragment frag #pragma multi_compile DUMMY pixelsnap_on            #include "unitycg.cginc" struct appdata_t {float4 vertex:position;            FLOAT4 Color:color;        FLOAT2 texcoord:texcoord0;        };            struct V2F {float4 vertex:sv_position;            Fixed4 Color:color;        Half2 texcoord:texcoord0;        };        Fixed4 _color; v2f Vert (appdata_tIn) {v2f out;            Out.vertex = Mul (UNITY_MATRIX_MVP, In.vertex);            Out.texcoord = In.texcoord;            Out.color = In.color * _COLOR;            #ifdef pixelsnap_on Out.vertex = Unitypixelsnap (Out.vertex);        #endif return out;        } sampler2d _maintex;            Fixed4 Frag (v2f in): sv_target {fixed4 c = tex2d (_maintex, In.texcoord) * IN.COLOR;            C.rgb *= C.A;            float Gray = dot (c.xyz, FLOAT3 (0.299, 0.587, 0.114));            C.XYZ = Float3 (Gray, Gray, gray);        return C; } ENDCG}}}



How to use:
Use the This for Initializationvoid Start () {    Spriterenderer render = this. Getcomponent<spriterenderer> ();    Render.material.shader = Shader.find ("Sprites/gray");}




UNITY2D Sprite Grey Chart (Unity3d development 11)

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.