Advertisement
Guest User

Unity Shader script

a guest
Mar 21st, 2017
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/Tree_Billboard"
  2. {
  3. Properties
  4. {
  5.    [PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {}
  6. _Color("Tint", Color) = (1,1,1,1)
  7.    //_Time ("Time", Float) = 0
  8.    [MaterialToggle] PixelSnap("Pixel snap", Float) = 0
  9. }
  10.  
  11.    SubShader
  12. {
  13.    Tags
  14. {
  15.    "Queue" = "Transparent"
  16.    "DisableBatching" = "True"
  17.    "SortingLayer" = "Resources_Sprites"
  18.    "IgnoreProjector" = "True"
  19.    "RenderType" = "Transparent"
  20.    "PreviewType" = "Plane"
  21.    "CanUseSpriteAtlas" = "True"
  22. }
  23.  
  24.    Cull Off
  25.    Lighting Off
  26.    ZWrite Off
  27.    Blend One OneMinusSrcAlpha
  28.  
  29.    Pass
  30. {
  31.    CGPROGRAM
  32. #pragma vertex vert
  33. #pragma fragment frag
  34. #pragma target 2.0
  35. #pragma multi_compile _ PIXELSNAP_ON
  36. #pragma multi_compile _ ETC1_EXTERNAL_ALPHA
  37. #include "UnityCG.cginc"
  38.  
  39.    //            uniform Float _Time;
  40.  
  41. struct appdata_t
  42. {
  43.    float4 vertex   : POSITION;
  44.    float4 color    : COLOR;
  45.    float2 texcoord : TEXCOORD0;
  46.    UNITY_VERTEX_INPUT_INSTANCE_ID
  47. };
  48.  
  49. struct v2f
  50. {
  51.    float4 vertex   : SV_POSITION;
  52.    fixed4 color : COLOR;
  53.    float2 texcoord  : TEXCOORD0;
  54.    UNITY_VERTEX_OUTPUT_STEREO
  55. };
  56.  
  57. fixed4 _Color;
  58.  
  59. v2f vert(appdata_t IN)
  60. {
  61.    v2f OUT;
  62.    UNITY_SETUP_INSTANCE_ID(IN);
  63.    UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
  64.    //                OUT.vertex = UnityObjectToClipPos(IN.vertex);
  65.    OUT.texcoord = IN.texcoord;
  66.    OUT.color = IN.color * _Color;
  67.    //    #ifdef PIXELSNAP_ON
  68.  
  69.    OUT.vertex = mul(UNITY_MATRIX_P,
  70.        mul(UNITY_MATRIX_MV, float4(0.0, 4.1, 0.0, 1.0))
  71.        - float4(IN.vertex.x, -IN.vertex.y, 0.0, 0.0)
  72.        * float4(6.0, 8.0, 1.0, 1.0));
  73.  
  74.    //                OUT.vertex = UnityPixelSnap (OUT.vertex);
  75.    //    #endif
  76.  
  77.    return OUT;
  78. }
  79.  
  80. sampler2D _MainTex;
  81. sampler2D _AlphaTex;
  82.  
  83. fixed4 SampleSpriteTexture(float2 uv)
  84. {
  85.    fixed4 color = tex2D(_MainTex, uv);
  86.  
  87. #if ETC1_EXTERNAL_ALPHA
  88.    // get the color from an external texture (usecase: Alpha support for           ETC1 on android)
  89.    color.a = tex2D(_AlphaTex, uv).r;
  90. #endif //ETC1_EXTERNAL_ALPHA
  91.  
  92.    return color;
  93. }
  94.  
  95. fixed4 frag(v2f IN) : SV_Target
  96. {
  97.    fixed4 c = SampleSpriteTexture(IN.texcoord) * IN.color;
  98. c.rgb *= c.a;
  99. return c;
  100. }
  101.    ENDCG
  102. }
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement