Search Unity

Why does this shader work on iOS devices with Metal API but not with OpenGL ?

Discussion in 'Shaders' started by PMerlaud, May 29, 2015.

  1. PMerlaud

    PMerlaud

    Joined:
    Apr 9, 2013
    Posts:
    64
    I have a simple shader I use to draw transparent highlights. It was working on any device when I was still using Unity 4.x, but since I upgraded to Unity 5.x, it doesn't work with iOS devices running OpenGL ES 2/3. It's fine though on devices running Metal.

    Code (CSharp):
    1. Shader "Lines/Colored Blended" {
    2.     SubShader {
    3.         Tags { "Queue" = "Transparent" }
    4.         Pass {
    5.             BindChannels { Bind "Color",color }  
    6.      
    7.             Blend SrcAlpha OneMinusSrcAlpha
    8.             ZWrite Off
    9.             //ZTest LEqual
    10.             Cull Off
    11.             Fog { Mode Off }
    12.        }
    13.     }
    14. }
    Do you guys have an idea ?
     
  2. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    Fixed-function shader support has been partially removed from Unity 5.
    https://unity3d.com/unity/whats-new/unity-5.0
     
  3. PMerlaud

    PMerlaud

    Joined:
    Apr 9, 2013
    Posts:
    64
    Anyone knows how I could rewrite this shader using vertex & fragment ? I have no knowledge with this. :(
     
  4. echo4papa

    echo4papa

    Joined:
    Mar 26, 2015
    Posts:
    158
    Like this:

    Code (CSharp):
    1. Shader "Custom/TransparentVertexColor" {
    2.     SubShader {
    3.         Pass {
    4.             Tags{"Queue"="Transparent"}
    5.             Blend SrcAlpha OneMinusSrcAlpha
    6.             Cull Off
    7.             ZWrite Off
    8.             CGPROGRAM
    9.             #pragma vertex vert
    10.             #pragma fragment frag
    11.  
    12.             #include "UnityCG.cginc"
    13.  
    14.             struct v2f {
    15.                 float4 pos:SV_POSITION;
    16.                 float4 color:COLOR;
    17.             };
    18.  
    19.             v2f vert(appdata_full v) {
    20.                 v2f o;
    21.                 o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
    22.                 o.color = v.color;
    23.                 return o;
    24.             }
    25.  
    26.             fixed4 frag(v2f i) : SV_Target {
    27.                
    28.                 return i.color;
    29.             }
    30.  
    31.             ENDCG
    32.         }
    33.     }
    34. }
    You need appdata_full to get your vertex color, which you need to pass from your vertex shader to your fragment shader for rendering. Also added the transparency stuff.

    This is what the old fixed function bind does.