Author Topic: Texture Mask working in Editor not on Devices!!  (Read 14597 times)

cbothra

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 13
    • View Profile
Texture Mask working in Editor not on Devices!!
« on: July 03, 2015, 05:30:42 AM »
Hi,

Right now I am facing a big problem. I created a texture and put a mask on it which is perfectly working in unity editor.
When I created the build and ran the same scene in Android device then I was surprised looking no masking there.

Please help me to get out of this issue.

Thanks-in-advance.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Texture Mask working in Editor not on Devices!!
« Reply #1 on: July 03, 2015, 11:42:38 AM »
I am not sure what this has to do with NGUI... Or were you talking about the clipping mask? If so, make sure your Quality Settings aren't set to Fastest, as this disables shader support.

cbothra

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 13
    • View Profile
Re: Texture Mask working in Editor not on Devices!!
« Reply #2 on: July 04, 2015, 01:32:05 AM »
Hi ArenMook,

First of all I would like to thank you for taking time to reply. Here's my complete scenario:

I create a Texture and put Unlit/Transparent Masked on it. In the Unlit/Transparent Masked shader, I put a another texture as mask in the shader which is working perfect in editor but when I create the apk and run it on device the the masking is no more effective. Following is the shader I am using:

  1. Shader "Unlit/Transparent Masked"
  2. {
  3.         Properties
  4.         {
  5.                 _MainTex ("Base (RGB), Alpha (A)", 2D) = "black" {}
  6.                 _Mask ("Alpha (A)", 2D) = "white" {}
  7.         }
  8.        
  9.         SubShader
  10.         {
  11.                 LOD 200
  12.  
  13.                 Tags
  14.                 {
  15.                         "Queue" = "Transparent"
  16.                         "IgnoreProjector" = "True"
  17.                         "RenderType" = "Transparent"
  18.                 }
  19.                
  20.                 Pass
  21.                 {
  22.                         Cull Off
  23.                         Lighting Off
  24.                         ZWrite Off
  25.                         Fog { Mode Off }
  26.                         Offset -1, -1
  27.                         Blend SrcAlpha OneMinusSrcAlpha
  28.  
  29.                         CGPROGRAM
  30.                         #pragma vertex vert
  31.                         #pragma fragment frag                  
  32.                         #include "UnityCG.cginc"
  33.  
  34.                         sampler2D _MainTex;
  35.                         sampler2D _Mask;
  36.                         float4 _MainTex_ST;
  37.        
  38.                         struct appdata_t
  39.                         {
  40.                                 float4 vertex : POSITION;
  41.                                 float2 texcoord : TEXCOORD0;
  42.                                 float2 texcoord1 : TEXCOORD1;
  43.                                 fixed4 color : COLOR;
  44.                         };
  45.        
  46.                         struct v2f
  47.                         {
  48.                                 float4 vertex : SV_POSITION;
  49.                                 float2 texcoord : TEXCOORD0;
  50.                                 float2 texcoord1 : TEXCOORD1;
  51.                                 fixed4 color : COLOR;
  52.                         };
  53.        
  54.                         v2f o;
  55.  
  56.                         v2f vert (appdata_t v)
  57.                         {
  58.                                 o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
  59.                                 o.texcoord = v.texcoord;
  60.                                 o.texcoord1 = v.texcoord1;
  61.                                 o.color = v.color;
  62.                                 return o;
  63.                         }
  64.                                
  65.                         fixed4 frag (v2f IN) : COLOR
  66.                         {
  67.                                 half4 col = tex2D(_MainTex, IN.texcoord) * IN.color;
  68.                                 col.a *= tex2D(_Mask, IN.texcoord1).a;
  69.                                 return col;
  70.                         }
  71.                         ENDCG
  72.                 }
  73.         }
  74.  
  75.         SubShader
  76.         {
  77.                 LOD 100
  78.  
  79.                 Tags
  80.                 {
  81.                         "Queue" = "Transparent"
  82.                         "IgnoreProjector" = "True"
  83.                         "RenderType" = "Transparent"
  84.                 }
  85.                
  86.                 Pass
  87.                 {
  88.                         Cull Off
  89.                         Lighting Off
  90.                         ZWrite Off
  91.                         Fog { Mode Off }
  92.                         Offset -1, -1
  93.                         ColorMask RGB
  94.                         Blend SrcAlpha OneMinusSrcAlpha
  95.                         ColorMaterial AmbientAndDiffuse
  96.                        
  97.                         SetTexture [_MainTex]
  98.                         {
  99.                                 Combine Texture * Primary
  100.                         }
  101.                 }
  102.         }
  103. }
  104.  


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Texture Mask working in Editor not on Devices!!
« Reply #3 on: July 06, 2015, 08:01:02 PM »
My last advice still stands. Double-check your quality settings.

