Search Unity

Shader depth and overlay.

Discussion in 'Shaders' started by TIGGYsmalls, Apr 25, 2013.

  1. TIGGYsmalls

    TIGGYsmalls

    Joined:
    Jan 10, 2013
    Posts:
    38
    I got this Scanlines shader off this forum.

    Where it says Depth it used to say Overlay. Now I have no idea what I'm doing but the Shader was overlaying over everything in the scene so i typed depth to see if it would do anything. To my amazement it did.

    But now I have this error:

    Undefined Queue: 'Depth'
    UnityEditor.DockArea:OnGUI()

    Do I need to worry about it? How Do I make it go away.

    Code (csharp):
    1. {
    2.     Properties
    3.         {
    4.             _LinesColor("LinesColor", Color) = (0,0,0,1)
    5.             _LinesSize("LinesSize", Range(1,10)) = 1
    6.         }
    7.    SubShader {
    8.                  Tags {"IgnoreProjector" = "True" "Queue" = "Depth"}
    9.                  Fog { Mode Off }
    10.       Pass {
    11.        
    12.        
    13.         ZTest Always
    14.         ZWrite On
    15.         Blend SrcAlpha OneMinusSrcAlpha
    16.  
    17.          CGPROGRAM
    18.  
    19.          #pragma vertex vert
    20.          #pragma fragment frag
    21.          #include "UnityCG.cginc"
    22.  
    23.          fixed4 _LinesColor;
    24.          half _LinesSize;
    25.  
    26.          struct v2f
    27.          {
    28.             half4 pos:POSITION;
    29.             fixed4 sPos:TEXCOORD;
    30.          };
    31.  
    32.          v2f vert(appdata_base v)
    33.          {
    34.             v2f o;
    35.             o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    36.             o.sPos = ComputeScreenPos(o.pos);
    37.             return o;
    38.          }
    39.  
    40.          fixed4 frag(v2f i) : COLOR
    41.          {
    42.             fixed p = i.sPos.y / i.sPos.w;
    43.  
    44.             if((int)(p*_ScreenParams.y/floor(_LinesSize))%2==0)
    45.                 discard;
    46.  
    47.             return _LinesColor;
    48.          }
    49.  
    50.          ENDCG
    51.       }
    52.    }
    53. }
     
  2. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
  3. TIGGYsmalls

    TIGGYsmalls

    Joined:
    Jan 10, 2013
    Posts:
    38
    Cheers, I guess it just went to default then.
     
  4. TIGGYsmalls

    TIGGYsmalls

    Joined:
    Jan 10, 2013
    Posts:
    38
    Code (csharp):
    1. hader "Scanlines"
    2. {
    3.     Properties
    4.         {
    5.             _LinesColor("LinesColor", Color) = (0,0,0,1)
    6.             _LinesSize("LinesSize", Range(1,10)) = 1
    7.         }
    8.    SubShader {
    9.                  Tags {"IgnoreProjector" = "True" "Queue" = "Geometry"}
    10.                  Fog { Mode Off }
    11.       Pass {
    12.        
    13.        
    14.         ZTest Always
    15.         ZWrite On
    16.         Blend SrcAlpha OneMinusSrcAlpha
    17.  
    18.          CGPROGRAM
    19.  
    20.          #pragma vertex vert
    21.          #pragma fragment frag
    22.          #include "UnityCG.cginc"
    23.  
    24.          fixed4 _LinesColor;
    25.          half _LinesSize;
    26.  
    27.          struct v2f
    28.          {
    29.             half4 pos:POSITION;
    30.             fixed4 sPos:TEXCOORD;
    31.          };
    32.  
    33.          v2f vert(appdata_base v)
    34.          {
    35.             v2f o;
    36.             o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    37.             o.sPos = ComputeScreenPos(o.pos);
    38.             return o;
    39.          }
    40.  
    41.          fixed4 frag(v2f i) : COLOR
    42.          {
    43.             fixed p = i.sPos.y / i.sPos.w;
    44.  
    45.             if((int)(p*_ScreenParams.y/floor(_LinesSize))%2==0)
    46.                 discard;
    47.  
    48.             return _LinesColor;
    49.          }
    50.  
    51.          ENDCG
    52.       }
    53.    }
    54. }
    Ok, I have another issue with this shader. In Unitys Game view port the shader works fine. But when I build the game it seems to go back to Overlay mode.

    What's wrong?
     
  5. TIGGYsmalls

    TIGGYsmalls

    Joined:
    Jan 10, 2013
    Posts:
    38
    aaaaaaaaaaaany ideas?
     
  6. cician

    cician

    Joined:
    Dec 10, 2012
    Posts:
    233
    I don't know what the shader should behave like, anyway change the line
    ZTest Always
    to
    ZTest LEqual

    As it is it renders on top of everything present in the framebuffer at the time of rendering, resulting in popping randomly over other objects.
     
  7. TIGGYsmalls

    TIGGYsmalls

    Joined:
    Jan 10, 2013
    Posts:
    38
    Works fine now.

    Thank you.