Z Fighting issue only on mobile device

Hello.

In the early steps of development, I test my game (that is running quiet nicely in Editor) on my Ipad device and there starts the troubles.

It seems like there is a Z-Fighting issue on device.

Solutions I tried to fix the issue :

1 - Change all materials used to : Mobile/Unlit
2 - Verify that there is no alpha on any png texture
3 - Turn texture to 24 png (no alpha)
4 - Turn texture to tga (no alpha)
5 - Change Camera settings
→ Increase Near clipping plane up to 2 (can’t go up that without loosing some of my scene)
→ Decrease Far clipping plane down to 20 (can’t go under without loosing some of my scene)
→ Changed Rendering Path to “Forward”
→ Activated / Deactivated Occlusion Culling

I’m kinda out of idea to solve this issue. Could you help me please ?

See image joined.
Character should be hidden by trees. Same for the little green tree next to the character, it should be 100% hidden by the big dark green tree.

Your issue looks like a simple layering/z depth problem. The closer to the camera the higher the Z value. 10 being closer than 9, and so on. What is the Z value of your trees? What is the Z value of your player? The player Z value should be lower than your tree Z value. If that’s not the issue, check your layers, if you are using them. They should be on different layers.

This also depends on the direction of your camera

Hello Sickwitit,

I guess the Z value you talking about is the one used in transform.position. If it’s the case this is the hierarchy of one exemple tree :

→ Prefab Tree (Clone) = x:1 y:0 z:3
→ Child = x:0.5 y:0 z:0.5
→ tree_mesh = x:0 y:0 z:0

So the prefab instance definitly use a z position, but the true tree mesh is alway with Vector(0, 0, 0), cause it’s local position from the parent I guess. Of corse, each instance of prefab as a different position on the map. Considering layers, all trees are on one layer, and player is on is own layer.

Note that there is no issue when debuging on my computer, only zhen i run on IOS device.

What Z index is your player at?

This is a screenshot showing of positions.

Character Z is set to 46,
Tree Z is set to 43
Camera Z is set to 42

I start to understand what you try to tell me, the camera is watching in the wrong direction to get objects sorted nicely, right ?

So following your idea, I changed my camera orientation, so now objects closers to the camera have higher Z values, and objects far from camera have lower Z value.

But this does not resolve my issue, this is two screenshot, one in debug mode on my computer :
As you can see , there is no Z fighting and all textures looks good.

One on my Ipad :
Z fightings and issues on character texture display :frowning:

Any idea please ? I can’t get away from this issue :frowning:

Still stuck, tried this morning to create my own shader, in case this issues comes from the shader, without luck.

Hmm… I’ve noticed a lot of texture fighting issues when I have textures on the same layers or same Z-index. So, instead of changing the camera. Check if any textures are on the same layers or same z-index. Check all the trees. I’ve noticed that if I have (2 trees) on the same z-index, they will start fighting.

Hello Sickwitit.

I tried to separate trees and character on two different layers, no luck there.
I tried to place each single tree on a separate layer, but seems there is only 31 different layers available.

I’m desperate…

Soooo …

Here is a little progress on this issue. I managed to resolve a part of the display issue by creating my own shader. Basically, the main thing that resolved the issue is turning the queue to Transparent, wich looks against documentation as my mesh does not contains alpha, but I guess this force to consider Z-Depth. Now, there is not more Z-Depth issue from one mesh to another, as you can see trees in forest are not overlapping to each other.

But there is still some poly not displayed or with wrong normals, like eyes of the character or darkest zone in trees foliages.

If that can help anyone, this is my current shader code :

Shader "Custom/Mobile/Test"
{
    Properties
    {      
        _MainText ("Texture", 2D)    = "white" {}
    }
  
  
    SubShader
    {
        Tags {"Queue" = "Transparent"}
        ZWrite On
      
        Pass
        {
            Lighting off
            Cull back
            Offset 0,1
          
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #pragma fragmentoption ARB_precision_hint_fastest
            #pragma target 2.0
            #include "UnityCG.cginc"
          

            uniform sampler2D _MainText;
            uniform float4      _MainText_ST;
          
            struct vertexInput
            {
                float4 vertex        :    POSITION;
                float4 texcoord        :    TEXCOORD0;
            };
          
            struct fragmentInput
            {
                float4 pos            :    SV_POSITION;
                half2  uv            :    TEXTCOORD0;
            };
          
          
          
          
            fragmentInput vert (vertexInput i)
            {
                fragmentInput o;
              
                o.pos        =    mul(UNITY_MATRIX_MVP, i.vertex);
                o.uv        =    TRANSFORM_TEX(i.texcoord, _MainText);
              
                return o;
            }
          
            half4 frag (fragmentInput i):COLOR
            {
                return tex2D(_MainText, i.uv);
            }
          
            ENDCG
        }
    }
  
    FallBack "Diffuse"
}

So the Z-Index issue is fixed now? Great!

Can you provide a few more zoomed in screenshots of your other issue?

Hello Sickwitit,

Yeah, let’s say it’s “fixed” between quotations marks, because my little finger says it’s probably very bad for performances to render all objects in transparent passes.

This is some screenshots, with the expected rendering on left (the one I get on Mac) and the final rendering on the device (the one I get on Ios). basically, looks like some polys are missing on the front or are rendered in background instead of being rendered in front.

The tree :

The houses :

The character :

  • Eyes are not rendered / rendered reverse normal ?
  • Missing one poly on the hood
  • Missing the gem on torso
  • Bracers is rendered as it was transparent, we see arms inside them
    2198165--145923--character_screen.png

Thanks for any help .

Well I guess I’ll have to get real support on this one. I’ll contact unity team soon.

Ok got it fixed by creating a new project from scratch. All is working well now and I can use shaders given zith unity without any trouble. All mesh are rendered correctly. All Z-Fighting is gone.