Search Unity

Shader not rendering on mobile.

Discussion in 'Shaders' started by Frostbite23, Jun 20, 2015.

  1. Frostbite23

    Frostbite23

    Joined:
    Mar 8, 2013
    Posts:
    458
    Hello guys, I have a shader that I wrote and it renders fine on my mac. However when I build my app and run it on mobile, everything in the scene that uses my shader is invisible. Like its not rendering them. What have I done wrong?

    Code (JavaScript):
    1. Shader "UnlitColor" {
    2.     Properties {
    3.         _Color("Color", Color) = (1,1,1,1)
    4.     }
    5.     SubShader {
    6.         Pass {
    7.             Tags { "LightMode" = "ForwardBase" "Queue" = "Opaque" }
    8.             Cull Off
    9.             CGPROGRAM
    10.             #pragma vertex vert
    11.             #pragma fragment frag
    12.             #include "UnityCG.cginc"
    13.      
    14.             fixed4 _Color;
    15.             fixed4 _LightColor0;
    16.      
    17.             struct vertexInput {
    18.                 fixed4 vertex : POSITION;
    19.                 fixed3 normal : NORMAL;
    20.             };
    21.      
    22.             struct vertexOutput {
    23.                 fixed4 pos : SV_POSITION;
    24.                 fixed4 posWorld : TEXCOORD0;
    25.                 fixed3 normalWorld : TEXCOORD1;
    26.             };
    27.      
    28.             vertexOutput vert(vertexInput v){
    29.                 vertexOutput o;
    30.          
    31.                 o.normalWorld = normalize( mul( fixed4( v.normal, 0.0), _World2Object ).xyz );
    32.                 o.posWorld = mul(_Object2World, v.vertex);
    33.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    34.          
    35.                 return o;
    36.             }
    37.  
    38.             fixed4 frag(vertexOutput i) : COLOR {
    39.                 fixed3 diffuse = saturate( dot( normalize( i.normalWorld ), normalize(_WorldSpaceLightPos0.xyz)) * 0.5 + 0.5);
    40.                 diffuse = _LightColor0.rgb * diffuse.rgb * _Color.rgb;
    41.  
    42.                 return fixed4(diffuse, 1.0);
    43.             }
    44.             ENDCG
    45.         }
    46.     }
    47. }
    48.  
    Note: I added a fallback but that didn't solve it.

    Using a nexus 4
     
  2. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Shot in the dark, try changing all your fixed to half.
     
  3. Frostbite23

    Frostbite23

    Joined:
    Mar 8, 2013
    Posts:
    458
    Tried that, didn't help.
     
  4. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Have you tried any other device? and what is the device?
     
  5. Frostbite23

    Frostbite23

    Joined:
    Mar 8, 2013
    Posts:
    458
    I tried an HTC one, don't know what version but I had the same issue.