Search Unity

Shader not working the same on iPhone vs PC

Discussion in 'Shaders' started by NeilM0, Aug 28, 2015.

  1. NeilM0

    NeilM0

    Joined:
    Mar 31, 2009
    Posts:
    135
    I've written a basic toon shader that doesn't seem to work properly on the iphone. On the PC it looks unlit, but on device it's lit. I'm assuming it's something to do with the Emission property, but I have no idea what. Can anyone spot what I've done wrong?

    Code (CSharp):
    1. Shader "Custom/Cartoon/Unlit"
    2. {
    3.     Properties {
    4.         _MainTex ("Base (RGB)", 2D) = "white" {}
    5.         _Color ("Color", Color) = (1.0, 1.0, 1.0, 1.0)
    6.         _OutlineColor ("Outline", Color) = (1.0, 1.0, 1.0, 1.0)
    7.         _Outline ("Outline width", Range (.002, 0.1)) = .005
    8.     }
    9.    
    10.     SubShader {
    11.         Tags { "RenderType"="Opaque" }
    12.         LOD 200
    13.         ZWrite On
    14.         Cull Front
    15.        
    16.         CGPROGRAM
    17.         #pragma surface surf Unlit vertex:vert
    18.  
    19.         half4 _Color;
    20.         half4 _OutlineColor;
    21.         half _Outline;
    22.  
    23.         struct Input {
    24.             float2 uv_MainTex;
    25.         };
    26.      
    27.         void vert (inout appdata_full v)
    28.         {
    29.             v.vertex.xyz += v.normal * _Outline;
    30.         }
    31.  
    32.         half4 LightingUnlit(SurfaceOutput s, half3 lightDir, half atten)
    33.         {
    34.             s.Emission = _OutlineColor;
    35.             return half4(0.0, 0.0, 0.0, 1.0);
    36.         }
    37.        
    38.         void surf (Input IN, inout SurfaceOutput o)
    39.         {
    40.             o.Albedo = _OutlineColor.rgb;
    41.             o.Emission = _OutlineColor.rgb;
    42.             o.Alpha = 1.0;
    43.         }
    44.         ENDCG
    45.        
    46.         ZWrite On
    47.         Cull Back
    48.         CGPROGRAM
    49.         #pragma surface surf Unlit
    50.         sampler2D _MainTex;
    51.         half4 _Color;
    52.  
    53.         struct Input {
    54.             float2 uv_MainTex;
    55.         };
    56.  
    57.         half4 LightingUnlit(SurfaceOutput s, half3 lightDir, half atten)
    58.         {
    59.             return half4(s.Albedo, s.Alpha);
    60.         }
    61.    
    62.         void surf (Input IN, inout SurfaceOutput o)
    63.         {
    64.             half4 c = tex2D (_MainTex, IN.uv_MainTex);
    65.             half4 final = saturate(c * _Color);
    66.             o.Emission = half4(0.0, 0.0, 0.0, 1.0);
    67.             o.Albedo = final;
    68.             o.Alpha = c.a;
    69.         }
    70.         ENDCG
    71.     }
    72.     // FallBack "Diffuse"
    73. }
    74.