Search Unity

Problems with additve shader on mobile.

Discussion in 'Shaders' started by cmcpasserby, Jul 30, 2014.

  1. cmcpasserby

    cmcpasserby

    Joined:
    Jul 18, 2014
    Posts:
    315
    Been working on shaders for mobile and have gotten a few alpha and multiplicative shaders working, but this additve shader always fails when i test it on my nexus7, even know it works with the opengl es 2 emulation
    Code (CSharp):
    1. Shader "DragonHill/Mobile/PowerUpShader" {
    2.     Properties {
    3.         _Color("Color", Color) = (0, 0, 1, 1)
    4.         _Intensity("Intensity", Float) = 1
    5.         _RimPower("Rim Power", Range(0.5, 8.0)) = 2.0
    6.     }
    7.     SubShader {
    8.         Tags {"Queue"="Transparent" "RenderType" = "Transparent" "IgnoreProjector"="True" "Bent"="Bent"}
    9.         LOD 200
    10.         ZWrite Off
    11.         ColorMask RGB
    12.         Blend  SrcAlpha One
    13.         Lighting Off
    14.         Pass {
    15.         Tags { "LightMode" = "ForwardBase" }
    16.             CGPROGRAM
    17.                 #pragma vertex vert
    18.                 #pragma fragment frag
    19.                 #include "UnityCG.cginc"
    20.                 #pragma target 2.0
    21.          
    22.                 struct v2f {
    23.                     float4 pos : SV_POSITION;
    24.                     float3 viewdir : TEXCOORD0;
    25.                     float3 norm : TEXCOORD1;
    26.                 };
    27.          
    28.                 fixed4 _Color;
    29.                 float _RimPower = 5;
    30.                 float _Intensity;
    31.  
    32.                 float _XTransform;
    33.                 float _YTransform;
    34.  
    35.                 v2f vert(appdata_full v)
    36.                 {
    37.                     v2f o;
    38.                     float4 vv = mul(_Object2World, v.vertex);
    39.                     vv.xyz -= _WorldSpaceCameraPos.xyz;
    40.                     vv = float4((vv.z * vv.z) * 0.00005 * _XTransform, (vv.z * vv.z) * 0.00005f * _YTransform, 0.0f, 0.0f);
    41.                     v.vertex += mul(_World2Object, vv);
    42.                     o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    43.                     o.norm = v.normal;
    44.                     o.viewdir = ObjSpaceViewDir( v.vertex );
    45.                     return o;
    46.                 }
    47.          
    48.                 float4 frag(v2f IN) : COLOR
    49.                 {
    50.                     half rim = 1 - saturate(dot(normalize(IN.viewdir), IN.norm));
    51.                     rim = pow(rim, _RimPower);
    52.                     _Color = _Color * _Intensity * rim;
    53.                     return _Color;
    54.                 }
    55.             ENDCG
    56.         }
    57.     }
    58.     FallBack "Diffuse"
    59. }
    60.  
    Ya one have similar issues, or does anyone know a way around this.
    It seems to just fall back to the fallback shader everytime i run on mobile
     
    Last edited: Jul 31, 2014
  2. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    The shader state settings should go in the Pass block instead of the SubShader block. So, these:
    Code (csharp):
    1.  
    2. ZWrite Off
    3. ColorMask RGB
    4. Blend  SrcAlpha One
    5. Lighting Off
    6.  
     
  3. cmcpasserby

    cmcpasserby

    Joined:
    Jul 18, 2014
    Posts:
    315
    ya didnt help, the problem seems to be related to my fresnel im calculating, but it dosnt seem to matter if im doing my
    Code (CSharp):
    1. half rim = 1 - saturate(dot(normalize(IN.viewdir), IN.norm));
    in the vertex program or the fragmeant, the shader still dosnt not work on mobile.