Culling Shader works in Editor, not on iOS device

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?

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:

Shader " Library/Cull All" {
SubShader {
  Tags {"Queue" = "Background"}
    Pass { 
      Lighting Off
      ZWrite On
      ColorMask 0
      Color(0,0,0,0)
    }
  }
}

Apparently that was it. Not sure why it ever worked before, but it’s fine now, thanks!

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.)

1 Like