Author Topic: UISprite scale using Billboard shader and Unlit/Transparent Color is not same.  (Read 3474 times)

yuewah

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 180
    • View Profile
I would like to replace the shader of UISprite using a Billboard shader, it show the sprite correctly but the scale is not the same as original shader.

  1. Shader "Billboard" {
  2. Properties {
  3.         _MainTex ("Base (RGB)", 2D) = "white" {}
  4. }
  5. SubShader {
  6.         Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
  7.         Cull Off Lighting Off ZWrite Off
  8.         ColorMask RGB
  9.         AlphaTest Greater .01
  10.         Blend SrcAlpha OneMinusSrcAlpha
  11.  
  12.         Pass { 
  13.                 CGPROGRAM
  14. // Upgrade NOTE: excluded shader from OpenGL ES 2.0 because it does not contain a surface program or both vertex and fragment programs.
  15.                 #pragma exclude_renderers gles
  16.                 #pragma vertex vert
  17.                 #pragma fragment frag
  18.  
  19.                 #include "UnityCG.cginc"
  20.  
  21.                 sampler2D _MainTex;
  22.                
  23.                 struct appdata_t {
  24.                         float4 vertex : POSITION;
  25.                         fixed4 color : COLOR;
  26.                         float2 texcoord : TEXCOORD0;
  27.                 };
  28.  
  29.                 struct v2f {
  30.                         float4 vertex : POSITION;
  31.                         fixed4 color : COLOR;
  32.                         float2 texcoord : TEXCOORD0;
  33.                 };
  34.  
  35.                 float4 _MainTex_ST;
  36.                
  37.                 v2f vert (appdata_t v)
  38.                 {
  39.                         v2f o;
  40.                        
  41.                         o.vertex = mul(UNITY_MATRIX_P , mul(UNITY_MATRIX_MV , float4(0.0,0.0,0.0,1.0)) + float4(v.vertex.x , v.vertex.y , 0.0 , 0.0));
  42.                         o.color = v.color;
  43.                         o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
  44.  
  45.                         return o;
  46.  
  47.                 }
  48.  
  49.                 fixed4 frag (v2f i) : COLOR
  50.                 {
  51.                         fixed4 col;
  52.                         fixed4 tex = tex2D(_MainTex, i.texcoord);
  53.                         col.rgb = i.color.rgb * tex.rgb;
  54.                         col.a = tex.a;
  55.                         return col;
  56.                 }
  57.                 ENDCG
  58.         }
  59. }      
  60.  
  61.  
  62. }
  63.  
  64.  
  65.  
  66.