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)