DepthCompositing icon indicating copy to clipboard operation
DepthCompositing copied to clipboard

Depth compositing broken in Unity 5.5

Open 3noneTwo opened this issue 8 years ago • 3 comments

This project was unfortunately broken by Unity 5.5, and depth compositing is no longer working as intended. The background simply draws over the top of realtime objects.

It was last functioning without issue in Unity 5.4.

3noneTwo avatar Feb 13 '17 12:02 3noneTwo

ChristmasGT on the Shader Forge forums found the cause, and shared this one-line fix.

Cause: Shaders: Z-buffer float inverted

Fix: Depth_Write.shader Find Line 54: clipSpace.z = 0.5*(clipSpace.z+1.0); Change it to: clipSpace.z = 0.5*(1.0-clipSpace.z);

I've tested, and this fix works for Unity 5.5 and Unity 5.6.

3noneTwo avatar Apr 03 '17 09:04 3noneTwo

Thanks for the solution. Here is one that is more robust:

#if defined(UNITY_REVERSED_Z)
  clipSpace.z = 0.5 * (1.0 - clipSpace.z);
#else
  clipSpace.z = 0.5 * (clipSpace.z + 1.0);
#endif

ijacquez avatar Apr 29 '17 05:04 ijacquez

Is this step equal to Linear01Step?

lingllting avatar Aug 25 '17 09:08 lingllting