Search Unity

(Offset Factor , Units) + shadows bring some ZFighting

Discussion in 'Shaders' started by kev42100, Feb 28, 2013.

  1. kev42100

    kev42100

    Joined:
    Apr 17, 2010
    Posts:
    61
    Hi all,

    In my scene, i've just 3 planes with the same position.
    The first one has the standard diffuse material.
    The second has the following shader :

    Code (csharp):
    1.  
    2. Shader "_Mine/ZFightPlane1"
    3. {
    4.     Properties
    5.     {
    6.         _MainTex ("Base (RGB)", 2D) = "white" {}
    7.         _Alpha ("Alpha", 2D) = "white" {}
    8.     }
    9.  
    10.     SubShader
    11.     {
    12.         Tags { "RenderType"="Opaque" }
    13.         Offset -1,-8
    14.  
    15.         Blend SrcAlpha OneMinusSrcAlpha
    16.        
    17.         CGPROGRAM
    18.         #pragma surface surf Lambert alpha
    19.  
    20.         sampler2D _MainTex;
    21.         sampler2D _Alpha;
    22.  
    23.         struct Input
    24.         {
    25.             float2 uv_MainTex;
    26.         };
    27.  
    28.         void surf (Input IN, inout SurfaceOutput o)
    29.         {
    30.             o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb;
    31.             o.Alpha = tex2D(_Alpha, IN.uv_MainTex).r;
    32.         }
    33.  
    34.         ENDCG
    35.     }
    36.    
    37. }
    38.  
    For the third plane, the shader is the same except the value of Offset :

    Code (csharp):
    1. Offset -1,-15
    I have one directional light in my scene.
    I disabled all "cast shadows" on the three planes renderer.

    When I active Hard or Soft shadows, ZFighting comes again !

    I added a cube in order to see shadows on my planes, but only the first one receive them...

    $zfighting.png

    How can we fix that ? If you can bring me some clarifications, it'll be great ;)

    Thanks in advance.
     
    Last edited: Mar 4, 2013