Search Unity

Stencil Shader and iOS

Discussion in 'Shaders' started by BenouKat, Nov 27, 2015.

  1. BenouKat

    BenouKat

    Joined:
    Feb 29, 2012
    Posts:
    222
    Hi !

    Since a the new UI we use Stencil Shader to display 3D elements in UI or 2D arrays.

    I always used this shader :

    Code (CSharp):
    1. Shader "Stencils/Diffuse" {
    2.     Properties {
    3.         _StencilId ("Stencil ID", Float) = 0
    4.         _MainTex ("Base (RGB)", 2D) = "white" {}
    5.         _Color ("Main Color", COLOR) = (0.58,0.58,0.58,1)
    6.     }
    7.     SubShader {
    8.         Stencil {
    9.             Ref [_StencilId]
    10.             Comp equal
    11.             Pass keep
    12.             Fail keep
    13.         }
    14.  
    15.         Tags { "RenderType"="Opaque" "Queue"="Transparent+100"}
    16.         LOD 200
    17.         Cull Off
    18.    
    19.         CGPROGRAM
    20.         #pragma surface surf Lambert
    21.  
    22.         sampler2D _MainTex;
    23.         float4 _Color;
    24.    
    25.         struct Input {
    26.             float2 uv_MainTex;
    27.             float4 color : COLOR;
    28.         };
    29.  
    30.         void surf (Input IN, inout SurfaceOutput o) {
    31.             half4 c = tex2D (_MainTex, IN.uv_MainTex);
    32.             o.Albedo = c.rgb * _Color.rgb;
    33.             o.Alpha = c.a;
    34.         }
    35.         ENDCG
    36.     }
    37.     FallBack "Diffuse"
    38. }
    But now on iOS (iPad Air) it renders black since I use Asset Bundle. I know Asset Bundle have issue with custom shaders, you need to add them in the built-in shader, but the shader is added.

    And more strange : My asset have two parts, both with this shader : one is rendered correctly, the other is black. To be more precise, it's a boat : The boat is correctly renderer, the sails is not (it's just a plane, one sided)

    When I debug the material, the shader is here, the color is here, the texture is here, it's just not rendered.

    I know that some custom shader doesn't work with iOS metal, usually I use shader force and check "iOS metal compatible", but I can't open this one on shader forge so i'm lost... :D

    Anyone have an idea ?

    [Unity 5.2.2p3]