Why would I want to Disable the Stencil and Depth?

In the latest version of Unity 5.5.x, there is a new option in Player Settings to disable the stencil and depth:

83589-screen-shot-2016-12-07-at-95059-am.png

I’ve tried disabling but noticed no difference in either performance or memory utilization on my iOS device. Why would a person want or need to disable?

Thanks,
Manny

3 Answers

3

Z-buffering is a way of keeping track of the depth of every pixel on the screen.

If your game does not use shaders which utilize the depth or stencil buffers, disabling them could (should) reduce the amount of workthe GPU/CPU must do and also free up a bit of memory.

Oculus recommends disabling this for Mobile VR games:
"Check the Disable Depth and Stencil checkbox in the Resolution and Presentation pane in Player Settings."*
https://developer3.oculus.com/documentation/game-engines/latest/concepts/unity-mobile-performance-intro/

After building to android this caused my app to have a number of very serious problems, including but not limited to:
-A UI text box was for some reason activated on the main scene, with text in it showing that wasn’t supposed to be there unless a condition was satisfied. That condition wasn’t satisfied at all.
-Sprites were supposed to be masked inside a specific shape. The sprites, instead, were spilling out all over the screen and ignoring the mask.

It appeared that this caused some weird problem with sorting, images, and seemingly even more than that.

I heard about this from another article. That article is, by the way, extremely informative and helpful (link below). The article was talking about some optimization that doesn’t involve “disabling it altogether.” I think that there was (or is) some way to optimize apps by doing something along the lines of “disabling it” but without actually disabling it altogether. In the past this was allowed in Unity but now you only have the option to disable it. So, it seems the powers that be have now deemed this entire thing to be not worth including in Unity anymore, and my conclusion is that the “disabling” button is just some weird, extreme option that may help you in some specific weird circumstance, and is only included still in Unity for completeness. I am in no way an expert on this topic and the article I was reading is linked here:

The article: Performance tips for Unity 2d mobile | Damian Connolly | divillysausages.com

Okay thank you Steen! Final thing before I mark it as correct; would PlayerPrefs be preferable over SQL, XML and JSON in the instance I'm talking about. If so I will mark this as correct then take some serious time learning about it before I start coding it. Thanks again :)

Only thing I know is, if you have canvas UI image and object that want to sort with UI, you might not want to disable this. With out depth and stencil buffer it will cause weird sorting result after you build an app. for example, in editor , cube is in front of UI image, after you build the app, cube is behind UI image if without depth and stencil buffer enable.

3D & UI stuff are not sorted using ZBuffer. They are using different rendering passes, that are sorted together. See Canvas & Camera's layers.

After a lot of optimization work on my app, I had a problem with my android build that was along the lines of what YHS is talking about. I had to search YHS's comment to confirm that it was "disable stencil and depth" that caused the problem. I enabled it, and built it again to android. The problem is now gone. YHS may or may not be technically correct, but the problem I had was on very similar lines to what he is saying and if he didn't say this, I'd still have the problem. Thanks YHS

dependant on your architecture you can store anything as it simply store floats and ints and strings. so it should be easy to simply convert that information to whatever you want. much like a database would. Remember to mark the question as correct, if it was, so others know this has been resolved. and , anytime, glad to help!