Search Unity

Culling Shader works in Editor, not on iOS device

Discussion in 'Shaders' started by MikaMobile, Jul 31, 2014.

  1. MikaMobile

    MikaMobile

    Joined:
    Jan 29, 2009
    Posts:
    845
    Howdy folks, I've been fooling around with an old app that's been out for a couple years (Zombieville USA 2) and I hadn't opened the project in a long time. I'm dusting some cobwebs off as I bring the project into the most recent release of Unity.

    The transition was pretty smooth except for one detail - I have an old shader I use to wrangle parts of my UI which culls everything behind it. Here's the code:

    Shader " Library/Cull All"
    {
    SubShader
    {
    Tags {"Queue" = "Background"}
    Blend SrcAlpha OneMinusSrcAlpha
    Lighting Off
    ZWrite On
    ZTest Always
    Pass
    {
    Color(0,0,0,0)
    }
    }
    }

    The expected result is that when applying this shader to an object, that object becomes invisible and causes everything behind it to also be culled. I use this to hide/reveal parts of my UI, it works in the current live version of Zombieville USA 2, and it works in the latest Unity editor as well. However, it doesn't work when built to an iOS device anymore - the result is that the object in question is simply invisible, but doesn't also cull things behind it.

    Any ideas why this stopped working in iOS builds?
     
  2. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    The reason is probably that most of those render state settings are not supposed to be placed in the SubShader block, but in the Pass block. Besides that you probably don't really need alpha blending, since you can disable color writes instead:
    Code (csharp):
    1.  
    2. Shader " Library/Cull All" {
    3. SubShader {
    4.   Tags {"Queue" = "Background"}
    5.     Pass {
    6.       Lighting Off
    7.       ZWrite On
    8.       ColorMask 0
    9.       Color(0,0,0,0)
    10.     }
    11.   }
    12. }
    13.  
     
  3. MikaMobile

    MikaMobile

    Joined:
    Jan 29, 2009
    Posts:
    845
    Apparently that was it. Not sure why it ever worked before, but it's fine now, thanks!
     
  4. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    It's probably Unity trying to help you by assigning these states to every pass that doesn't have it assigned yet. (Except after you publish.)
     
    Lulucifer likes this.