clip area shader in Unity3D -


first of all, don't have idea shader programming need game found clip area shader on internet trying modify , add features ! added shader sprite , checked on pc , android devices after i've checked on htc 1 (my friend mobile) weird problem happening !

enter image description here

as see left side not clipping visually.

the first shader found had width , length clipping sprite added width left , width right , color tint shader.

there code :

shader "sprites/clipareawithalpha" {     properties     {         _color ("color tint", color) = (1,1,1,1)         _maintex ("base (rgb), alpha (a)", 2d) = "white" {}         _length ("length", range(0.0, 1.0)) = 1.0         _widthr("width right", range(0.0, 1.0)) = 1.0         _widthl ("width left", range(0.0, 1.0)) = 0.0      }      subshader     {         lod 200          tags         {             "queue" = "transparent"             "ignoreprojector" = "true"             "rendertype" = "transparent"         }          pass         {             cull off             lighting off             zwrite off             offset -1, -1             fog { mode off }             colormask rgb             blend srcalpha oneminussrcalpha              cgprogram             #pragma vertex vert             #pragma fragment frag              #include "unitycg.cginc"              sampler2d _maintex;             float4 _maintex_st;             float _length;             float _widthr;             float _widthl;             half4 _color;              struct appdata_t             {                 float4 vertex : position;                 float2 texcoord : texcoord0;             };              struct v2f             {                 float4 vertex : position;                 float2 texcoord : texcoord0;                 half4 color : color;             };              v2f vert (appdata_t v)             {                 v2f o;                 o.vertex = mul(unity_matrix_mvp, v.vertex);                 o.texcoord = v.texcoord;                 o.color = _color;                 return o;             }              half4 frag (v2f in) : color             {                 if ((in.texcoord.x<_widthl) || (in.texcoord.x>_widthr) || (in.texcoord.y<0) || (in.texcoord.y>_length))                 {                     half4 colortransparent = half4(0,0,0,0) ;                     return colortransparent;                 }                 else                 {                     half4 tex = tex2d(_maintex, in.texcoord);                     tex.a = in.color.a;                     return tex;                 }             }             endcg         }     } } 

as said before shader ok on android devices checked on htc 1 doesn't work nicely , correctly. don't know problem is! i'm thankful solution.

and shader has warning : materialpropertyblock used modify these values

i have had same problem. try setting value of generate mip maps off, shader works correctly.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -