Unity 5.5, custom matrix doesn't seem to write into z buffer

So for awhile we’ve been using this method to render our first person weapons in our game: http://jetfistgames.com/blog/post/first-person-mesh-rendering-unity-54

Works like a charm, although with unity 5.5, it breaks, and looks like it doesnt test depth or anything.

How it looked before:

In 5.5

If there is a solution I would be greatful :slight_smile:

The depth in 5.5 is inverted (for DirectX 11), which I think requires flipping culling so “Cull Back” actually means “Cull Front”. You can either flip your projection matrix as well, or try setting the shader’s culling to Front for DX11. There’s not a great way of handling this purely in the shader that I know of unfortunately, maybe having two SubShaders, one with #pragma exclude_renderers dx11 and one with #pragma only_renderers dx11

Unfortunately that didn’t solve the issue, I’m 100% sure that its something to do with the z testing. I can get the exact same result if I write ZTest always in the shader, quite an annoying issue :frowning:

Oh, right, you probably also need ZTest GEqual if you’re not doing the inverse z too.

Nope it just doesn’t even render with that :frowning: confusing stuff. I’m not too familiar with this stuff and the person who wrote our original solution is now on holidays for awhile so its up to me to solve it :slight_smile:

Try going back to the original shader, but adding this to the end of the script that creates the custom projection matrix.

ret.z = 1.0 - ret.z;