Search Unity

Changing depth in shader iOS not working anymore?

Discussion in 'Shaders' started by Antony-Blackett, Mar 24, 2017.

  1. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    Hi All.

    I have a shader that I use to push some object in my game forward in the depth buffer so that they appear on top of other objects near by. Here's the vert function I have.

    Code (csharp):
    1.  
    2.         FragmentInput vert ( VertexInput i )
    3.         {
    4.             FragmentInput o;
    5.             float4 worldPosition = mul ( unity_ObjectToWorld, i.vertex );
    6.             float4 cameraPos = float4(_WorldSpaceCameraPos, 1);
    7.             worldPosition = cameraPos + ((worldPosition - cameraPos) * _DepthScale);
    8.             float4 depth = mul ( UNITY_MATRIX_MVP, mul( unity_WorldToObject, worldPosition ) );
    9.             o.position = mul ( UNITY_MATRIX_MVP, i.vertex );
    10.             o.position.z = depth.z;
    11.  
    12.             o.uv = TRANSFORM_TEX( i.texcoord, _MainTex );
    13.             o.color = i.color;
    14.             return o;
    15.         }
    16.  
    This use to work fine on all platforms but since I updated to Unity 5.5.1 I've found that it has stopped working on iOS.

    Is this a bug in Unity? Can someone think of another way to get a similar effect?

    I don't want these objects to draw on top of everything, I just want to push them forward about 5-10 units in world space without their apparent size increasing.
     
  2. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778