Search Unity

dof behaviour with transparent material over another transparent material

Discussion in 'Image Effects' started by ghiboz, Mar 12, 2017.

  1. ghiboz

    ghiboz

    Joined:
    Sep 7, 2012
    Posts:
    465
    hi all!
    I've this issue with the dof usage:

    seems that the dof of the window is relative to the back position of the focus area.. the material is the same.. have you got any ideas?
    the shader that I use is this:
    Code (CSharp):
    1. Shader "gRally/Window"
    2. {
    3.     Properties
    4.     {
    5.         _Color("Spec Color", Color) = (1, 1, 1, 1)
    6.         _Smooth("Smoothness", Range(0,1)) = 0.5
    7.         _MainTex("Albedo", 2D) = "white" {}
    8.         _Dirty("Dirty", Range(0,5)) = 0.0
    9.     }
    10.     SubShader
    11.     {
    12.         Tags{ "Queue" = "Transparent" "IgnoreProjector" = "False" "RenderType" = "Transparent" }
    13.         LOD 300
    14.         CGPROGRAM
    15.         #pragma surface surf StandardSpecular alpha:premul vertex:vert
    16.         #pragma target 3.0
    17.         sampler2D _MainTex;
    18.         half _MainTexID;
    19.         half _Dirty;
    20.         half _Smooth;
    21.         fixed _DIRT_1_LEVEL;
    22.         fixed4 _Color;
    23.         struct Input
    24.         {
    25.             float2 uv_MainTex;
    26.             half3 normal;
    27.             float3 worldRefl;
    28.         };
    29.         void vert(inout appdata_full v, out Input o)
    30.         {
    31.             // appdata_full
    32.             UNITY_INITIALIZE_OUTPUT(Input, o);
    33.             o.normal = v.normal;
    34.         }
    35.         void surf(Input IN, inout SurfaceOutputStandardSpecular o)
    36.         {
    37.             // diffuse color
    38.             fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
    39.             o.Albedo = c.rgb;
    40.             o.Specular = _Color;
    41.             if (_Dirty == 0.0f)
    42.             {
    43.                 _Dirty = _DIRT_1_LEVEL;
    44.             }
    45.             if (c.a < 0.8f)
    46.             {
    47.                 o.Alpha = c.a * _Dirty;
    48.             }
    49.             else
    50.             {
    51.                 o.Alpha = c.a;
    52.             }
    53.             o.Smoothness = _Smooth;
    54.         }
    55.         ENDCG
    56.     }
    57. }
    58.  
     
  2. Chman

    Chman

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    721
    Transparent materials don't write to depth. Depth of field has no knowledge of them as it relies on depth-testing. In your case it's even worse has you have multiple layers of transparency (which most games avoid doing in the first place as it breaks a lot of effects, including DoF).
     
  3. ghiboz

    ghiboz

    Joined:
    Sep 7, 2012
    Posts:
    465
    thanks for your reply @Chman ... and have you got any fixes for my usage? unlike a car with some transparent windows has usually the situation where one mesh is in front of another....