Author Topic: UITexture not displaying  (Read 15124 times)

devomage

  • Sr. Member
  • ****
  • Thank You
  • -Given: 7
  • -Receive: 67
  • Posts: 250
    • View Profile
UITexture not displaying
« on: December 06, 2016, 06:26:05 AM »
I have a UITexture that is using a material with a cutout shader.  The texture stopped displaying after upgrading to 3.11.0.  Previous version was 3.10.2.


3rd party shader code:

  1. Shader "UI/AvatarCutout" {
  2. Properties {
  3.  _MainTex ("Base (RGB)", 2D) = "white" { }
  4.  _Mask ("Culling Mask", 2D) = "white" { }
  5.  _Cutoff ("Alpha cutoff", Range(0.000000,1.000000)) = 0.100000
  6. }
  7. SubShader {
  8.  Tags { "QUEUE"="Transparent" }
  9.  Pass {
  10.   Tags { "QUEUE"="Transparent" }
  11.   ZWrite Off
  12.   Blend SrcAlpha OneMinusSrcAlpha
  13. CGPROGRAM
  14. #pragma vertex vert
  15. #pragma fragment frag
  16. #pragma target 2.0
  17. #include "UnityCG.cginc"
  18. #pragma multi_compile_fog
  19. #define USING_FOG (defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2))
  20.  
  21. // uniforms
  22. float4 _Mask_ST;
  23. float4 _MainTex_ST;
  24.  
  25. // vertex shader input data
  26. struct appdata {
  27.   float3 pos : POSITION;
  28.   float3 uv0 : TEXCOORD0;
  29. };
  30.  
  31. // vertex-to-fragment interpolators
  32. struct v2f {
  33.   fixed4 color : COLOR0;
  34.   float2 uv0 : TEXCOORD0;
  35.   float2 uv1 : TEXCOORD1;
  36.   #if USING_FOG
  37.     fixed fog : TEXCOORD2;
  38.   #endif
  39.   float4 pos : SV_POSITION;
  40. };
  41.  
  42. // vertex shader
  43. v2f vert (appdata IN) {
  44.   v2f o;
  45.   half4 color = half4(0,0,0,1.1);
  46.   float3 eyePos = mul (UNITY_MATRIX_MV, float4(IN.pos,1)).xyz;
  47.   half3 viewDir = 0.0;
  48.   o.color = saturate(color);
  49.   // compute texture coordinates
  50.   o.uv0 = IN.uv0.xy * _Mask_ST.xy + _Mask_ST.zw;
  51.   o.uv1 = IN.uv0.xy * _MainTex_ST.xy + _MainTex_ST.zw;
  52.   // fog
  53.   #if USING_FOG
  54.     float fogCoord = length(eyePos.xyz); // radial fog distance
  55.     UNITY_CALC_FOG_FACTOR(fogCoord);
  56.     o.fog = saturate(unityFogFactor);
  57.   #endif
  58.   // transform position
  59.   o.pos = UnityObjectToClipPos(IN.pos);
  60.   return o;
  61. }
  62.  
  63. // textures
  64. sampler2D _Mask;
  65. sampler2D _MainTex;
  66. fixed _Cutoff;
  67.  
  68. // fragment shader
  69. fixed4 frag (v2f IN) : SV_Target {
  70.   fixed4 col;
  71.   fixed4 tex, tmp0, tmp1, tmp2;
  72.   // SetTexture #0
  73.   tex = tex2D (_Mask, IN.uv0.xy);
  74.   col = tex;
  75.   // SetTexture #1
  76.   tex = tex2D (_MainTex, IN.uv1.xy);
  77.   col.rgb = tex;
  78.   col.a = col.a;
  79.   // alpha test
  80.   if (col.a < _Cutoff) clip(-1);
  81.   // fog
  82.   #if USING_FOG
  83.     col.rgb = lerp (unity_FogColor.rgb, col.rgb, IN.fog);
  84.   #endif
  85.   return col;
  86. }
  87.  
  88. // texenvs
  89. //! TexEnv0: 01010000 01010000 [_Mask]
  90. //! TexEnv1: 01010000 01040004 [_MainTex]
  91. ENDCG
  92.  }
  93. }
  94. }
  95.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UITexture not displaying
« Reply #1 on: December 06, 2016, 06:38:58 AM »
Turn off culling.
  1. Cull off

devomage

  • Sr. Member
  • ****
  • Thank You
  • -Given: 7
  • -Receive: 67
  • Posts: 250
    • View Profile
Re: UITexture not displaying
« Reply #2 on: December 06, 2016, 05:37:30 PM »
Thanks for this.  I pray to never have to learn shaders...

devomage

  • Sr. Member
  • ****
  • Thank You
  • -Given: 7
  • -Receive: 67
  • Posts: 250
    • View Profile
Re: UITexture not displaying
« Reply #3 on: December 14, 2016, 05:23:02 PM »
this did not solve the problem.

PS  sure wish i could edit or delete my own posts...

devomage

  • Sr. Member
  • ****
  • Thank You
  • -Given: 7
  • -Receive: 67
  • Posts: 250
    • View Profile
Re: UITexture not displaying
« Reply #4 on: December 14, 2016, 05:46:54 PM »
  1. Shader "UI/AvatarCutout"
  2. {
  3.    Properties
  4.    {
  5.       _MainTex ("Base (RGB)", 2D) = "white" {}
  6.       _Mask ("Culling Mask", 2D) = "white" {}
  7.       _Cutoff ("Alpha cutoff", Range (0,1)) = 0.1
  8.    }
  9.    SubShader
  10.    {
  11.       Tags {"Queue"="Transparent"}
  12.       Lighting Off
  13.       ZWrite Off
  14.       Blend SrcAlpha OneMinusSrcAlpha
  15.       AlphaTest GEqual [_Cutoff]
  16.       Cull Off
  17.  
  18.       Pass
  19.       {
  20.          SetTexture [_Mask] {combine texture}
  21.          SetTexture [_MainTex] {combine texture, previous}
  22.       }
  23.    }
  24. }
  25.  

devomage

  • Sr. Member
  • ****
  • Thank You
  • -Given: 7
  • -Receive: 67
  • Posts: 250
    • View Profile
Re: UITexture not displaying
« Reply #5 on: December 14, 2016, 05:52:47 PM »
now the texture displays, but the cutout is not working

ps 180 seconds to post again  >:(

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UITexture not displaying
« Reply #6 on: December 15, 2016, 09:21:56 AM »
Does that shader even work at all? I thought Unity deprecated fixed function pipeline stuff ages ago now... I'm not even sure how to do what you're trying to do with fixed function.

Unity comes with a set of cutout shaders you can use, and they include source code that uses actual shader code, not fixed function stuff. Adapting it to use a second texture for the cutout source is trivial.

devomage

  • Sr. Member
  • ****
  • Thank You
  • -Given: 7
  • -Receive: 67
  • Posts: 250
    • View Profile
Re: UITexture not displaying
« Reply #7 on: December 15, 2016, 07:03:18 PM »
everything worked fine with the versions stated above...  oh well, i'll move on and leave this for another day.

devomage

  • Sr. Member
  • ****
  • Thank You
  • -Given: 7
  • -Receive: 67
  • Posts: 250
    • View Profile
Re: UITexture not displaying
« Reply #8 on: December 15, 2016, 07:26:17 PM »
apparently my scene reverted changes i made previously.  your original suggestion fixed the problem and the final cutout code works fine!