Search Unity

Tiling not working on iOS

Discussion in 'Shaders' started by reduktion, Mar 26, 2014.

  1. reduktion

    reduktion

    Joined:
    Sep 27, 2012
    Posts:
    25
    Hey

    My CG shaders often ignore tiling, when running on iOS. They act, as If the material's tiling property was set to 1, 1. What am I doing wrong?

    Here is an example for a shader, which does not tile properly:

    Code (csharp):
    1. Shader "CS/Textured Vertex Colored Blended" {
    2. Properties {
    3.     _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
    4.     }
    5.  
    6.  
    7.     SubShader {
    8.         Tags { "RenderType"="Transparent" "Queue"="Transparent"}
    9.         Blend SrcAlpha OneMinusSrcAlpha
    10.         ZWrite Off
    11.         Pass {
    12.             Name "BASE"
    13.            
    14.             CGPROGRAM
    15.             #pragma vertex vert
    16.             #pragma fragment frag
    17.             #pragma fragmentoption ARB_precision_hint_fastest
    18.             #include "UnityCG.cginc"
    19.  
    20.             sampler2D _MainTex;
    21.  
    22.             struct appdata {
    23.                 fixed4 vertex : POSITION;
    24.                 fixed4 color : COLOR;
    25.                 float2 texcoord : TEXCOORD0;
    26.             };
    27.            
    28.             fixed4 _MainTex_ST;
    29.            
    30.             struct v2f {
    31.                 fixed4 pos : POSITION;
    32.                 fixed4 color : COLOR;
    33.                 float2 texcoord : TEXCOORD0;
    34.             };
    35.  
    36.             v2f vert (appdata v)
    37.             {
    38.                 v2f o;
    39.                 o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
    40.                 o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
    41.                 o.color = v.color;
    42.                 return o;
    43.             }
    44.  
    45.             fixed4 frag (v2f i) : COLOR
    46.             {
    47.                 fixed4 col = i.color * tex2D(_MainTex, i.texcoord);
    48.                 return col;
    49.             }
    50.             ENDCG          
    51.         }
    52.     }
    53.  
    54.    
    55.     Fallback "VertexLit"
    56. }
    57.  
     
  2. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,688
    Set
    Code (csharp):
    1.  fixed4 _MainTex_ST;
    to
    Code (csharp):
    1. float4 _MainTex_ST;
    and it will work.
     
  3. reduktion

    reduktion

    Joined:
    Sep 27, 2012
    Posts:
    25
    You're right, problem solved.
    Thank you!
     
  4. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,688
    If something is not running on the device always check for a precision error first.

    I think this problem should not occur on a 5S and iPad Air so always test on all target generations.