Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Trouble with ZWrite

Discussion in 'Shaders' started by MikeyMyk, Nov 20, 2012.

  1. MikeyMyk

    MikeyMyk

    Joined:
    Nov 20, 2012
    Posts:
    9
    Hi,

    I'm trying to create a simple shader that draws its geometry on top of everything else. Here's where I am.

    Code (csharp):
    1.  
    2. Shader "Custom/Unlit ZtestAlways" {
    3.     Properties {
    4.         _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
    5.     }
    6.     SubShader {
    7.         Tags { "Queue"="Overlay" "IgnoreProjector"="True" "RenderType"="Transparent"}
    8.         LOD 200
    9.         ZTest Always
    10.        
    11.         CGPROGRAM
    12.         #pragma surface surf Lambert
    13.  
    14.         sampler2D _MainTex;
    15.  
    16.         struct Input {
    17.             float2 uv_MainTex;
    18.         };
    19.  
    20.         void surf (Input IN, inout SurfaceOutput o) {
    21.             half4 c = tex2D (_MainTex, IN.uv_MainTex);
    22.             o.Albedo = c.rgb;
    23.             o.Alpha = c.a;
    24.         }
    25.         ENDCG
    26.     }
    27.     FallBack "Diffuse"
    28. }
    I have it in the overlay queue, so the rest of the scene (terrain) should be rendered already, I would have though. ZTest is set to Always. The geometry using this shader still gets obscured by the landscape. Note that i've not put any Alpha blending in yet as I am just testing the ztest.

    Must be something dead obvious, does anyone have any thoughts?

    Thanks,

    /Mike
     
    Last edited: Nov 20, 2012
  2. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    Surely you want ZTest Off? Otherwise it will ZTest it and then occlude your geo by what's already in the ZBuffer?
     
  3. MikeyMyk

    MikeyMyk

    Joined:
    Nov 20, 2012
    Posts:
    9
    Hehe, yes, you are correct - I was thinking that "Always" always passed the test.

    Thanks:)
     
  4. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    That doesn't exist.

    No. Always does always pass the test.

    Your shader is not "unlit". I can't tell you why it's failing, unless the landscape is also in the overlay queue and this mesh is behind the landscape.
     
  5. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    Ah, my bad :p