Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Z buffer problems on Apple7GPU (while working on SGX554 and 543)

Discussion in 'Editor & General Support' started by Fuegan, Oct 9, 2014.

  1. Fuegan

    Fuegan

    Joined:
    Dec 5, 2012
    Posts:
    20
    I am currently working on a painting tool for an iOS app. It is based on transforming the usert input to a spline and then creating a mesh following that spline.

    One of the features is painting with semi-transparent colors and it works like photoshop painter, meaning the alpha blending is done only for differents draws (the generated mesh is flat).

    I'm using this shader
    Code (CSharp):
    1. Properties
    2.     {
    3.         _Color ("Main Color", Color) = (1,1,1,1)
    4.     }
    5.    
    6.     SubShader
    7.     {
    8.         Tags {"Queue"="Transparent"}
    9.         LOD 100
    10.        
    11.         Pass
    12.         {
    13.             Zwrite On
    14.             ZTest Less
    15.             Blend SrcAlpha OneMinusSrcAlpha
    16.             Lighting Off
    17.             ColorMask RGB
    18.             CGPROGRAM
    19.  
    20.             #pragma vertex vert
    21.             #pragma fragment frag
    22.            
    23.             uniform fixed4 _Color;
    24.            
    25.             struct appdata
    26.             {
    27.                 float4 vertex : POSITION;
    28.             };
    29.  
    30.             struct v2f
    31.             {
    32.                 float4 pos : POSITION;
    33.             };
    34.  
    35.             v2f vert (appdata v)
    36.             {
    37.                 v2f o;
    38.                 o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
    39.                 return o;
    40.             }
    41.  
    42.             half4 frag (v2f i) : COLOR
    43.             {
    44.                 return _Color;
    45.             }
    46.             ENDCG
    47.         }
    48.     }
    The point of this shader is to have a transparent_unlit writing in the z buffer (and displaying only if closer, not displaying if equal).

    This is an example of a generated mesh, all points are on a single plane. The mesh is not optimized but worked fine on iPad2.

    Scene_wire.png

    The color used has an oppacity of approximately 50%

    This is the wanted result (as I have on ipad 2,3,4)

    Game.png

    and this is what i have on ipad air, mini retina
    Game_artifacts.png

    I had this kind of artifacts on all devices when my camera had a farclip of 20 (near 1) but when set to 100 I have the correct results (I supposed it has to do with float precision). I tried different camera settings but the only differences are where those artifacts are on screen.


    Here are the camera settings. The object is placed 19.8m in front of the camera.
    Camera.png

    The same problems occur with forced openGLES 2.0 and 3.0.

    I found here that A7GPU uses different way to treat vectors so I guess my problem maybe has to do with it but I don't know if there is a solution.

    I'm stuck here, so if anyone knows what I did wrong or how can I make a workaround I would be glad.
    Thanks.