cbothra

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 13
    • View Profile
Re: Texture Mask working in Editor not on Devices!!
« Reply #4 on: July 08, 2015, 02:31:07 AM »
I confirm that my Quality settings is not set to fastest, but still no luck with the issue.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Texture Mask working in Editor not on Devices!!
« Reply #5 on: July 08, 2015, 08:12:39 PM »
What device is it? Does it actually support shaders? Did you ensure that the shader gets included in the build? Do other shader-based things work, such as clipped panels?

cbothra

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 13
    • View Profile
Re: Texture Mask working in Editor not on Devices!!
« Reply #6 on: July 09, 2015, 12:40:55 AM »
Quote
What device is it?
Nexus 7

Quote
Does it actually support shaders?
Yes

Quote
Did you ensure that the shader gets included in the build?
Could you please let me know how to check that?

Quote
Do other shader-based things work, such as clipped panels?
Yes clipping is working perfectly.


cbothra

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 13
    • View Profile
Re: Texture Mask working in Editor not on Devices!!
« Reply #7 on: July 09, 2015, 01:00:58 AM »
Hi ArenMook,

I checked the editor log and confirm that the shader is being included in the build.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Texture Mask working in Editor not on Devices!!
« Reply #8 on: July 12, 2015, 07:48:02 PM »
Then I am out of ideas. If clipping works fine, but mask doesn't and it gets included, then it should work. If it doesn't, I wouldn't know why that is. It all works as expected on my end, but I don't have a Nexus 7.

cbothra

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 13
    • View Profile
Re: Texture Mask working in Editor not on Devices!!
« Reply #9 on: July 17, 2015, 01:17:16 AM »
Hi ArenMook,

Could you please do me one favour? Could you please pass me the download link to your project, so that I can check on Nexus 7 by creating the build. And if it works then I can check where I am going wrong.

Thanks-in-advance.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Texture Mask working in Editor not on Devices!!
« Reply #10 on: July 21, 2015, 09:38:41 AM »
What project? The examples that come with NGUI? You already have them.

cbothra

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 13
    • View Profile
Re: Texture Mask working in Editor not on Devices!!
« Reply #11 on: July 27, 2015, 07:26:04 AM »
Not the projects that comes with NGUI package but the one which you can create which just contains this masking stuff and I will compile it here for android and run on device.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Texture Mask working in Editor not on Devices!!
« Reply #12 on: July 27, 2015, 08:54:16 PM »
0. New scene.
1. ALT+SHIFT+T to add a texture and choose one.
2. Select the sprite, right-click, Create -> Scroll View.
3. Drag & drop the texture to be a child of this scroll view.
4. Select the scroll view object and on its UIPanel change Clipping to be Texture Mask and choose any texture with alpha in it.

That's all I do. But sure, I've attached the scene that takes the steps above. Tested & works properly on my Asus tablet.

slookdesign

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Texture Mask working in Editor not on Devices!!
« Reply #13 on: October 12, 2015, 11:11:41 AM »
Just curious if OP found a solution?  I am having the same issue and haven't been able to get it working on android or ios.

I have tried multiple texture import settings to no avail.

*EDIT: I actually just got one to work where the texture's only difference is that the compression is set to truecolor.  Gonna test out the others.
« Last Edit: October 12, 2015, 02:36:07 PM by slookdesign »